2018-05-15 23:52:57 +02:00
|
|
|
import React from 'react';
|
2018-12-20 12:14:25 +11:00
|
|
|
import { storiesOf, configure, addDecorator, addParameters } from '@storybook/react';
|
2019-03-04 21:05:01 +01:00
|
|
|
import { Global, ThemeProvider, themes, createReset, create, convert } from '@storybook/theming';
|
2018-12-10 19:27:12 +01:00
|
|
|
|
|
|
|
import { withCssResources } from '@storybook/addon-cssresources';
|
2019-03-04 13:00:17 +08:00
|
|
|
import { withA11y } from '@storybook/addon-a11y';
|
2018-12-20 12:14:25 +11:00
|
|
|
import { withNotes } from '@storybook/addon-notes';
|
2018-05-15 23:52:57 +02:00
|
|
|
|
2019-01-18 15:37:08 +11:00
|
|
|
import 'storybook-chromatic';
|
2018-12-10 19:27:12 +01:00
|
|
|
|
2018-01-06 22:49:40 +03:00
|
|
|
import addHeadWarning from './head-warning';
|
|
|
|
|
2018-10-14 17:39:35 +02:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
if (!process.env.DOTENV_DEVELOPMENT_DISPLAY_WARNING) {
|
2018-12-29 19:50:44 +01:00
|
|
|
addHeadWarning('dotenv-env', 'Dotenv development file not loaded');
|
2018-10-14 17:39:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!process.env.STORYBOOK_DISPLAY_WARNING) {
|
2018-12-29 19:50:44 +01:00
|
|
|
addHeadWarning('env-glob', 'Global storybook env var not loaded');
|
2018-10-14 17:39:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.DISPLAY_WARNING) {
|
2018-12-29 19:50:44 +01:00
|
|
|
addHeadWarning('env-extra', 'Global non-storybook env var loaded');
|
2018-10-14 17:39:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 19:50:44 +01: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-12-10 19:27:12 +01:00
|
|
|
addDecorator(withCssResources);
|
2019-03-04 13:00:17 +08:00
|
|
|
addDecorator(withA11y);
|
2018-12-20 12:14:25 +11:00
|
|
|
addDecorator(withNotes);
|
2017-11-27 13:48:46 +11:00
|
|
|
|
2019-02-20 01:45:52 +01:00
|
|
|
addDecorator(storyFn => (
|
2019-03-04 21:05:01 +01:00
|
|
|
<ThemeProvider theme={convert(themes.light)}>
|
2019-02-14 15:04:55 +01:00
|
|
|
<Global styles={createReset} />
|
2019-02-20 01:45:52 +01:00
|
|
|
{storyFn()}
|
2018-12-29 19:50:44 +01:00
|
|
|
</ThemeProvider>
|
|
|
|
));
|
2018-05-15 23:52:57 +02:00
|
|
|
|
2018-12-06 12:02:21 +01:00
|
|
|
addParameters({
|
2019-02-21 21:28:32 +01:00
|
|
|
a11y: {
|
2019-03-06 17:40:33 +01:00
|
|
|
config: {},
|
2019-02-21 21:28:32 +01:00
|
|
|
options: {
|
|
|
|
checks: { 'color-contrast': { options: { noScroll: true } } },
|
|
|
|
restoreScroll: true,
|
|
|
|
},
|
|
|
|
},
|
2018-12-10 19:27:12 +01:00
|
|
|
options: {
|
|
|
|
hierarchySeparator: /\/|\./,
|
|
|
|
hierarchyRootSeparator: '|',
|
2019-03-04 21:05:01 +01:00
|
|
|
theme: create({ colorPrimary: 'hotpink', colorSecondary: 'orangered' }),
|
2018-12-10 19:27:12 +01:00
|
|
|
},
|
2019-02-14 15:04:55 +01:00
|
|
|
backgrounds: [
|
2019-03-04 21:05:01 +01:00
|
|
|
{ name: 'storybook app', value: themes.light.appBg, default: true },
|
2019-02-14 15:04:55 +01:00
|
|
|
{ name: 'light', value: '#eeeeee' },
|
|
|
|
{ name: 'dark', value: '#222222' },
|
|
|
|
],
|
2018-02-26 00:00:28 +01:00
|
|
|
});
|
|
|
|
|
2018-12-21 11:34:24 +11:00
|
|
|
let previousExports = {};
|
|
|
|
if (module && module.hot && module.hot.dispose) {
|
|
|
|
({ previousExports = {} } = module.hot.data || {});
|
|
|
|
|
|
|
|
module.hot.dispose(data => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
data.previousExports = previousExports;
|
|
|
|
});
|
|
|
|
}
|
2018-12-20 12:14:25 +11:00
|
|
|
|
|
|
|
// The simplest version of examples would just export this function for users to use
|
2018-12-20 14:16:17 +11:00
|
|
|
function importAll(context) {
|
2018-12-20 12:14:25 +11:00
|
|
|
const storyStore = window.__STORYBOOK_CLIENT_API__._storyStore; // eslint-disable-line no-undef, no-underscore-dangle
|
|
|
|
|
|
|
|
context.keys().forEach(filename => {
|
|
|
|
const fileExports = context(filename);
|
2018-12-20 14:16:17 +11:00
|
|
|
|
|
|
|
// A old-style story file
|
|
|
|
if (!fileExports.default) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-20 12:14:25 +11:00
|
|
|
const { default: component, ...examples } = fileExports;
|
|
|
|
let componentOptions = component;
|
|
|
|
if (component.prototype && component.prototype.isReactComponent) {
|
|
|
|
componentOptions = { component };
|
|
|
|
}
|
|
|
|
const kindName = componentOptions.title || componentOptions.component.displayName;
|
|
|
|
|
|
|
|
if (previousExports[filename]) {
|
|
|
|
if (previousExports[filename] === fileExports) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise clear this kind
|
|
|
|
storyStore.removeStoryKind(kindName);
|
|
|
|
storyStore.incrementRevision();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We pass true here to avoid the warning about HMR. It's cool clientApi, we got this
|
|
|
|
const kind = storiesOf(kindName, true);
|
|
|
|
|
|
|
|
(componentOptions.decorators || []).forEach(decorator => {
|
|
|
|
kind.addDecorator(decorator);
|
|
|
|
});
|
|
|
|
if (componentOptions.parameters) {
|
|
|
|
kind.addParameters(componentOptions.parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(examples).forEach(key => {
|
|
|
|
const example = examples[key];
|
|
|
|
const { title = key, parameters } = example;
|
|
|
|
kind.add(title, example, parameters);
|
|
|
|
});
|
|
|
|
|
|
|
|
previousExports[filename] = fileExports;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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);
|