Skip to content

Commit

Permalink
Use Template to write Pager story fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
roshni73 authored and samshara committed Jun 11, 2024
1 parent bf5f0c6 commit 68831d3
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions packages/go-ui-storybook/src/stories/Pager.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { PagerProps } from '@ifrc-go/ui';
import { useArgs } from '@storybook/preview-api';
import type {
Args,
Meta,
StoryObj,
} from '@storybook/react';
import { fn } from '@storybook/test';

import Pager from './Pager';

type PagerSpecificProps = PagerProps & {
onChange: (e: number) => void;
};
type PagerSpecificProps = PagerProps

type Story = StoryObj<PagerSpecificProps>;

Expand All @@ -23,52 +23,53 @@ const meta: Meta<typeof Pager> = {
url: 'https://www.figma.com/file/myeW85ibN5p2SlnXcEpxFD/IFRC-GO---UI-Current---1?type=design&node-id=0-4957&mode=design&t=KwxbuoUQxqcLyZbG-0',
},
},
args: {
onActivePageChange: fn(),
},
tags: ['autodocs'],
decorators: [
function Component(_, ctx) {
const componentArgs = ctx.args as PagerSpecificProps;
const [{ activePage, maxItemsPerPage }, handleArgsChange] = useArgs();

const setActivePage = (e: number) => {
handleArgsChange({ activePage: e });
};

return (
<Pager
// eslint-disable-next-line react/jsx-props-no-spreading
{...componentArgs}
onActivePageChange={setActivePage}
maxItemsPerPage={maxItemsPerPage}
activePage={activePage}
/>
);
},
],
};

export default meta;

function Template(args:Args) {
const [{ activePage, maxItemsPerPage }, handleArgsChange] = useArgs();

const onChange = (e: number) => {
handleArgsChange({ activePage: e });
};
return (
<Pager
// eslint-disable-next-line react/jsx-props-no-spreading
{...args}
onActivePageChange={onChange}
maxItemsPerPage={maxItemsPerPage}
activePage={activePage}
itemsCount={10}
/>
);
}

export const Default: Story = {
render: Template,
args: {
activePage: 3,
itemsCount: 10,
maxItemsPerPage: 1,
},
};

export const Disabled: Story = {
render: Template,
args: {
activePage: 5,
itemsCount: 10,
maxItemsPerPage: 1,
disabled: true,
},
};

export const ShowAllPages: Story = {
render: Template,
args: {
activePage: 5,
itemsCount: 10,
maxItemsPerPage: 1,
showAllPages: true,
},
Expand Down

0 comments on commit 68831d3

Please sign in to comment.