Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Grid Story #1068

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/go-ui-storybook/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@ifrc-go/ui/index.css';
import type { Preview } from "@storybook/react";

import '../src/stories/timeseries.css';
import '../src/stories/index.css';

const preview: Preview = {
parameters: {
Expand Down
104 changes: 104 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,104 @@
import { GridProps } from '@ifrc-go/ui';
import type {
Meta,
StoryObj,
} from '@storybook/react';

import Grid from './Grid';

interface Option {
key: string;
label: string;
}

const options: Option[] = [
{ key: '1', label: 'Cat' },
{ key: '2', label: 'Dog' },
{ key: '3', label: 'Elephant' },
{ key: '4', label: 'Giraffe' },
{ key: '5', label: 'Lion' },
];

type RendererProps = {
label: string;
};

type GridSpecificProps = GridProps<Option, string, 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'],
};

export default meta;

function Option({ label }: RendererProps) {
return (
<div className="grid-item">
{label}
</div>
);
}

const keySelector = (datum: Option) => datum.key;

const rendererParams = (_key: string, option: Option) => ({ label: option.label });

export const Default: Story = {
args: {
className: 'grid-story',
data: options,
keySelector,
renderer: Option,
rendererParams,
},
};

export const WithPreferredColumns: Story = {
args: {
className: 'grid-story',
data: options,
keySelector,
renderer: Option,
rendererParams,
numPreferredColumns: 2,
},
};

export const Pending: Story = {
args: {
className: 'grid-story',
keySelector,
renderer: Option,
rendererParams,
pending: true,
},
};

export const Errored: Story = {
args: {
className: 'grid-story',
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;
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@
.list-story {
width: 30rem;
}

.grid-story {
.grid-item {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 0;
padding: var(--go-ui-spacing-sm);
border-radius: var(--go-ui-border-radius-md);
box-shadow: var(--go-ui-box-shadow-md);
}
}
Loading