From 62c186edec879b6bfd279d975d8f68d61feae612 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 16 Oct 2024 20:05:06 +0530 Subject: [PATCH 1/2] fixed the issue of unable to select and unselect the items --- .../src/components/Table/Table.stories.tsx | 202 ++++++++++-------- 1 file changed, 116 insertions(+), 86 deletions(-) diff --git a/packages/fuselage/src/components/Table/Table.stories.tsx b/packages/fuselage/src/components/Table/Table.stories.tsx index 084f7760aa..f1f94f2cec 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'; import { Table } from './Table'; @@ -62,93 +63,122 @@ 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 = () => ( From 1e55db04464f7140595eea2189c70e232bc45e67 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 16 Oct 2024 20:20:29 +0530 Subject: [PATCH 2/2] fixed linting errors --- .../src/components/Table/Table.stories.tsx | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/packages/fuselage/src/components/Table/Table.stories.tsx b/packages/fuselage/src/components/Table/Table.stories.tsx index f1f94f2cec..760e892426 100644 --- a/packages/fuselage/src/components/Table/Table.stories.tsx +++ b/packages/fuselage/src/components/Table/Table.stories.tsx @@ -74,9 +74,9 @@ export const WithSelection: StoryFn = () => { }); const handleCheckBoxChange = (item: string) => { - setCheckedItems(prevState => ({ + setCheckedItems((prevState) => ({ ...prevState, - [item]: !prevState[item] + [item]: !prevState[item], })); }; @@ -98,7 +98,11 @@ export const WithSelection: StoryFn = () => { - + Dessert (100g serving) Calories @@ -110,7 +114,11 @@ export const WithSelection: StoryFn = () => { - handleCheckBoxChange('item1')} /> + handleCheckBoxChange('item1')} + /> Frozen yoghurt @@ -122,7 +130,11 @@ export const WithSelection: StoryFn = () => { - handleCheckBoxChange('item2')} /> + handleCheckBoxChange('item2')} + /> Frozen yoghurt @@ -134,7 +146,11 @@ export const WithSelection: StoryFn = () => { - handleCheckBoxChange('item3')} /> + handleCheckBoxChange('item3')} + /> Frozen yoghurt @@ -146,7 +162,11 @@ export const WithSelection: StoryFn = () => { - handleCheckBoxChange('item4')} /> + handleCheckBoxChange('item4')} + /> Frozen yoghurt @@ -158,7 +178,11 @@ export const WithSelection: StoryFn = () => { - handleCheckBoxChange('item5')} /> + handleCheckBoxChange('item5')} + /> Frozen yoghurt