|
| 1 | +import React from 'react'; |
| 2 | +import isChromatic from 'chromatic/isChromatic'; |
1 | 3 | import { withKnobs } from '@storybook/addon-knobs'; |
2 | 4 | import { withA11y } from '@storybook/addon-a11y'; |
3 | 5 | import { addDecorator, addParameters, configure } from '@storybook/react'; |
4 | 6 | import { themes } from '@storybook/theming'; |
5 | | -import isChromatic from 'chromatic/isChromatic'; |
6 | | -import React from 'react'; |
7 | 7 | import { createGlobalStyle, ThemeProvider } from 'styled-components'; |
8 | | - |
9 | 8 | import { makeTheme, getThemes } from '../src/components/ThemeProvider'; |
10 | | - |
11 | 9 | import { withThemesProvider } from './storybook-addon-styled-component-theme'; |
12 | 10 |
|
13 | 11 | type Theme = { |
@@ -37,6 +35,8 @@ const viewports = { |
37 | 35 | // new globals based on theme? |
38 | 36 | // using sidebar as the styles for body for now 🤷 |
39 | 37 | const GlobalStyle = createGlobalStyle` |
| 38 | +
|
| 39 | +
|
40 | 40 | html body { |
41 | 41 | font-family: 'Inter', sans-serif; |
42 | 42 | -webkit-font-smoothing: auto; |
@@ -64,43 +64,45 @@ const GlobalStyle = createGlobalStyle` |
64 | 64 | a { |
65 | 65 | color: #40a9f3; |
66 | 66 | } |
| 67 | +
|
67 | 68 | } |
68 | 69 | `; |
69 | | -const allThemes: Theme[] = getThemes(); |
70 | | -const vsCodeThemes: Theme[] = allThemes.map(b => makeTheme(b, b.name)); |
| 70 | +const allThemes = getThemes(); |
| 71 | +const vsCodeThemes = allThemes.map((b) => makeTheme(b, b.name)); |
71 | 72 |
|
72 | | -const CodeSandboxBlack = vsCodeThemes.find( |
73 | | - ({ name }) => name === 'CodeSandbox Black' |
| 73 | +const blackCodesandbox = vsCodeThemes.find( |
| 74 | + (theme: Theme) => theme.name === 'CodeSandbox Black' |
74 | 75 | ); |
75 | 76 |
|
76 | | -if (isChromatic()) { |
77 | | - const withGlobal = (story: any) => ( |
78 | | - <ThemeProvider theme={makeTheme(CodeSandboxBlack, 'default')}> |
| 77 | +if (!isChromatic()) { |
| 78 | + const withGlobal = (cb: any) => ( |
| 79 | + <> |
79 | 80 | <GlobalStyle /> |
80 | | - |
81 | | - {story()} |
82 | | - </ThemeProvider> |
| 81 | + {cb()} |
| 82 | + </> |
83 | 83 | ); |
84 | 84 |
|
| 85 | + const rest = vsCodeThemes.filter( |
| 86 | + (theme: Theme) => theme.name !== 'CodeSandbox Black' |
| 87 | + ); |
85 | 88 | addDecorator(withGlobal); |
| 89 | + addDecorator(withThemesProvider([blackCodesandbox, ...rest])); |
86 | 90 | } else { |
87 | | - const withGlobal = (story: any) => ( |
88 | | - <> |
| 91 | + const withGlobal = (cb: any) => ( |
| 92 | + <ThemeProvider theme={makeTheme(blackCodesandbox, 'default')}> |
89 | 93 | <GlobalStyle /> |
90 | | - |
91 | | - {story()} |
92 | | - </> |
| 94 | + {cb()} |
| 95 | + </ThemeProvider> |
93 | 96 | ); |
94 | 97 |
|
95 | | - const rest = vsCodeThemes.filter(({ name }) => name !== 'CodeSandbox Black'); |
96 | 98 | addDecorator(withGlobal); |
97 | | - addDecorator(withThemesProvider([CodeSandboxBlack, ...rest])); |
98 | 99 | } |
99 | 100 | addDecorator(withA11y); |
100 | 101 | addDecorator(withKnobs); |
101 | | - |
102 | 102 | addParameters({ viewport: { viewports } }); |
| 103 | + |
| 104 | +// Option defaults. |
103 | 105 | addParameters({ options: { theme: themes.dark } }); |
104 | 106 |
|
105 | | -// automatically import all files ending in *.stories.tsx |
| 107 | +// automatically import all files ending in *.stories.js |
106 | 108 | configure(require.context('../src', true, /\.stories\.tsx$/), module); |
0 commit comments