diff --git a/packages/react-core/src/components/Chip/examples/Chip.md b/packages/react-core/src/components/Chip/examples/Chip.md index aae5468e6d4..c740435a418 100644 --- a/packages/react-core/src/components/Chip/examples/Chip.md +++ b/packages/react-core/src/components/Chip/examples/Chip.md @@ -10,77 +10,5 @@ ouia: true ### Default -```js -import React from 'react'; -import { Badge, Chip } from '@patternfly/react-core'; - -class SingleChip extends React.Component { - constructor(props) { - super(props); - this.state = { - chip: { - name: 'Chip 1' - }, - longchip: { - name: 'Really long chip that goes on and on' - }, - badgechip: { - name: 'Chip', - isRead: true, - count: 7 - }, - readonlychip: { - name: 'Read-only chip' - }, - overflowchip: { - name: 'Overflow chip' - } - }; - this.deleteItem = id => { - this.setState({ [id]: null }); - }; - } - - render() { - const { chip, longchip, badgechip, readonlychip, overflowchip } = this.state; - return ( - - {chip && ( - - this.deleteItem('chip')}> - {chip.name} - -

-
- )} - {longchip && ( - - this.deleteItem('longchip')}> - {longchip.name} - -

-
- )} - {badgechip && ( - - this.deleteItem('badgechip')}> - {badgechip.name} - {badgechip.count} - -

-
- )} - this.deleteItem('readonlychip')} isReadOnly> - {readonlychip.name} - -

- {overflowchip && ( - this.deleteItem('overflowchip')} isOverflowChip> - {overflowchip.name} - - )} -
- ); - } -} +```ts file='./ChipDefault.tsx' ``` diff --git a/packages/react-core/src/components/Chip/examples/ChipDefault.tsx b/packages/react-core/src/components/Chip/examples/ChipDefault.tsx new file mode 100644 index 00000000000..5411b30e91f --- /dev/null +++ b/packages/react-core/src/components/Chip/examples/ChipDefault.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import { Badge, Chip } from '@patternfly/react-core'; + +export const ChipDefault: React.FunctionComponent = () => { + const [chips, setChips] = React.useState({ + chip: { + name: 'Chip 1' + }, + longchip: { + name: 'Really long chip that goes on and on' + }, + badgechip: { + name: 'Chip', + isRead: true, + count: 7 + }, + readonlychip: { + name: 'Read-only chip' + }, + overflowchip: { + name: 'Overflow chip' + } + }); + + const deleteItem = (id: string) => { + setChips({ ...chips, [id]: null }); + }; + + const { chip, longchip, badgechip, readonlychip, overflowchip } = chips; + return ( + + {chip && ( + + deleteItem('chip')}> + {chip.name} + +

+
+ )} + {longchip && ( + + deleteItem('longchip')}> + {longchip.name} + +

+
+ )} + {badgechip && ( + + deleteItem('badgechip')}> + {badgechip.name} + {badgechip.count} + +

+
+ )} + deleteItem('readonlychip')} isReadOnly> + {readonlychip.name} + +

+ {overflowchip && ( + deleteItem('overflowchip')} isOverflowChip> + {overflowchip.name} + + )} +
+ ); +};