Skip to content

Commit 6dcf09b

Browse files
pfultonRajdeep Chandragithub-actions[bot]castastrophe
authored
feat: update to Storybook v7 (#1935)
* chore(storybook): upgrade to v7 * fix: added storybook build and removed build-storybook * chore: updated storybook addons with v7 * chore: updated main.js and preview.js with s7 * fix: actions errors fix * chore: updated Readme * chore: updated stories with withActions decorators for actions handler for s7 * chore: updated changelog * fix: withActions decorators * fix: reverted changes on stories * fix: addon status version bump * fix: updated changelog * chore: updated makeDecorator in decorators * chore: migration to storybook 7 readme update * fix: identation fixes * fix: identation fixes * fix: remove postcss from features * fix: temp fix on disabling lazy loading in webpack 5 * fix: actions not firing * docs: add boolean arg to colorloupe story * chore: update to latest storybook releases --------- Co-authored-by: Rajdeep Chandra <rajdeepc@adobe.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: [ Cassondra ] <castastrophe@users.noreply.github.com>
1 parent 9d7bc21 commit 6dcf09b

File tree

11 files changed

+3558
-3915
lines changed

11 files changed

+3558
-3915
lines changed

components/calendar/stories/template.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ export const Template = ({
114114
.map((_val, idx) =>
115115
new Array(DOW.length).fill(0).map((_v, i) => {
116116
const thisDay = idx * DOW.length + i + 1 - firstDOWInMonth;
117+
const isOutsideMonth =
118+
displayedDate.getDate() < 1 ||
119+
displayedDate.getDate() > lastDateInMonth;
117120
/* Determine if this entry exists within this month or the next or prev month */
118121
let thisMonth = !isOutsideMonth
119122
? displayedMonth
120123
: displayedMonth + (thisDay < 1 ? -1 : 1);
121124
/* Determine if the displayed date is in this year or the previous one */
122125
let thisYear = displayedYear;
123126

124-
const isOutsideMonth =
125-
displayedDate.getDate() < 1 ||
126-
displayedDate.getDate() > lastDateInMonth;
127127
if (isOutsideMonth) {
128128
if (thisMonth < 0) {
129129
thisMonth = 11;

components/colorloupe/stories/colorloupe.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default {
2121
},
2222
args: {
2323
rootClass: "spectrum-ColorLoupe",
24+
isOpen: true,
2425
},
2526
parameters: {
2627
actions: {

tools/preview/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,4 @@ Co-authored-by: castastrophe <castastrophe@users.noreply.github.com>
404404

405405
🗓 2022-12-13
406406

407-
**Note:** Version bump only for package @spectrum-css/preview
407+
**Note:** Version bump only for package @spectrum-css/preview

tools/preview/README.md

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Storybook leverages webpack for bundling and we have updated it with the followi
5757
}
5858
```
5959

60-
We are leaning on Storybook's `@storybook/web-components` framework configuration as our stories rely on lit-html for dynamic attribute assignment.
60+
We are leaning on Storybook's `@storybook/web-components-webpack5` framework configuration as our stories rely on lit-html for dynamic attribute assignment.
6161

6262
## Add-ons
6363

@@ -338,3 +338,139 @@ You can pass any supported [chromatic flag](https://www.chromatic.com/docs/cli#c
338338
Runs will generate a JUnit XML file with build results (`chromatic-build-{buildNumber}.xml`). This file should not be committed and is part of the .gitignore rules.
339339
340340
Running without publishing to Chromatic? Add the `--dry-run` flag. Need more information to debug a run? Try the `--diagnostics` flag (writes process context information to `chromatic-diagnostics.json`).
341+
342+
343+
344+
# Migration to Storybook 7.0(Draft)
345+
346+
347+
## Updates:
348+
---
349+
`*` Added support for handler actions with ```withActions``` on each stories which have action handlers.
350+
351+
Example:
352+
```js
353+
import globalThis from 'global';
354+
+ import { withActions } from '@storybook/addon-actions/decorator';
355+
356+
export default {
357+
component: globalThis.Components.Button,
358+
args: {
359+
label: 'Click Me!',
360+
},
361+
parameters: {
362+
chromatic: { disable: true },
363+
},
364+
};
365+
export const Basic = {
366+
parameters: {
367+
handles: [{ click: 'clicked', contextmenu: 'right clicked' }],
368+
},
369+
+ decorators: [withActions],
370+
};
371+
```
372+
373+
`*` Upgraded to ```Webpack 5``` for improved bundling and performance from ```webpack 4```
374+
375+
`*` @storybook addons dependencies are upgraded to v7 from v6
376+
```js
377+
"@storybook/addon-docs": "^7.0.12",
378+
"@storybook/addon-essentials": "^7.0.12",
379+
"@storybook/api": "^7.0.12",
380+
"@storybook/client-api": "^7.0.12",
381+
"@storybook/components": "^7.0.12",
382+
"@storybook/core-events": "^7.0.12",
383+
"@storybook/manager-api": "^7.0.12",
384+
"@storybook/preview-api": "^7.0.12",
385+
"@storybook/theming": "^7.0.12",
386+
"@storybook/web-components-webpack5": "^7.0.12",
387+
"@whitespace/storybook-addon-html": "^5.1.4",
388+
```
389+
390+
`*` Added a new "Controls" addon for interactive component props editing.
391+
392+
`*` Introduced a new "Docs-only" mode for isolating component documentation.
393+
394+
`*` Improved the addon ecosystem with new and updated addons.
395+
396+
397+
<br></br>
398+
## Breaking Changes:
399+
---
400+
`*` client-api is deperacted and preview-api is introduced
401+
402+
```js
403+
- import { useEffect } from '@storybook/client-api';
404+
+ import { useEffect } from '@storybook/preview-api';
405+
```
406+
407+
`*` @storybook/addons is deperacted and replaced with @storybook/manager-api
408+
409+
```js
410+
- import { addons } from '@storybook/addons';
411+
+ import { addons } from '@storybook/manager-api';
412+
```
413+
414+
`*` ```@storybook-webcomponents``` is deprecated. ```@storybook/web-components-webpack'``` is added with webpack 5 support.
415+
416+
```js
417+
- framework: '@storybook/web-components',
418+
+ framework: {
419+
name: '@storybook/web-components-webpack5',
420+
options: {
421+
fastRefresh: true,
422+
builder: { lazyCompilation: true },
423+
},
424+
},
425+
426+
```
427+
428+
`*` Docs is now added to every component on the sidebar with the below code in Storybook 7
429+
```js
430+
docs: {
431+
autodocs: true,
432+
defaultName: 'Docs',
433+
},
434+
```
435+
436+
`*` preview.js is exported as default in Storybook 7
437+
438+
```js
439+
- export const parameters = {
440+
- actions: { argTypesRegex: '^on[A-Z].*' },
441+
- };
442+
443+
+ export default {
444+
+ parameters: {
445+
+ actions: { argTypesRegex: '^on[A-Z].*' },
446+
+ },
447+
+ };
448+
```
449+
## Deprecations(Addons):
450+
---
451+
452+
`*` ```"@storybook/client-api"``` is deprecated
453+
454+
`*` ```"@storybook/addons"``` is deprecated
455+
456+
457+
## Bug Fixes:
458+
---
459+
`*` Fixed various issues related to performance, rendering, and compatibility.
460+
461+
`*` Resolved problems with the Storybook UI, including layout glitches and navigation bugs.
462+
463+
`*` Fixed bugs in calender storybook
464+
465+
466+
## Improvements:
467+
---
468+
`*` Improved the overall performance and stability of the Storybook development environment.
469+
470+
`*` Enhanced the documentation with updated examples and guides.
471+
472+
`*` Optimized the build process for faster bundling and reduced file sizes.
473+
474+
`*` Upgraded dependencies to their latest versions for improved compatibility and security.
475+
476+
---
Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
1-
import { useEffect } from "@storybook/client-api";
1+
import { useEffect, makeDecorator } from "@storybook/preview-api";
22

33
/**
44
* @type import('@storybook/csf').DecoratorFunction<import('@storybook/web-components').WebComponentsFramework>
55
* @description Global properties added to each component; determines what stylesheets are loaded
66
**/
7-
export const withContextWrapper = (StoryFn, context) => {
8-
const { args, argTypes } = context;
9-
10-
const getDefaultValue = (type) => {
11-
if (!type) return null;
12-
if (type.defaultValue) return type.defaultValue;
13-
return type.options ? type.options[0] : null;
14-
};
15-
16-
// This property informs which context stylesheets to source
17-
// but does not source a stylesheet for itself
18-
/** @type boolean */
19-
const isExpress = args.express
20-
? args.express
21-
: getDefaultValue(argTypes.express);
22-
/** @type string */
23-
const color = args.color ? args.color : getDefaultValue(argTypes.color);
24-
/** @type string */
25-
const scale = args.scale ? args.scale : getDefaultValue(argTypes.scale);
26-
27-
const colors = argTypes.color.options;
28-
const scales = argTypes.scale.options;
29-
30-
useEffect(() => {
31-
document.body.classList.toggle("spectrum--express", isExpress);
32-
33-
for (const c of colors) {
34-
document.body.classList.toggle(`spectrum--${c}`, c === color);
35-
}
36-
37-
for (const s of scales) {
38-
document.body.classList.toggle(`spectrum--${s}`, s === scale);
39-
}
40-
}, [color, scale, isExpress]);
41-
42-
return StoryFn(context);
43-
};
7+
export const withContextWrapper = makeDecorator({
8+
name: "withContextWrapper",
9+
parameterName: "context",
10+
wrapper: (StoryFn, context) => {
11+
const { args, argTypes } = context;
12+
13+
const getDefaultValue = (type) => {
14+
if (!type) return null;
15+
if (type.defaultValue) return type.defaultValue;
16+
return type.options ? type.options[0] : null;
17+
};
18+
19+
// This property informs which context stylesheets to source
20+
// but does not source a stylesheet for itself
21+
/** @type boolean */
22+
const isExpress = args.express
23+
? args.express
24+
: getDefaultValue(argTypes.express);
25+
/** @type string */
26+
const color = args.color ? args.color : getDefaultValue(argTypes.color);
27+
/** @type string */
28+
const scale = args.scale ? args.scale : getDefaultValue(argTypes.scale);
29+
30+
const colors = argTypes.color.options;
31+
const scales = argTypes.scale.options;
32+
33+
useEffect(() => {
34+
document.body.classList.toggle("spectrum--express", isExpress);
35+
36+
for (const c of colors) {
37+
document.body.classList.toggle(`spectrum--${c}`, c === color);
38+
}
39+
40+
for (const s of scales) {
41+
document.body.classList.toggle(`spectrum--${s}`, s === scale);
42+
}
43+
}, [color, scale, isExpress]);
44+
45+
return StoryFn(context);
46+
},
47+
});

0 commit comments

Comments
 (0)