Skip to content

Commit d2e5afe

Browse files
Upgrade storybook to v6 (#1350)
* Upgrade storybook to v6 * add storybook dark mode so we can have the storybook chrome match our currently selected theme no good way to update one based on the other right now * Rename files more clearly, we can't use webpack.config.js because storybook will try to do some things automatically with that * remove added tsconfig include Co-authored-by: Danni <[email protected]>
1 parent 594e9aa commit d2e5afe

File tree

16 files changed

+2741
-2602
lines changed

16 files changed

+2741
-2602
lines changed

.chromatic/addons.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

.chromatic/config.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

.chromatic/main.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
const webpackconfig = require('./webpack-chromatic.config.js');
3+
4+
module.exports = {
5+
stories: ['../packages/**/chromatic/**/*.chromatic.@(js|jsx|ts|tsx)'],
6+
addons: [
7+
'@storybook/addon-actions',
8+
'@storybook/addon-links',
9+
'@storybook/addon-a11y',
10+
'@storybook/addon-knobs'
11+
],
12+
typescript: {
13+
check: false,
14+
reactDocgen: false
15+
},
16+
webpackFinal: async (config) => {
17+
let custom = webpackconfig();
18+
19+
let resultConfig = {
20+
...config,
21+
plugins: config.plugins.concat(custom.plugins),
22+
parallelism: 1,
23+
module: {
24+
...config.module,
25+
rules: custom.module.rules
26+
}
27+
};
28+
29+
if (resultConfig.mode === 'production') {
30+
// see https://github.com/storybooks/storybook/issues/1570
31+
resultConfig.plugins = resultConfig.plugins.filter(plugin => plugin.constructor.name !== 'UglifyJsPlugin')
32+
}
33+
34+
return resultConfig;
35+
}
36+
};

.chromatic/manager.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import addons from '@storybook/addons';
2+
3+
addons.setConfig({
4+
showRoots: false,
5+
enableShortcuts: false
6+
});

.chromatic/preview.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {configureActions} from '@storybook/addon-actions';
2+
import React from 'react';
3+
import {VerticalCenter} from './layout';
4+
import {withChromaticProvider} from './custom-addons/chromatic';
5+
6+
7+
// decorator order matters, the last one will be the outer most
8+
9+
configureActions({
10+
depth: 1
11+
});
12+
13+
export const parameters = {
14+
options: {
15+
storySort: (a, b) => a[1].kind === b[1].kind ? 0 : a[1].id.localeCompare(b[1].id, undefined, { numeric: true }),
16+
},
17+
a11y: {},
18+
layout: 'fullscreen'
19+
};
20+
21+
export const decorators = [
22+
story => (
23+
<VerticalCenter style={{alignItems: 'center', minHeight: null, boxSizing: 'border-box', display: 'flex', justifyContent: 'center'}}>
24+
{story()}
25+
</VerticalCenter>
26+
),
27+
withChromaticProvider
28+
];

.chromatic/webpack.config.js renamed to .chromatic/webpack-chromatic.config.js

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require('path');
22
const webpack = require('webpack');
33
const md5 = require('md5');
44
const fs = require('fs');
5+
const reactVersion = require('react/package.json').version;
56

67
const fileHashMemo = {};
78

@@ -22,15 +23,9 @@ const generateScopedName = (localName, resourcePath) => {
2223
return `${componentName}_${localName}_${contentHash}`;
2324
};
2425

25-
module.exports = ({config}, env) => {
26-
if (env === 'PRODUCTION') {
27-
// see https://github.com/storybooks/storybook/issues/1570
28-
config.plugins = config.plugins.filter(plugin => plugin.constructor.name !== 'UglifyJsPlugin')
29-
}
30-
31-
config.resolve.extensions.push('.ts', '.tsx');
32-
33-
return Object.assign(config, {
26+
module.exports = () => {
27+
return {
28+
plugins: [new webpack.DefinePlugin({REACT_VERSION: JSON.stringify(reactVersion)})],
3429
parallelism: 1,
3530
module: {
3631
rules: [
@@ -45,28 +40,6 @@ module.exports = ({config}, env) => {
4540
{ loader: require.resolve('babel-loader') },
4641
]
4742
},
48-
{
49-
test: /\.styl$/,
50-
use: [
51-
'style-loader',
52-
'css-loader',
53-
{
54-
loader: 'stylus-loader',
55-
options: {
56-
paths: [__dirname + '/../node_modules'],
57-
define: {
58-
'embedurl': require('stylus').url()
59-
},
60-
'resolve url': true,
61-
set: {
62-
'include css': true
63-
},
64-
use: [require('svg-stylus')()]
65-
}
66-
}
67-
],
68-
include: path.resolve(__dirname, '../')
69-
},
7043
{
7144
test: /packages[\\/].*\.css$/,
7245
use: [
@@ -103,5 +76,5 @@ module.exports = ({config}, env) => {
10376
}
10477
]
10578
}
106-
});
79+
};
10780
};

.storybook/addons.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

.storybook/config.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

.storybook/custom-addons/provider/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Text} from '@react-spectrum/text';
88
import {themes, defaultTheme} from '../../constants';
99
import {Dialog, DialogTrigger} from '@react-spectrum/dialog';
1010

11-
document.body.style.margin = 0;
11+
document.body.style.margin = '0';
1212

1313
const providerValuesFromUrl = Object.entries(getQueryParams()).reduce((acc, [k, v]) => {
1414
if (k.includes('providerSwitcher-')) {

.storybook/main.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
const webpackconfig = require('./webpack-storybook.config.js');
3+
4+
module.exports = {
5+
stories: ['../packages/**/stories/**/*.stories.@(js|jsx|ts|tsx)'],
6+
addons: [
7+
'@storybook/addon-actions',
8+
'@storybook/addon-links',
9+
'@storybook/addon-a11y',
10+
'@storybook/addon-knobs',
11+
'storybook-dark-mode',
12+
'./custom-addons/provider/register',
13+
'./theme.register'
14+
],
15+
typescript: {
16+
check: false,
17+
reactDocgen: false
18+
},
19+
webpackFinal: async (config) => {
20+
let custom = webpackconfig();
21+
22+
let resultConfig = {
23+
...config,
24+
plugins: config.plugins.concat(custom.plugins),
25+
parallelism: 1,
26+
module: {
27+
...config.module,
28+
rules: custom.module.rules
29+
}
30+
};
31+
32+
if (resultConfig.mode === 'production') {
33+
// see https://github.com/storybooks/storybook/issues/1570
34+
resultConfig.plugins = resultConfig.plugins.filter(plugin => plugin.constructor.name !== 'UglifyJsPlugin')
35+
}
36+
37+
return resultConfig;
38+
}
39+
};

0 commit comments

Comments
 (0)