@storybook/nextjs 7.0.0-alpha.41
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/README.md +603 -0
- package/dist/chunk-D2N66TOG.mjs +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/next-image-loader-stub.d.ts +8 -0
- package/dist/next-image-loader-stub.js +1 -0
- package/dist/next-image-loader-stub.mjs +1 -0
- package/dist/preset.d.ts +14 -0
- package/dist/preset.js +5 -0
- package/dist/preset.mjs +5 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +10 -0
- package/dist/preview.mjs +10 -0
- package/dist/types-4223e3ef.d.ts +28 -0
- package/package.json +124 -0
- package/preset.js +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
# Storybook for Next.js <!-- omit in toc -->
|
|
2
|
+
|
|
3
|
+
## Table of Contents <!-- omit in toc -->
|
|
4
|
+
|
|
5
|
+
- [Supported Features](#supported-features)
|
|
6
|
+
- [Requirements](#requirements)
|
|
7
|
+
- [Getting Started](#getting-started)
|
|
8
|
+
- [In a project without Storybook](#in-a-project-without-storybook)
|
|
9
|
+
- [In a project with Storybook](#in-a-project-with-storybook)
|
|
10
|
+
- [Documentation](#documentation)
|
|
11
|
+
- [Options](#options)
|
|
12
|
+
- [Next.js's Image Component](#nextjss-image-component)
|
|
13
|
+
- [Local Images](#local-images)
|
|
14
|
+
- [Remote Images](#remote-images)
|
|
15
|
+
- [Optimization](#optimization)
|
|
16
|
+
- [AVIF](#avif)
|
|
17
|
+
- [Next.js Routing](#nextjs-routing)
|
|
18
|
+
- [Overriding defaults](#overriding-defaults)
|
|
19
|
+
- [Global Defaults](#global-defaults)
|
|
20
|
+
- [Default Router](#default-router)
|
|
21
|
+
- [Actions Integration Caveats](#actions-integration-caveats)
|
|
22
|
+
- [Sass/Scss](#sassscss)
|
|
23
|
+
- [Css/Sass/Scss Modules](#csssassscss-modules)
|
|
24
|
+
- [Styled JSX](#styled-jsx)
|
|
25
|
+
- [Postcss](#postcss)
|
|
26
|
+
- [Absolute Imports](#absolute-imports)
|
|
27
|
+
- [Runtime Config](#runtime-config)
|
|
28
|
+
- [Custom Webpack Config](#custom-webpack-config)
|
|
29
|
+
- [Typescript](#typescript)
|
|
30
|
+
- [Notes for Yarn v2 and v3 users](#notes-for-yarn-v2-and-v3-users)
|
|
31
|
+
- [FAQ](#faq)
|
|
32
|
+
- [Stories for pages](#stories-for-pages)
|
|
33
|
+
- [Statically imported images won't load](#statically-imported-images-wont-load)
|
|
34
|
+
- [Module not found: Error: Can't resolve [package name]](#module-not-found-error-cant-resolve-package-name)
|
|
35
|
+
- [Acknowledgements](#acknowledgements)
|
|
36
|
+
|
|
37
|
+
## Supported Features
|
|
38
|
+
|
|
39
|
+
👉 [Next.js's Image Component](#nextjss-image-component)
|
|
40
|
+
|
|
41
|
+
👉 [Next.js Routing](#nextjs-routing)
|
|
42
|
+
|
|
43
|
+
👉 [Sass/Scss](#sassscss)
|
|
44
|
+
|
|
45
|
+
👉 [Css/Sass/Scss Modules](#csssassscss-modules)
|
|
46
|
+
|
|
47
|
+
👉 [Styled JSX](#styled-jsx)
|
|
48
|
+
|
|
49
|
+
👉 [Postcss](#postcss)
|
|
50
|
+
|
|
51
|
+
👉 [Absolute Imports](#absolute-imports)
|
|
52
|
+
|
|
53
|
+
👉 [Runtime Config](#runtime-config)
|
|
54
|
+
|
|
55
|
+
👉 [Custom Webpack Config](#custom-webpack-config)
|
|
56
|
+
|
|
57
|
+
👉 [Typescript](#typescript) (already supported out of the box by Storybook)
|
|
58
|
+
|
|
59
|
+
## Requirements
|
|
60
|
+
|
|
61
|
+
- [Next.js](https://nextjs.org/) >= 9.x
|
|
62
|
+
- [Storybook](https://storybook.js.org/) >= 7.x
|
|
63
|
+
|
|
64
|
+
## Getting Started
|
|
65
|
+
|
|
66
|
+
### In a project without Storybook
|
|
67
|
+
|
|
68
|
+
Follow the prompts after running this command in your Next.js project's root directory:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx storybook init
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
[More on getting started with Storybook](https://storybook.js.org/docs/react/get-started/introduction)
|
|
75
|
+
|
|
76
|
+
### In a project with Storybook
|
|
77
|
+
|
|
78
|
+
Update your `main.js` to look something like this:
|
|
79
|
+
|
|
80
|
+
Install the framework:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
yarn install @storybook/nextjs
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
// .storybook/main.js
|
|
88
|
+
module.exports = {
|
|
89
|
+
framework: {
|
|
90
|
+
name: '@storybook/nextjs',
|
|
91
|
+
options: {};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Documentation
|
|
97
|
+
|
|
98
|
+
### Options
|
|
99
|
+
|
|
100
|
+
You can be pass an options object for addional configuration if needed.
|
|
101
|
+
|
|
102
|
+
For example:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
// .storybook/main.js
|
|
106
|
+
const path = require('path');
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
// other config ommited for brevity
|
|
110
|
+
framework: {
|
|
111
|
+
name: '@storybook/nextjs',
|
|
112
|
+
options: {
|
|
113
|
+
nextConfigPath: path.resolve(__dirname, '../next.config.js'),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
// ...
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- `nextConfigPath`: The absolute path to the `next.config.js`
|
|
121
|
+
|
|
122
|
+
### Next.js's Image Component
|
|
123
|
+
|
|
124
|
+
[next/image](https://nextjs.org/docs/api-reference/next/image) is [notoriously difficult](https://github.com/vercel/next.js/issues/18393) to get working with Storybook. This framework allows you to use Next.js's `Image` component with no configuration!
|
|
125
|
+
|
|
126
|
+
#### Local Images
|
|
127
|
+
|
|
128
|
+
[Local images](https://nextjs.org/docs/basic-features/image-optimization#local-images) work just fine! Keep in mind that this feature was [only added in Next.js v11](https://nextjs.org/blog/next-11#automatic-size-detection-local-images).
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
import Image from 'next/image';
|
|
132
|
+
import profilePic from '../public/me.png';
|
|
133
|
+
|
|
134
|
+
function Home() {
|
|
135
|
+
return (
|
|
136
|
+
<>
|
|
137
|
+
<h1>My Homepage</h1>
|
|
138
|
+
<Image
|
|
139
|
+
src={profilePic}
|
|
140
|
+
alt="Picture of the author"
|
|
141
|
+
// width={500} automatically provided
|
|
142
|
+
// height={500} automatically provided
|
|
143
|
+
// blurDataURL="../public/me.png" set to equal the image itself (for this framework)
|
|
144
|
+
// placeholder="blur" // Optional blur-up while loading
|
|
145
|
+
/>
|
|
146
|
+
<p>Welcome to my homepage!</p>
|
|
147
|
+
</>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Remote Images
|
|
153
|
+
|
|
154
|
+
[Remote images](https://nextjs.org/docs/basic-features/image-optimization#remote-images) also work just fine!
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import Image from 'next/image';
|
|
158
|
+
|
|
159
|
+
export default function Home() {
|
|
160
|
+
return (
|
|
161
|
+
<>
|
|
162
|
+
<h1>My Homepage</h1>
|
|
163
|
+
<Image src="/me.png" alt="Picture of the author" width={500} height={500} />
|
|
164
|
+
<p>Welcome to my homepage!</p>
|
|
165
|
+
</>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### Optimization
|
|
171
|
+
|
|
172
|
+
All Next.js `Image`s are automatically [unoptimized](https://nextjs.org/docs/api-reference/next/image#unoptimized) for you.
|
|
173
|
+
|
|
174
|
+
If [placeholder="blur"](https://nextjs.org/docs/api-reference/next/image#placeholder) is used, the [blurDataURL](https://nextjs.org/docs/api-reference/next/image#blurdataurl) used is the [src](https://nextjs.org/docs/api-reference/next/image#src) of the image (thus effectively disabling the placeholder).
|
|
175
|
+
|
|
176
|
+
See [this issue](https://github.com/vercel/next.js/issues/18393) for more discussion on how Next.js `Image`s are handled for Storybook.
|
|
177
|
+
|
|
178
|
+
#### AVIF
|
|
179
|
+
|
|
180
|
+
This format is not supported by this framework yet. Feel free to [open up an issue](https://github.com/storybookjs/storybook/issues) if this is something you want to see.
|
|
181
|
+
|
|
182
|
+
### Next.js Routing
|
|
183
|
+
|
|
184
|
+
[Next.js's router](https://nextjs.org/docs/routing/introduction) is automatically stubbed for you so that when the router is interacted with, all of its interactions are automatically logged to the [Storybook actions tab](https://storybook.js.org/docs/react/essentials/actions) if you have the actions addon.
|
|
185
|
+
|
|
186
|
+
#### Overriding defaults
|
|
187
|
+
|
|
188
|
+
Per-story overrides can be done by adding a `nextRouter` property onto the story [parameters](https://storybook.js.org/docs/react/writing-stories/parameters). The framework will shallowly merge whatever you put here into the router.
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
// SomeComponentThatUsesTheRouter.stories.js
|
|
192
|
+
import SomeComponentThatUsesTheRouter from './SomeComponentThatUsesTheRouter';
|
|
193
|
+
|
|
194
|
+
export default {
|
|
195
|
+
component: SomeComponentThatUsesTheRouter,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// if you have the actions addon
|
|
199
|
+
// you can click the links and see the route change events there
|
|
200
|
+
export const Example = {
|
|
201
|
+
parameters: {
|
|
202
|
+
nextRouter: {
|
|
203
|
+
path: '/profile/[id]',
|
|
204
|
+
asPath: '/profile/ryanclementshax',
|
|
205
|
+
query: {
|
|
206
|
+
id: 'ryanclementshax',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Global Defaults
|
|
214
|
+
|
|
215
|
+
Global defaults can be set in [preview.js](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering) and will be shallowly merged with the default router.
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
// .storybook/main.js
|
|
219
|
+
|
|
220
|
+
export const parameters = {
|
|
221
|
+
nextRouter: {
|
|
222
|
+
path: '/some-default-path',
|
|
223
|
+
asPath: '/some-default-path',
|
|
224
|
+
query: {},
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### Default Router
|
|
230
|
+
|
|
231
|
+
The default values on the stubbed router are as follows (see [globals](https://storybook.js.org/docs/react/essentials/toolbars-and-globals#globals) for more details on how globals work)
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
const defaultRouter = {
|
|
235
|
+
locale: context?.globals?.locale,
|
|
236
|
+
route: '/',
|
|
237
|
+
pathname: '/',
|
|
238
|
+
query: {},
|
|
239
|
+
asPath: '/',
|
|
240
|
+
push(...args: unknown[]) {
|
|
241
|
+
action('nextRouter.push')(...args);
|
|
242
|
+
return Promise.resolve(true);
|
|
243
|
+
},
|
|
244
|
+
replace(...args: unknown[]) {
|
|
245
|
+
action('nextRouter.replace')(...args);
|
|
246
|
+
return Promise.resolve(true);
|
|
247
|
+
},
|
|
248
|
+
reload(...args: unknown[]) {
|
|
249
|
+
action('nextRouter.reload')(...args);
|
|
250
|
+
},
|
|
251
|
+
back(...args: unknown[]) {
|
|
252
|
+
action('nextRouter.back')(...args);
|
|
253
|
+
},
|
|
254
|
+
prefetch(...args: unknown[]) {
|
|
255
|
+
action('nextRouter.prefetch')(...args);
|
|
256
|
+
return Promise.resolve();
|
|
257
|
+
},
|
|
258
|
+
beforePopState(...args: unknown[]) {
|
|
259
|
+
action('nextRouter.beforePopState')(...args);
|
|
260
|
+
},
|
|
261
|
+
events: {
|
|
262
|
+
on(...args: unknown[]) {
|
|
263
|
+
action('nextRouter.events.on')(...args);
|
|
264
|
+
},
|
|
265
|
+
off(...args: unknown[]) {
|
|
266
|
+
action('nextRouter.events.off')(...args);
|
|
267
|
+
},
|
|
268
|
+
emit(...args: unknown[]) {
|
|
269
|
+
action('nextRouter.events.emit')(...args);
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
isFallback: false,
|
|
273
|
+
};
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
#### Actions Integration Caveats
|
|
277
|
+
|
|
278
|
+
If you override a function, you lose the automatic action tab integration and have to build it out yourself.
|
|
279
|
+
|
|
280
|
+
```js
|
|
281
|
+
// .storybook/main.js
|
|
282
|
+
|
|
283
|
+
export const parameters = {
|
|
284
|
+
nextRouter: {
|
|
285
|
+
push() {
|
|
286
|
+
// The default implementation that logs the action into the action tab is lost
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Doing this yourself looks something like this (make sure you install the `@storybook/addon-actions` package):
|
|
293
|
+
|
|
294
|
+
```js
|
|
295
|
+
// .storybook/main.js
|
|
296
|
+
import { action } from '@storybook/addon-actions';
|
|
297
|
+
|
|
298
|
+
export const parameters = {
|
|
299
|
+
nextRouter: {
|
|
300
|
+
push(...args) {
|
|
301
|
+
// custom logic can go here
|
|
302
|
+
// this logs to the actions tab
|
|
303
|
+
action('nextRouter.push')(...args);
|
|
304
|
+
// return whatever you want here
|
|
305
|
+
return Promise.resolve(true);
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Sass/Scss
|
|
312
|
+
|
|
313
|
+
[Global sass/scss stylesheets](https://nextjs.org/docs/basic-features/built-in-css-support#sass-support) are supported without any additional configuration as well. Just import them into [preview.js](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering)
|
|
314
|
+
|
|
315
|
+
```js
|
|
316
|
+
import '../styles/globals.scss';
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
This will automatically include any of your [custom sass configurations](https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options) in your `next.config.js` file.
|
|
320
|
+
|
|
321
|
+
```js
|
|
322
|
+
// next.config.js
|
|
323
|
+
const path = require('path');
|
|
324
|
+
|
|
325
|
+
module.exports = {
|
|
326
|
+
// any options here are included in sass compilation for your stories
|
|
327
|
+
sassOptions: {
|
|
328
|
+
includePaths: [path.join(__dirname, 'styles')],
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Css/Sass/Scss Modules
|
|
334
|
+
|
|
335
|
+
[css modules](https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css) work as expected.
|
|
336
|
+
|
|
337
|
+
```js
|
|
338
|
+
// this import works just fine in Storybook now
|
|
339
|
+
import styles from './Button.module.css';
|
|
340
|
+
// sass/scss is also supported
|
|
341
|
+
// import styles from './Button.module.scss'
|
|
342
|
+
// import styles from './Button.module.sass'
|
|
343
|
+
|
|
344
|
+
export function Button() {
|
|
345
|
+
return (
|
|
346
|
+
<button type="button" className={styles.error}>
|
|
347
|
+
Destroy
|
|
348
|
+
</button>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Styled JSX
|
|
354
|
+
|
|
355
|
+
The built in CSS-in-JS solution for Next.js is [styled-jsx](https://nextjs.org/docs/basic-features/built-in-css-support#css-in-js), and this framework supports that out of the box too, zero config.
|
|
356
|
+
|
|
357
|
+
```js
|
|
358
|
+
// This works just fine in Storybook now
|
|
359
|
+
function HelloWorld() {
|
|
360
|
+
return (
|
|
361
|
+
<div>
|
|
362
|
+
Hello world
|
|
363
|
+
<p>scoped!</p>
|
|
364
|
+
<style jsx>{`
|
|
365
|
+
p {
|
|
366
|
+
color: blue;
|
|
367
|
+
}
|
|
368
|
+
div {
|
|
369
|
+
background: red;
|
|
370
|
+
}
|
|
371
|
+
@media (max-width: 600px) {
|
|
372
|
+
div {
|
|
373
|
+
background: blue;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
`}</style>
|
|
377
|
+
<style global jsx>{`
|
|
378
|
+
body {
|
|
379
|
+
background: black;
|
|
380
|
+
}
|
|
381
|
+
`}</style>
|
|
382
|
+
</div>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export default HelloWorld;
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
You can use your own babel config too. This is an example of how you can customize styled-jsx.
|
|
390
|
+
|
|
391
|
+
```json
|
|
392
|
+
// .babelrc or whatever config file you use
|
|
393
|
+
{
|
|
394
|
+
"presets": [
|
|
395
|
+
[
|
|
396
|
+
"next/babel",
|
|
397
|
+
{
|
|
398
|
+
"styled-jsx": {
|
|
399
|
+
"plugins": ["@styled-jsx/plugin-sass"]
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
If you use a monorepo, you may need to add the babel config yourself to your storybook project. Just add a babel config to your storybook project with the following contents to get started.
|
|
408
|
+
|
|
409
|
+
```json
|
|
410
|
+
{
|
|
411
|
+
"presets": ["next/babel"]
|
|
412
|
+
}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
### Postcss
|
|
416
|
+
|
|
417
|
+
Next.js lets you [customize postcss config](https://nextjs.org/docs/advanced-features/customizing-postcss-config#default-behavior). Thus this framework will automatically handle your postcss config for you.
|
|
418
|
+
|
|
419
|
+
This allows for cool things like zero config tailwindcss! (See [Next.js' example](https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss))
|
|
420
|
+
|
|
421
|
+
### Absolute Imports
|
|
422
|
+
|
|
423
|
+
Goodbye `../`! Absolute imports from the root directory work just fine.
|
|
424
|
+
|
|
425
|
+
```js
|
|
426
|
+
// All good!
|
|
427
|
+
import Button from 'components/button';
|
|
428
|
+
// Also good!
|
|
429
|
+
import styles from 'styles/HomePage.module.css';
|
|
430
|
+
|
|
431
|
+
export default function HomePage() {
|
|
432
|
+
return (
|
|
433
|
+
<>
|
|
434
|
+
<h1 className={styles.title}>Hello World</h1>
|
|
435
|
+
<Button />
|
|
436
|
+
</>
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
```js
|
|
442
|
+
// preview.js
|
|
443
|
+
|
|
444
|
+
// Also ok in preview.js!
|
|
445
|
+
import 'styles/globals.scss';
|
|
446
|
+
|
|
447
|
+
// ...
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Runtime Config
|
|
451
|
+
|
|
452
|
+
Next.js allows for [Runtime Configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration) which lets you import a handy `getConfig` function to get certain configuration defined in your `next.config.js` file at runtime.
|
|
453
|
+
|
|
454
|
+
In the context of Storybook with this framework, you can expect Next.js's [Runtime Configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration) feature to work just fine.
|
|
455
|
+
|
|
456
|
+
Note, because Storybook doesn't server render your components, your components will only see what they normally see on the client side (i.e. they won't see `serverRuntimeConfig` but will see `publicRuntimeConfig`).
|
|
457
|
+
|
|
458
|
+
For example, consider the following Next.js config:
|
|
459
|
+
|
|
460
|
+
```js
|
|
461
|
+
// next.config.js
|
|
462
|
+
module.exports = {
|
|
463
|
+
serverRuntimeConfig: {
|
|
464
|
+
mySecret: 'secret',
|
|
465
|
+
secondSecret: process.env.SECOND_SECRET, // Pass through env variables
|
|
466
|
+
},
|
|
467
|
+
publicRuntimeConfig: {
|
|
468
|
+
staticFolder: '/static',
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
Calls to `getConfig` would return the following object when called within Storybook:
|
|
474
|
+
|
|
475
|
+
```json
|
|
476
|
+
{
|
|
477
|
+
"serverRuntimeConfig": {},
|
|
478
|
+
"publicRuntimeConfig": {
|
|
479
|
+
"staticFolder": "/static"
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Custom Webpack Config
|
|
485
|
+
|
|
486
|
+
Next.js comes with a lot of things for free out of the box like sass support, but sometimes you add [custom webpack config modifications to Next.js](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config). This framework takes care of most of the webpack modifications you would want to add. If Next.js supports a feature out of the box, then that feature will work out of the box in Storybook. If Next.js doesn't support something out of the box, but makes it easy to configure, then this framework will do the same for that thing for Storybook.
|
|
487
|
+
|
|
488
|
+
Any webpack modifications desired for Storybook should be made in [.storybook/main.js](https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config).
|
|
489
|
+
|
|
490
|
+
Note: Not all webpack modifications are copy/paste-able between `next.config.js` and `.storybook/main.js`. It is recommended to do your reasearch on how to properly make your modifcation to Storybook's webpack config and on how [webpack works](https://webpack.js.org/concepts/).
|
|
491
|
+
|
|
492
|
+
Below is an example of how to add svgr support to Storybook with this framework.
|
|
493
|
+
|
|
494
|
+
```js
|
|
495
|
+
// .storybook/main.js
|
|
496
|
+
module.exports = {
|
|
497
|
+
// other config omitted for brevity
|
|
498
|
+
webpackFinal: async (config) => {
|
|
499
|
+
// this modifies the existing image rule to exclude .svg files
|
|
500
|
+
// since you want to handle those files with @svgr/webpack
|
|
501
|
+
const imageRule = config.module.rules.find((rule) => rule.test.test('.svg'));
|
|
502
|
+
imageRule.exclude = /\.svg$/;
|
|
503
|
+
|
|
504
|
+
// configure .svg files to be loaded with @svgr/webpack
|
|
505
|
+
config.module.rules.push({
|
|
506
|
+
test: /\.svg$/,
|
|
507
|
+
use: ['@svgr/webpack'],
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
return config;
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### Typescript
|
|
516
|
+
|
|
517
|
+
Storybook handles most [Typescript](https://www.typescriptlang.org/) configurations, but this framework adds additional support for Next.js's support for [Absolute Imports and Module path aliases](https://nextjs.org/docs/advanced-features/module-path-aliases). In short, it takes into account your `tsconfig.json`'s [baseUrl](https://www.typescriptlang.org/tsconfig#baseUrl) and [paths](https://www.typescriptlang.org/tsconfig#paths). Thus, a `tsconfig.json` like the one below would work out of the box.
|
|
518
|
+
|
|
519
|
+
```json
|
|
520
|
+
{
|
|
521
|
+
"compilerOptions": {
|
|
522
|
+
"baseUrl": ".",
|
|
523
|
+
"paths": {
|
|
524
|
+
"@/components/*": ["components/*"]
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Notes for Yarn v2 and v3 users
|
|
531
|
+
|
|
532
|
+
If you're using [Yarn](https://yarnpkg.com/) v2 or v3, you may run into issues where Storybook can't resolve `style-loader` or `css-loader`. For example, you might get errors like:
|
|
533
|
+
|
|
534
|
+
`Module not found: Error: Can't resolve 'css-loader'`\
|
|
535
|
+
`Module not found: Error: Can't resolve 'style-loader'`
|
|
536
|
+
|
|
537
|
+
This is because those versions of Yarn have different package resolution rules than Yarn v1.x. If this is the case for you, just install the package directly.
|
|
538
|
+
|
|
539
|
+
### FAQ
|
|
540
|
+
|
|
541
|
+
#### Stories for pages
|
|
542
|
+
|
|
543
|
+
Next.js page files can contain imports to modules meant to run in a node environment (for use in data fetching functions). If you import from a Next.js page file containing those node module imports in your stories, your Storybook's Webpack will crash because those modules will not run in a browser. To get around this, you can extract the component in your page file into a separate file and import that component in your stories. Or, if that's not feasible for some reason, you can [polyfill those modules](https://webpack.js.org/configuration/node/) in your Storybook's [`webpackFinal` configuration](https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config).
|
|
544
|
+
|
|
545
|
+
**Before**
|
|
546
|
+
|
|
547
|
+
```jsx
|
|
548
|
+
// ./pages/my-page.jsx
|
|
549
|
+
import fs from 'fs';
|
|
550
|
+
|
|
551
|
+
export default MyPage = (props) => (
|
|
552
|
+
// ...
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
export const getStaticProps = async () => {
|
|
556
|
+
// Logic that uses `fs`
|
|
557
|
+
};
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
**After**
|
|
561
|
+
|
|
562
|
+
```jsx
|
|
563
|
+
// ./pages/my-page.jsx
|
|
564
|
+
import fs from 'fs';
|
|
565
|
+
|
|
566
|
+
import MyPage from 'components/MyPage';
|
|
567
|
+
|
|
568
|
+
export default MyPage;
|
|
569
|
+
|
|
570
|
+
export const getStaticProps = async () => {
|
|
571
|
+
// Logic that uses `fs`
|
|
572
|
+
};
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
#### Statically imported images won't load
|
|
576
|
+
|
|
577
|
+
Make sure you are treating image imports the same way you treat them when using `next/image` in normal development.
|
|
578
|
+
|
|
579
|
+
Before using this framework, image imports just imported the raw path to the image (e.g. `'static/media/stories/assets/logo.svg'`). Now image imports work the "Next.js way", meaning that you now get an object when importing an image. For example:
|
|
580
|
+
|
|
581
|
+
```json
|
|
582
|
+
{
|
|
583
|
+
"src": "static/media/stories/assets/logo.svg",
|
|
584
|
+
"height": 48,
|
|
585
|
+
"width": 48,
|
|
586
|
+
"blurDataURL": "static/media/stories/assets/logo.svg"
|
|
587
|
+
}
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
Therefore, if something in storybook isn't showing the image properly, make sure you expect the object to be returned from an import instead of just the asset path.
|
|
591
|
+
|
|
592
|
+
See [local images](https://nextjs.org/docs/basic-features/image-optimization#local-images) for more detail on how Next.js treats static image imports.
|
|
593
|
+
|
|
594
|
+
#### Module not found: Error: Can't resolve [package name]
|
|
595
|
+
|
|
596
|
+
You might get this if you're using Yarn v2 or v3. See [Notes for Yarn v2 and v3 users](#notes-for-yarn-v2-and-v3-users) for more details.
|
|
597
|
+
|
|
598
|
+
## Acknowledgements
|
|
599
|
+
|
|
600
|
+
This framework borrows heavily from these Storybook addons:
|
|
601
|
+
|
|
602
|
+
- [storybook-addon-next](https://github.com/RyanClementsHax/storybook-addon-next) by [RyanClementsHax](https://github.com/RyanClementsHax/)
|
|
603
|
+
- [storybook-addon-next-router](https://github.com/lifeiscontent/storybook-addon-next-router) by [lifeiscontent](https://github.com/lifeiscontent)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=(a=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(a,{get:(b,c)=>(typeof require!="undefined"?require:b)[c]}):a)(function(a){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+a+'" is not supported')});var d=(a,b)=>()=>(a&&(b=a(a=0)),b);var h=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var k,f=d(()=>{k={}});export{g as a,h as b,f as c,k as d};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(r,o,m,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==m&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},p=(r,o,m)=>(t(r,o,"default"),m&&t(m,o,"default"));var g=r=>t(a({},"__esModule",{value:!0}),r);var f={};module.exports=g(f);p(f,require("@storybook/react"),module.exports);
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as o}from"./chunk-D2N66TOG.mjs";o();export*from"@storybook/react";o();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var m=Object.create;var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var c=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var x=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of h(e))!u.call(t,o)&&o!==i&&a(t,o,{get:()=>e[o],enumerable:!(r=p(e,o))||r.enumerable});return t};var d=(t,e,i)=>(i=t!=null?m(c(t)):{},x(e||!t||!t.__esModule?a(i,"default",{value:t,enumerable:!0}):i,t));var n=require("loader-utils"),s=d(require("image-size")),f=function(t){let{filename:e}=this.getOptions(),i=(0,n.interpolateName)(this,e.replace("[ext]",".[ext]"),{context:this.rootContext,content:t});this.emitFile(i,t);let{width:r,height:o}=(0,s.default)(t);return`export default ${JSON.stringify({src:i,height:o,width:r,blurDataURL:i})};`};f.raw=!0;module.exports=f;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as f,c as i}from"./chunk-D2N66TOG.mjs";import{interpolateName as m}from"loader-utils";import p from"image-size";var h=f((d,r)=>{i();var o=function(t){let{filename:a}=this.getOptions(),e=m(this,a.replace("[ext]",".[ext]"),{context:this.rootContext,content:t});this.emitFile(e,t);let{width:n,height:s}=p(t);return`export default ${JSON.stringify({src:e,height:s,width:n,blurDataURL:e})};`};o.raw=!0;r.exports=o});export default h();
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PresetProperty, Options } from '@storybook/core-common';
|
|
2
|
+
import { TransformOptions } from '@babel/core';
|
|
3
|
+
import { S as StorybookConfig } from './types-4223e3ef.js';
|
|
4
|
+
import '@storybook/preset-react-webpack';
|
|
5
|
+
import '@storybook/builder-webpack5';
|
|
6
|
+
|
|
7
|
+
declare const addons: PresetProperty<'addons', StorybookConfig>;
|
|
8
|
+
declare const frameworkOptions: (_: never, options: Options) => Promise<StorybookConfig['framework']>;
|
|
9
|
+
declare const core: PresetProperty<'core', StorybookConfig>;
|
|
10
|
+
declare const config: StorybookConfig['previewAnnotations'];
|
|
11
|
+
declare const babel: (baseConfig: TransformOptions) => Promise<TransformOptions>;
|
|
12
|
+
declare const webpackFinal: StorybookConfig['webpackFinal'];
|
|
13
|
+
|
|
14
|
+
export { addons, babel, config, core, frameworkOptions, webpackFinal };
|
package/dist/preset.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var U=Object.create;var l=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var B=(o,e)=>{for(var t in e)l(o,t,{get:e[t],enumerable:!0})},k=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of G(e))!z.call(o,s)&&s!==t&&l(o,s,{get:()=>e[s],enumerable:!(r=X(e,s))||r.enumerable});return o};var n=(o,e,t)=>(t=o!=null?U(H(o)):{},k(e||!o||!o.__esModule?l(t,"default",{value:o,enumerable:!0}):t,o)),K=o=>k(l({},"__esModule",{value:!0}),o);var fo={};B(fo,{addons:()=>ro,babel:()=>po,config:()=>no,core:()=>io,frameworkOptions:()=>so,webpackFinal:()=>ao});module.exports=K(fo);var p=require("path");var w=require("next/constants"),C=n(require("find-up")),j=require("fs-extra"),R=n(require("ts-dedent")),h=require("webpack");var u=n(require("path")),v=require("webpack"),b=o=>{var e;(e=o.plugins)==null||e.push(new v.DefinePlugin({"process.env.__NEXT_VERSION":JSON.stringify(a())}))},a=()=>require(g("next/package.json")).version,i=(o,e,t)=>{o.resolve??={},o.resolve.alias??={};let r=o.resolve.alias,s=g(`${t??e}`);Array.isArray(r)?r.push({name:e,alias:s}):r[e]=s},g=o=>{let e=require.resolve(o,{paths:[u.default.resolve()]}),r=e.lastIndexOf(o.replace(/\//g,u.default.sep))+o.length;return e.substring(0,r)};var P=async({baseConfig:o,nextConfigPath:e,configDir:t})=>{let r=await Y({baseConfig:o,nextConfigPath:e,configDir:t});return i(o,"next/config"),Z(o,r),r},Q=async o=>["mjs","js"].reduce(async(t,r)=>(await t||(t=(0,C.default)(`next.config.${r}`,{cwd:o})),t),Promise.resolve(void 0)),Y=async({baseConfig:o,nextConfigPath:e,configDir:t})=>{let r=e||await Q(t);if(!r||await(0,j.pathExists)(r)===!1)throw new Error(R.default`
|
|
2
|
+
Could not find or resolve your Next config file. Please provide the next config file path as a framework option.
|
|
3
|
+
|
|
4
|
+
More info: https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/README.md#options
|
|
5
|
+
`);let s=await import(r);return typeof s=="function"?s(w.PHASE_DEVELOPMENT_SERVER,{defaultConfig:o}):s},Z=(o,e)=>{var t;(t=o.plugins)==null||t.push(new h.DefinePlugin({"process.env.__NEXT_RUNTIME_CONFIG":JSON.stringify({serverRuntimeConfig:{},publicRuntimeConfig:e.publicRuntimeConfig})}))};var d=require("next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent"),x=require("next/dist/build/webpack/config/blocks/css/loaders/file-resolve"),E=n(require("semver"));var T=(o,e)=>{var r,s,f;let t=(r=o.module)==null?void 0:r.rules;t==null||t.forEach((c,m)=>{typeof c!="string"&&c.test instanceof RegExp&&c.test.test("test.css")&&(t[m]={test:/\.css$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:1,...O(e),modules:{auto:!0,getLocalIdent:d.getCssModuleLocalIdent}}},"postcss-loader"]})}),t==null||t.push({test:/\.(scss|sass)$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:3,...O(e),modules:{auto:!0,getLocalIdent:d.getCssModuleLocalIdent}}},"postcss-loader","resolve-url-loader",{loader:"sass-loader",options:{sourceMap:!0,sassOptions:e.sassOptions,additionalData:((s=e.sassOptions)==null?void 0:s.prependData)||((f=e.sassOptions)==null?void 0:f.additionalData)}}]})},O=o=>oo()?{url:{filter:S(o)},import:{filter:N(o)}}:{url:S(o),import:N(o)},S=o=>(e,t)=>{var r;return(0,x.cssFileResolve)(e,t,(r=o.experimental)==null?void 0:r.urlImports)},N=o=>(e,t,r)=>{var s;return(0,x.cssFileResolve)(typeof e=="string"?e:e.url,r,(s=o.experimental)==null?void 0:s.urlImports)},oo=()=>{try{let o=require(g("css-loader/package.json")).version;return E.default.gte(o,"6.0.0")}catch{return!1}};var W=n(require("tsconfig-paths-webpack-plugin")),I=require("tsconfig-paths"),F=o=>{let e=(0,I.loadConfig)();e.resultType==="failed"||!e.baseUrl||(o.resolve??={},o.resolve.plugins??=[],o.resolve.plugins.push(new W.default({configFile:e.configFileAbsolutePath,extensions:[".js",".jsx",".ts",".tsx"]})))};var A=n(require("semver"));var L=o=>{let e=eo();i(o,e)},eo=()=>{let o=a();return A.default.gte(o,"11.1.0")?"next/dist/shared/lib/router-context":"next/dist/next-server/lib/router-context"};var D=n(require("semver"));var V=o=>{let e=a();D.default.gte(e,"12.0.0")?i(o,"styled-jsx"):(i(o,"styled-jsx/babel"),i(o,"styled-jsx/css"),i(o,"styled-jsx/macro"),i(o,"styled-jsx/server"),i(o,"styled-jsx/style"),i(o,"styled-jsx/webpack"))};var _=async o=>{o.plugins||=[],o.plugins.includes("styled-jsx/babel")||o.plugins.push("styled-jsx/babel")};var q=n(require("semver"));var $=o=>{to(o),i(o,"next/image")},to=o=>{var s,f,c;let e=a();if(q.default.lt(e,"11.0.0"))return;let t=(s=o.module)==null?void 0:s.rules,r=t==null?void 0:t.find(m=>typeof m!="string"&&m.test instanceof RegExp&&m.test.test("test.jpg"));!r||(r.test=/\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,t==null||t.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:{not:/\.(css|scss|sass)$/},use:[{loader:require.resolve("@storybook/nextjs/next-image-loader-stub.js"),options:{filename:(f=r.generator)==null?void 0:f.filename}}]}),t==null||t.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:/\.(css|scss|sass)$/,type:"asset/resource",generator:{filename:(c=r.generator)==null?void 0:c.filename}}))};var M=require("tsconfig-paths"),J=async o=>{(0,M.loadConfig)().resultType==="success"&&(o.presets||=[],o.presets.includes("@babel/preset-typescript")||o.presets.push("@babel/preset-typescript"))};var ro=[(0,p.dirname)(require.resolve((0,p.join)("@storybook/preset-react-webpack","package.json"))),(0,p.dirname)(require.resolve((0,p.join)("@storybook/react","package.json"))),(0,p.dirname)(require.resolve((0,p.join)("@storybook/builder-webpack5","package.json")))],y={},so=async(o,e)=>{let t=await e.presets.apply("framework");return typeof t=="string"?{name:t,options:y}:typeof t>"u"?{name:require.resolve("@storybook/nextjs"),options:y}:{name:t.name,options:{...y,...t.options}}},io=async(o,e)=>{let t=await e.presets.apply("framework");return{...o,builder:{name:(0,p.dirname)(require.resolve((0,p.join)("@storybook/builder-webpack5","package.json"))),options:typeof t=="string"?{}:t.options.builder||{}}}},no=(o=[])=>[...o,require.resolve("@storybook/nextjs/preview.js")],po=async o=>(J(o),_(o),o),ao=async(o,e)=>{let t=await e.presets.apply("frameworkOptions"),{options:{nextConfigPath:r}={}}=t,s=await P({baseConfig:o,nextConfigPath:r,configDir:e.configDir});return b(o),F(o),T(o,s),$(o),L(o),V(o),o};0&&(module.exports={addons,babel,config,core,frameworkOptions,webpackFinal});
|
package/dist/preset.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as n,c as s}from"./chunk-D2N66TOG.mjs";s();import{dirname as m,join as l}from"path";s();import{PHASE_DEVELOPMENT_SERVER as E}from"next/constants";import T from"find-up";import{pathExists as W}from"fs-extra";import I from"ts-dedent";import{DefinePlugin as F}from"webpack";s();import u from"path";import{DefinePlugin as N}from"webpack";var d=o=>{o.plugins?.push(new N({"process.env.__NEXT_VERSION":JSON.stringify(f())}))},f=()=>n(c("next/package.json")).version,p=(o,e,t)=>{o.resolve??={},o.resolve.alias??={};let r=o.resolve.alias,i=c(`${t??e}`);Array.isArray(r)?r.push({name:e,alias:i}):r[e]=i},c=o=>{let e=n.resolve(o,{paths:[u.resolve()]}),r=e.lastIndexOf(o.replace(/\//g,u.sep))+o.length;return e.substring(0,r)};var x=async({baseConfig:o,nextConfigPath:e,configDir:t})=>{let r=await L({baseConfig:o,nextConfigPath:e,configDir:t});return p(o,"next/config"),D(o,r),r},A=async o=>["mjs","js"].reduce(async(t,r)=>(await t||(t=T(`next.config.${r}`,{cwd:o})),t),Promise.resolve(void 0)),L=async({baseConfig:o,nextConfigPath:e,configDir:t})=>{let r=e||await A(t);if(!r||await W(r)===!1)throw new Error(I`
|
|
2
|
+
Could not find or resolve your Next config file. Please provide the next config file path as a framework option.
|
|
3
|
+
|
|
4
|
+
More info: https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/README.md#options
|
|
5
|
+
`);let i=await import(r);return typeof i=="function"?i(E,{defaultConfig:o}):i},D=(o,e)=>{o.plugins?.push(new F({"process.env.__NEXT_RUNTIME_CONFIG":JSON.stringify({serverRuntimeConfig:{},publicRuntimeConfig:e.publicRuntimeConfig})}))};s();import{getCssModuleLocalIdent as y}from"next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent";import{cssFileResolve as w}from"next/dist/build/webpack/config/blocks/css/loaders/file-resolve";import V from"semver";var C=(o,e)=>{let t=o.module?.rules;t?.forEach((r,i)=>{typeof r!="string"&&r.test instanceof RegExp&&r.test.test("test.css")&&(t[i]={test:/\.css$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:1,...k(e),modules:{auto:!0,getLocalIdent:y}}},"postcss-loader"]})}),t?.push({test:/\.(scss|sass)$/,use:["style-loader",{loader:"css-loader",options:{importLoaders:3,...k(e),modules:{auto:!0,getLocalIdent:y}}},"postcss-loader","resolve-url-loader",{loader:"sass-loader",options:{sourceMap:!0,sassOptions:e.sassOptions,additionalData:e.sassOptions?.prependData||e.sassOptions?.additionalData}}]})},k=o=>_()?{url:{filter:v(o)},import:{filter:b(o)}}:{url:v(o),import:b(o)},v=o=>(e,t)=>w(e,t,o.experimental?.urlImports),b=o=>(e,t,r)=>w(typeof e=="string"?e:e.url,r,o.experimental?.urlImports),_=()=>{try{let o=n(c("css-loader/package.json")).version;return V.gte(o,"6.0.0")}catch{return!1}};s();import q from"tsconfig-paths-webpack-plugin";import{loadConfig as $}from"tsconfig-paths";var j=o=>{let e=$();e.resultType==="failed"||!e.baseUrl||(o.resolve??={},o.resolve.plugins??=[],o.resolve.plugins.push(new q({configFile:e.configFileAbsolutePath,extensions:[".js",".jsx",".ts",".tsx"]})))};s();import M from"semver";var R=o=>{let e=J();p(o,e)},J=()=>{let o=f();return M.gte(o,"11.1.0")?"next/dist/shared/lib/router-context":"next/dist/next-server/lib/router-context"};s();import U from"semver";var h=o=>{let e=f();U.gte(e,"12.0.0")?p(o,"styled-jsx"):(p(o,"styled-jsx/babel"),p(o,"styled-jsx/css"),p(o,"styled-jsx/macro"),p(o,"styled-jsx/server"),p(o,"styled-jsx/style"),p(o,"styled-jsx/webpack"))};s();var P=async o=>{o.plugins||=[],o.plugins.includes("styled-jsx/babel")||o.plugins.push("styled-jsx/babel")};s();import X from"semver";var O=o=>{G(o),p(o,"next/image")},G=o=>{let e=f();if(X.lt(e,"11.0.0"))return;let t=o.module?.rules,r=t?.find(i=>typeof i!="string"&&i.test instanceof RegExp&&i.test.test("test.jpg"));!r||(r.test=/\.(apng|eot|otf|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,t?.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:{not:/\.(css|scss|sass)$/},use:[{loader:n.resolve("@storybook/nextjs/next-image-loader-stub.js"),options:{filename:r.generator?.filename}}]}),t?.push({test:/\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i,issuer:/\.(css|scss|sass)$/,type:"asset/resource",generator:{filename:r.generator?.filename}}))};s();import{loadConfig as H}from"tsconfig-paths";var S=async o=>{H().resultType==="success"&&(o.presets||=[],o.presets.includes("@babel/preset-typescript")||o.presets.push("@babel/preset-typescript"))};var Do=[m(n.resolve(l("@storybook/preset-react-webpack","package.json"))),m(n.resolve(l("@storybook/react","package.json"))),m(n.resolve(l("@storybook/builder-webpack5","package.json")))],g={},Vo=async(o,e)=>{let t=await e.presets.apply("framework");return typeof t=="string"?{name:t,options:g}:typeof t>"u"?{name:n.resolve("@storybook/nextjs"),options:g}:{name:t.name,options:{...g,...t.options}}},_o=async(o,e)=>{let t=await e.presets.apply("framework");return{...o,builder:{name:m(n.resolve(l("@storybook/builder-webpack5","package.json"))),options:typeof t=="string"?{}:t.options.builder||{}}}},qo=(o=[])=>[...o,n.resolve("@storybook/nextjs/preview.js")],$o=async o=>(S(o),P(o),o),Mo=async(o,e)=>{let t=await e.presets.apply("frameworkOptions"),{options:{nextConfigPath:r}={}}=t,i=await x({baseConfig:o,nextConfigPath:r,configDir:e.configDir});return d(o),j(o),C(o,i),O(o),R(o),h(o),o};export{Do as addons,$o as babel,qo as config,_o as core,Vo as frameworkOptions,Mo as webpackFinal};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as lib_addons_dist from 'lib/addons/dist';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
|
|
4
|
+
declare type AnyFramework = {
|
|
5
|
+
component: unknown;
|
|
6
|
+
storyResult: unknown;
|
|
7
|
+
T?: unknown;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
declare const decorators: ((Story: react.FC<{}>, { globals, parameters }: lib_addons_dist.StoryContext<AnyFramework>) => react.ReactNode)[];
|
|
11
|
+
|
|
12
|
+
export { decorators };
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";var M=Object.create;var y=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var x=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),K=(t,r)=>{for(var i in r)y(t,i,{get:r[i],enumerable:!0})},N=(t,r,i,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of U(r))!G.call(t,n)&&n!==i&&y(t,n,{get:()=>r[n],enumerable:!(e=H(r,n))||e.enumerable});return t};var h=(t,r,i)=>(i=t!=null?M($(t)):{},N(r||!t||!t.__esModule?y(i,"default",{value:t,enumerable:!0}):i,t)),Q=t=>N(y({},"__esModule",{value:!0}),t);var X=x(p=>{var m=require("react");function Y(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var v=Y(m);function T(t,r){for(var i=0;i<r.length;i++){var e=r[i];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function Z(t,r,i){return r&&T(t.prototype,r),i&&T(t,i),t}var S=typeof process<"u"&&process.env&&process.env.NODE_ENV==="production",z=function(t){return Object.prototype.toString.call(t)==="[object String]"},ee=function(){function t(i){var e=i===void 0?{}:i,n=e.name,o=n===void 0?"stylesheet":n,s=e.optimizeForSpeed,u=s===void 0?S:s;l(z(o),"`name` must be a string"),this._name=o,this._deletedRulePlaceholder="#"+o+"-deleted-rule____{}",l(typeof u=="boolean","`optimizeForSpeed` must be a boolean"),this._optimizeForSpeed=u,this._serverSheet=void 0,this._tags=[],this._injected=!1,this._rulesCount=0;var c=typeof window<"u"&&document.querySelector('meta[property="csp-nonce"]');this._nonce=c?c.getAttribute("content"):null}var r=t.prototype;return r.setOptimizeForSpeed=function(e){l(typeof e=="boolean","`setOptimizeForSpeed` accepts a boolean"),l(this._rulesCount===0,"optimizeForSpeed cannot be when rules have already been inserted"),this.flush(),this._optimizeForSpeed=e,this.inject()},r.isOptimizeForSpeed=function(){return this._optimizeForSpeed},r.inject=function(){var e=this;if(l(!this._injected,"sheet already injected"),this._injected=!0,typeof window<"u"&&this._optimizeForSpeed){this._tags[0]=this.makeStyleTag(this._name),this._optimizeForSpeed="insertRule"in this.getSheet(),this._optimizeForSpeed||(S||console.warn("StyleSheet: optimizeForSpeed mode not supported falling back to standard mode."),this.flush(),this._injected=!0);return}this._serverSheet={cssRules:[],insertRule:function(n,o){return typeof o=="number"?e._serverSheet.cssRules[o]={cssText:n}:e._serverSheet.cssRules.push({cssText:n}),o},deleteRule:function(n){e._serverSheet.cssRules[n]=null}}},r.getSheetForTag=function(e){if(e.sheet)return e.sheet;for(var n=0;n<document.styleSheets.length;n++)if(document.styleSheets[n].ownerNode===e)return document.styleSheets[n]},r.getSheet=function(){return this.getSheetForTag(this._tags[this._tags.length-1])},r.insertRule=function(e,n){if(l(z(e),"`insertRule` accepts only strings"),typeof window>"u")return typeof n!="number"&&(n=this._serverSheet.cssRules.length),this._serverSheet.insertRule(e,n),this._rulesCount++;if(this._optimizeForSpeed){var o=this.getSheet();typeof n!="number"&&(n=o.cssRules.length);try{o.insertRule(e,n)}catch{return S||console.warn(`StyleSheet: illegal rule:
|
|
2
|
+
|
|
3
|
+
`+e+`
|
|
4
|
+
|
|
5
|
+
See https://stackoverflow.com/q/20007992 for more info`),-1}}else{var s=this._tags[n];this._tags.push(this.makeStyleTag(this._name,e,s))}return this._rulesCount++},r.replaceRule=function(e,n){if(this._optimizeForSpeed||typeof window>"u"){var o=typeof window<"u"?this.getSheet():this._serverSheet;if(n.trim()||(n=this._deletedRulePlaceholder),!o.cssRules[e])return e;o.deleteRule(e);try{o.insertRule(n,e)}catch{S||console.warn(`StyleSheet: illegal rule:
|
|
6
|
+
|
|
7
|
+
`+n+`
|
|
8
|
+
|
|
9
|
+
See https://stackoverflow.com/q/20007992 for more info`),o.insertRule(this._deletedRulePlaceholder,e)}}else{var s=this._tags[e];l(s,"old rule at index `"+e+"` not found"),s.textContent=n}return e},r.deleteRule=function(e){if(typeof window>"u"){this._serverSheet.deleteRule(e);return}if(this._optimizeForSpeed)this.replaceRule(e,"");else{var n=this._tags[e];l(n,"rule at index `"+e+"` not found"),n.parentNode.removeChild(n),this._tags[e]=null}},r.flush=function(){this._injected=!1,this._rulesCount=0,typeof window<"u"?(this._tags.forEach(function(e){return e&&e.parentNode.removeChild(e)}),this._tags=[]):this._serverSheet.cssRules=[]},r.cssRules=function(){var e=this;return typeof window>"u"?this._serverSheet.cssRules:this._tags.reduce(function(n,o){return o?n=n.concat(Array.prototype.map.call(e.getSheetForTag(o).cssRules,function(s){return s.cssText===e._deletedRulePlaceholder?null:s})):n.push(null),n},[])},r.makeStyleTag=function(e,n,o){n&&l(z(n),"makeStyleTag accepts only strings as second parameter");var s=document.createElement("style");this._nonce&&s.setAttribute("nonce",this._nonce),s.type="text/css",s.setAttribute("data-"+e,""),n&&s.appendChild(document.createTextNode(n));var u=document.head||document.getElementsByTagName("head")[0];return o?u.insertBefore(s,o):u.appendChild(s),s},Z(t,[{key:"length",get:function(){return this._rulesCount}}]),t}();function l(t,r){if(!t)throw new Error("StyleSheet: "+r+".")}function te(t){for(var r=5381,i=t.length;i;)r=r*33^t.charCodeAt(--i);return r>>>0}var re=te,ne=function(t){return t.replace(/\/style/gi,"\\/style")},d={};function C(t,r){if(!r)return"jsx-"+t;var i=String(r),e=t+i;return d[e]||(d[e]="jsx-"+re(t+"-"+i)),d[e]}function I(t,r){var i=/__jsx-style-dynamic-selector/g;typeof window>"u"&&(r=ne(r));var e=t+r;return d[e]||(d[e]=r.replace(i,t)),d[e]}function ie(t,r){return r===void 0&&(r={}),t.map(function(i){var e=i[0],n=i[1];return v.default.createElement("style",{id:"__"+e,key:"__"+e,nonce:r.nonce?r.nonce:void 0,dangerouslySetInnerHTML:{__html:n}})})}var oe=function(){function t(i){var e=i===void 0?{}:i,n=e.styleSheet,o=n===void 0?null:n,s=e.optimizeForSpeed,u=s===void 0?!1:s;this._sheet=o||new ee({name:"styled-jsx",optimizeForSpeed:u}),this._sheet.inject(),o&&typeof u=="boolean"&&(this._sheet.setOptimizeForSpeed(u),this._optimizeForSpeed=this._sheet.isOptimizeForSpeed()),this._fromServer=void 0,this._indices={},this._instancesCounts={}}var r=t.prototype;return r.add=function(e){var n=this;this._optimizeForSpeed===void 0&&(this._optimizeForSpeed=Array.isArray(e.children),this._sheet.setOptimizeForSpeed(this._optimizeForSpeed),this._optimizeForSpeed=this._sheet.isOptimizeForSpeed()),typeof window<"u"&&!this._fromServer&&(this._fromServer=this.selectFromServer(),this._instancesCounts=Object.keys(this._fromServer).reduce(function(f,J){return f[J]=0,f},{}));var o=this.getIdAndRules(e),s=o.styleId,u=o.rules;if(s in this._instancesCounts){this._instancesCounts[s]+=1;return}var c=u.map(function(f){return n._sheet.insertRule(f)}).filter(function(f){return f!==-1});this._indices[s]=c,this._instancesCounts[s]=1},r.remove=function(e){var n=this,o=this.getIdAndRules(e).styleId;if(se(o in this._instancesCounts,"styleId: `"+o+"` not found"),this._instancesCounts[o]-=1,this._instancesCounts[o]<1){var s=this._fromServer&&this._fromServer[o];s?(s.parentNode.removeChild(s),delete this._fromServer[o]):(this._indices[o].forEach(function(u){return n._sheet.deleteRule(u)}),delete this._indices[o]),delete this._instancesCounts[o]}},r.update=function(e,n){this.add(n),this.remove(e)},r.flush=function(){this._sheet.flush(),this._sheet.inject(),this._fromServer=void 0,this._indices={},this._instancesCounts={}},r.cssRules=function(){var e=this,n=this._fromServer?Object.keys(this._fromServer).map(function(s){return[s,e._fromServer[s]]}):[],o=this._sheet.cssRules();return n.concat(Object.keys(this._indices).map(function(s){return[s,e._indices[s].map(function(u){return o[u].cssText}).join(e._optimizeForSpeed?"":`
|
|
10
|
+
`)]}).filter(function(s){return Boolean(s[1])}))},r.styles=function(e){return ie(this.cssRules(),e)},r.getIdAndRules=function(e){var n=e.children,o=e.dynamic,s=e.id;if(o){var u=C(s,o);return{styleId:u,rules:Array.isArray(n)?n.map(function(c){return I(u,c)}):[I(u,n)]}}return{styleId:C(s),rules:Array.isArray(n)?n:[n]}},r.selectFromServer=function(){var e=Array.prototype.slice.call(document.querySelectorAll('[id^="__jsx-"]'));return e.reduce(function(n,o){var s=o.id.slice(2);return n[s]=o,n},{})},t}();function se(t,r){if(!t)throw new Error("StyleSheetRegistry: "+r+".")}var R=m.createContext(null);R.displayName="StyleSheetContext";function b(){return new oe}function ue(t){var r=t.registry,i=t.children,e=m.useContext(R),n=m.useState(function(){return e||r||b()}),o=n[0];return v.default.createElement(R.Provider,{value:o},i)}function q(){return m.useContext(R)}var ae=v.default.useInsertionEffect||v.default.useLayoutEffect,A=typeof window<"u"?b():void 0;function D(t){var r=A||q();return r?typeof window>"u"?(r.add(t),null):(ae(function(){return r.add(t),function(){r.remove(t)}},[t.id,String(t.dynamic)]),null):null}D.dynamic=function(t){return t.map(function(r){var i=r[0],e=r[1];return C(i,e)}).join(" ")};p.StyleRegistry=ue;p.createStyleRegistry=b;p.style=D;p.useStyleRegistry=q});var V=x((me,L)=>{L.exports=X()});var ce={};K(ce,{decorators:()=>le});module.exports=Q(ce);var P=require("next/config");(0,P.setConfig)(process.env.__NEXT_RUNTIME_CONFIG);var w=h(require("react")),O=require("next/dist/shared/lib/router-context"),F=h(require("next/router")),a;try{a=require("@storybook/addon-actions").action}catch{a=()=>()=>{}}var W={route:"/",pathname:"/",query:{},asPath:"/",push(...t){return a("nextRouter.push")(...t),Promise.resolve(!0)},replace(...t){return a("nextRouter.replace")(...t),Promise.resolve(!0)},reload(...t){a("nextRouter.reload")(...t)},back(...t){a("nextRouter.back")(...t)},prefetch(...t){return a("nextRouter.prefetch")(...t),Promise.resolve()},beforePopState(...t){a("nextRouter.beforePopState")(...t)},events:{on(...t){a("nextRouter.events.on")(...t)},off(...t){a("nextRouter.events.off")(...t)},emit(...t){a("nextRouter.events.emit")(...t)}},isFallback:!1},E=(t,{globals:r,parameters:i})=>{let e=i.nextRouter??{};return F.default.router={...W,locale:r==null?void 0:r.locale,...e},w.createElement(O.RouterContext.Provider,{value:F.default.router},w.createElement(t,null))};var _=h(require("react")),j;try{j=V().StyleRegistry}catch{j=_.Fragment}var B=t=>_.createElement(j,null,_.createElement(t,null));var k=h(require("react")),g=h(require("semver"));if(g.default.gt(process.env.__NEXT_VERSION,"9.0.0")){let t=require("next/image"),r=t.default;Object.defineProperty(t,"default",{configurable:!0,value:i=>typeof i.src=="string"?k.createElement(r,{...i,unoptimized:!0,blurDataURL:i.src}):k.createElement(r,{...i,unoptimized:!0})}),g.default.gte(process.env.__NEXT_VERSION,"12.1.5")&&g.default.lt(process.env.__NEXT_VERSION,"12.2.0")&&Object.defineProperty(t,"__esModule",{configurable:!0,value:!0})}var le=[B,E];0&&(module.exports={decorators});
|
package/dist/preview.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{a as g,b as x,c as a,d as l}from"./chunk-D2N66TOG.mjs";var q=x(_=>{a();var p=g("react");function H(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var v=H(p);function O(t,n){for(var i=0;i<n.length;i++){var e=n[i];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function U(t,n,i){return n&&O(t.prototype,n),i&&O(t,i),t}var S=typeof process<"u"&&l&&!0,F=function(t){return Object.prototype.toString.call(t)==="[object String]"},$=function(){function t(i){var e=i===void 0?{}:i,r=e.name,o=r===void 0?"stylesheet":r,s=e.optimizeForSpeed,u=s===void 0?S:s;f(F(o),"`name` must be a string"),this._name=o,this._deletedRulePlaceholder="#"+o+"-deleted-rule____{}",f(typeof u=="boolean","`optimizeForSpeed` must be a boolean"),this._optimizeForSpeed=u,this._serverSheet=void 0,this._tags=[],this._injected=!1,this._rulesCount=0;var d=typeof window<"u"&&document.querySelector('meta[property="csp-nonce"]');this._nonce=d?d.getAttribute("content"):null}var n=t.prototype;return n.setOptimizeForSpeed=function(e){f(typeof e=="boolean","`setOptimizeForSpeed` accepts a boolean"),f(this._rulesCount===0,"optimizeForSpeed cannot be when rules have already been inserted"),this.flush(),this._optimizeForSpeed=e,this.inject()},n.isOptimizeForSpeed=function(){return this._optimizeForSpeed},n.inject=function(){var e=this;if(f(!this._injected,"sheet already injected"),this._injected=!0,typeof window<"u"&&this._optimizeForSpeed){this._tags[0]=this.makeStyleTag(this._name),this._optimizeForSpeed="insertRule"in this.getSheet(),this._optimizeForSpeed||(S||console.warn("StyleSheet: optimizeForSpeed mode not supported falling back to standard mode."),this.flush(),this._injected=!0);return}this._serverSheet={cssRules:[],insertRule:function(r,o){return typeof o=="number"?e._serverSheet.cssRules[o]={cssText:r}:e._serverSheet.cssRules.push({cssText:r}),o},deleteRule:function(r){e._serverSheet.cssRules[r]=null}}},n.getSheetForTag=function(e){if(e.sheet)return e.sheet;for(var r=0;r<document.styleSheets.length;r++)if(document.styleSheets[r].ownerNode===e)return document.styleSheets[r]},n.getSheet=function(){return this.getSheetForTag(this._tags[this._tags.length-1])},n.insertRule=function(e,r){if(f(F(e),"`insertRule` accepts only strings"),typeof window>"u")return typeof r!="number"&&(r=this._serverSheet.cssRules.length),this._serverSheet.insertRule(e,r),this._rulesCount++;if(this._optimizeForSpeed){var o=this.getSheet();typeof r!="number"&&(r=o.cssRules.length);try{o.insertRule(e,r)}catch{return S||console.warn(`StyleSheet: illegal rule:
|
|
2
|
+
|
|
3
|
+
`+e+`
|
|
4
|
+
|
|
5
|
+
See https://stackoverflow.com/q/20007992 for more info`),-1}}else{var s=this._tags[r];this._tags.push(this.makeStyleTag(this._name,e,s))}return this._rulesCount++},n.replaceRule=function(e,r){if(this._optimizeForSpeed||typeof window>"u"){var o=typeof window<"u"?this.getSheet():this._serverSheet;if(r.trim()||(r=this._deletedRulePlaceholder),!o.cssRules[e])return e;o.deleteRule(e);try{o.insertRule(r,e)}catch{S||console.warn(`StyleSheet: illegal rule:
|
|
6
|
+
|
|
7
|
+
`+r+`
|
|
8
|
+
|
|
9
|
+
See https://stackoverflow.com/q/20007992 for more info`),o.insertRule(this._deletedRulePlaceholder,e)}}else{var s=this._tags[e];f(s,"old rule at index `"+e+"` not found"),s.textContent=r}return e},n.deleteRule=function(e){if(typeof window>"u"){this._serverSheet.deleteRule(e);return}if(this._optimizeForSpeed)this.replaceRule(e,"");else{var r=this._tags[e];f(r,"rule at index `"+e+"` not found"),r.parentNode.removeChild(r),this._tags[e]=null}},n.flush=function(){this._injected=!1,this._rulesCount=0,typeof window<"u"?(this._tags.forEach(function(e){return e&&e.parentNode.removeChild(e)}),this._tags=[]):this._serverSheet.cssRules=[]},n.cssRules=function(){var e=this;return typeof window>"u"?this._serverSheet.cssRules:this._tags.reduce(function(r,o){return o?r=r.concat(Array.prototype.map.call(e.getSheetForTag(o).cssRules,function(s){return s.cssText===e._deletedRulePlaceholder?null:s})):r.push(null),r},[])},n.makeStyleTag=function(e,r,o){r&&f(F(r),"makeStyleTag accepts only strings as second parameter");var s=document.createElement("style");this._nonce&&s.setAttribute("nonce",this._nonce),s.type="text/css",s.setAttribute("data-"+e,""),r&&s.appendChild(document.createTextNode(r));var u=document.head||document.getElementsByTagName("head")[0];return o?u.insertBefore(s,o):u.appendChild(s),s},U(t,[{key:"length",get:function(){return this._rulesCount}}]),t}();function f(t,n){if(!t)throw new Error("StyleSheet: "+n+".")}function G(t){for(var n=5381,i=t.length;i;)n=n*33^t.charCodeAt(--i);return n>>>0}var K=G,Q=function(t){return t.replace(/\/style/gi,"\\/style")},m={};function b(t,n){if(!n)return"jsx-"+t;var i=String(n),e=t+i;return m[e]||(m[e]="jsx-"+K(t+"-"+i)),m[e]}function E(t,n){var i=/__jsx-style-dynamic-selector/g;typeof window>"u"&&(n=Q(n));var e=t+n;return m[e]||(m[e]=n.replace(i,t)),m[e]}function W(t,n){return n===void 0&&(n={}),t.map(function(i){var e=i[0],r=i[1];return v.default.createElement("style",{id:"__"+e,key:"__"+e,nonce:n.nonce?n.nonce:void 0,dangerouslySetInnerHTML:{__html:r}})})}var Y=function(){function t(i){var e=i===void 0?{}:i,r=e.styleSheet,o=r===void 0?null:r,s=e.optimizeForSpeed,u=s===void 0?!1:s;this._sheet=o||new $({name:"styled-jsx",optimizeForSpeed:u}),this._sheet.inject(),o&&typeof u=="boolean"&&(this._sheet.setOptimizeForSpeed(u),this._optimizeForSpeed=this._sheet.isOptimizeForSpeed()),this._fromServer=void 0,this._indices={},this._instancesCounts={}}var n=t.prototype;return n.add=function(e){var r=this;this._optimizeForSpeed===void 0&&(this._optimizeForSpeed=Array.isArray(e.children),this._sheet.setOptimizeForSpeed(this._optimizeForSpeed),this._optimizeForSpeed=this._sheet.isOptimizeForSpeed()),typeof window<"u"&&!this._fromServer&&(this._fromServer=this.selectFromServer(),this._instancesCounts=Object.keys(this._fromServer).reduce(function(h,V){return h[V]=0,h},{}));var o=this.getIdAndRules(e),s=o.styleId,u=o.rules;if(s in this._instancesCounts){this._instancesCounts[s]+=1;return}var d=u.map(function(h){return r._sheet.insertRule(h)}).filter(function(h){return h!==-1});this._indices[s]=d,this._instancesCounts[s]=1},n.remove=function(e){var r=this,o=this.getIdAndRules(e).styleId;if(Z(o in this._instancesCounts,"styleId: `"+o+"` not found"),this._instancesCounts[o]-=1,this._instancesCounts[o]<1){var s=this._fromServer&&this._fromServer[o];s?(s.parentNode.removeChild(s),delete this._fromServer[o]):(this._indices[o].forEach(function(u){return r._sheet.deleteRule(u)}),delete this._indices[o]),delete this._instancesCounts[o]}},n.update=function(e,r){this.add(r),this.remove(e)},n.flush=function(){this._sheet.flush(),this._sheet.inject(),this._fromServer=void 0,this._indices={},this._instancesCounts={}},n.cssRules=function(){var e=this,r=this._fromServer?Object.keys(this._fromServer).map(function(s){return[s,e._fromServer[s]]}):[],o=this._sheet.cssRules();return r.concat(Object.keys(this._indices).map(function(s){return[s,e._indices[s].map(function(u){return o[u].cssText}).join(e._optimizeForSpeed?"":`
|
|
10
|
+
`)]}).filter(function(s){return Boolean(s[1])}))},n.styles=function(e){return W(this.cssRules(),e)},n.getIdAndRules=function(e){var r=e.children,o=e.dynamic,s=e.id;if(o){var u=b(s,o);return{styleId:u,rules:Array.isArray(r)?r.map(function(d){return E(u,d)}):[E(u,r)]}}return{styleId:b(s),rules:Array.isArray(r)?r:[r]}},n.selectFromServer=function(){var e=Array.prototype.slice.call(document.querySelectorAll('[id^="__jsx-"]'));return e.reduce(function(r,o){var s=o.id.slice(2);return r[s]=o,r},{})},t}();function Z(t,n){if(!t)throw new Error("StyleSheetRegistry: "+n+".")}var R=p.createContext(null);R.displayName="StyleSheetContext";function z(){return new Y}function ee(t){var n=t.registry,i=t.children,e=p.useContext(R),r=p.useState(function(){return e||n||z()}),o=r[0];return v.default.createElement(R.Provider,{value:o},i)}function I(){return p.useContext(R)}var te=v.default.useInsertionEffect||v.default.useLayoutEffect,T=typeof window<"u"?z():void 0;function A(t){var n=T||I();return n?typeof window>"u"?(n.add(t),null):(te(function(){return n.add(t),function(){n.remove(t)}},[t.id,String(t.dynamic)]),null):null}A.dynamic=function(t){return t.map(function(n){var i=n[0],e=n[1];return b(i,e)}).join(" ")};_.StyleRegistry=ee;_.createStyleRegistry=z;_.style=A;_.useStyleRegistry=I});var X=x((ue,D)=>{a();D.exports=q()});a();a();import{setConfig as B}from"next/config";B(l.__NEXT_RUNTIME_CONFIG);a();import*as w from"react";import{RouterContext as J}from"next/dist/shared/lib/router-context";import N from"next/router";var c;try{c=g("@storybook/addon-actions").action}catch{c=()=>()=>{}}var M={route:"/",pathname:"/",query:{},asPath:"/",push(...t){return c("nextRouter.push")(...t),Promise.resolve(!0)},replace(...t){return c("nextRouter.replace")(...t),Promise.resolve(!0)},reload(...t){c("nextRouter.reload")(...t)},back(...t){c("nextRouter.back")(...t)},prefetch(...t){return c("nextRouter.prefetch")(...t),Promise.resolve()},beforePopState(...t){c("nextRouter.beforePopState")(...t)},events:{on(...t){c("nextRouter.events.on")(...t)},off(...t){c("nextRouter.events.off")(...t)},emit(...t){c("nextRouter.events.emit")(...t)}},isFallback:!1},P=(t,{globals:n,parameters:i})=>{let e=i.nextRouter??{};return N.router={...M,locale:n?.locale,...e},w.createElement(J.Provider,{value:N.router},w.createElement(t,null))};a();import*as y from"react";var C;try{C=X().StyleRegistry}catch{C=y.Fragment}var L=t=>y.createElement(C,null,y.createElement(t,null));a();import*as k from"react";import j from"semver";if(j.gt(l.__NEXT_VERSION,"9.0.0")){let t=g("next/image"),n=t.default;Object.defineProperty(t,"default",{configurable:!0,value:i=>typeof i.src=="string"?k.createElement(n,{...i,unoptimized:!0,blurDataURL:i.src}):k.createElement(n,{...i,unoptimized:!0})}),j.gte(l.__NEXT_VERSION,"12.1.5")&&j.lt(l.__NEXT_VERSION,"12.2.0")&&Object.defineProperty(t,"__esModule",{configurable:!0,value:!0})}var me=[L,P];export{me as decorators};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ReactOptions, StorybookConfig as StorybookConfig$1, TypescriptOptions as TypescriptOptions$1 } from '@storybook/preset-react-webpack';
|
|
2
|
+
import { BuilderOptions, StorybookConfigWebpack, TypescriptOptions } from '@storybook/builder-webpack5';
|
|
3
|
+
|
|
4
|
+
declare type FrameworkName = '@storybook/nextjs';
|
|
5
|
+
declare type BuilderName = '@storybook/builder-webpack5';
|
|
6
|
+
declare type FrameworkOptions = ReactOptions & {
|
|
7
|
+
nextConfigPath?: string;
|
|
8
|
+
builder?: BuilderOptions;
|
|
9
|
+
};
|
|
10
|
+
declare type StorybookConfigFramework = {
|
|
11
|
+
framework: FrameworkName | {
|
|
12
|
+
name: FrameworkName;
|
|
13
|
+
options: FrameworkOptions;
|
|
14
|
+
};
|
|
15
|
+
core?: StorybookConfig$1['core'] & {
|
|
16
|
+
builder?: BuilderName | {
|
|
17
|
+
name: BuilderName;
|
|
18
|
+
options: BuilderOptions;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
typescript?: Partial<TypescriptOptions & TypescriptOptions$1> & StorybookConfig$1['typescript'];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The interface for Storybook configuration in `main.ts` files.
|
|
25
|
+
*/
|
|
26
|
+
declare type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigWebpack | keyof StorybookConfigFramework> & StorybookConfigWebpack & StorybookConfigFramework;
|
|
27
|
+
|
|
28
|
+
export { FrameworkOptions as F, StorybookConfig as S };
|
package/package.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storybook/nextjs",
|
|
3
|
+
"version": "7.0.0-alpha.41",
|
|
4
|
+
"description": "Storybook for Next.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"storybook",
|
|
7
|
+
"nextjs"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/frameworks/nextjs",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/storybookjs/storybook/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/storybookjs/storybook.git",
|
|
16
|
+
"directory": "code/frameworks/nextjs"
|
|
17
|
+
},
|
|
18
|
+
"funding": {
|
|
19
|
+
"type": "opencollective",
|
|
20
|
+
"url": "https://opencollective.com/storybook"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"import": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./preset": {
|
|
30
|
+
"require": "./dist/preset.js",
|
|
31
|
+
"import": "./dist/preset.mjs",
|
|
32
|
+
"types": "./dist/preset.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./preview.js": {
|
|
35
|
+
"require": "./dist/preview.js",
|
|
36
|
+
"import": "./dist/preview.mjs",
|
|
37
|
+
"types": "./dist/preview.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./next-image-loader-stub.js": {
|
|
40
|
+
"require": "./dist/next-image-loader-stub.js",
|
|
41
|
+
"import": "./dist/next-image-loader-stub.mjs",
|
|
42
|
+
"types": "./dist/next-image-loader-stub.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"main": "dist/index.js",
|
|
47
|
+
"module": "dist/index.mjs",
|
|
48
|
+
"types": "dist/index.d.ts",
|
|
49
|
+
"files": [
|
|
50
|
+
"dist/**/*",
|
|
51
|
+
"types/**/*",
|
|
52
|
+
"README.md",
|
|
53
|
+
"*.js",
|
|
54
|
+
"*.d.ts"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"check": "tsc --noEmit",
|
|
58
|
+
"prep": "../../../scripts/prepare/bundle.ts"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
62
|
+
"@storybook/addons": "7.0.0-alpha.41",
|
|
63
|
+
"@storybook/builder-webpack5": "7.0.0-alpha.41",
|
|
64
|
+
"@storybook/core-common": "7.0.0-alpha.41",
|
|
65
|
+
"@storybook/node-logger": "7.0.0-alpha.41",
|
|
66
|
+
"@storybook/preset-react-webpack": "7.0.0-alpha.41",
|
|
67
|
+
"@storybook/react": "7.0.0-alpha.41",
|
|
68
|
+
"@types/node": "^14.14.20 || ^16.0.0",
|
|
69
|
+
"find-up": "^5.0.0",
|
|
70
|
+
"fs-extra": "^9.0.1",
|
|
71
|
+
"image-size": "^1.0.0",
|
|
72
|
+
"loader-utils": "^3.2.0",
|
|
73
|
+
"pnp-webpack-plugin": "^1.7.0",
|
|
74
|
+
"postcss-loader": "^6.2.1",
|
|
75
|
+
"resolve-url-loader": "^5.0.0",
|
|
76
|
+
"sass-loader": "^12.4.0",
|
|
77
|
+
"semver": "^7.3.5",
|
|
78
|
+
"ts-dedent": "^2.0.0",
|
|
79
|
+
"tsconfig-paths": "^4.0.0",
|
|
80
|
+
"tsconfig-paths-webpack-plugin": "^3.5.2"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@storybook/addon-actions": "7.0.0-alpha.41",
|
|
84
|
+
"@types/loader-utils": "^2.0.3",
|
|
85
|
+
"next": "^12.2.4",
|
|
86
|
+
"typescript": "~4.6.3",
|
|
87
|
+
"webpack": "^5.65.0"
|
|
88
|
+
},
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"@babel/core": "^7.11.5",
|
|
91
|
+
"@storybook/addon-actions": "7.0.0-alpha.40",
|
|
92
|
+
"next": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
93
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
94
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
95
|
+
"webpack": "^5.0.0"
|
|
96
|
+
},
|
|
97
|
+
"peerDependenciesMeta": {
|
|
98
|
+
"@babel/core": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@storybook/addon-actions": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"typescript": {
|
|
105
|
+
"optional": true
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"engines": {
|
|
109
|
+
"node": ">=10.13.0"
|
|
110
|
+
},
|
|
111
|
+
"publishConfig": {
|
|
112
|
+
"access": "public"
|
|
113
|
+
},
|
|
114
|
+
"bundler": {
|
|
115
|
+
"entries": [
|
|
116
|
+
"./src/index.ts",
|
|
117
|
+
"./src/preset.ts",
|
|
118
|
+
"./src/preview.tsx",
|
|
119
|
+
"./src/next-image-loader-stub.ts"
|
|
120
|
+
],
|
|
121
|
+
"platform": "node"
|
|
122
|
+
},
|
|
123
|
+
"gitHead": "7ec6f916eb875bd2e3cf3aa6b1afcd1fe25d1637"
|
|
124
|
+
}
|
package/preset.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/preset');
|