Skip to content

Commit

Permalink
Docs(web-react): Introduce stories to the rest of the components #DS-476
Browse files Browse the repository at this point in the history
Affected components are Accordion, Breadcrumbs, Collapse, Dropdown, Header,
Icon, Pagination, ScrollView, Spinner, Tabs and Tooltip.
  • Loading branch information
crishpeen committed Sep 1, 2023
1 parent f1882dc commit 56f3d60
Show file tree
Hide file tree
Showing 66 changed files with 4,349 additions and 304 deletions.
20 changes: 0 additions & 20 deletions packages/web-react/src/components/Accordion/Accordion.stories.ts

This file was deleted.

84 changes: 84 additions & 0 deletions packages/web-react/src/components/Accordion/Accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React, { useState } from 'react';
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';

import { AccordionOpenStateType, AccordionProps } from '../../types';
import { Link } from '../Link';
import { Pill } from '../Pill';
import toggleValueByType from './demo/toggleValueByType';
import content from './stories/content';
import ReadMe from './README.md';
import { Accordion, AccordionHeader, AccordionContent, AccordionItem } from '.';

const meta: Meta<typeof Accordion> = {
title: 'Components/Accordion',
component: Accordion,
parameters: {
docs: {
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
argTypes: {
elementType: {
control: 'text',
table: {
defaultValue: { summary: 'section' },
},
},
open: {
control: 'text',
},
toggle: {
control: 'text',
},
},
args: {
elementType: 'section',
},
};

export default meta;
type Story = StoryObj<typeof Accordion>;

const AccordionWithHooks = (args: AccordionProps) => {
const [openState, setOpenState] = useState<AccordionOpenStateType>('AccordionItemExample1');

const toggle = (id: string) => {
setOpenState(toggleValueByType(id, openState));
};

return (
<Accordion {...args} open={openState} toggle={toggle}>
<AccordionItem id="AccordionItemExample0">
<AccordionHeader
slot={
<>
<Link href="/">Link</Link>
<Pill>3</Pill>
</>
}
>
Accordion Header #0
</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample1">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #1</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample2">
<AccordionHeader>Accordion Header #2</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample3">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #3</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
</Accordion>
);
};

export const Playground: Story = {
name: 'Accordion',
render: (args) => <AccordionWithHooks {...args} />,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { useState } from 'react';
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';

import { AccordionContentProps, AccordionOpenStateType } from '../../types';
import { Link } from '../Link';
import { Pill } from '../Pill';
import toggleValueByType from './demo/toggleValueByType';
import content from './stories/content';
import ReadMe from './README.md';
import { Accordion, AccordionHeader, AccordionContent, AccordionItem } from '.';

const meta: Meta<typeof AccordionContent> = {
title: 'Components/Accordion',
component: AccordionContent,
parameters: {
docs: {
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
argTypes: {
children: {
control: 'text',
},
},
args: {
children: 'Accordion Content',
},
};

export default meta;
type Story = StoryObj<typeof AccordionContent>;

const AccordionWithHooks = (args: AccordionContentProps) => {
const [openState, setOpenState] = useState<AccordionOpenStateType>('AccordionItemExample0');

const toggle = (id: string) => {
setOpenState(toggleValueByType(id, openState));
};

return (
<Accordion open={openState} toggle={toggle}>
<AccordionItem id="AccordionItemExample0">
<AccordionHeader
slot={
<>
<Link href="/">Link</Link>
<Pill>3</Pill>
</>
}
>
Accordion Header #0
</AccordionHeader>
<AccordionContent {...args} />
</AccordionItem>
<AccordionItem id="AccordionItemExample1">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #1</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample2">
<AccordionHeader>Accordion Header #2</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample3">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #3</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
</Accordion>
);
};

export const AccordionContentPlayground: Story = {
name: 'AccordionContent',
render: (args) => <AccordionWithHooks {...args} />,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React, { useState } from 'react';
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';

import { AccordionHeaderProps, AccordionOpenStateType } from '../../types';
import { Link } from '../Link';
import { Pill } from '../Pill';
import toggleValueByType from './demo/toggleValueByType';
import content from './stories/content';
import ReadMe from './README.md';
import { Accordion, AccordionHeader, AccordionContent, AccordionItem } from '.';

const meta: Meta<typeof AccordionHeader> = {
title: 'Components/Accordion',
component: AccordionHeader,
parameters: {
docs: {
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
argTypes: {
children: {
control: 'text',
},
elementType: {
control: 'text',
table: {
defaultValue: { summary: 'h3' },
},
},
slot: {
control: 'select',
options: ['pill', 'link & pill', undefined],
description:
'This is the place for the content of the slot. In the real code you can pass in any ' +
'children you want. In this demo we have predefined options: `pill` and `link & pill`. ' +
'Please note the predefined options in this demo are not customizable.',
mapping: {
pill: <Pill>3</Pill>,
'link & pill': (
<>
<Link href="/">Link</Link>
<Pill>3</Pill>
</>
),
},
},
},
args: {
children: 'Accordion Header #0',
elementType: 'h3',
slot: undefined,
},
};

export default meta;
type Story = StoryObj<typeof AccordionHeader>;

const AccordionWithHooks = (args: AccordionHeaderProps) => {
const [openState, setOpenState] = useState<AccordionOpenStateType>('AccordionItemExample1');

const toggle = (id: string) => {
setOpenState(toggleValueByType(id, openState));
};

return (
<Accordion open={openState} toggle={toggle}>
<AccordionItem id="AccordionItemExample0">
<AccordionHeader {...args} />
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample1">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #1</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample2">
<AccordionHeader>Accordion Header #2</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample3">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #3</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
</Accordion>
);
};

export const AccordionHeaderPlayground: Story = {
name: 'AccordionHeader',
render: (args) => <AccordionWithHooks {...args} />,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { useState } from 'react';
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';

import { AccordionItemProps, AccordionOpenStateType } from '../../types';
import { Link } from '../Link';
import { Pill } from '../Pill';
import toggleValueByType from './demo/toggleValueByType';
import content from './stories/content';
import ReadMe from './README.md';
import { Accordion, AccordionHeader, AccordionContent, AccordionItem } from '.';

const meta: Meta<typeof AccordionItem> = {
title: 'Components/Accordion',
component: AccordionItem,
parameters: {
docs: {
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
argTypes: {
elementType: {
control: 'text',
table: {
defaultValue: { summary: 'article' },
},
},
id: {
control: 'text',
},
},
args: {
elementType: 'article',
},
};

export default meta;
type Story = StoryObj<typeof AccordionItem>;

const AccordionWithHooks = (args: AccordionItemProps) => {
const [openState, setOpenState] = useState<AccordionOpenStateType>('AccordionItemExample1');

const toggle = (id: string) => {
setOpenState(toggleValueByType(id, openState));
};

return (
<Accordion open={openState} toggle={toggle}>
<AccordionItem {...args} id="AccordionItemExample0">
<AccordionHeader
slot={
<>
<Link href="/">Link</Link>
<Pill>3</Pill>
</>
}
>
Accordion Header #0
</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample1">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #1</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample2">
<AccordionHeader>Accordion Header #2</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
<AccordionItem id="AccordionItemExample3">
<AccordionHeader slot={<Pill>3</Pill>}>Accordion Header #3</AccordionHeader>
<AccordionContent>{content}</AccordionContent>
</AccordionItem>
</Accordion>
);
};

export const AccordionItemPlayground: Story = {
name: 'AccordionItem',
render: (args) => <AccordionWithHooks {...args} />,
};
Loading

0 comments on commit 56f3d60

Please sign in to comment.