-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from open-formulieren/refactor/454-nlds-based…
…-editgrid Use NL DS components (where possible) for edit grid component
- Loading branch information
Showing
20 changed files
with
430 additions
and
135 deletions.
There are no files selected for viewing
Submodule design-tokens
updated
3 files
+2 −2 | package-lock.json | |
+1 −1 | package.json | |
+1 −1 | src/components/editgrid.tokens.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {ButtonGroup} from '@utrecht/component-library-react'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import {OFButton} from 'components/Button'; | ||
import FAIcon from 'components/FAIcon'; | ||
|
||
const DefaultAddButtonLabel = () => ( | ||
<> | ||
<FAIcon icon="plus" />{' '} | ||
<FormattedMessage | ||
description="Edit grid add button, default label text" | ||
defaultMessage="Add another" | ||
/> | ||
</> | ||
); | ||
|
||
const EditGrid = ({children, onAddItem, addButtonLabel}) => ( | ||
<div className="openforms-editgrid"> | ||
<div>{children}</div> | ||
|
||
{onAddItem && ( | ||
<ButtonGroup> | ||
<OFButton type="button" appearance="primary-action-button" onClick={onAddItem}> | ||
{addButtonLabel || <DefaultAddButtonLabel />} | ||
</OFButton> | ||
</ButtonGroup> | ||
)} | ||
</div> | ||
); | ||
|
||
EditGrid.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
addButtonLabel: PropTypes.node, | ||
onAddItem: PropTypes.func, | ||
}; | ||
|
||
export default EditGrid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Body from 'components/Body'; | ||
import {OFButton} from 'components/Button'; | ||
|
||
import {EditGrid, EditGridButtonGroup, EditGridItem} from '.'; | ||
|
||
export default { | ||
title: 'Pure React components / EditGrid / EditGrid', | ||
component: EditGrid, | ||
argTypes: { | ||
children: {control: false}, | ||
onAddItem: {control: false}, | ||
}, | ||
args: { | ||
children: ( | ||
<> | ||
<EditGridItem | ||
heading="Item 1" | ||
buttons={ | ||
<EditGridButtonGroup> | ||
<OFButton appearance="primary-action-button">A button</OFButton> | ||
</EditGridButtonGroup> | ||
} | ||
> | ||
<Body>First item</Body> | ||
</EditGridItem> | ||
<EditGridItem | ||
heading="Item 2" | ||
buttons={ | ||
<EditGridButtonGroup> | ||
<OFButton appearance="primary-action-button">A button</OFButton> | ||
</EditGridButtonGroup> | ||
} | ||
> | ||
<Body>Second item</Body> | ||
</EditGridItem> | ||
</> | ||
), | ||
}, | ||
parameters: { | ||
controls: {sort: 'requiredFirst'}, | ||
}, | ||
}; | ||
|
||
export const WithAddButton = {}; | ||
|
||
export const WithCustomAddButtonLabel = { | ||
args: { | ||
addButtonLabel: 'Custom add button label', | ||
}, | ||
}; | ||
|
||
export const WithoutAddbutton = { | ||
args: { | ||
onAddItem: undefined, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {ButtonGroup} from '@utrecht/component-library-react'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
const EditGridButtonGroup = ({children}) => ( | ||
<ButtonGroup className="utrecht-button-group--openforms-editgrid">{children}</ButtonGroup> | ||
); | ||
|
||
EditGridButtonGroup.propTypes = { | ||
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired, | ||
}; | ||
|
||
export default EditGridButtonGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Fieldset, FieldsetLegend} from '@utrecht/component-library-react'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
const EditGridItem = ({heading, children: body, buttons}) => { | ||
return ( | ||
<Fieldset className="openforms-editgrid__item"> | ||
<FieldsetLegend className="openforms-editgrid__item-heading">{heading}</FieldsetLegend> | ||
{body} | ||
{buttons} | ||
</Fieldset> | ||
); | ||
}; | ||
|
||
EditGridItem.propTypes = { | ||
heading: PropTypes.node.isRequired, | ||
children: PropTypes.node, | ||
buttons: PropTypes.node, | ||
}; | ||
|
||
export default EditGridItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Body from 'components/Body'; | ||
import {OFButton} from 'components/Button'; | ||
|
||
import {EditGridButtonGroup, EditGridItem as EditGridItemComponent} from '.'; | ||
|
||
export default { | ||
title: 'Pure React components / EditGrid / Item', | ||
component: EditGridItemComponent, | ||
argTypes: { | ||
children: {control: false}, | ||
buttons: {control: false}, | ||
}, | ||
args: { | ||
heading: 'Item heading', | ||
children: <Body>Item body, typically form fields</Body>, | ||
buttons: ( | ||
<EditGridButtonGroup> | ||
<OFButton appearance="primary-action-button">Save</OFButton> | ||
<OFButton appearance="primary-action-button" hint="danger"> | ||
Remove | ||
</OFButton> | ||
</EditGridButtonGroup> | ||
), | ||
}, | ||
parameters: { | ||
controls: {sort: 'requiredFirst'}, | ||
}, | ||
}; | ||
|
||
export const Item = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import ofTokens from '@open-formulieren/design-tokens/dist/tokens'; | ||
import {Meta} from '@storybook/addon-docs'; | ||
import utrechtTokens from '@utrecht/design-tokens/dist/tokens'; | ||
import TokensTable from 'design-token-editor/lib/esm/TokensTable'; | ||
|
||
<Meta title="Pure React components / EditGrid" name="Design tokens" /> | ||
|
||
## Available design tokens | ||
|
||
**Open Forms specific tokens** | ||
|
||
<TokensTable container={ofTokens} limitTo="of.editgrid" autoExpand /> | ||
|
||
**Utrecht tokens** | ||
|
||
Under the hood, the following components & tokens are used & can be leveraged to change the | ||
appearance of the editgrid component. | ||
|
||
- `utrecht.button-group` | ||
- `utrecht.form-fieldset` | ||
|
||
## Updating your theme | ||
|
||
Before SDK 1.6, the CSS for edit grid was hardcoded. With 1.6, this is now parametrized, but there | ||
are no backwards compatible defaults set. To recover the original styles, use the following tokens: | ||
|
||
```json | ||
{ | ||
"of": { | ||
"editgrid": { | ||
"line-height": {"value": 1.5}, | ||
"gap": {"value": "12px"}, | ||
|
||
"item": { | ||
"gap": {"value": "12px"}, | ||
"border": {"value": "solid 1px {of.color.border}"}, | ||
"padding-block-end": {"value": "24px"}, | ||
"padding-block-start": {"value": "24px"}, | ||
"padding-inline-end": {"value": "24px"}, | ||
"padding-inline-start": {"value": "24px"} | ||
}, | ||
|
||
"item-heading": { | ||
"font-family": {"value": "{of.typography.sans-serif.font-family}"}, | ||
"font-size": {"value": "0.875rem"}, | ||
"line-height": {"value": "1.2"}, | ||
"margin-block-end": {"value": "24px"} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
or in CSS: | ||
|
||
```css | ||
.your-theme { | ||
--of-editgrid-item-border: solid 1px var(--of-color-border); | ||
--of-editgrid-item-gap: 12px; | ||
--of-editgrid-item-padding-block-end: 24px; | ||
--of-editgrid-item-padding-block-start: 24px; | ||
--of-editgrid-item-padding-inline-start: 24px; | ||
--of-editgrid-item-padding-inline-end: 24px; | ||
|
||
--of-editgrid-item-heading-font-family: var(--of-typography-sans-serif-font-family); | ||
--of-editgrid-item-heading-font-size: 0.875rem; | ||
--of-editgrid-item-heading-line-height: 1.2; | ||
--of-editgrid-item-heading-margin-block-end: 24px; | ||
|
||
--of-editgrid-line-height: 1.5; | ||
--of-editgrid-gap: 12p; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export {default as EditGridButtonGroup} from './EditGridButtonGroup'; | ||
export {default as EditGridItem} from './EditGridItem'; | ||
export {default as EditGrid} from './EditGrid'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.