|
1 | 1 | import React from 'react'; |
2 | | - |
| 2 | +import isChromatic from 'storybook-chromatic/isChromatic'; |
3 | 3 | import { withKnobs } from '@storybook/addon-knobs'; |
4 | 4 | import { withA11y } from '@storybook/addon-a11y'; |
5 | 5 | import { addDecorator, addParameters, configure } from '@storybook/react'; |
6 | 6 | import { themes } from '@storybook/theming'; |
7 | | -import { createGlobalStyle } from 'styled-components'; |
| 7 | +import { createGlobalStyle, ThemeProvider } from 'styled-components'; |
8 | 8 | // @ts-ignore |
9 | 9 | import global from '@codesandbox/common/lib/global.css'; |
10 | 10 | import { makeTheme, getThemes } from '../src/components/ThemeProvider'; |
@@ -48,23 +48,34 @@ const GlobalStyle = createGlobalStyle` |
48 | 48 |
|
49 | 49 | } |
50 | 50 | `; |
51 | | - |
52 | | -export const withGlobal = (cb: any) => ( |
53 | | - <> |
54 | | - <GlobalStyle /> |
55 | | - {cb()} |
56 | | - </> |
57 | | -); |
58 | | - |
59 | 51 | const allThemes = getThemes(); |
60 | 52 | const vsCodeThemes = allThemes.map(b => makeTheme(b, b.name)); |
| 53 | + |
61 | 54 | const blackCodesandbox = vsCodeThemes.find( |
62 | 55 | theme => theme.name === 'CodeSandbox Black' |
63 | 56 | ); |
| 57 | +console.log(isChromatic()); |
| 58 | +if (!isChromatic()) { |
| 59 | + const withGlobal = (cb: any) => ( |
| 60 | + <> |
| 61 | + <GlobalStyle /> |
| 62 | + {cb()} |
| 63 | + </> |
| 64 | + ); |
| 65 | + |
| 66 | + const rest = vsCodeThemes.filter(theme => theme.name !== 'CodeSandbox Black'); |
| 67 | + addDecorator(withGlobal); |
| 68 | + addDecorator(withThemesProvider([blackCodesandbox, ...rest])); |
| 69 | +} else { |
| 70 | + const withGlobal = (cb: any) => ( |
| 71 | + <ThemeProvider theme={makeTheme(blackCodesandbox, 'default')}> |
| 72 | + <GlobalStyle /> |
| 73 | + {cb()} |
| 74 | + </ThemeProvider> |
| 75 | + ); |
64 | 76 |
|
65 | | -const rest = vsCodeThemes.filter(theme => theme.name !== 'CodeSandbox Black'); |
66 | | -addDecorator(withGlobal); |
67 | | -addDecorator(withThemesProvider([blackCodesandbox, ...rest])); |
| 77 | + addDecorator(withGlobal); |
| 78 | +} |
68 | 79 | addDecorator(withA11y); |
69 | 80 | addDecorator(withKnobs); |
70 | 81 | addParameters({ viewport: { viewports } }); |
|
0 commit comments