Skip to content

Commit 58bc0f9

Browse files
feat(storybook): Implement Storybook 5.0 (#3821)
* feat(storybook): Implement Storybook 5.0 * Fix compiling error on docs generation
1 parent 0987d49 commit 58bc0f9

File tree

13 files changed

+15177
-4183
lines changed

13 files changed

+15177
-4183
lines changed

.babelrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"presets": ["react"],
33
"plugins": [
44
"transform-es2015-modules-commonjs",
5-
"transform-object-rest-spread"
5+
"transform-object-rest-spread",
6+
"syntax-dynamic-import"
67
],
78
"env": {
89
"test": {

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
!/.travis.yml
1919
!/.github
2020
!/.prettierignore
21+
!/.storybook
2122

2223
# Add a .gitkeep file in an empty
2324
# directory to check it in the repository

.storybook/addons.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import '@storybook/addon-viewport/register';
2+
import '@storybook/addon-options/register';
3+
import '@storybook/addon-a11y/register';

.storybook/config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { configure, addDecorator, addParameters } from '@storybook/react';
2+
import { withA11y } from '@storybook/addon-a11y';
3+
import { create } from '@storybook/theming';
4+
5+
const req = require.context('../ui/', true, /\.stories\.js$/);
6+
7+
function loadStories() {
8+
req.keys().forEach(filename => req(filename));
9+
}
10+
11+
// Global Decorators
12+
// https://storybook.js.org/addons/introduction/#1-decorators
13+
addDecorator(withA11y);
14+
addParameters({
15+
options: {
16+
theme: create({
17+
base: 'light',
18+
brandTitle: 'SLDS',
19+
brandUrl: 'http://www.lightningdesignsystem.com'
20+
})
21+
}
22+
});
23+
24+
configure(loadStories, module);

.storybook/preview-head.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<style>.sb-show-main { background: white; padding: 2rem; height: 100vh; } </style>

.storybook/scss/framework/config.scss

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is used to override any system variables when webpack is compiling the
2+
// modules stylesheets for story book etc. as they can't be reletive to the
3+
// assets folder, as that doesn't exist in the storybook environement
4+
5+
$static-image-path: '../../assets/images';
6+
$static-font-path: '../../assets/fonts/webfonts';

.storybook/webpack.config.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const path = require('path');
2+
const paths = require('../scripts/helpers/paths');
3+
const CopyWebpackPlugin = require('copy-webpack-plugin');
4+
5+
module.exports = async ({ config, mode }) => {
6+
config.module.rules.push(
7+
{
8+
test: /\.scss$/,
9+
include: [
10+
path.resolve(__dirname, '../ui'),
11+
path.resolve(__dirname, '../.storybook'),
12+
path.resolve(__dirname, '../shared'),
13+
path.resolve(__dirname, '../assets')
14+
],
15+
use: [
16+
{
17+
loader: path.resolve(
18+
__dirname,
19+
'../scripts/compile/lwc-style-loader.js'
20+
)
21+
},
22+
{
23+
loader: 'css-loader',
24+
options: { importLoaders: 2 }
25+
},
26+
{
27+
loader: 'postcss-loader',
28+
options: { sourceMap: true }
29+
},
30+
{
31+
loader: 'resolve-url-loader',
32+
options: { sourceMap: true }
33+
},
34+
{
35+
loader: 'sass-loader',
36+
options: { sourceMap: true, outputStyle: 'compressed' }
37+
},
38+
// Reads Sass vars from files or inlined in the options property
39+
// needed to reset the asset paths for webpack to load them, as we
40+
// assume we're loading from the assets folder with a relitive path
41+
// from the compile css monolith to the assets, like fonts
42+
{
43+
loader: '@epegzz/sass-vars-loader',
44+
options: {
45+
syntax: 'scss',
46+
files: [path.resolve(__dirname, './scss/framework/config.scss')]
47+
}
48+
}
49+
]
50+
},
51+
{
52+
test: /\.css$/,
53+
include: path.resolve(__dirname, '../ui'),
54+
use: ['raw-loader']
55+
}
56+
);
57+
config.plugins.push(
58+
new CopyWebpackPlugin([
59+
{
60+
from: paths.icons,
61+
to: '/assets/icons'
62+
}
63+
])
64+
);
65+
return config;
66+
};

0 commit comments

Comments
 (0)