@storybook/react-webpack5 9.0.0-alpha.9 → 9.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -6
- package/template/cli/.eslintrc.json +5 -0
- package/template/cli/js/Button.jsx +37 -0
- package/template/cli/js/Button.stories.js +49 -0
- package/template/cli/js/Header.jsx +54 -0
- package/template/cli/js/Header.stories.js +29 -0
- package/template/cli/js/Page.jsx +69 -0
- package/template/cli/js/Page.stories.js +28 -0
- package/template/cli/ts/Button.stories.ts +54 -0
- package/template/cli/ts/Button.tsx +35 -0
- package/template/cli/ts/Header.stories.ts +34 -0
- package/template/cli/ts/Header.tsx +54 -0
- package/template/cli/ts/Page.stories.ts +33 -0
- package/template/cli/ts/Page.tsx +73 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/react-webpack5",
|
3
|
-
"version": "9.0.0-
|
3
|
+
"version": "9.0.0-beta.0",
|
4
4
|
"description": "Storybook for React: Develop React Component in isolation with Hot Reloading.",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
@@ -43,6 +43,7 @@
|
|
43
43
|
"types": "dist/index.d.ts",
|
44
44
|
"files": [
|
45
45
|
"dist/**/*",
|
46
|
+
"template/cli/**/*",
|
46
47
|
"README.md",
|
47
48
|
"*.js",
|
48
49
|
"*.d.ts",
|
@@ -53,9 +54,9 @@
|
|
53
54
|
"prep": "jiti ../../../scripts/prepare/bundle.ts"
|
54
55
|
},
|
55
56
|
"dependencies": {
|
56
|
-
"@storybook/builder-webpack5": "9.0.0-
|
57
|
-
"@storybook/preset-react-webpack": "9.0.0-
|
58
|
-
"@storybook/react": "9.0.0-
|
57
|
+
"@storybook/builder-webpack5": "9.0.0-beta.0",
|
58
|
+
"@storybook/preset-react-webpack": "9.0.0-beta.0",
|
59
|
+
"@storybook/react": "9.0.0-beta.0"
|
59
60
|
},
|
60
61
|
"devDependencies": {
|
61
62
|
"@types/node": "^22.0.0"
|
@@ -63,7 +64,7 @@
|
|
63
64
|
"peerDependencies": {
|
64
65
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
|
65
66
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
|
66
|
-
"storybook": "^9.0.0-
|
67
|
+
"storybook": "^9.0.0-beta.0",
|
67
68
|
"typescript": ">= 4.9.x"
|
68
69
|
},
|
69
70
|
"peerDependenciesMeta": {
|
@@ -72,7 +73,7 @@
|
|
72
73
|
}
|
73
74
|
},
|
74
75
|
"engines": {
|
75
|
-
"node": ">=
|
76
|
+
"node": ">=20.0.0"
|
76
77
|
},
|
77
78
|
"publishConfig": {
|
78
79
|
"access": "public"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import PropTypes from 'prop-types';
|
2
|
+
|
3
|
+
import './button.css';
|
4
|
+
|
5
|
+
/** Primary UI component for user interaction */
|
6
|
+
export const Button = ({
|
7
|
+
primary = false,
|
8
|
+
backgroundColor = null,
|
9
|
+
size = 'medium',
|
10
|
+
label,
|
11
|
+
...props
|
12
|
+
}) => {
|
13
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
14
|
+
return (
|
15
|
+
<button
|
16
|
+
type="button"
|
17
|
+
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
18
|
+
style={backgroundColor && { backgroundColor }}
|
19
|
+
{...props}
|
20
|
+
>
|
21
|
+
{label}
|
22
|
+
</button>
|
23
|
+
);
|
24
|
+
};
|
25
|
+
|
26
|
+
Button.propTypes = {
|
27
|
+
/** Is this the principal call to action on the page? */
|
28
|
+
primary: PropTypes.bool,
|
29
|
+
/** What background color to use */
|
30
|
+
backgroundColor: PropTypes.string,
|
31
|
+
/** How large should the button be? */
|
32
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
33
|
+
/** Button contents */
|
34
|
+
label: PropTypes.string.isRequired,
|
35
|
+
/** Optional click handler */
|
36
|
+
onClick: PropTypes.func,
|
37
|
+
};
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { fn } from 'storybook/test';
|
2
|
+
|
3
|
+
import { Button } from './Button';
|
4
|
+
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
6
|
+
export default {
|
7
|
+
title: 'Example/Button',
|
8
|
+
component: Button,
|
9
|
+
parameters: {
|
10
|
+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
11
|
+
layout: 'centered',
|
12
|
+
},
|
13
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
14
|
+
tags: ['autodocs'],
|
15
|
+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
16
|
+
argTypes: {
|
17
|
+
backgroundColor: { control: 'color' },
|
18
|
+
},
|
19
|
+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
20
|
+
args: { onClick: fn() },
|
21
|
+
};
|
22
|
+
|
23
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
24
|
+
export const Primary = {
|
25
|
+
args: {
|
26
|
+
primary: true,
|
27
|
+
label: 'Button',
|
28
|
+
},
|
29
|
+
};
|
30
|
+
|
31
|
+
export const Secondary = {
|
32
|
+
args: {
|
33
|
+
label: 'Button',
|
34
|
+
},
|
35
|
+
};
|
36
|
+
|
37
|
+
export const Large = {
|
38
|
+
args: {
|
39
|
+
size: 'large',
|
40
|
+
label: 'Button',
|
41
|
+
},
|
42
|
+
};
|
43
|
+
|
44
|
+
export const Small = {
|
45
|
+
args: {
|
46
|
+
size: 'small',
|
47
|
+
label: 'Button',
|
48
|
+
},
|
49
|
+
};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import PropTypes from 'prop-types';
|
2
|
+
|
3
|
+
import { Button } from './Button';
|
4
|
+
import './header.css';
|
5
|
+
|
6
|
+
export const Header = ({ user = null, onLogin, onLogout, onCreateAccount }) => (
|
7
|
+
<header>
|
8
|
+
<div className="storybook-header">
|
9
|
+
<div>
|
10
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
11
|
+
<g fill="none" fillRule="evenodd">
|
12
|
+
<path
|
13
|
+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
14
|
+
fill="#FFF"
|
15
|
+
/>
|
16
|
+
<path
|
17
|
+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
18
|
+
fill="#555AB9"
|
19
|
+
/>
|
20
|
+
<path
|
21
|
+
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
|
22
|
+
fill="#91BAF8"
|
23
|
+
/>
|
24
|
+
</g>
|
25
|
+
</svg>
|
26
|
+
<h1>Acme</h1>
|
27
|
+
</div>
|
28
|
+
<div>
|
29
|
+
{user ? (
|
30
|
+
<>
|
31
|
+
<span className="welcome">
|
32
|
+
Welcome, <b>{user.name}</b>!
|
33
|
+
</span>
|
34
|
+
<Button size="small" onClick={onLogout} label="Log out" />
|
35
|
+
</>
|
36
|
+
) : (
|
37
|
+
<>
|
38
|
+
<Button size="small" onClick={onLogin} label="Log in" />
|
39
|
+
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
40
|
+
</>
|
41
|
+
)}
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</header>
|
45
|
+
);
|
46
|
+
|
47
|
+
Header.propTypes = {
|
48
|
+
user: PropTypes.shape({
|
49
|
+
name: PropTypes.string.isRequired,
|
50
|
+
}),
|
51
|
+
onLogin: PropTypes.func.isRequired,
|
52
|
+
onLogout: PropTypes.func.isRequired,
|
53
|
+
onCreateAccount: PropTypes.func.isRequired,
|
54
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { fn } from 'storybook/test';
|
2
|
+
|
3
|
+
import { Header } from './Header';
|
4
|
+
|
5
|
+
export default {
|
6
|
+
title: 'Example/Header',
|
7
|
+
component: Header,
|
8
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
9
|
+
tags: ['autodocs'],
|
10
|
+
parameters: {
|
11
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
12
|
+
layout: 'fullscreen',
|
13
|
+
},
|
14
|
+
args: {
|
15
|
+
onLogin: fn(),
|
16
|
+
onLogout: fn(),
|
17
|
+
onCreateAccount: fn(),
|
18
|
+
},
|
19
|
+
};
|
20
|
+
|
21
|
+
export const LoggedIn = {
|
22
|
+
args: {
|
23
|
+
user: {
|
24
|
+
name: 'Jane Doe',
|
25
|
+
},
|
26
|
+
},
|
27
|
+
};
|
28
|
+
|
29
|
+
export const LoggedOut = {};
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
import { Header } from './Header';
|
4
|
+
import './page.css';
|
5
|
+
|
6
|
+
export const Page = () => {
|
7
|
+
const [user, setUser] = React.useState();
|
8
|
+
|
9
|
+
return (
|
10
|
+
<article>
|
11
|
+
<Header
|
12
|
+
user={user}
|
13
|
+
onLogin={() => setUser({ name: 'Jane Doe' })}
|
14
|
+
onLogout={() => setUser(undefined)}
|
15
|
+
onCreateAccount={() => setUser({ name: 'Jane Doe' })}
|
16
|
+
/>
|
17
|
+
|
18
|
+
<section className="storybook-page">
|
19
|
+
<h2>Pages in Storybook</h2>
|
20
|
+
<p>
|
21
|
+
We recommend building UIs with a{' '}
|
22
|
+
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
|
23
|
+
<strong>component-driven</strong>
|
24
|
+
</a>{' '}
|
25
|
+
process starting with atomic components and ending with pages.
|
26
|
+
</p>
|
27
|
+
<p>
|
28
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
29
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page
|
30
|
+
data in Storybook:
|
31
|
+
</p>
|
32
|
+
<ul>
|
33
|
+
<li>
|
34
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
35
|
+
"args" of child component stories
|
36
|
+
</li>
|
37
|
+
<li>
|
38
|
+
Assemble data in the page component from your services. You can mock these services out
|
39
|
+
using Storybook.
|
40
|
+
</li>
|
41
|
+
</ul>
|
42
|
+
<p>
|
43
|
+
Get a guided tutorial on component-driven development at{' '}
|
44
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
45
|
+
Storybook tutorials
|
46
|
+
</a>
|
47
|
+
. Read more in the{' '}
|
48
|
+
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
|
49
|
+
docs
|
50
|
+
</a>
|
51
|
+
.
|
52
|
+
</p>
|
53
|
+
<div className="tip-wrapper">
|
54
|
+
<span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
|
55
|
+
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
56
|
+
<g fill="none" fillRule="evenodd">
|
57
|
+
<path
|
58
|
+
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
59
|
+
id="a"
|
60
|
+
fill="#999"
|
61
|
+
/>
|
62
|
+
</g>
|
63
|
+
</svg>
|
64
|
+
Viewports addon in the toolbar
|
65
|
+
</div>
|
66
|
+
</section>
|
67
|
+
</article>
|
68
|
+
);
|
69
|
+
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { expect, userEvent, within } from 'storybook/test';
|
2
|
+
|
3
|
+
import { Page } from './Page';
|
4
|
+
|
5
|
+
export default {
|
6
|
+
title: 'Example/Page',
|
7
|
+
component: Page,
|
8
|
+
parameters: {
|
9
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
10
|
+
layout: 'fullscreen',
|
11
|
+
},
|
12
|
+
};
|
13
|
+
|
14
|
+
export const LoggedOut = {};
|
15
|
+
|
16
|
+
// More on component testing: https://storybook.js.org/docs/writing-tests/component-testing
|
17
|
+
export const LoggedIn = {
|
18
|
+
play: async ({ canvasElement }) => {
|
19
|
+
const canvas = within(canvasElement);
|
20
|
+
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
21
|
+
await expect(loginButton).toBeInTheDocument();
|
22
|
+
await userEvent.click(loginButton);
|
23
|
+
await expect(loginButton).not.toBeInTheDocument();
|
24
|
+
|
25
|
+
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
26
|
+
await expect(logoutButton).toBeInTheDocument();
|
27
|
+
},
|
28
|
+
};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-webpack5';
|
2
|
+
|
3
|
+
import { fn } from 'storybook/test';
|
4
|
+
|
5
|
+
import { Button } from './Button';
|
6
|
+
|
7
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
8
|
+
const meta = {
|
9
|
+
title: 'Example/Button',
|
10
|
+
component: Button,
|
11
|
+
parameters: {
|
12
|
+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
13
|
+
layout: 'centered',
|
14
|
+
},
|
15
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
16
|
+
tags: ['autodocs'],
|
17
|
+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
18
|
+
argTypes: {
|
19
|
+
backgroundColor: { control: 'color' },
|
20
|
+
},
|
21
|
+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
22
|
+
args: { onClick: fn() },
|
23
|
+
} satisfies Meta<typeof Button>;
|
24
|
+
|
25
|
+
export default meta;
|
26
|
+
type Story = StoryObj<typeof meta>;
|
27
|
+
|
28
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
29
|
+
export const Primary: Story = {
|
30
|
+
args: {
|
31
|
+
primary: true,
|
32
|
+
label: 'Button',
|
33
|
+
},
|
34
|
+
};
|
35
|
+
|
36
|
+
export const Secondary: Story = {
|
37
|
+
args: {
|
38
|
+
label: 'Button',
|
39
|
+
},
|
40
|
+
};
|
41
|
+
|
42
|
+
export const Large: Story = {
|
43
|
+
args: {
|
44
|
+
size: 'large',
|
45
|
+
label: 'Button',
|
46
|
+
},
|
47
|
+
};
|
48
|
+
|
49
|
+
export const Small: Story = {
|
50
|
+
args: {
|
51
|
+
size: 'small',
|
52
|
+
label: 'Button',
|
53
|
+
},
|
54
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import './button.css';
|
2
|
+
|
3
|
+
export interface ButtonProps {
|
4
|
+
/** Is this the principal call to action on the page? */
|
5
|
+
primary?: boolean;
|
6
|
+
/** What background color to use */
|
7
|
+
backgroundColor?: string;
|
8
|
+
/** How large should the button be? */
|
9
|
+
size?: 'small' | 'medium' | 'large';
|
10
|
+
/** Button contents */
|
11
|
+
label: string;
|
12
|
+
/** Optional click handler */
|
13
|
+
onClick?: () => void;
|
14
|
+
}
|
15
|
+
|
16
|
+
/** Primary UI component for user interaction */
|
17
|
+
export const Button = ({
|
18
|
+
primary = false,
|
19
|
+
size = 'medium',
|
20
|
+
backgroundColor,
|
21
|
+
label,
|
22
|
+
...props
|
23
|
+
}: ButtonProps) => {
|
24
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
25
|
+
return (
|
26
|
+
<button
|
27
|
+
type="button"
|
28
|
+
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
29
|
+
style={{ backgroundColor }}
|
30
|
+
{...props}
|
31
|
+
>
|
32
|
+
{label}
|
33
|
+
</button>
|
34
|
+
);
|
35
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-webpack5';
|
2
|
+
|
3
|
+
import { fn } from 'storybook/test';
|
4
|
+
|
5
|
+
import { Header } from './Header';
|
6
|
+
|
7
|
+
const meta = {
|
8
|
+
title: 'Example/Header',
|
9
|
+
component: Header,
|
10
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
11
|
+
tags: ['autodocs'],
|
12
|
+
parameters: {
|
13
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
14
|
+
layout: 'fullscreen',
|
15
|
+
},
|
16
|
+
args: {
|
17
|
+
onLogin: fn(),
|
18
|
+
onLogout: fn(),
|
19
|
+
onCreateAccount: fn(),
|
20
|
+
},
|
21
|
+
} satisfies Meta<typeof Header>;
|
22
|
+
|
23
|
+
export default meta;
|
24
|
+
type Story = StoryObj<typeof meta>;
|
25
|
+
|
26
|
+
export const LoggedIn: Story = {
|
27
|
+
args: {
|
28
|
+
user: {
|
29
|
+
name: 'Jane Doe',
|
30
|
+
},
|
31
|
+
},
|
32
|
+
};
|
33
|
+
|
34
|
+
export const LoggedOut: Story = {};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { Button } from './Button';
|
2
|
+
import './header.css';
|
3
|
+
|
4
|
+
type User = {
|
5
|
+
name: string;
|
6
|
+
};
|
7
|
+
|
8
|
+
export interface HeaderProps {
|
9
|
+
user?: User;
|
10
|
+
onLogin?: () => void;
|
11
|
+
onLogout?: () => void;
|
12
|
+
onCreateAccount?: () => void;
|
13
|
+
}
|
14
|
+
|
15
|
+
export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
|
16
|
+
<header>
|
17
|
+
<div className="storybook-header">
|
18
|
+
<div>
|
19
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
20
|
+
<g fill="none" fillRule="evenodd">
|
21
|
+
<path
|
22
|
+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
23
|
+
fill="#FFF"
|
24
|
+
/>
|
25
|
+
<path
|
26
|
+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
27
|
+
fill="#555AB9"
|
28
|
+
/>
|
29
|
+
<path
|
30
|
+
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
|
31
|
+
fill="#91BAF8"
|
32
|
+
/>
|
33
|
+
</g>
|
34
|
+
</svg>
|
35
|
+
<h1>Acme</h1>
|
36
|
+
</div>
|
37
|
+
<div>
|
38
|
+
{user ? (
|
39
|
+
<>
|
40
|
+
<span className="welcome">
|
41
|
+
Welcome, <b>{user.name}</b>!
|
42
|
+
</span>
|
43
|
+
<Button size="small" onClick={onLogout} label="Log out" />
|
44
|
+
</>
|
45
|
+
) : (
|
46
|
+
<>
|
47
|
+
<Button size="small" onClick={onLogin} label="Log in" />
|
48
|
+
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
49
|
+
</>
|
50
|
+
)}
|
51
|
+
</div>
|
52
|
+
</div>
|
53
|
+
</header>
|
54
|
+
);
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-webpack5';
|
2
|
+
|
3
|
+
import { expect, userEvent, within } from 'storybook/test';
|
4
|
+
|
5
|
+
import { Page } from './Page';
|
6
|
+
|
7
|
+
const meta = {
|
8
|
+
title: 'Example/Page',
|
9
|
+
component: Page,
|
10
|
+
parameters: {
|
11
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
12
|
+
layout: 'fullscreen',
|
13
|
+
},
|
14
|
+
} satisfies Meta<typeof Page>;
|
15
|
+
|
16
|
+
export default meta;
|
17
|
+
type Story = StoryObj<typeof meta>;
|
18
|
+
|
19
|
+
export const LoggedOut: Story = {};
|
20
|
+
|
21
|
+
// More on component testing: https://storybook.js.org/docs/writing-tests/component-testing
|
22
|
+
export const LoggedIn: Story = {
|
23
|
+
play: async ({ canvasElement }) => {
|
24
|
+
const canvas = within(canvasElement);
|
25
|
+
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
26
|
+
await expect(loginButton).toBeInTheDocument();
|
27
|
+
await userEvent.click(loginButton);
|
28
|
+
await expect(loginButton).not.toBeInTheDocument();
|
29
|
+
|
30
|
+
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
31
|
+
await expect(logoutButton).toBeInTheDocument();
|
32
|
+
},
|
33
|
+
};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
import { Header } from './Header';
|
4
|
+
import './page.css';
|
5
|
+
|
6
|
+
type User = {
|
7
|
+
name: string;
|
8
|
+
};
|
9
|
+
|
10
|
+
export const Page: React.FC = () => {
|
11
|
+
const [user, setUser] = React.useState<User>();
|
12
|
+
|
13
|
+
return (
|
14
|
+
<article>
|
15
|
+
<Header
|
16
|
+
user={user}
|
17
|
+
onLogin={() => setUser({ name: 'Jane Doe' })}
|
18
|
+
onLogout={() => setUser(undefined)}
|
19
|
+
onCreateAccount={() => setUser({ name: 'Jane Doe' })}
|
20
|
+
/>
|
21
|
+
|
22
|
+
<section className="storybook-page">
|
23
|
+
<h2>Pages in Storybook</h2>
|
24
|
+
<p>
|
25
|
+
We recommend building UIs with a{' '}
|
26
|
+
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
|
27
|
+
<strong>component-driven</strong>
|
28
|
+
</a>{' '}
|
29
|
+
process starting with atomic components and ending with pages.
|
30
|
+
</p>
|
31
|
+
<p>
|
32
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
33
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page
|
34
|
+
data in Storybook:
|
35
|
+
</p>
|
36
|
+
<ul>
|
37
|
+
<li>
|
38
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
39
|
+
"args" of child component stories
|
40
|
+
</li>
|
41
|
+
<li>
|
42
|
+
Assemble data in the page component from your services. You can mock these services out
|
43
|
+
using Storybook.
|
44
|
+
</li>
|
45
|
+
</ul>
|
46
|
+
<p>
|
47
|
+
Get a guided tutorial on component-driven development at{' '}
|
48
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
49
|
+
Storybook tutorials
|
50
|
+
</a>
|
51
|
+
. Read more in the{' '}
|
52
|
+
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
|
53
|
+
docs
|
54
|
+
</a>
|
55
|
+
.
|
56
|
+
</p>
|
57
|
+
<div className="tip-wrapper">
|
58
|
+
<span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
|
59
|
+
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
60
|
+
<g fill="none" fillRule="evenodd">
|
61
|
+
<path
|
62
|
+
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
63
|
+
id="a"
|
64
|
+
fill="#999"
|
65
|
+
/>
|
66
|
+
</g>
|
67
|
+
</svg>
|
68
|
+
Viewports addon in the toolbar
|
69
|
+
</div>
|
70
|
+
</section>
|
71
|
+
</article>
|
72
|
+
);
|
73
|
+
};
|