diff --git a/modules/preview-react/table/stories/Table.stories.mdx b/modules/preview-react/table/stories/Table.stories.mdx index 68ae97f9d4..0f4a8ee229 100644 --- a/modules/preview-react/table/stories/Table.stories.mdx +++ b/modules/preview-react/table/stories/Table.stories.mdx @@ -47,6 +47,10 @@ Users may add styles to the `Table.Header` to render a fixed column. The example +### Selectable Rows + + + ## Component API diff --git a/modules/preview-react/table/stories/examples/SelectableRows.tsx b/modules/preview-react/table/stories/examples/SelectableRows.tsx new file mode 100644 index 0000000000..f3c1bf436b --- /dev/null +++ b/modules/preview-react/table/stories/examples/SelectableRows.tsx @@ -0,0 +1,74 @@ +import React from 'react'; + +import {Table} from '@workday/canvas-kit-preview-react/table'; +import {Heading} from '@workday/canvas-kit-react/text'; +import {Checkbox} from '@workday/canvas-kit-react/checkbox'; +import {styled, useUniqueId} from '@workday/canvas-kit-react/common'; +import {Tooltip} from '@workday/canvas-kit-react/tooltip'; +import {colors} from '@workday/canvas-kit-react/tokens'; + +const pizzaToppingData = [ + {topping: 'Pepperoni', amount: '2.5 oz.'}, + {topping: 'Mozzarella', amount: '5 oz.'}, + {topping: 'Basil', amount: '10 Leaves'}, + {topping: 'Roasted Red Peppers', amount: '3 oz.'}, + {topping: 'Mushrooms', amount: '2 oz.'}, +]; + +const StyledCell = styled(Table.Cell)({ + backgroundColor: 'transparent', +}); + +const CustomRow = props => { + const [isSelected, setIsSelected] = React.useState(props.selected); + const selectRowHandler = e => { + setIsSelected(e.target.checked); + }; + + return ( + + + + + + + {props.rowData.topping} + {props.rowData.amount} + + ); +}; + +export const SelectableRows = () => { + const headingID = useUniqueId(); + const [selectAll, setSelectAll] = React.useState(false); + const selectAllHandler = e => { + setSelectAll(e.target.checked); + }; + + return ( + <> + + Pizza Toppings + + + + + + + + + + Toppings + + + Amount + + + + {pizzaToppingData.map(i => ( + + ))} +
+ + ); +};