-
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.
♻️ [#454] Refactor React editgrid into isolated component
* Updated the ChooseProductStep from appointments to use the component * Add stories for with/without add button * Centralized the markup/class names for edit grid so we can refactor more to NL DS components
- Loading branch information
1 parent
0dd09ae
commit 838431e
Showing
8 changed files
with
132 additions
and
33 deletions.
There are no files selected for viewing
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 PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import OFButton from 'components/Button'; | ||
import FAIcon from 'components/FAIcon'; | ||
import {getBEMClassName} from 'utils'; | ||
|
||
const DefaultAddButtonLabel = () => ( | ||
<> | ||
<FAIcon icon="plus" />{' '} | ||
<FormattedMessage | ||
description="Edit grid add button, default label text" | ||
defaultMessage="Add another" | ||
/> | ||
</> | ||
); | ||
|
||
const EditGrid = ({children, onAddItem, addButtonLabel}) => ( | ||
<div className={getBEMClassName('editgrid')}> | ||
<div className={getBEMClassName('editgrid__groups')}>{children}</div> | ||
|
||
{onAddItem && ( | ||
<div className={getBEMClassName('editgrid__add-button')}> | ||
<OFButton type="button" appearance="primary-action-button" onClick={onAddItem}> | ||
{addButtonLabel || <DefaultAddButtonLabel />} | ||
</OFButton> | ||
</div> | ||
)} | ||
</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,41 @@ | ||
import Body from 'components/Body'; | ||
|
||
import {EditGrid, 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"> | ||
<Body>First item</Body> | ||
</EditGridItem> | ||
<EditGridItem heading="Item 2"> | ||
<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 |
---|---|---|
@@ -1,2 +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
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
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