Skip to content

Commit fd2b969

Browse files
committed
upgrade to storybook 9
1 parent 32b911b commit fd2b969

File tree

33 files changed

+2193
-8774
lines changed

33 files changed

+2193
-8774
lines changed

.github/workflows/chromatic.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# .github/workflows/chromatic.yml
22

3-
name: "Chromatic"
3+
name: 'Chromatic'
44

5-
on:
5+
on:
66
push:
77
branches-ignore:
88
- deployment
99
tags-ignore:
10-
- v0.*
10+
- '**'
1111

1212
jobs:
1313
chromatic:
@@ -21,7 +21,8 @@ jobs:
2121
- name: Install dependencies
2222
run: npm ci
2323

24-
- name: Publish to Chromatic
24+
- name: Build storybook and run chromatic
2525
uses: chromaui/action@latest
2626
with:
27-
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
27+
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
28+
onlyChanged: true

.storybook/main.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,62 @@
11
/** @type { import('@storybook/svelte-vite').StorybookConfig } */
2+
process.env.CHROMATIC_DISABLE = 'true';
3+
24
const config = {
5+
framework: '@storybook/svelte-vite',
36
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|svelte)'],
47
addons: [
58
'@storybook/addon-links',
6-
'@storybook/addon-essentials',
7-
'@storybook/addon-interactions',
8-
'@storybook/addon-designs',
9+
'@storybook/addon-docs',
10+
'@storybook/addon-vitest',
11+
'@chromatic-com/storybook',
12+
'@storybook/addon-a11y',
913
],
10-
framework: {
11-
name: '@storybook/svelte-vite',
12-
options: {},
13-
},
1414
features: {
15-
interactionsDebugger: true,
15+
interactions: true,
1616
},
1717
docs: {},
1818
staticDirs: ['../src/public'],
1919
async viteFinal(config, { configType }) {
2020
const { mergeConfig } = await import('vite');
21-
22-
if (configType === 'DEVELOPMENT') {
23-
// Your development configuration goes here
24-
}
21+
2522
if (configType === 'PRODUCTION') {
26-
// Your production configuration goes here.
27-
config.plugins = config.plugins.filter(plugin => {
28-
return plugin.name != 'postbuild-commands'
29-
})
23+
config.plugins = config.plugins.filter((plugin) => {
24+
return plugin.name != 'postbuild-commands';
25+
});
3026
}
3127
return mergeConfig(config, {
32-
// Your environment configuration here
28+
//this plugin is a (hopefully) temporary workaround for storybook not picking up our local styles
29+
//we use an alias to reference bootstrap styles and they weren't getting picked up by storybook at all during prod build
30+
//if we only used storybook for dev, I would've never seen this issue, but chromatic builds for prod for our snapshots
31+
plugins: [
32+
{
33+
name: 'inject-preview-css',
34+
enforce: 'post',
35+
generateBundle(options, bundle) {
36+
//find the style.css chunk
37+
const cssChunk = Object.values(bundle).find(
38+
(chunk) => chunk.type === 'asset' && chunk.name === 'style.css'
39+
);
40+
41+
if (cssChunk) {
42+
const iframeHtml = Object.values(bundle).find(
43+
(chunk) => chunk.type === 'asset' && chunk.fileName === 'iframe.html'
44+
);
45+
46+
if (iframeHtml) {
47+
iframeHtml.source = iframeHtml.source.replace(
48+
'</head>',
49+
` <link rel="stylesheet" href="/${cssChunk.fileName}">\n</head>`
50+
);
51+
}
52+
}
53+
},
54+
},
55+
],
3356
build: {
57+
cssCodeSplit: false,
3458
rollupOptions: {
35-
external: [
36-
/^..\/fonts/,
37-
/^\/common\/firebird/
38-
]
59+
external: [/^..\/fonts/, /^\/common\/firebird/],
3960
},
4061
},
4162
});

.storybook/manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addons } from "@storybook/manager-api";
1+
import { addons } from "storybook/manager-api";
22

33
addons.setConfig({
44
panelPosition: 'right'

.storybook/preview.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import '../src/scss/styles.scss';
22
import * as bootstrap from 'bootstrap';
3-
// import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
43

54
const BOOTSTRAP_VIEWPORTS = {
65
bsXs: {
@@ -49,18 +48,24 @@ const BOOTSTRAP_VIEWPORTS = {
4948

5049
const preview = {
5150
parameters: {
52-
backgrounds: {
53-
default: 'light',
54-
},
55-
actions: { argTypesRegex: '^on[A-Z].*' },
5651
controls: {
5752
matchers: {
5853
color: /(background|color)$/i,
5954
date: /Date$/,
6055
},
6156
},
6257
viewport: {
63-
viewports: BOOTSTRAP_VIEWPORTS,
58+
options: BOOTSTRAP_VIEWPORTS, // Keep as 'options' in Storybook 9
59+
},
60+
},
61+
62+
initialGlobals: {
63+
backgrounds: {
64+
value: 'light',
65+
},
66+
viewport: {
67+
value: 'bsXl', // Optional: set a default viewport
68+
isRotated: false,
6469
},
6570
},
6671
};

.storybook/vitest.setup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { setProjectAnnotations } from '@storybook/svelte-vite';
2+
import * as projectAnnotations from './preview';
3+
4+
// This is an important step to apply the right configuration when testing your stories.
5+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
6+
setProjectAnnotations([projectAnnotations]);

chromatic.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"onlyChanged": true,
3+
"projectId": "Project:656a2bfa011def621f569319",
4+
"zip": true
5+
}

0 commit comments

Comments
 (0)