83 lines
2.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
2018-08-24 23:20:17 +02:00
import ThemeProvider from '@emotion/provider';
import styled from '@emotion/styled';
import { configure, addDecorator } from '@storybook/react';
import { themes } from '@storybook/components';
import { withOptions } from '@storybook/addon-options';
import { configureViewport, INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
2018-12-04 21:23:02 +01:00
import { cssResources } from '@storybook/addon-cssresources';
2017-12-18 17:16:19 +11:00
import 'react-chromatic/storybook-addon';
import addHeadWarning from './head-warning';
import extraViewports from './extra-viewports.json';
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-12-04 21:23:02 +01:00
addDecorator(cssResources);
addDecorator(
withOptions({
hierarchySeparator: /\/|\./,
2018-09-12 12:40:58 +02:00
hierarchyRootSeparator: '|',
// theme: themes.dark,
})
);
2017-11-27 13:48:46 +11:00
const Reset = styled.div(({ theme }) => ({
fontFamily: theme.mainTextFace,
color: theme.mainTextColor,
WebkitFontSmoothing: 'antialiased',
fontSize: theme.mainTextSize,
}));
2018-09-12 12:40:58 +02:00
addDecorator((story, { kind }) => (kind === 'Core|Errors' ? story() : <Reset>{story()}</Reset>));
addDecorator(
(story, { kind }) =>
kind === 'Core|Errors' ? (
story()
) : (
<ThemeProvider theme={themes.normal}>{story()}</ThemeProvider>
)
);
configureViewport({
viewports: {
...INITIAL_VIEWPORTS,
...extraViewports,
},
});
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;
req = require.context('../../lib/ui/src', true, /\.stories\.js$/);
2018-01-31 14:54:29 +02:00
importAll(req);
req = require.context('../../lib/components/src', true, /\.stories\.js$/);
2018-01-31 14:54:29 +02:00
importAll(req);
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);