Skip to content

Commit

Permalink
Add Grid Story
Browse files Browse the repository at this point in the history
  • Loading branch information
roshni73 committed May 28, 2024
1 parent 5a15eed commit b4657e3
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
108 changes: 108 additions & 0 deletions packages/go-ui-storybook/src/stories/Grid.stories.tsx
Original file line number Diff line number Diff line change
@@ -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<Option, ListKey, RendererProps>;

type Story = StoryObj<GridSpecificProps>;

const meta: Meta<typeof Grid> = {
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 (
<Grid
// eslint-disable-next-line react/jsx-props-no-spreading
{...componentArgs}
data={data}
/>
);
},
],

};

export default meta;

function Option({ children }: RendererProps) {
return (
<div>
{ children }
</div>
);
}

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,
},
};
18 changes: 18 additions & 0 deletions packages/go-ui-storybook/src/stories/Grid.tsx
Original file line number Diff line number Diff line change
@@ -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
<DATUM, KEY extends ListKey, RENDERER_PROPS>(props: GridProps<DATUM, KEY, RENDERER_PROPS>) {
return (
<PureGrid {...props} />// eslint-disable-line react/jsx-props-no-spreading
);
}

export default WrappedGrid;

0 comments on commit b4657e3

Please sign in to comment.