aboutsummaryrefslogtreecommitdiffstats
path: root/.storybook
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-01-04 12:16:14 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2019-01-04 12:16:14 +0100
commit010917a05e70216e13902aa255ee247c3e1ffdfa (patch)
treecf5d4f04381f9dceeb570e8a3ad63f346ca3096d /.storybook
parentFix missing packages in build (diff)
downloadferdium-app-010917a05e70216e13902aa255ee247c3e1ffdfa.tar.gz
ferdium-app-010917a05e70216e13902aa255ee247c3e1ffdfa.tar.zst
ferdium-app-010917a05e70216e13902aa255ee247c3e1ffdfa.zip
move storybook to root + typescript
TODO: fix modules
Diffstat (limited to '.storybook')
-rw-r--r--.storybook/addons.ts2
-rw-r--r--.storybook/config.ts15
-rw-r--r--.storybook/preview-head.html7
-rw-r--r--.storybook/webpack.config.js17
-rw-r--r--.storybook/withTheme/index.tsx59
5 files changed, 100 insertions, 0 deletions
diff --git a/.storybook/addons.ts b/.storybook/addons.ts
new file mode 100644
index 000000000..6aed412d0
--- /dev/null
+++ b/.storybook/addons.ts
@@ -0,0 +1,2 @@
1import '@storybook/addon-actions/register';
2import '@storybook/addon-links/register';
diff --git a/.storybook/config.ts b/.storybook/config.ts
new file mode 100644
index 000000000..d1f3d3053
--- /dev/null
+++ b/.storybook/config.ts
@@ -0,0 +1,15 @@
1import { configure, addDecorator } from '@storybook/react';
2import { withInfo } from '@storybook/addon-info';
3import withTheme from '../.storybook/withTheme';
4
5// automatically import all files ending in *.stories.js
6const req = require.context('../stories', true, /.stories.tsx$/);
7
8addDecorator(withInfo());
9addDecorator(withTheme());
10
11function loadStories() {
12 req.keys().forEach(filename => req(filename));
13}
14
15configure(loadStories, module);
diff --git a/.storybook/preview-head.html b/.storybook/preview-head.html
new file mode 100644
index 000000000..f5bf78b7a
--- /dev/null
+++ b/.storybook/preview-head.html
@@ -0,0 +1,7 @@
1<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,800" rel="stylesheet">
2<style>
3 * {
4 font-family: 'Open Sans', sans-serif;
5 font-size: 14px;
6 }
7</style>
diff --git a/.storybook/webpack.config.js b/.storybook/webpack.config.js
new file mode 100644
index 000000000..e542f1387
--- /dev/null
+++ b/.storybook/webpack.config.js
@@ -0,0 +1,17 @@
1const path = require('path');
2
3module.exports = (baseConfig, env, config) => {
4 config.module.rules.push({
5 test: /\.(ts|tsx)$/,
6 use: [{
7 loader: require.resolve('awesome-typescript-loader'),
8 options: {
9 configFileName: path.join(__dirname, '..', 'tsconfig.storybook.json'),
10 }
11 }, {
12 loader: require.resolve('react-docgen-typescript-loader'),
13 }]
14 });
15 config.resolve.extensions.push('.ts', '.tsx');
16 return config;
17};
diff --git a/.storybook/withTheme/index.tsx b/.storybook/withTheme/index.tsx
new file mode 100644
index 000000000..b357aa658
--- /dev/null
+++ b/.storybook/withTheme/index.tsx
@@ -0,0 +1,59 @@
1import React from 'react';
2import { Classes } from 'jss';
3import injectSheet, { ThemeProvider } from 'react-jss';
4import addons, { makeDecorator } from '@storybook/addons';
5import theme, { Theme, ThemeType } from '../../packages/theme/src';
6
7const defaultTheme = {
8 name: 'Default',
9 variables: theme(ThemeType.default),
10};
11
12const darkTheme = {
13 name: 'Dark Mode',
14 variables: theme(ThemeType.dark),
15};
16
17const themes = [defaultTheme, darkTheme];
18
19const styles = (theme: Theme) => ({
20 title: {
21 fontSize: 14,
22 },
23 container: {
24 border: theme.inputBorder,
25 borderRadius: theme.borderRadiusSmall,
26 marginBottom: 20,
27 padding: 20,
28 background: theme.colorContentBackground,
29 },
30});
31
32const Container = injectSheet(styles)(({ name, classes, story }: { name: string, classes: Classes, story: React.ReactNode }) => (
33 <article>
34 <h1 className={classes.title}>{name}</h1>
35 <div className={classes.container}>
36 {story}
37 </div>
38 </article>
39));
40
41export default makeDecorator({
42 name: 'withTheme',
43 parameterName: 'theme',
44 // This means don't run this decorator if the notes decorator is not set
45 // skipIfNoParametersOrOptions: true,
46 wrapper: (getStory: Function, context: any, { options }: any) => {
47 const channel = addons.getChannel();
48
49 return (
50 <>
51 {themes.map(theme => (
52 <ThemeProvider theme={theme.variables}>
53 <Container story={getStory(context)} name={theme.name} />
54 </ThemeProvider>
55 ))}
56 </>
57 );
58 }
59})