diff options
author | 2019-01-04 12:16:14 +0100 | |
---|---|---|
committer | 2019-01-04 12:16:14 +0100 | |
commit | 010917a05e70216e13902aa255ee247c3e1ffdfa (patch) | |
tree | cf5d4f04381f9dceeb570e8a3ad63f346ca3096d /.storybook | |
parent | Fix missing packages in build (diff) | |
download | ferdium-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.ts | 2 | ||||
-rw-r--r-- | .storybook/config.ts | 15 | ||||
-rw-r--r-- | .storybook/preview-head.html | 7 | ||||
-rw-r--r-- | .storybook/webpack.config.js | 17 | ||||
-rw-r--r-- | .storybook/withTheme/index.tsx | 59 |
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 @@ | |||
1 | import '@storybook/addon-actions/register'; | ||
2 | import '@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 @@ | |||
1 | import { configure, addDecorator } from '@storybook/react'; | ||
2 | import { withInfo } from '@storybook/addon-info'; | ||
3 | import withTheme from '../.storybook/withTheme'; | ||
4 | |||
5 | // automatically import all files ending in *.stories.js | ||
6 | const req = require.context('../stories', true, /.stories.tsx$/); | ||
7 | |||
8 | addDecorator(withInfo()); | ||
9 | addDecorator(withTheme()); | ||
10 | |||
11 | function loadStories() { | ||
12 | req.keys().forEach(filename => req(filename)); | ||
13 | } | ||
14 | |||
15 | configure(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 @@ | |||
1 | const path = require('path'); | ||
2 | |||
3 | module.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 @@ | |||
1 | import React from 'react'; | ||
2 | import { Classes } from 'jss'; | ||
3 | import injectSheet, { ThemeProvider } from 'react-jss'; | ||
4 | import addons, { makeDecorator } from '@storybook/addons'; | ||
5 | import theme, { Theme, ThemeType } from '../../packages/theme/src'; | ||
6 | |||
7 | const defaultTheme = { | ||
8 | name: 'Default', | ||
9 | variables: theme(ThemeType.default), | ||
10 | }; | ||
11 | |||
12 | const darkTheme = { | ||
13 | name: 'Dark Mode', | ||
14 | variables: theme(ThemeType.dark), | ||
15 | }; | ||
16 | |||
17 | const themes = [defaultTheme, darkTheme]; | ||
18 | |||
19 | const 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 | |||
32 | const 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 | |||
41 | export 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 | }) | ||