@storybook/experimental-nextjs-vite 8.3.0-alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -0
- package/dist/chunk-4N4PSHX6.mjs +3 -0
- package/dist/chunk-DWCMLBIB.mjs +20 -0
- package/dist/chunk-GKRSUUNG.mjs +6 -0
- package/dist/export-mocks/cache/index.d.ts +14 -0
- package/dist/export-mocks/cache/index.js +1 -0
- package/dist/export-mocks/cache/index.mjs +6 -0
- package/dist/export-mocks/headers/index.d.ts +36 -0
- package/dist/export-mocks/headers/index.js +1 -0
- package/dist/export-mocks/headers/index.mjs +10 -0
- package/dist/export-mocks/navigation/index.d.ts +42 -0
- package/dist/export-mocks/navigation/index.js +1 -0
- package/dist/export-mocks/navigation/index.mjs +11 -0
- package/dist/export-mocks/router/index.d.ts +46 -0
- package/dist/export-mocks/router/index.js +1 -0
- package/dist/export-mocks/router/index.mjs +10 -0
- package/dist/images/decorator.d.ts +6 -0
- package/dist/images/decorator.js +1 -0
- package/dist/images/decorator.mjs +2 -0
- package/dist/index.d-5a935e77.d.ts +266 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +11 -0
- package/dist/preset.d.ts +8 -0
- package/dist/preset.js +1 -0
- package/dist/preview.d.ts +18 -0
- package/dist/preview.js +1 -0
- package/dist/preview.mjs +3 -0
- package/dist/react-18-7IRF6A5G.mjs +7 -0
- package/package.json +143 -0
- package/preset.js +1 -0
- package/template/cli/.eslintrc.json +7 -0
- package/template/cli/js/Button.jsx +56 -0
- package/template/cli/js/Button.stories.js +49 -0
- package/template/cli/js/Configure.mdx +446 -0
- package/template/cli/js/Header.jsx +60 -0
- package/template/cli/js/Header.stories.js +30 -0
- package/template/cli/js/Page.jsx +68 -0
- package/template/cli/js/Page.stories.js +28 -0
- package/template/cli/ts-3-8/Button.stories.ts +53 -0
- package/template/cli/ts-3-8/Button.tsx +53 -0
- package/template/cli/ts-3-8/Configure.mdx +446 -0
- package/template/cli/ts-3-8/Header.stories.ts +33 -0
- package/template/cli/ts-3-8/Header.tsx +56 -0
- package/template/cli/ts-3-8/Page.stories.ts +32 -0
- package/template/cli/ts-3-8/Page.tsx +73 -0
- package/template/cli/ts-4-9/Button.stories.ts +53 -0
- package/template/cli/ts-4-9/Button.tsx +53 -0
- package/template/cli/ts-4-9/Configure.mdx +446 -0
- package/template/cli/ts-4-9/Header.stories.ts +33 -0
- package/template/cli/ts-4-9/Header.tsx +56 -0
- package/template/cli/ts-4-9/Page.stories.ts +32 -0
- package/template/cli/ts-4-9/Page.tsx +73 -0
- package/template/next-env.d.ts +7 -0
- package/template/typings.d.ts +14 -0
@@ -0,0 +1,446 @@
|
|
1
|
+
import { Meta } from "@storybook/blocks";
|
2
|
+
import Image from "next/image";
|
3
|
+
|
4
|
+
import Github from "./assets/github.svg";
|
5
|
+
import Discord from "./assets/discord.svg";
|
6
|
+
import Youtube from "./assets/youtube.svg";
|
7
|
+
import Tutorials from "./assets/tutorials.svg";
|
8
|
+
import Styling from "./assets/styling.png";
|
9
|
+
import Context from "./assets/context.png";
|
10
|
+
import Assets from "./assets/assets.png";
|
11
|
+
import Docs from "./assets/docs.png";
|
12
|
+
import Share from "./assets/share.png";
|
13
|
+
import FigmaPlugin from "./assets/figma-plugin.png";
|
14
|
+
import Testing from "./assets/testing.png";
|
15
|
+
import Accessibility from "./assets/accessibility.png";
|
16
|
+
import Theming from "./assets/theming.png";
|
17
|
+
import AddonLibrary from "./assets/addon-library.png";
|
18
|
+
|
19
|
+
export const RightArrow = () => <svg
|
20
|
+
viewBox="0 0 14 14"
|
21
|
+
width="8px"
|
22
|
+
height="14px"
|
23
|
+
style={{
|
24
|
+
marginLeft: '4px',
|
25
|
+
display: 'inline-block',
|
26
|
+
shapeRendering: 'inherit',
|
27
|
+
verticalAlign: 'middle',
|
28
|
+
fill: 'currentColor',
|
29
|
+
'path fill': 'currentColor'
|
30
|
+
}}
|
31
|
+
>
|
32
|
+
<path d="m11.1 7.35-5.5 5.5a.5.5 0 0 1-.7-.7L10.04 7 4.9 1.85a.5.5 0 1 1 .7-.7l5.5 5.5c.2.2.2.5 0 .7Z" />
|
33
|
+
</svg>
|
34
|
+
|
35
|
+
<Meta title="Configure your project" />
|
36
|
+
|
37
|
+
<div className="sb-container">
|
38
|
+
<div className='sb-section-title'>
|
39
|
+
# Configure your project
|
40
|
+
|
41
|
+
Because Storybook works separately from your app, you'll need to configure it for your specific stack and setup. Below, explore guides for configuring Storybook with popular frameworks and tools. If you get stuck, learn how you can ask for help from our community.
|
42
|
+
</div>
|
43
|
+
<div className="sb-section">
|
44
|
+
<div className="sb-section-item">
|
45
|
+
<Image
|
46
|
+
src={Styling}
|
47
|
+
alt="A wall of logos representing different styling technologies"
|
48
|
+
width={0}
|
49
|
+
height={0}
|
50
|
+
style={{ width: '100%', height: 'auto' }}
|
51
|
+
/>
|
52
|
+
<h4 className="sb-section-item-heading">Add styling and CSS</h4>
|
53
|
+
<p className="sb-section-item-paragraph">Like with web applications, there are many ways to include CSS within Storybook. Learn more about setting up styling within Storybook.</p>
|
54
|
+
<a
|
55
|
+
href="https://storybook.js.org/docs/configure/styling-and-css/?renderer=react"
|
56
|
+
target="_blank"
|
57
|
+
>Learn more<RightArrow /></a>
|
58
|
+
</div>
|
59
|
+
<div className="sb-section-item">
|
60
|
+
<Image
|
61
|
+
width={0}
|
62
|
+
height={0}
|
63
|
+
style={{ width: '100%', height: 'auto' }}
|
64
|
+
src={Context}
|
65
|
+
alt="An abstraction representing the composition of data for a component"
|
66
|
+
/>
|
67
|
+
<h4 className="sb-section-item-heading">Provide context and mocking</h4>
|
68
|
+
<p className="sb-section-item-paragraph">Often when a story doesn't render, it's because your component is expecting a specific environment or context (like a theme provider) to be available.</p>
|
69
|
+
<a
|
70
|
+
href="https://storybook.js.org/docs/writing-stories/decorators/?renderer=react#context-for-mocking"
|
71
|
+
target="_blank"
|
72
|
+
>Learn more<RightArrow /></a>
|
73
|
+
</div>
|
74
|
+
<div className="sb-section-item">
|
75
|
+
<Image
|
76
|
+
width={0}
|
77
|
+
height={0}
|
78
|
+
style={{ width: '100%', height: 'auto' }}
|
79
|
+
src={Assets}
|
80
|
+
alt="A representation of typography and image assets"
|
81
|
+
/>
|
82
|
+
<div>
|
83
|
+
<h4 className="sb-section-item-heading">Load assets and resources</h4>
|
84
|
+
<p className="sb-section-item-paragraph">To link static files (like fonts) to your projects and stories, use the
|
85
|
+
`staticDirs` configuration option to specify folders to load when
|
86
|
+
starting Storybook.</p>
|
87
|
+
<a
|
88
|
+
href="https://storybook.js.org/docs/configure/images-and-assets/?renderer=react"
|
89
|
+
target="_blank"
|
90
|
+
>Learn more<RightArrow /></a>
|
91
|
+
</div>
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
<div className="sb-container">
|
96
|
+
<div className='sb-section-title'>
|
97
|
+
# Do more with Storybook
|
98
|
+
|
99
|
+
Now that you know the basics, let's explore other parts of Storybook that will improve your experience. This list is just to get you started. You can customise Storybook in many ways to fit your needs.
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<div className="sb-section">
|
103
|
+
<div className="sb-features-grid">
|
104
|
+
<div className="sb-grid-item">
|
105
|
+
<Image
|
106
|
+
width={0}
|
107
|
+
height={0}
|
108
|
+
style={{ width: '100%', height: 'auto' }}
|
109
|
+
src={Docs}
|
110
|
+
alt="A screenshot showing the autodocs tag being set, pointing a docs page being generated"
|
111
|
+
/>
|
112
|
+
<h4 className="sb-section-item-heading">Autodocs</h4>
|
113
|
+
<p className="sb-section-item-paragraph">Auto-generate living,
|
114
|
+
interactive reference documentation from your components and stories.</p>
|
115
|
+
<a
|
116
|
+
href="https://storybook.js.org/docs/writing-docs/autodocs/?renderer=react"
|
117
|
+
target="_blank"
|
118
|
+
>Learn more<RightArrow /></a>
|
119
|
+
</div>
|
120
|
+
<div className="sb-grid-item">
|
121
|
+
<Image
|
122
|
+
width={0}
|
123
|
+
height={0}
|
124
|
+
style={{ width: '100%', height: 'auto' }}
|
125
|
+
src={Share}
|
126
|
+
alt="A browser window showing a Storybook being published to a chromatic.com URL"
|
127
|
+
/>
|
128
|
+
<h4 className="sb-section-item-heading">Publish to Chromatic</h4>
|
129
|
+
<p className="sb-section-item-paragraph">Publish your Storybook to review and collaborate with your entire team.</p>
|
130
|
+
<a
|
131
|
+
href="https://storybook.js.org/docs/sharing/publish-storybook/?renderer=react#publish-storybook-with-chromatic"
|
132
|
+
target="_blank"
|
133
|
+
>Learn more<RightArrow /></a>
|
134
|
+
</div>
|
135
|
+
<div className="sb-grid-item">
|
136
|
+
<Image
|
137
|
+
width={0}
|
138
|
+
height={0}
|
139
|
+
style={{ width: '100%', height: 'auto' }}
|
140
|
+
src={FigmaPlugin}
|
141
|
+
alt="Windows showing the Storybook plugin in Figma"
|
142
|
+
/>
|
143
|
+
<h4 className="sb-section-item-heading">Figma Plugin</h4>
|
144
|
+
<p className="sb-section-item-paragraph">Embed your stories into Figma to cross-reference the design and live
|
145
|
+
implementation in one place.</p>
|
146
|
+
<a
|
147
|
+
href="https://storybook.js.org/docs/sharing/design-integrations/?renderer=react#embed-storybook-in-figma-with-the-plugin"
|
148
|
+
target="_blank"
|
149
|
+
>Learn more<RightArrow /></a>
|
150
|
+
</div>
|
151
|
+
<div className="sb-grid-item">
|
152
|
+
<Image
|
153
|
+
width={0}
|
154
|
+
height={0}
|
155
|
+
style={{ width: '100%', height: 'auto' }}
|
156
|
+
src={Testing}
|
157
|
+
alt="Screenshot of tests passing and failing"
|
158
|
+
/>
|
159
|
+
<h4 className="sb-section-item-heading">Testing</h4>
|
160
|
+
<p className="sb-section-item-paragraph">Use stories to test a component in all its variations, no matter how
|
161
|
+
complex.</p>
|
162
|
+
<a
|
163
|
+
href="https://storybook.js.org/docs/writing-tests/?renderer=react"
|
164
|
+
target="_blank"
|
165
|
+
>Learn more<RightArrow /></a>
|
166
|
+
</div>
|
167
|
+
<div className="sb-grid-item">
|
168
|
+
<Image
|
169
|
+
width={0}
|
170
|
+
height={0}
|
171
|
+
style={{ width: '100%', height: 'auto' }}
|
172
|
+
src={Accessibility}
|
173
|
+
alt="Screenshot of accessibility tests passing and failing"
|
174
|
+
/>
|
175
|
+
<h4 className="sb-section-item-heading">Accessibility</h4>
|
176
|
+
<p className="sb-section-item-paragraph">Automatically test your components for a11y issues as you develop.</p>
|
177
|
+
<a
|
178
|
+
href="https://storybook.js.org/docs/writing-tests/accessibility-testing/?renderer=react"
|
179
|
+
target="_blank"
|
180
|
+
>Learn more<RightArrow /></a>
|
181
|
+
</div>
|
182
|
+
<div className="sb-grid-item">
|
183
|
+
<Image
|
184
|
+
width={0}
|
185
|
+
height={0}
|
186
|
+
style={{ width: '100%', height: 'auto' }}
|
187
|
+
src={Theming}
|
188
|
+
alt="Screenshot of Storybook in light and dark mode"
|
189
|
+
/>
|
190
|
+
<h4 className="sb-section-item-heading">Theming</h4>
|
191
|
+
<p className="sb-section-item-paragraph">Theme Storybook's UI to personalize it to your project.</p>
|
192
|
+
<a
|
193
|
+
href="https://storybook.js.org/docs/configure/theming/?renderer=react"
|
194
|
+
target="_blank"
|
195
|
+
>Learn more<RightArrow /></a>
|
196
|
+
</div>
|
197
|
+
</div>
|
198
|
+
</div>
|
199
|
+
</div>
|
200
|
+
<div className='sb-addon'>
|
201
|
+
<div className='sb-addon-text'>
|
202
|
+
<h4>Addons</h4>
|
203
|
+
<p className="sb-section-item-paragraph">Integrate your tools with Storybook to connect workflows.</p>
|
204
|
+
<a
|
205
|
+
href="https://storybook.js.org/addons/"
|
206
|
+
target="_blank"
|
207
|
+
>Discover all addons<RightArrow /></a>
|
208
|
+
</div>
|
209
|
+
<div className='sb-addon-img'>
|
210
|
+
<Image
|
211
|
+
width={650}
|
212
|
+
height={347}
|
213
|
+
src={AddonLibrary}
|
214
|
+
alt="Integrate your tools with Storybook to connect workflows."
|
215
|
+
/>
|
216
|
+
</div>
|
217
|
+
</div>
|
218
|
+
|
219
|
+
<div className="sb-section sb-socials">
|
220
|
+
<div className="sb-section-item">
|
221
|
+
<Image
|
222
|
+
width={32}
|
223
|
+
height={32}
|
224
|
+
layout="fixed"
|
225
|
+
src={Github}
|
226
|
+
alt="Github logo"
|
227
|
+
className="sb-explore-image"
|
228
|
+
/>
|
229
|
+
Join our contributors building the future of UI development.
|
230
|
+
|
231
|
+
<a
|
232
|
+
href="https://github.com/storybookjs/storybook"
|
233
|
+
target="_blank"
|
234
|
+
>Star on GitHub<RightArrow /></a>
|
235
|
+
</div>
|
236
|
+
<div className="sb-section-item">
|
237
|
+
<Image
|
238
|
+
width={33}
|
239
|
+
height={32}
|
240
|
+
layout="fixed"
|
241
|
+
src={Discord}
|
242
|
+
alt="Discord logo"
|
243
|
+
className="sb-explore-image"
|
244
|
+
/>
|
245
|
+
<div>
|
246
|
+
Get support and chat with frontend developers.
|
247
|
+
|
248
|
+
<a
|
249
|
+
href="https://discord.gg/storybook"
|
250
|
+
target="_blank"
|
251
|
+
>Join Discord server<RightArrow /></a>
|
252
|
+
</div>
|
253
|
+
</div>
|
254
|
+
<div className="sb-section-item">
|
255
|
+
<Image
|
256
|
+
width={32}
|
257
|
+
height={32}
|
258
|
+
layout="fixed"
|
259
|
+
src={Youtube}
|
260
|
+
alt="Youtube logo"
|
261
|
+
className="sb-explore-image"
|
262
|
+
/>
|
263
|
+
<div>
|
264
|
+
Watch tutorials, feature previews and interviews.
|
265
|
+
|
266
|
+
<a
|
267
|
+
href="https://www.youtube.com/@chromaticui"
|
268
|
+
target="_blank"
|
269
|
+
>Watch on YouTube<RightArrow /></a>
|
270
|
+
</div>
|
271
|
+
</div>
|
272
|
+
<div className="sb-section-item">
|
273
|
+
<Image
|
274
|
+
width={33}
|
275
|
+
height={32}
|
276
|
+
layout="fixed"
|
277
|
+
src={Tutorials}
|
278
|
+
alt="A book"
|
279
|
+
className="sb-explore-image"
|
280
|
+
/>
|
281
|
+
<p>Follow guided walkthroughs on for key workflows.</p>
|
282
|
+
|
283
|
+
<a
|
284
|
+
href="https://storybook.js.org/tutorials/"
|
285
|
+
target="_blank"
|
286
|
+
>Discover tutorials<RightArrow /></a>
|
287
|
+
</div>
|
288
|
+
</div>
|
289
|
+
|
290
|
+
<style>
|
291
|
+
{`
|
292
|
+
.sb-container {
|
293
|
+
margin-bottom: 48px;
|
294
|
+
}
|
295
|
+
|
296
|
+
.sb-section {
|
297
|
+
width: 100%;
|
298
|
+
display: flex;
|
299
|
+
flex-direction: row;
|
300
|
+
gap: 20px;
|
301
|
+
}
|
302
|
+
|
303
|
+
img {
|
304
|
+
object-fit: cover;
|
305
|
+
}
|
306
|
+
|
307
|
+
.sb-section-title {
|
308
|
+
margin-bottom: 32px;
|
309
|
+
}
|
310
|
+
|
311
|
+
.sb-section a:not(h1 a, h2 a, h3 a) {
|
312
|
+
font-size: 14px;
|
313
|
+
}
|
314
|
+
|
315
|
+
.sb-section-item, .sb-grid-item {
|
316
|
+
flex: 1;
|
317
|
+
display: flex;
|
318
|
+
flex-direction: column;
|
319
|
+
}
|
320
|
+
|
321
|
+
.sb-section-item-heading {
|
322
|
+
padding-top: 20px !important;
|
323
|
+
padding-bottom: 5px !important;
|
324
|
+
margin: 0 !important;
|
325
|
+
}
|
326
|
+
.sb-section-item-paragraph {
|
327
|
+
margin: 0;
|
328
|
+
padding-bottom: 10px;
|
329
|
+
}
|
330
|
+
|
331
|
+
.sb-chevron {
|
332
|
+
margin-left: 5px;
|
333
|
+
}
|
334
|
+
|
335
|
+
.sb-features-grid {
|
336
|
+
display: grid;
|
337
|
+
grid-template-columns: repeat(2, 1fr);
|
338
|
+
grid-gap: 32px 20px;
|
339
|
+
}
|
340
|
+
|
341
|
+
.sb-socials {
|
342
|
+
display: grid;
|
343
|
+
grid-template-columns: repeat(4, 1fr);
|
344
|
+
}
|
345
|
+
|
346
|
+
.sb-socials p {
|
347
|
+
margin-bottom: 10px;
|
348
|
+
}
|
349
|
+
|
350
|
+
.sb-explore-image {
|
351
|
+
max-height: 32px;
|
352
|
+
align-self: flex-start;
|
353
|
+
}
|
354
|
+
|
355
|
+
.sb-addon {
|
356
|
+
width: 100%;
|
357
|
+
display: flex;
|
358
|
+
align-items: center;
|
359
|
+
position: relative;
|
360
|
+
background-color: #EEF3F8;
|
361
|
+
border-radius: 5px;
|
362
|
+
border: 1px solid rgba(0, 0, 0, 0.05);
|
363
|
+
background: #EEF3F8;
|
364
|
+
height: 180px;
|
365
|
+
margin-bottom: 48px;
|
366
|
+
overflow: hidden;
|
367
|
+
}
|
368
|
+
|
369
|
+
.sb-addon-text {
|
370
|
+
padding-left: 48px;
|
371
|
+
max-width: 240px;
|
372
|
+
}
|
373
|
+
|
374
|
+
.sb-addon-text h4 {
|
375
|
+
padding-top: 0px;
|
376
|
+
}
|
377
|
+
|
378
|
+
.sb-addon-img {
|
379
|
+
position: absolute;
|
380
|
+
left: 345px;
|
381
|
+
top: 0;
|
382
|
+
height: 100%;
|
383
|
+
width: 200%;
|
384
|
+
overflow: hidden;
|
385
|
+
}
|
386
|
+
|
387
|
+
.sb-addon-img img {
|
388
|
+
width: 650px;
|
389
|
+
transform: rotate(-15deg);
|
390
|
+
margin-left: 40px;
|
391
|
+
margin-top: -72px;
|
392
|
+
box-shadow: 0 0 1px rgba(255, 255, 255, 0);
|
393
|
+
backface-visibility: hidden;
|
394
|
+
}
|
395
|
+
|
396
|
+
@media screen and (max-width: 800px) {
|
397
|
+
.sb-addon-img {
|
398
|
+
left: 300px;
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
@media screen and (max-width: 600px) {
|
403
|
+
.sb-section {
|
404
|
+
flex-direction: column;
|
405
|
+
}
|
406
|
+
|
407
|
+
.sb-features-grid {
|
408
|
+
grid-template-columns: repeat(1, 1fr);
|
409
|
+
}
|
410
|
+
|
411
|
+
.sb-socials {
|
412
|
+
grid-template-columns: repeat(2, 1fr);
|
413
|
+
}
|
414
|
+
|
415
|
+
.sb-addon {
|
416
|
+
height: 280px;
|
417
|
+
align-items: flex-start;
|
418
|
+
padding-top: 32px;
|
419
|
+
overflow: hidden;
|
420
|
+
}
|
421
|
+
|
422
|
+
.sb-addon-text {
|
423
|
+
padding-left: 24px;
|
424
|
+
}
|
425
|
+
|
426
|
+
.sb-addon-img {
|
427
|
+
right: 0;
|
428
|
+
left: 0;
|
429
|
+
top: 130px;
|
430
|
+
bottom: 0;
|
431
|
+
overflow: hidden;
|
432
|
+
height: auto;
|
433
|
+
width: 124%;
|
434
|
+
}
|
435
|
+
|
436
|
+
.sb-addon-img img {
|
437
|
+
width: 1200px;
|
438
|
+
transform: rotate(-12deg);
|
439
|
+
margin-left: 0;
|
440
|
+
margin-top: 48px;
|
441
|
+
margin-bottom: -40px;
|
442
|
+
margin-left: -24px;
|
443
|
+
}
|
444
|
+
}
|
445
|
+
`}
|
446
|
+
</style>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
2
|
+
import { fn } from '@storybook/test';
|
3
|
+
|
4
|
+
import { Header } from './Header';
|
5
|
+
|
6
|
+
const meta = {
|
7
|
+
title: 'Example/Header',
|
8
|
+
component: Header,
|
9
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
10
|
+
tags: ['autodocs'],
|
11
|
+
parameters: {
|
12
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
13
|
+
layout: 'fullscreen',
|
14
|
+
},
|
15
|
+
args: {
|
16
|
+
onLogin: fn(),
|
17
|
+
onLogout: fn(),
|
18
|
+
onCreateAccount: fn(),
|
19
|
+
},
|
20
|
+
} satisfies Meta<typeof Header>;
|
21
|
+
|
22
|
+
export default meta;
|
23
|
+
type Story = StoryObj<typeof meta>;
|
24
|
+
|
25
|
+
export const LoggedIn: Story = {
|
26
|
+
args: {
|
27
|
+
user: {
|
28
|
+
name: 'Jane Doe',
|
29
|
+
},
|
30
|
+
},
|
31
|
+
};
|
32
|
+
|
33
|
+
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
|
+
export 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="storybook-header">
|
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,32 @@
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
2
|
+
import { expect, userEvent, within } from '@storybook/test';
|
3
|
+
|
4
|
+
import { Page } from './Page';
|
5
|
+
|
6
|
+
const meta = {
|
7
|
+
title: 'Example/Page',
|
8
|
+
component: Page,
|
9
|
+
parameters: {
|
10
|
+
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
11
|
+
layout: 'fullscreen',
|
12
|
+
},
|
13
|
+
} satisfies Meta<typeof Page>;
|
14
|
+
|
15
|
+
export default meta;
|
16
|
+
type Story = StoryObj<typeof meta>;
|
17
|
+
|
18
|
+
export const LoggedOut: Story = {};
|
19
|
+
|
20
|
+
// More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing
|
21
|
+
export const LoggedIn: Story = {
|
22
|
+
play: async ({ canvasElement }) => {
|
23
|
+
const canvas = within(canvasElement);
|
24
|
+
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
25
|
+
await expect(loginButton).toBeInTheDocument();
|
26
|
+
await userEvent.click(loginButton);
|
27
|
+
await expect(loginButton).not.toBeInTheDocument();
|
28
|
+
|
29
|
+
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
30
|
+
await expect(logoutButton).toBeInTheDocument();
|
31
|
+
},
|
32
|
+
};
|
@@ -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
|
+
};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// Reference necessary since Next.js 13.2.0, because types in `next/navigation` are not exported per default, but
|
2
|
+
// type references are dynamically created during Next.js start up.
|
3
|
+
// See https://github.com/vercel/next.js/commit/cdf1d52d9aed42d01a46539886a4bda14cb77a99
|
4
|
+
// for more insights.
|
5
|
+
|
6
|
+
/// <reference types="next" />
|
7
|
+
/// <reference types="next/navigation-types/navigation" />
|
@@ -0,0 +1,14 @@
|
|
1
|
+
declare module '*.svg' {
|
2
|
+
const content: string;
|
3
|
+
export default content;
|
4
|
+
}
|
5
|
+
|
6
|
+
declare module '*.avif' {
|
7
|
+
const content: string;
|
8
|
+
export default content;
|
9
|
+
}
|
10
|
+
|
11
|
+
declare module '*.png' {
|
12
|
+
const content: string;
|
13
|
+
export default content;
|
14
|
+
}
|