@storybook/nextjs 7.0.0-alpha.46 → 7.0.0-alpha.48

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/dist/preset.d.ts CHANGED
@@ -912,7 +912,6 @@ interface CoreCommon_StoryIndex {
912
912
  interface CoreCommon_StoryIndexer {
913
913
  test: RegExp;
914
914
  indexer: (fileName: string, options: CoreCommon_IndexerOptions) => Promise<CoreCommon_StoryIndex>;
915
- addDocsTemplate?: boolean;
916
915
  }
917
916
  /**
918
917
  * Options for TypeScript usage within Storybook.
@@ -973,9 +972,10 @@ declare type DocsOptions = {
973
972
  */
974
973
  defaultName?: string;
975
974
  /**
976
- * Should we generate a docs entry per CSF file?
975
+ * Should we generate a docs entry per CSF file with the `docsPage` tag?
976
+ * Set to 'automatic' to generate an entry irrespective of tag.
977
977
  */
978
- docsPage?: boolean;
978
+ docsPage?: boolean | 'automatic';
979
979
  /**
980
980
  * Only show doc entries in the side bar (usually set with the `--docs` CLI flag)
981
981
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/nextjs",
3
- "version": "7.0.0-alpha.46",
3
+ "version": "7.0.0-alpha.48",
4
4
  "description": "Storybook for Next.js",
5
5
  "keywords": [
6
6
  "storybook",
@@ -48,6 +48,7 @@
48
48
  "types": "dist/index.d.ts",
49
49
  "files": [
50
50
  "dist/**/*",
51
+ "template/**/*",
51
52
  "types/**/*",
52
53
  "README.md",
53
54
  "*.js",
@@ -59,12 +60,12 @@
59
60
  },
60
61
  "dependencies": {
61
62
  "@babel/preset-typescript": "^7.18.6",
62
- "@storybook/addons": "7.0.0-alpha.46",
63
- "@storybook/builder-webpack5": "7.0.0-alpha.46",
64
- "@storybook/core-common": "7.0.0-alpha.46",
65
- "@storybook/node-logger": "7.0.0-alpha.46",
66
- "@storybook/preset-react-webpack": "7.0.0-alpha.46",
67
- "@storybook/react": "7.0.0-alpha.46",
63
+ "@storybook/addons": "7.0.0-alpha.48",
64
+ "@storybook/builder-webpack5": "7.0.0-alpha.48",
65
+ "@storybook/core-common": "7.0.0-alpha.48",
66
+ "@storybook/node-logger": "7.0.0-alpha.48",
67
+ "@storybook/preset-react-webpack": "7.0.0-alpha.48",
68
+ "@storybook/react": "7.0.0-alpha.48",
68
69
  "@types/node": "^14.14.20 || ^16.0.0",
69
70
  "find-up": "^5.0.0",
70
71
  "fs-extra": "^9.0.1",
@@ -80,7 +81,7 @@
80
81
  "tsconfig-paths-webpack-plugin": "^3.5.2"
81
82
  },
82
83
  "devDependencies": {
83
- "@storybook/addon-actions": "7.0.0-alpha.46",
84
+ "@storybook/addon-actions": "7.0.0-alpha.48",
84
85
  "@types/loader-utils": "^2.0.3",
85
86
  "next": "^12.2.4",
86
87
  "typescript": "~4.6.3",
@@ -120,5 +121,5 @@
120
121
  ],
121
122
  "platform": "node"
122
123
  },
123
- "gitHead": "c64b5be851ed2affac56e1daaac3f453fbe6f230"
124
+ "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd"
124
125
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "rules": {
3
+ "import/no-extraneous-dependencies": "off",
4
+ "import/extensions": "off",
5
+ "react/no-unknown-property": "off"
6
+ }
7
+ }
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import './button.css';
4
+
5
+ /**
6
+ * Primary UI component for user interaction
7
+ */
8
+ export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
9
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
10
+ return (
11
+ <button
12
+ type="button"
13
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
14
+ {...props}
15
+ >
16
+ {label}
17
+ <style jsx>{`
18
+ button {
19
+ background-color: ${backgroundColor};
20
+ }
21
+ `}</style>
22
+ </button>
23
+ );
24
+ };
25
+
26
+ Button.propTypes = {
27
+ /**
28
+ * Is this the principal call to action on the page?
29
+ */
30
+ primary: PropTypes.bool,
31
+ /**
32
+ * What background color to use
33
+ */
34
+ backgroundColor: PropTypes.string,
35
+ /**
36
+ * How large should the button be?
37
+ */
38
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
39
+ /**
40
+ * Button contents
41
+ */
42
+ label: PropTypes.string.isRequired,
43
+ /**
44
+ * Optional click handler
45
+ */
46
+ onClick: PropTypes.func,
47
+ };
48
+
49
+ Button.defaultProps = {
50
+ backgroundColor: null,
51
+ primary: false,
52
+ size: 'medium',
53
+ onClick: undefined,
54
+ };
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+
3
+ import { Button } from './Button';
4
+
5
+ // More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
6
+ export default {
7
+ title: 'Example/Button',
8
+ component: Button,
9
+ // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/react/writing-docs/docs-page
10
+ tags: ['docsPage'],
11
+ // More on argTypes: https://storybook.js.org/docs/react/api/argtypes
12
+ argTypes: {
13
+ backgroundColor: { control: 'color' },
14
+ },
15
+ };
16
+
17
+ // More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
18
+ const Template = (args) => <Button {...args} />;
19
+
20
+ export const Primary = Template.bind({});
21
+ // More on args: https://storybook.js.org/docs/react/writing-stories/args
22
+ Primary.args = {
23
+ primary: true,
24
+ label: 'Button',
25
+ };
26
+
27
+ export const Secondary = Template.bind({});
28
+ Secondary.args = {
29
+ label: 'Button',
30
+ };
31
+
32
+ export const Large = Template.bind({});
33
+ Large.args = {
34
+ size: 'large',
35
+ label: 'Button',
36
+ };
37
+
38
+ export const Small = Template.bind({});
39
+ Small.args = {
40
+ size: 'small',
41
+ label: 'Button',
42
+ };
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import { Button } from './Button';
5
+ import './header.css';
6
+
7
+ export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
8
+ <header>
9
+ <div className="wrapper">
10
+ <div>
11
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
12
+ <g fill="none" fillRule="evenodd">
13
+ <path
14
+ d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
15
+ fill="#FFF"
16
+ />
17
+ <path
18
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
19
+ fill="#555AB9"
20
+ />
21
+ <path
22
+ d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
23
+ fill="#91BAF8"
24
+ />
25
+ </g>
26
+ </svg>
27
+ <h1>Acme</h1>
28
+ </div>
29
+ <div>
30
+ {user ? (
31
+ <>
32
+ <span className="welcome">
33
+ Welcome, <b>{user.name}</b>!
34
+ </span>
35
+ <Button size="small" onClick={onLogout} label="Log out" />
36
+ </>
37
+ ) : (
38
+ <>
39
+ <Button size="small" onClick={onLogin} label="Log in" />
40
+ <Button primary size="small" onClick={onCreateAccount} label="Sign up" />
41
+ </>
42
+ )}
43
+ </div>
44
+ </div>
45
+ </header>
46
+ );
47
+
48
+ Header.propTypes = {
49
+ user: PropTypes.shape({
50
+ name: PropTypes.string.isRequired,
51
+ }),
52
+ onLogin: PropTypes.func.isRequired,
53
+ onLogout: PropTypes.func.isRequired,
54
+ onCreateAccount: PropTypes.func.isRequired,
55
+ };
56
+
57
+ Header.defaultProps = {
58
+ user: null,
59
+ };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
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 docsPage entry: https://storybook.js.org/docs/react/writing-docs/docs-page
9
+ tags: ['docsPage'],
10
+ parameters: {
11
+ // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
12
+ layout: 'fullscreen',
13
+ },
14
+ };
15
+
16
+ const Template = (args) => <Header {...args} />;
17
+
18
+ export const LoggedIn = Template.bind({});
19
+ LoggedIn.args = {
20
+ user: {
21
+ name: 'Jane Doe',
22
+ },
23
+ };
24
+
25
+ export const LoggedOut = Template.bind({});
26
+ LoggedOut.args = {};
@@ -0,0 +1,228 @@
1
+ import { Meta } from '@storybook/addon-docs';
2
+ import Image from 'next/image';
3
+
4
+ import Code from './assets/code-brackets.svg';
5
+ import Colors from './assets/colors.svg';
6
+ import Comments from './assets/comments.svg';
7
+ import Direction from './assets/direction.svg';
8
+ import Flow from './assets/flow.svg';
9
+ import Plugin from './assets/plugin.svg';
10
+ import Repo from './assets/repo.svg';
11
+ import StackAlt from './assets/stackalt.svg';
12
+
13
+ <Meta title="Example/Introduction" />
14
+
15
+ <style>
16
+ {`
17
+ .subheading {
18
+ --mediumdark: '#999999';
19
+ font-weight: 900;
20
+ font-size: 13px;
21
+ color: #999;
22
+ letter-spacing: 6px;
23
+ line-height: 24px;
24
+ text-transform: uppercase;
25
+ margin-bottom: 12px;
26
+ margin-top: 40px;
27
+ }
28
+
29
+ .link-list {
30
+ display: grid;
31
+ grid-template-columns: 1fr;
32
+ grid-template-rows: 1fr 1fr;
33
+ row-gap: 10px;
34
+ }
35
+
36
+ @media (min-width: 620px) {
37
+ .link-list {
38
+ row-gap: 20px;
39
+ column-gap: 20px;
40
+ grid-template-columns: 1fr 1fr;
41
+ }
42
+ }
43
+
44
+ @media all and (-ms-high-contrast:none) {
45
+ .link-list {
46
+ display: -ms-grid;
47
+ -ms-grid-columns: 1fr 1fr;
48
+ -ms-grid-rows: 1fr 1fr;
49
+ }
50
+ }
51
+
52
+ .link-item {
53
+ display: block;
54
+ padding: 20px 30px 20px 15px;
55
+ border: 1px solid #00000010;
56
+ border-radius: 5px;
57
+ transition: background 150ms ease-out, border 150ms ease-out, transform 150ms ease-out;
58
+ color: #333333;
59
+ display: flex;
60
+ align-items: flex-start;
61
+ }
62
+
63
+ .link-item:hover {
64
+ border-color: #1EA7FD50;
65
+ transform: translate3d(0, -3px, 0);
66
+ box-shadow: rgba(0, 0, 0, 0.08) 0 3px 10px 0;
67
+ }
68
+
69
+ .link-item:active {
70
+ border-color: #1EA7FD;
71
+ transform: translate3d(0, 0, 0);
72
+ }
73
+
74
+ .link-item strong {
75
+ font-weight: 700;
76
+ display: block;
77
+ margin-bottom: 2px;
78
+ }
79
+
80
+ .link-item-img-wrapper {
81
+ height: 40px;
82
+ width: 40px;
83
+ margin-right: 15px;
84
+ flex: none;
85
+ }
86
+
87
+ .link-item span {
88
+ font-size: 14px;
89
+ line-height: 20px;
90
+ }
91
+
92
+ .tip {
93
+ display: inline-block;
94
+ border-radius: 1em;
95
+ font-size: 11px;
96
+ line-height: 12px;
97
+ font-weight: 700;
98
+ background: #E7FDD8;
99
+ color: #66BF3C;
100
+ padding: 4px 12px;
101
+ margin-right: 10px;
102
+ vertical-align: top;
103
+ }
104
+
105
+ .tip-wrapper {
106
+ font-size: 13px;
107
+ line-height: 20px;
108
+ margin-top: 40px;
109
+ margin-bottom: 40px;
110
+ }
111
+
112
+ .tip-wrapper code {
113
+ font-size: 12px;
114
+ display: inline-block;
115
+ }
116
+ `}
117
+ </style>
118
+
119
+ # Welcome to Storybook
120
+
121
+ Storybook helps you build UI components in isolation from your app's business logic, data, and context.
122
+ That makes it easy to develop hard-to-reach states. Save these UI states as **stories** to revisit during development, testing, or QA.
123
+
124
+ Browse example stories now by navigating to them in the sidebar.
125
+ View their code in the `stories` directory to learn how they work.
126
+ We recommend building UIs with a [**component-driven**](https://componentdriven.org) process starting with atomic components and ending with pages.
127
+
128
+ <div className="subheading">Configure</div>
129
+
130
+ <div className="link-list">
131
+ <a
132
+ className="link-item"
133
+ href="https://storybook.js.org/docs/react/addons/addon-types"
134
+ target="_blank"
135
+ >
136
+ <div className="link-item-img-wrapper">
137
+ <Image src={Plugin} alt="plugin" />
138
+ </div>
139
+ <span>
140
+ <strong>Presets for popular tools</strong>
141
+ Easy setup for TypeScript, SCSS and more.
142
+ </span>
143
+ </a>
144
+ <a
145
+ className="link-item"
146
+ href="https://storybook.js.org/docs/react/configure/webpack"
147
+ target="_blank"
148
+ >
149
+ <div className="link-item-img-wrapper">
150
+ <Image src={StackAlt} alt="Build" />
151
+ </div>
152
+ <span>
153
+ <strong>Build configuration</strong>
154
+ How to customize webpack and Babel
155
+ </span>
156
+ </a>
157
+ <a
158
+ className="link-item"
159
+ href="https://storybook.js.org/docs/react/configure/styling-and-css"
160
+ target="_blank"
161
+ >
162
+ <div className="link-item-img-wrapper">
163
+ <Image src={Colors} alt="colors" />
164
+ </div>
165
+ <span>
166
+ <strong>Styling</strong>
167
+ How to load and configure CSS libraries
168
+ </span>
169
+ </a>
170
+ <a
171
+ className="link-item"
172
+ href="https://storybook.js.org/docs/react/get-started/setup#configure-storybook-for-your-stack"
173
+ target="_blank"
174
+ >
175
+ <div className="link-item-img-wrapper">
176
+ <Image src={Flow} alt="flow" />
177
+ </div>
178
+ <span>
179
+ <strong>Data</strong>
180
+ Providers and mocking for data libraries
181
+ </span>
182
+ </a>
183
+ </div>
184
+
185
+ <div className="subheading">Learn</div>
186
+
187
+ <div className="link-list">
188
+ <a className="link-item" href="https://storybook.js.org/docs" target="_blank">
189
+ <div className="link-item-img-wrapper">
190
+ <Image src={Repo} alt="repo" />
191
+ </div>
192
+ <span>
193
+ <strong>Storybook documentation</strong>
194
+ Configure, customize, and extend
195
+ </span>
196
+ </a>
197
+ <a className="link-item" href="https://storybook.js.org/tutorials/" target="_blank">
198
+ <div className="link-item-img-wrapper">
199
+ <Image src={Direction} alt="direction" />
200
+ </div>
201
+ <span>
202
+ <strong>In-depth guides</strong>
203
+ Best practices from leading teams
204
+ </span>
205
+ </a>
206
+ <a className="link-item" href="https://github.com/storybookjs/storybook" target="_blank">
207
+ <div className="link-item-img-wrapper">
208
+ <Image src={Code} alt="code" />
209
+ </div>
210
+ <span>
211
+ <strong>GitHub project</strong>
212
+ View the source and add issues
213
+ </span>
214
+ </a>
215
+ <a className="link-item" href="https://discord.gg/storybook" target="_blank">
216
+ <div className="link-item-img-wrapper">
217
+ <Image src={Comments} alt="comments" />
218
+ </div>
219
+ <span>
220
+ <strong>Discord chat</strong>
221
+ Chat with maintainers and the community
222
+ </span>
223
+ </a>
224
+ </div>
225
+
226
+ <div className="tip-wrapper">
227
+ <span className="tip">Tip</span>Edit the Markdown in <code>stories/Introduction.stories.mdx</code>
228
+ </div>
@@ -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>
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,25 @@
1
+ import React from 'react';
2
+ import { within, userEvent } from '@storybook/testing-library';
3
+
4
+ import { Page } from './Page';
5
+
6
+ export default {
7
+ title: 'Example/Page',
8
+ component: Page,
9
+ parameters: {
10
+ // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ };
14
+
15
+ const Template = (args) => <Page {...args} />;
16
+
17
+ // More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing
18
+ export const LoggedOut = Template.bind({});
19
+
20
+ export const LoggedIn = Template.bind({});
21
+ LoggedIn.play = async ({ canvasElement }) => {
22
+ const canvas = within(canvasElement);
23
+ const loginButton = await canvas.getByRole('button', { name: /Log in/i });
24
+ await userEvent.click(loginButton);
25
+ };
@@ -0,0 +1,48 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+
3
+ import { Button } from './Button';
4
+
5
+ // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
6
+ const meta: Meta<typeof Button> = {
7
+ title: 'Example/Button',
8
+ component: Button,
9
+ // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/react/writing-docs/docs-page
10
+ tags: ['docsPage'],
11
+ // More on argTypes: https://storybook.js.org/docs/react/api/argtypes
12
+ argTypes: {
13
+ backgroundColor: {
14
+ control: 'color',
15
+ },
16
+ },
17
+ };
18
+
19
+ export default meta;
20
+ type Story = StoryObj<typeof Button>;
21
+
22
+ // More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
23
+ export const Primary: Story = {
24
+ args: {
25
+ primary: true,
26
+ label: 'Button',
27
+ },
28
+ };
29
+
30
+ export const Secondary: Story = {
31
+ args: {
32
+ label: 'Button',
33
+ },
34
+ };
35
+
36
+ export const Large: Story = {
37
+ args: {
38
+ size: 'large',
39
+ label: 'Button',
40
+ },
41
+ };
42
+
43
+ export const Small: Story = {
44
+ args: {
45
+ size: 'small',
46
+ label: 'Button',
47
+ },
48
+ };
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import './button.css';
3
+
4
+ interface ButtonProps {
5
+ /**
6
+ * Is this the principal call to action on the page?
7
+ */
8
+ primary?: boolean;
9
+ /**
10
+ * What background color to use
11
+ */
12
+ backgroundColor?: string;
13
+ /**
14
+ * How large should the button be?
15
+ */
16
+ size?: 'small' | 'medium' | 'large';
17
+ /**
18
+ * Button contents
19
+ */
20
+ label: string;
21
+ /**
22
+ * Optional click handler
23
+ */
24
+ onClick?: () => void;
25
+ }
26
+
27
+ /**
28
+ * Primary UI component for user interaction
29
+ */
30
+ export const Button = ({
31
+ primary = false,
32
+ size = 'medium',
33
+ backgroundColor,
34
+ label,
35
+ ...props
36
+ }: ButtonProps) => {
37
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
38
+ return (
39
+ <button
40
+ type="button"
41
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
42
+ {...props}
43
+ >
44
+ {label}
45
+ <style jsx>{`
46
+ button {
47
+ background-color: ${backgroundColor};
48
+ }
49
+ `}</style>
50
+ </button>
51
+ );
52
+ };
@@ -0,0 +1,26 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Header } from './Header';
3
+
4
+ const meta: Meta<typeof Header> = {
5
+ title: 'Example/Header',
6
+ component: Header,
7
+ // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/react/writing-docs/docs-page
8
+ tags: ['docsPage'],
9
+ parameters: {
10
+ // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ };
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof Header>;
17
+
18
+ export const LoggedIn: Story = {
19
+ args: {
20
+ user: {
21
+ name: 'Jane Doe',
22
+ },
23
+ },
24
+ };
25
+
26
+ export const LoggedOut: Story = {};
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+
3
+ import { Button } from './Button';
4
+ import './header.css';
5
+
6
+ type User = {
7
+ name: string;
8
+ };
9
+
10
+ interface HeaderProps {
11
+ user?: User;
12
+ onLogin: () => void;
13
+ onLogout: () => void;
14
+ onCreateAccount: () => void;
15
+ }
16
+
17
+ export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
18
+ <header>
19
+ <div className="wrapper">
20
+ <div>
21
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
22
+ <g fill="none" fillRule="evenodd">
23
+ <path
24
+ d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
25
+ fill="#FFF"
26
+ />
27
+ <path
28
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
29
+ fill="#555AB9"
30
+ />
31
+ <path
32
+ d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
33
+ fill="#91BAF8"
34
+ />
35
+ </g>
36
+ </svg>
37
+ <h1>Acme</h1>
38
+ </div>
39
+ <div>
40
+ {user ? (
41
+ <>
42
+ <span className="welcome">
43
+ Welcome, <b>{user.name}</b>!
44
+ </span>
45
+ <Button size="small" onClick={onLogout} label="Log out" />
46
+ </>
47
+ ) : (
48
+ <>
49
+ <Button size="small" onClick={onLogin} label="Log in" />
50
+ <Button primary size="small" onClick={onCreateAccount} label="Sign up" />
51
+ </>
52
+ )}
53
+ </div>
54
+ </div>
55
+ </header>
56
+ );
@@ -0,0 +1,228 @@
1
+ import { Meta } from '@storybook/addon-docs';
2
+ import Image from 'next/image';
3
+
4
+ import Code from './assets/code-brackets.svg';
5
+ import Colors from './assets/colors.svg';
6
+ import Comments from './assets/comments.svg';
7
+ import Direction from './assets/direction.svg';
8
+ import Flow from './assets/flow.svg';
9
+ import Plugin from './assets/plugin.svg';
10
+ import Repo from './assets/repo.svg';
11
+ import StackAlt from './assets/stackalt.svg';
12
+
13
+ <Meta title="Example/Introduction" />
14
+
15
+ <style>
16
+ {`
17
+ .subheading {
18
+ --mediumdark: '#999999';
19
+ font-weight: 900;
20
+ font-size: 13px;
21
+ color: #999;
22
+ letter-spacing: 6px;
23
+ line-height: 24px;
24
+ text-transform: uppercase;
25
+ margin-bottom: 12px;
26
+ margin-top: 40px;
27
+ }
28
+
29
+ .link-list {
30
+ display: grid;
31
+ grid-template-columns: 1fr;
32
+ grid-template-rows: 1fr 1fr;
33
+ row-gap: 10px;
34
+ }
35
+
36
+ @media (min-width: 620px) {
37
+ .link-list {
38
+ row-gap: 20px;
39
+ column-gap: 20px;
40
+ grid-template-columns: 1fr 1fr;
41
+ }
42
+ }
43
+
44
+ @media all and (-ms-high-contrast:none) {
45
+ .link-list {
46
+ display: -ms-grid;
47
+ -ms-grid-columns: 1fr 1fr;
48
+ -ms-grid-rows: 1fr 1fr;
49
+ }
50
+ }
51
+
52
+ .link-item {
53
+ display: block;
54
+ padding: 20px 30px 20px 15px;
55
+ border: 1px solid #00000010;
56
+ border-radius: 5px;
57
+ transition: background 150ms ease-out, border 150ms ease-out, transform 150ms ease-out;
58
+ color: #333333;
59
+ display: flex;
60
+ align-items: flex-start;
61
+ }
62
+
63
+ .link-item:hover {
64
+ border-color: #1EA7FD50;
65
+ transform: translate3d(0, -3px, 0);
66
+ box-shadow: rgba(0, 0, 0, 0.08) 0 3px 10px 0;
67
+ }
68
+
69
+ .link-item:active {
70
+ border-color: #1EA7FD;
71
+ transform: translate3d(0, 0, 0);
72
+ }
73
+
74
+ .link-item strong {
75
+ font-weight: 700;
76
+ display: block;
77
+ margin-bottom: 2px;
78
+ }
79
+
80
+ .link-item-img-wrapper {
81
+ height: 40px;
82
+ width: 40px;
83
+ margin-right: 15px;
84
+ flex: none;
85
+ }
86
+
87
+ .link-item span {
88
+ font-size: 14px;
89
+ line-height: 20px;
90
+ }
91
+
92
+ .tip {
93
+ display: inline-block;
94
+ border-radius: 1em;
95
+ font-size: 11px;
96
+ line-height: 12px;
97
+ font-weight: 700;
98
+ background: #E7FDD8;
99
+ color: #66BF3C;
100
+ padding: 4px 12px;
101
+ margin-right: 10px;
102
+ vertical-align: top;
103
+ }
104
+
105
+ .tip-wrapper {
106
+ font-size: 13px;
107
+ line-height: 20px;
108
+ margin-top: 40px;
109
+ margin-bottom: 40px;
110
+ }
111
+
112
+ .tip-wrapper code {
113
+ font-size: 12px;
114
+ display: inline-block;
115
+ }
116
+ `}
117
+ </style>
118
+
119
+ # Welcome to Storybook
120
+
121
+ Storybook helps you build UI components in isolation from your app's business logic, data, and context.
122
+ That makes it easy to develop hard-to-reach states. Save these UI states as **stories** to revisit during development, testing, or QA.
123
+
124
+ Browse example stories now by navigating to them in the sidebar.
125
+ View their code in the `stories` directory to learn how they work.
126
+ We recommend building UIs with a [**component-driven**](https://componentdriven.org) process starting with atomic components and ending with pages.
127
+
128
+ <div className="subheading">Configure</div>
129
+
130
+ <div className="link-list">
131
+ <a
132
+ className="link-item"
133
+ href="https://storybook.js.org/docs/react/addons/addon-types"
134
+ target="_blank"
135
+ >
136
+ <div className="link-item-img-wrapper">
137
+ <Image src={Plugin} alt="plugin" />
138
+ </div>
139
+ <span>
140
+ <strong>Presets for popular tools</strong>
141
+ Easy setup for TypeScript, SCSS and more.
142
+ </span>
143
+ </a>
144
+ <a
145
+ className="link-item"
146
+ href="https://storybook.js.org/docs/react/configure/webpack"
147
+ target="_blank"
148
+ >
149
+ <div className="link-item-img-wrapper">
150
+ <Image src={StackAlt} alt="Build" />
151
+ </div>
152
+ <span>
153
+ <strong>Build configuration</strong>
154
+ How to customize webpack and Babel
155
+ </span>
156
+ </a>
157
+ <a
158
+ className="link-item"
159
+ href="https://storybook.js.org/docs/react/configure/styling-and-css"
160
+ target="_blank"
161
+ >
162
+ <div className="link-item-img-wrapper">
163
+ <Image src={Colors} alt="colors" />
164
+ </div>
165
+ <span>
166
+ <strong>Styling</strong>
167
+ How to load and configure CSS libraries
168
+ </span>
169
+ </a>
170
+ <a
171
+ className="link-item"
172
+ href="https://storybook.js.org/docs/react/get-started/setup#configure-storybook-for-your-stack"
173
+ target="_blank"
174
+ >
175
+ <div className="link-item-img-wrapper">
176
+ <Image src={Flow} alt="flow" />
177
+ </div>
178
+ <span>
179
+ <strong>Data</strong>
180
+ Providers and mocking for data libraries
181
+ </span>
182
+ </a>
183
+ </div>
184
+
185
+ <div className="subheading">Learn</div>
186
+
187
+ <div className="link-list">
188
+ <a className="link-item" href="https://storybook.js.org/docs" target="_blank">
189
+ <div className="link-item-img-wrapper">
190
+ <Image src={Repo} alt="repo" />
191
+ </div>
192
+ <span>
193
+ <strong>Storybook documentation</strong>
194
+ Configure, customize, and extend
195
+ </span>
196
+ </a>
197
+ <a className="link-item" href="https://storybook.js.org/tutorials/" target="_blank">
198
+ <div className="link-item-img-wrapper">
199
+ <Image src={Direction} alt="direction" />
200
+ </div>
201
+ <span>
202
+ <strong>In-depth guides</strong>
203
+ Best practices from leading teams
204
+ </span>
205
+ </a>
206
+ <a className="link-item" href="https://github.com/storybookjs/storybook" target="_blank">
207
+ <div className="link-item-img-wrapper">
208
+ <Image src={Code} alt="code" />
209
+ </div>
210
+ <span>
211
+ <strong>GitHub project</strong>
212
+ View the source and add issues
213
+ </span>
214
+ </a>
215
+ <a className="link-item" href="https://discord.gg/storybook" target="_blank">
216
+ <div className="link-item-img-wrapper">
217
+ <Image src={Comments} alt="comments" />
218
+ </div>
219
+ <span>
220
+ <strong>Discord chat</strong>
221
+ Chat with maintainers and the community
222
+ </span>
223
+ </a>
224
+ </div>
225
+
226
+ <div className="tip-wrapper">
227
+ <span className="tip">Tip</span>Edit the Markdown in <code>stories/Introduction.stories.mdx</code>
228
+ </div>
@@ -0,0 +1,29 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { within, userEvent } from '@storybook/testing-library';
3
+
4
+ import { Page } from './Page';
5
+
6
+ const meta: Meta<typeof Page> = {
7
+ title: 'Example/Page',
8
+ component: Page,
9
+ parameters: {
10
+ // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ };
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof Page>;
17
+
18
+ export const LoggedOut: Story = {};
19
+
20
+ // More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing
21
+ export const LoggedIn: Story = {
22
+ play: async ({ canvasElement }) => {
23
+ const canvas = within(canvasElement);
24
+ const loginButton = await canvas.getByRole('button', {
25
+ name: /Log in/i,
26
+ });
27
+ await userEvent.click(loginButton);
28
+ },
29
+ };
@@ -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.VFC = () => {
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>
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
+ };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import Image from 'next/image';
3
+ // eslint-disable-next-line import/extensions
4
+ import StackAlt from '../../assets/colors.svg';
5
+
6
+ const Component = () => <Image src={StackAlt} placeholder="blur" />;
7
+
8
+ export default {
9
+ component: Component,
10
+ };
11
+
12
+ export const Default = {};
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import Link from 'next/link';
3
+
4
+ const Component = () => (
5
+ <ul>
6
+ <li>
7
+ <Link href="/">
8
+ <a>Home</a>
9
+ </Link>
10
+ </li>
11
+ <li>
12
+ <Link href="/about">
13
+ <a>About Us</a>
14
+ </Link>
15
+ </li>
16
+ <li>
17
+ <Link href="/blog/hello-world">
18
+ <a>Blog Post</a>
19
+ </Link>
20
+ </li>
21
+ </ul>
22
+ );
23
+
24
+ export default {
25
+ component: Component,
26
+ };
27
+
28
+ export const Default = {};
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ const Component = () => (
4
+ <div>
5
+ <style jsx>{`
6
+ .main p {
7
+ color: #ff4785;
8
+ }
9
+ `}</style>
10
+ <main className="main">
11
+ <p>This is styled using Styled JSX</p>
12
+ </main>
13
+ </div>
14
+ );
15
+
16
+ export default {
17
+ component: Component,
18
+ };
19
+
20
+ export const Default = {};