diff --git a/packages/react-core/src/components/SimpleList/examples/SimpleList.md b/packages/react-core/src/components/SimpleList/examples/SimpleList.md index 8f38100ca8e..d1e5eb43817 100644 --- a/packages/react-core/src/components/SimpleList/examples/SimpleList.md +++ b/packages/react-core/src/components/SimpleList/examples/SimpleList.md @@ -9,120 +9,16 @@ propComponents: ['SimpleList', 'SimpleListGroup', 'SimpleListItem'] ### Simple list -```js -import React from 'react'; -import { SimpleList, SimpleListItem } from '@patternfly/react-core'; - -class SimpleListDemo extends React.Component { - onSelect(selectedItem, selectedItemProps) { - console.log('new selection SimpleListDemo', selectedItem, selectedItemProps); - } - - render() { - const items = [ - - List item 1 - , - - List item 2 - , - List item 3 - ]; - - return ( - - {items} - - ); - } -} +```ts file="SimpleListBasic.tsx" ``` ### Grouped list -```js -import React from 'react'; -import { SimpleList, SimpleListItem, SimpleListGroup } from '@patternfly/react-core'; - -class SimpleListGroupDemo extends React.Component { - onSelect(selectedItem, selectedItemProps) { - console.log('new selection SimpleListGroupDemo', selectedItem, selectedItemProps); - } - - render() { - const group1Items = [ - - List item 1 - , - - List item 2 - , - List item 3, - List item 4 - ]; - - const group2Items = [ - List item 1, - - List item 2 - , - - List item 3 - , - List item 4 - ]; - - return ( - - - {group1Items} - - - {group2Items} - - - ); - } -} +```ts file="SimpleListGrouped.tsx" ``` ### Uncontrolled simple list -```js -import React from 'react'; -import { SimpleList, SimpleListItem } from '@patternfly/react-core'; - -class SimpleListUncontrolledDemo extends React.Component { - constructor(props) { - super(props); - this.state = { - activeItem: 0 - }; - this.onSelect = (selectedItem, selectedItemProps) => { - console.log('new selection SimpleListUncontrolledDemo', selectedItem, selectedItemProps); - this.setState({ activeItem: selectedItemProps.itemId }); - }; - } - - render() { - const { activeItem } = this.state; - const items = [ - - List item 1 - , - - List item 2 - , - - List item 3 - - ]; - - return ( - - {items} - - ); - } -} +```ts file="SimpleListUncontrolled.tsx" ``` + diff --git a/packages/react-core/src/components/SimpleList/examples/SimpleListBasic.tsx b/packages/react-core/src/components/SimpleList/examples/SimpleListBasic.tsx new file mode 100644 index 00000000000..130782a6d5d --- /dev/null +++ b/packages/react-core/src/components/SimpleList/examples/SimpleListBasic.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { SimpleList, SimpleListItem } from '@patternfly/react-core'; + +export const SimpleListBasic: React.FunctionComponent = () => { + const items = [ + + List item 1 + , + + List item 2 + , + List item 3 + ]; + + return {items}; +}; diff --git a/packages/react-core/src/components/SimpleList/examples/SimpleListGrouped.tsx b/packages/react-core/src/components/SimpleList/examples/SimpleListGrouped.tsx new file mode 100644 index 00000000000..25e5f35d594 --- /dev/null +++ b/packages/react-core/src/components/SimpleList/examples/SimpleListGrouped.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { SimpleList, SimpleListItem, SimpleListGroup } from '@patternfly/react-core'; + +export const SimpleListGrouped: React.FunctionComponent = () => { + const group1Items = [ + + List item 1 + , + List item 2, + List item 3, + List item 4 + ]; + + const group2Items = [ + List item 1, + + List item 2 + , + + List item 3 + , + List item 4 + ]; + + return ( + + + {group1Items} + + + {group2Items} + + + ); +}; diff --git a/packages/react-core/src/components/SimpleList/examples/SimpleListUncontrolled.tsx b/packages/react-core/src/components/SimpleList/examples/SimpleListUncontrolled.tsx new file mode 100644 index 00000000000..63ed0cc6dac --- /dev/null +++ b/packages/react-core/src/components/SimpleList/examples/SimpleListUncontrolled.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { SimpleList, SimpleListItem, SimpleListItemProps } from '@patternfly/react-core'; + +export const SimpleListUncontrolled: React.FunctionComponent = () => { + const [activeItem, setActiveItem] = React.useState(0); + + const onSelect = ( + selectedItem: React.RefObject | React.RefObject, + selectedItemProps: SimpleListItemProps + ) => { + setActiveItem(selectedItemProps.itemId as number); + }; + + const items = [ + + List item 1 + , + + List item 2 + , + + List item 3 + + ]; + + return ( + + {items} + + ); +};