diff --git a/packages/fuselage/src/components/Table/Table.stories.tsx b/packages/fuselage/src/components/Table/Table.stories.tsx index 9e57ab14d6..9d4ebcf116 100644 --- a/packages/fuselage/src/components/Table/Table.stories.tsx +++ b/packages/fuselage/src/components/Table/Table.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryFn } from '@storybook/react'; +import { useState } from 'react'; import { CheckBox } from '../CheckBox'; @@ -63,93 +64,146 @@ export const Default: StoryFn = () => ( ); -export const WithSelection: StoryFn = () => ( - <> - - - - - - - Dessert (100g serving) - Calories - Fat (g) - Carbs (g) - Protein (g) - - - - - - - - - Frozen yoghurt - - 159 - 6 - 24 - 4 - - - - - - - Frozen yoghurt - - 159 - 6 - 24 - 4 - - - - - - - Frozen yoghurt - - 159 - 6 - 24 - 4 - - - - - - - Frozen yoghurt - - 159 - 6 - 24 - 4 - - - - - - - Frozen yoghurt - - 159 - 6 - 24 - 4 - - -
- - - Delete - Cancel - - - -); +export const WithSelection: StoryFn = () => { + const [checkedAll, setCheckedAll] = useState(false); + const [checkedItems, setCheckedItems] = useState>({ + item1: false, + item2: false, + item3: false, + item4: false, + item5: false, + }); + + const handleCheckBoxChange = (item: string) => { + setCheckedItems((prevState) => ({ + ...prevState, + [item]: !prevState[item], + })); + }; + + const handleAllCheckBoxChange = () => { + const newCheckedAll = !checkedAll; + setCheckedAll(newCheckedAll); + setCheckedItems({ + item1: newCheckedAll, + item2: newCheckedAll, + item3: newCheckedAll, + item4: newCheckedAll, + item5: newCheckedAll, + }); + }; + return ( + <> + + + + + + + Dessert (100g serving) + Calories + Fat (g) + Carbs (g) + Protein (g) + + + + + + handleCheckBoxChange('item1')} + /> + + + Frozen yoghurt + + 159 + 6 + 24 + 4 + + + + handleCheckBoxChange('item2')} + /> + + + Frozen yoghurt + + 159 + 6 + 24 + 4 + + + + handleCheckBoxChange('item3')} + /> + + + Frozen yoghurt + + 159 + 6 + 24 + 4 + + + + handleCheckBoxChange('item4')} + /> + + + Frozen yoghurt + + 159 + 6 + 24 + 4 + + + + handleCheckBoxChange('item5')} + /> + + + Frozen yoghurt + + 159 + 6 + 24 + 4 + + +
+ + + Delete + Cancel + + + + ); +}; export const Striped: StoryFn = () => (