Skip to content

Commit

Permalink
🚧 [#462] Replace usage of OF Button component with Utrecht button com…
Browse files Browse the repository at this point in the history
…ponents
  • Loading branch information
SilviaAmAm committed Oct 23, 2023
1 parent 156ebad commit 0e2f956
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 38 deletions.
27 changes: 20 additions & 7 deletions src/components/ButtonsToolbar/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {
Button as UtrechtButton,
LinkButton as UtrechtLinkButton,
} from '@utrecht/component-library-react';
import PropTypes from 'prop-types';
import React from 'react';

import Button from 'components/Button';
import {Literal, LiteralsProvider} from 'components/Literal';
import Loader from 'components/Loader';
import LogoutButton from 'components/LogoutButton';
Expand All @@ -28,27 +31,37 @@ const ButtonsToolbar = ({
<Toolbar modifiers={['mobile-reverse-order', 'bottom']}>
<ToolbarList>
{onNavigatePrevPage && (
<Button variant="anchor" onClick={onNavigatePrevPage}>
<UtrechtLinkButton onClick={onNavigatePrevPage} appearance="subtle-button">
<Literal name="previousText" />
</Button>
</UtrechtLinkButton>
)}
</ToolbarList>
<ToolbarList>
{/* TODO: refactor: `const canSuspendForm = onFormSave === undefined` - this does not
need to be its own prop */}
{canSuspendForm && (
<Button type="button" variant="secondary" name="save" onClick={onFormSave}>
<UtrechtButton
type="button"
appearance="secondary-action-button"
name="save"
onClick={onFormSave}
>
<Literal name="saveText" />
</Button>
</UtrechtButton>
)}
{showSubmitButton && (
<Button type="submit" variant="primary" name="next" disabled={!canSubmitStep}>
<UtrechtButton
type="submit"
appearance="primary-action-button"
name="next"
disabled={!canSubmitStep}
>
{isCheckingLogic ? (
<Loader modifiers={['centered', 'only-child', 'small']} />
) : (
<Literal name="nextText" />
)}
</Button>
</UtrechtButton>
)}
</ToolbarList>
</Toolbar>
Expand Down
10 changes: 3 additions & 7 deletions src/components/LanguageSelection/LanguageSelectionDisplay.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {ButtonGroup, Heading} from '@utrecht/component-library-react';
import {ButtonGroup, Heading, LinkButton} from '@utrecht/component-library-react';
import PropTypes from 'prop-types';
import {Fragment} from 'react';

import Button from 'components/Button';

const Spacer = () => <span aria-hidden="true">{'|'}</span>;

const LanguageSelectionDisplay = ({heading, headingLevel, headingId, items, onLanguageChange}) => (
Expand All @@ -14,17 +12,15 @@ const LanguageSelectionDisplay = ({heading, headingLevel, headingId, items, onLa
<ButtonGroup>
{items.map(({current, label, lang, textContent}, i, a) => (
<Fragment key={lang}>
<Button
variant="anchor"
component="button"
<LinkButton
pressed={current}
lang={lang}
aria-label={label}
onClick={() => onLanguageChange(lang)}
inline
>
{textContent}
</Button>
</LinkButton>
{i + 1 < a.length ? <Spacer /> : null}
</Fragment>
))}
Expand Down
13 changes: 8 additions & 5 deletions src/components/LoginButton/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
Button as UtrechtButton,
ButtonLink as UtrechtButtonLink,
} from '@utrecht/component-library-react';
import React from 'react';

import Button from 'components/Button';
import FormattedLoginOption from 'types/FormattedLoginOption';
import {getBEMClassName} from 'utils';

Expand All @@ -9,19 +12,19 @@ import LoginButtonIcon from './LoginButtonIcon';
const LoginButton = ({option, ...extra}) => {
let url = option.url;
let extraProps = {...extra};
let component = 'a';
let ButtonComponent = UtrechtButtonLink;

if (!url) {
url = '#';
extraProps = {...extraProps, type: 'submit'};
component = 'button';
ButtonComponent = UtrechtButton;
}

return (
<div className={getBEMClassName('login-button')}>
<Button variant="primary" component={component} href={url} {...extraProps}>
<ButtonComponent href={url} appearance="primary-action-button" {...extraProps}>
{option.label}
</Button>
</ButtonComponent>
<LoginButtonIcon identifier={option.identifier} logo={option.logo} />
</div>
);
Expand Down
15 changes: 9 additions & 6 deletions src/components/SummaryConfirmation/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
Button as UtrechtButton,
LinkButton as UtrechtLinkButton,
} from '@utrecht/component-library-react';
import {useFormikContext} from 'formik';
import PropTypes from 'prop-types';
import React, {useState} from 'react';

import Button from 'components/Button';
import {Literal} from 'components/Literal';
import StatementCheckboxes from 'components/StatementCheckboxes';
import {Toolbar, ToolbarList} from 'components/Toolbar';
Expand Down Expand Up @@ -36,22 +39,22 @@ const SummaryConfirmation = ({submissionAllowed, onPrevPage}) => {
<Toolbar modifiers={['mobile-reverse-order', 'bottom']}>
<ToolbarList>
{!!onPrevPage && (
<Button variant="anchor" component="a" onClick={onPrevPage}>
<UtrechtLinkButton onClick={onPrevPage} appearance="subtle-button">
<Literal name="previousText" />
</Button>
</UtrechtLinkButton>
)}
</ToolbarList>
<ToolbarList>
{canSubmit ? (
<Button
<UtrechtButton
type="submit"
variant="primary"
appearance="primary-action-button"
name="confirm"
disabled={submitDisabled}
onDisabledClick={() => setShowStatementWarnings(true)}
>
<Literal name="confirmText" />
</Button>
</UtrechtButton>
) : null}
</ToolbarList>
</Toolbar>
Expand Down
6 changes: 1 addition & 5 deletions src/formio/components/Button.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import {Formio} from 'react-formio';

import {applyPrefix} from '../utils';

/**
* Extend the default button field to modify it to our needs.
*/
class Button extends Formio.Components.components.button {
get inputInfo() {
const info = super.inputInfo;
// change the default CSS classes
info.attr.class = [applyPrefix('button'), 'utrecht-button', 'utrecht-button--html-button'].join(
' '
);
info.attr.class = ['utrecht-button'].join(' ');
return info;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/formio/templates/editGrid.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<div class="{{ctx.ofPrefix}}editgrid__group-actions {{ctx.ofPrefix}}toolbar {{ctx.ofPrefix}}toolbar--reverse">
<ul class="{{ctx.ofPrefix}}toolbar__list">
<li class="{{ctx.ofPrefix}}toolbar__list-item">
<button class="{{ctx.ofPrefix}}button {{ctx.ofPrefix}}button--primary utrecht-button utrecht-button--html-button utrecht-button--primary-action" ref="{{ctx.ref.saveRow}}">{{ctx.t(ctx.component.saveRow || 'Save', { _userInput: true })}}</button>
<button class="utrecht-button utrecht-button--primary-action" ref="{{ctx.ref.saveRow}}">{{ctx.t(ctx.component.saveRow || 'Save', { _userInput: true })}}</button>
</li>
{% if (ctx.component.removeRow) { %}
<li class="{{ctx.ofPrefix}}toolbar__list-item">
<button class="{{ctx.ofPrefix}}button {{ctx.ofPrefix}}button--danger utrecht-button utrecht-button--html-button utrecht-button--secondary-action utrecht-button--danger" ref="{{ctx.ref.cancelRow}}">{{ctx.t(ctx.component.removeRow || 'Cancel', { _userInput: true })}}</button>
<button class="utrecht-button utrecht-button--secondary-action utrecht-button--danger" ref="{{ctx.ref.cancelRow}}">{{ctx.t(ctx.component.removeRow || 'Cancel', { _userInput: true })}}</button>
</li>
{% } %}
</ul>
Expand All @@ -34,7 +34,7 @@

{% if (!ctx.readOnly && ctx.hasAddButton) { %}
<div class="{{ctx.ofPrefix}}editgrid__add-button">
<button class="{{ctx.ofPrefix}}button {{ctx.ofPrefix}}button--primary utrecht-button utrecht-button--html-button utrecht-button--primary-action" ref="{{ctx.ref.addRow}}">
<button class="utrecht-button utrecht-button--primary-action" ref="{{ctx.ref.addRow}}">
<i class="{{ctx.iconClass('plus')}}"></i> {{ctx.t(ctx.component.addAnother || 'Add Another', { _userInput: true })}}
</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/formio/templates/editGridRow.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<div class="{{ctx.ofPrefix}}toolbar {{ctx.ofPrefix}}toolbar--reverse">
<ul class="{{ctx.ofPrefix}}toolbar__list">
<li class="{{ctx.ofPrefix}}toolbar__list-item">
<button class="{{ctx.ofPrefix}}button editRow"><i class="{{ ctx.iconClass('edit') }}"></i></button>
<button class="utrecht-button editRow"><i class="{{ ctx.iconClass('edit') }}"></i></button>
</li>
<li class="{{ctx.ofPrefix}}toolbar__list-item">
<button class="{{ctx.ofPrefix}}button {{ctx.ofPrefix}}button--danger removeRow"><i class="{{ ctx.iconClass('trash-can') }}"></i></button>
<button class="utrecht-button utrecht-button--secondary-action utrecht-button--danger removeRow"><i class="{{ ctx.iconClass('trash-can') }}"></i></button>
</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/formio/templates/file.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="row">
{% if (!ctx.disabled) { %}
<div class="col-md-1">
<button type="button" class="{{ctx.ofPrefix}}button {{ctx.ofPrefix}}button--icon-only {{ctx.ofPrefix}}button--danger" ref="removeLink" title="{{ctx.t('Remove')}}">
<button type="button" class="utrecht-button utrecht-button--subtle utrecht-button--danger" ref="removeLink" title="{{ctx.t('Remove')}}">
<i class="{{ctx.iconClass('trash-can')}}"></i>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/formio/templates/multiValueRow.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</td>
{% if (!ctx.disabled) { %}
<td class="{{ctx.ofPrefix}}multi-value-row__remove">
<button type="button" class="{{ctx.ofPrefix}}button {{ctx.ofPrefix}}button--icon-only {{ctx.ofPrefix}}button--danger" title="{{ctx.t('Remove')}}" ref="removeRow">
<button type="button" class="utrecht-button utrecht-button--subtle utrecht-button--danger" title="{{ctx.t('Remove')}}" ref="removeRow">
<i class="{{ctx.iconClass('trash-can')}}"></i>
</button>
</td>
Expand Down
2 changes: 1 addition & 1 deletion src/formio/templates/multiValueTable.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% if (!ctx.disabled) {%}
<tr>
<td colspan="2">
<button class="{{ctx.ofPrefix}}button {{ctx.ofPrefix}}button--primary utrecht-button utrecht-button--html-button utrecht-button--primary-action" ref="addButton">
<button class="utrecht-button utrecht-button--primary-action" ref="addButton">
<i class="{{ctx.iconClass('plus')}}"></i>
<div class="{{ctx.ofPrefix}}multi-value-table__button-label">{{ctx.t(ctx.addAnother, {_userInput: true})}}</div>
</button>
Expand Down

0 comments on commit 0e2f956

Please sign in to comment.