Skip to content

Commit

Permalink
Docs(web-react): Introduce new Stories for Button, Modal and Pill
Browse files Browse the repository at this point in the history
  • Loading branch information
crishpeen committed Aug 29, 2023
1 parent a0fe11c commit 86acc0b
Show file tree
Hide file tree
Showing 18 changed files with 514 additions and 124 deletions.
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const config: StorybookViteConfig = {

docs: {
autodocs: true,
defaultName: 'Overview',
},
};

Expand Down
3 changes: 3 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const parameters = {
color: /(background|color)$/i,
date: /Date$/,
},
expanded: true,
sort: 'alpha',
hideNoControlsWarning: true,
},
docs: {
theme: SpiritTheme,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@storybook/addon-links": "7.3.2",
"@storybook/addon-mdx-gfm": "7.3.2",
"@storybook/addons": "7.3.2",
"@storybook/blocks": "7.3.2",
"@storybook/client-api": "7.3.2",
"@storybook/html": "7.3.2",
"@storybook/react": "7.3.2",
Expand Down
11 changes: 10 additions & 1 deletion packages/web-react/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.md', 'raw', '.md?raw'],
},
},
},
Expand Down Expand Up @@ -63,6 +63,15 @@ module.exports = {
'no-param-reassign': ['warn', { props: false }],
// support monorepos
'import/no-extraneous-dependencies': ['error', { packageDir: ['./', '../../'] }],
'import/no-unresolved': [
2,
{
ignore: [
// Ignore vite's ?raw imports
'.*?raw',
],
},
],
// disable double quotes
quotes: ['warn', 'single'],
},
Expand Down
27 changes: 0 additions & 27 deletions packages/web-react/src/components/Button/Button.stories.ts

This file was deleted.

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

import { Button } from './Button';
import { args, argTypes } from './stories/args';
import ReadMe from './README.md?raw';

const meta: Meta<typeof Button> = {
title: 'Components/Button',
component: Button,
parameters: {
docs: {
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
argTypes: {
...argTypes,
type: {
control: 'select',
options: ['button', 'submit', 'reset'],
},
},
args: {
...args,
type: 'button',
},
};

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

export const Playground: Story = {
name: 'Button',
};
36 changes: 18 additions & 18 deletions packages/web-react/src/components/Button/ButtonLink.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { ComponentMeta } from '@storybook/react';
import argTypes from './demo/argTypes';
import ButtonLink from './ButtonLink';
import React from 'react';
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';

export default {
import { ButtonLink } from './ButtonLink';
import { args, argTypes } from './stories/args';
import ReadMe from './README.md?raw';

const meta: Meta<typeof ButtonLink> = {
title: 'Components/ButtonLink',
component: ButtonLink,
parameters: {
docs: {
description: {
component: 'ButtonLinks allow users to take actions.',
},
},
},
argTypes: {
...argTypes,
href: {
control: {
type: 'text',
},
defaultValue: '#',
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
} as ComponentMeta<typeof ButtonLink>;
argTypes,
args,
};

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

export { default as ButtonLink } from './demo/ButtonLink';
export const Playground: Story = {
name: 'ButtonLink',
};
42 changes: 0 additions & 42 deletions packages/web-react/src/components/Button/demo/argTypes.ts

This file was deleted.

56 changes: 56 additions & 0 deletions packages/web-react/src/components/Button/stories/args.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { ActionColors, EmotionColors, Sizes } from '../../../constants';
import { Icon } from '../../Icon';

export const argTypes = {
children: {
control: 'text',
description:
'This is the place for the content of the button. In the real code you can pass in any JSX. ' +
'In this demo you can set any text you want, or use one of the predefined texts: `<Icon />` ' +
'(to see how it looks with an Icon) or `<Icon /> Text` (to see how it looks with an Icon ' +
'and text). Please note the predefined texts in this demo are not customizable and have ' +
'to be written exactly as shown.',
mapping: {
'<Icon />': <Icon name="profile" />,
'<Icon /> Text': (
<>
<Icon name="profile" UNSAFE_className="mr-400" /> Text
</>
),
},
},
color: {
control: 'select',
options: [...Object.values(ActionColors), ...Object.values(EmotionColors)],
table: {
defaultValue: { summary: ActionColors.PRIMARY },
},
},
isBlock: {
control: 'boolean',
},
isDisabled: {
control: 'boolean',
},
isLoading: {
control: 'boolean',
},
isSquare: {
control: 'boolean',
},
size: {
control: 'select',
options: [...Object.values(Sizes)],
},
};

export const args = {
children: 'Click me',
color: ActionColors.PRIMARY,
isBlock: false,
isDisabled: false,
isLoading: false,
isSquare: false,
size: Sizes.MEDIUM,
};
76 changes: 69 additions & 7 deletions packages/web-react/src/components/Modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,78 @@
import { ComponentMeta } from '@storybook/react';
import Modal from './Modal';
import React, { useState } from 'react';
import { Markdown } from '@storybook/blocks';
import type { Meta, StoryObj } from '@storybook/react';

export default {
import { SpiritModalProps } from '../../types';
import { Button } from '../Button';
import ReadMe from './README.md?raw';
import { Modal, ModalHeader, ModalDialog, ModalBody, ModalFooter } from '.';

const meta: Meta<typeof Modal> = {
title: 'Components/Modal',
component: Modal,
parameters: {
docs: {
description: {
component: 'Add dialogs to your site for lightboxes, user notifications, or completely custom content.',
page: () => <Markdown>{ReadMe}</Markdown>,
},
},
argTypes: {
id: {
control: 'text',
},
isOpen: {
control: 'boolean',
table: {
defaultValue: { summary: false },
},
},
onClose: {
control: 'function',
},
},
args: {
id: 'modal',
isOpen: false,
},
} as ComponentMeta<typeof Modal>;
};

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

const ModalWithHooks = (args: SpiritModalProps) => {
const [isModalOpen, setModalOpen] = useState(false);

const toggleModal = () => setModalOpen(!isModalOpen);

const handleClose = () => {
setModalOpen(false);
};

const { isOpen } = args;

return (
<>
<Button onClick={toggleModal} aria-expanded={isOpen || isModalOpen}>
Open Modal
</Button>
<Modal {...args} isOpen={isOpen || isModalOpen} onClose={handleClose}>
<ModalDialog preferredHeightOnMobile="500px">
<ModalHeader>Modal Header</ModalHeader>
<ModalBody>Body</ModalBody>
<ModalFooter>
<Button color="primary" onClick={handleClose}>
Confirm
</Button>
<Button color="tertiary" onClick={handleClose}>
Cancel
</Button>
</ModalFooter>
</ModalDialog>
</Modal>
</>
);
};

export { default as Modal } from './demo/Modal';
export const Playground: Story = {
name: 'Modal',
render: (args) => <ModalWithHooks {...args} />,
};
Loading

0 comments on commit 86acc0b

Please sign in to comment.