2018-05-15 23:52:57 +02:00
|
|
|
import React from 'react';
|
2018-08-31 12:18:01 +02:00
|
|
|
import ThemeProvider from '@emotion/provider';
|
2018-05-15 23:52:57 +02:00
|
|
|
import { configure, addDecorator } from '@storybook/react';
|
|
|
|
import { themes } from '@storybook/components';
|
2018-09-10 00:50:25 -07:00
|
|
|
import { withOptions } from '@storybook/addon-options';
|
2018-04-13 00:09:33 +02:00
|
|
|
import { configureViewport, INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
|
2018-11-22 14:40:19 -08:00
|
|
|
import { withCssResources } from '@storybook/addon-cssresources';
|
2018-05-15 23:52:57 +02:00
|
|
|
|
2017-12-18 17:16:19 +11:00
|
|
|
import 'react-chromatic/storybook-addon';
|
2018-01-06 22:49:40 +03:00
|
|
|
import addHeadWarning from './head-warning';
|
2018-02-26 00:00:28 +01:00
|
|
|
import extraViewports from './extra-viewports.json';
|
2018-01-06 22:49:40 +03:00
|
|
|
|
2018-10-14 17:39:35 +02:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
if (!process.env.DOTENV_DEVELOPMENT_DISPLAY_WARNING) {
|
|
|
|
addHeadWarning('Dotenv development file not loaded');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!process.env.STORYBOOK_DISPLAY_WARNING) {
|
|
|
|
addHeadWarning('Global storybook env var not loaded');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.DISPLAY_WARNING) {
|
|
|
|
addHeadWarning('Global non-storybook env var loaded');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 00:41:29 +03:00
|
|
|
addHeadWarning('Preview head not loaded', 'preview-head-not-loaded');
|
|
|
|
addHeadWarning('Dotenv file not loaded', 'dotenv-file-not-loaded');
|
2017-12-27 10:39:31 +01:00
|
|
|
|
2018-09-10 00:50:25 -07:00
|
|
|
addDecorator(
|
|
|
|
withOptions({
|
|
|
|
hierarchySeparator: /\/|\./,
|
|
|
|
hierarchyRootSeparator: /\|/,
|
|
|
|
theme: themes.dark,
|
|
|
|
})
|
|
|
|
);
|
2017-11-27 13:48:46 +11:00
|
|
|
|
2018-10-20 01:39:21 -07:00
|
|
|
addDecorator(
|
2018-11-22 14:40:19 -08:00
|
|
|
withCssResources({
|
2018-10-29 15:03:59 -07:00
|
|
|
cssresources: [
|
|
|
|
{
|
|
|
|
name: `bluetheme`,
|
|
|
|
code: `<style>body {
|
|
|
|
background-color: lightblue;
|
|
|
|
}</style>`,
|
|
|
|
picked: false,
|
|
|
|
},
|
|
|
|
],
|
2018-10-20 01:39:21 -07:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2018-12-04 19:54:10 +01:00
|
|
|
addDecorator((story, { kind }) =>
|
|
|
|
kind === 'Core|Errors' ? story() : <ThemeProvider theme={themes.normal}>{story()}</ThemeProvider>
|
2018-08-09 11:50:48 +10:00
|
|
|
);
|
2018-05-15 23:52:57 +02:00
|
|
|
|
2018-02-26 00:00:28 +01:00
|
|
|
configureViewport({
|
|
|
|
viewports: {
|
|
|
|
...INITIAL_VIEWPORTS,
|
2018-03-09 00:51:35 +01:00
|
|
|
...extraViewports,
|
|
|
|
},
|
2018-02-26 00:00:28 +01:00
|
|
|
});
|
|
|
|
|
2018-01-31 14:54:29 +02:00
|
|
|
function importAll(req) {
|
|
|
|
req.keys().forEach(filename => req(filename));
|
|
|
|
}
|
|
|
|
|
2017-11-27 13:48:46 +11:00
|
|
|
function loadStories() {
|
|
|
|
let req;
|
2017-12-20 15:22:08 +11:00
|
|
|
req = require.context('../../lib/ui/src', true, /\.stories\.js$/);
|
2018-01-31 14:54:29 +02:00
|
|
|
importAll(req);
|
2017-11-27 13:56:00 +11:00
|
|
|
|
2017-12-20 15:22:08 +11:00
|
|
|
req = require.context('../../lib/components/src', true, /\.stories\.js$/);
|
2018-01-31 14:54:29 +02:00
|
|
|
importAll(req);
|
2017-12-20 15:22:08 +11:00
|
|
|
|
|
|
|
req = require.context('./stories', true, /\.stories\.js$/);
|
2018-01-31 14:54:29 +02:00
|
|
|
importAll(req);
|
2017-11-27 13:48:46 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
configure(loadStories, module);
|