Enable sass theme change in Storybook

This commit is contained in:
Dominik Prokop
2019-03-21 16:06:55 +01:00
parent 56251ca546
commit 35f6039da7
3 changed files with 29 additions and 9 deletions

View File

@@ -2,13 +2,25 @@ import { configure, addDecorator } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import { withTheme } from '../src/utils/storybook/withTheme';
import '../../../public/sass/grafana.light.scss';
// @ts-ignore
import lightTheme from '../../../public/sass/grafana.light.scss';
// @ts-ignore
import darkTheme from '../../../public/sass/grafana.dark.scss';
const handleThemeChange = (theme: string) => {
if (theme !== 'light') {
lightTheme.unuse();
darkTheme.use();
} else {
darkTheme.unuse();
lightTheme.use();
}
};
// automatically import all files ending in *.stories.tsx
const req = require.context('../src/components', true, /.story.tsx$/);
addDecorator(withKnobs);
addDecorator(withTheme);
addDecorator(withTheme(handleThemeChange));
function loadStories() {
req.keys().forEach(req);

View File

@@ -14,15 +14,15 @@ module.exports = (baseConfig, env, config) => {
test: /\.scss$/,
use: [
{
loader: 'style-loader',
loader: 'style-loader/useable',
},
{
loader: 'css-loader',
options: {
importLoaders: 2,
url: false,
sourceMap: false,
minimize: false,
// url: false,
// sourceMap: false,
// minimize: false,
},
},
{
@@ -35,7 +35,7 @@ module.exports = (baseConfig, env, config) => {
{
loader: 'sass-loader',
options: {
sourceMap: false
sourceMap: false,
},
},
],