From ea0279207c34801edaabf721d29697ee6651f27f Mon Sep 17 00:00:00 2001 From: roshni73 Date: Tue, 21 May 2024 14:37:43 +0545 Subject: [PATCH] Add Grid Story --- .../src/stories/Grid.stories.tsx | 108 ++++++++++++++++++ packages/go-ui-storybook/src/stories/Grid.tsx | 18 +++ 2 files changed, 126 insertions(+) create mode 100644 packages/go-ui-storybook/src/stories/Grid.stories.tsx create mode 100644 packages/go-ui-storybook/src/stories/Grid.tsx diff --git a/packages/go-ui-storybook/src/stories/Grid.stories.tsx b/packages/go-ui-storybook/src/stories/Grid.stories.tsx new file mode 100644 index 0000000000..eb9697697f --- /dev/null +++ b/packages/go-ui-storybook/src/stories/Grid.stories.tsx @@ -0,0 +1,108 @@ +import { + GridProps, + ListKey, +} from '@ifrc-go/ui'; +import { useArgs } from '@storybook/preview-api'; +import type { + Meta, + StoryObj, +} from '@storybook/react'; + +import Grid from './Grid'; + +interface Option { + key: string; + label: string; +} + +const options: Option[] = [ + { key: '1', label: 'Vegetables' }, + { key: '2', label: 'Fruits' }, + { key: '3', label: 'Dairy' }, +]; +type RendererProps = { + children: React.ReactNode + +}; + +type GridSpecificProps = GridProps; + +type Story = StoryObj; + +const meta: Meta = { + title: 'Components/Grid', + component: Grid, + parameters: { + layout: 'centered', + design: { + type: 'figma', + url: 'https://www.figma.com/file/myeW85ibN5p2SlnXcEpxFD/IFRC-GO---UI-Current---1?type=design&node-id=0-4957&mode=design&t=KwxbuoUQxqcLyZbG-0', + }, + }, + tags: ['autodocs'], + decorators: [ + function Component(_, ctx) { + const componentArgs = ctx.args as GridSpecificProps; + const [args] = useArgs(); + const { data } = args; + return ( + + ); + }, + ], + +}; + +export default meta; + +function Option({ children }: RendererProps) { + return ( +
+ { children } +
+ ); +} + +const keySelector = (datum: Option) => datum.key; + +const rendererParams = (_key: string, option: Option) => ({ children: option.label }); + +export const Default: Story = { + args: { + data: options, + keySelector, + renderer: Option, + rendererParams, + }, +}; + +export const Pending: Story = { + args: { + keySelector, + renderer: Option, + rendererParams, + pending: true, + }, +}; + +export const Errored: Story = { + args: { + keySelector, + renderer: Option, + rendererParams, + errored: true, + errorMessage: 'Failed to fetch data!', + }, +}; +export const Filtered: Story = { + args: { + keySelector, + renderer: Option, + rendererParams, + filtered: true, + }, +}; diff --git a/packages/go-ui-storybook/src/stories/Grid.tsx b/packages/go-ui-storybook/src/stories/Grid.tsx new file mode 100644 index 0000000000..6dd930cd09 --- /dev/null +++ b/packages/go-ui-storybook/src/stories/Grid.tsx @@ -0,0 +1,18 @@ +import { + Grid as PureGrid, + GridProps as PureGridProps, + ListKey, +} from '@ifrc-go/ui'; + +interface GridProps< DATUM, KEY extends ListKey, RENDERER_PROPS> +extends PureGridProps< DATUM, KEY, RENDERER_PROPS> {} + +function WrappedGrid +// eslint-disable-next-line max-len +(props: GridProps) { + return ( + // eslint-disable-line react/jsx-props-no-spreading + ); +} + +export default WrappedGrid;