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