|
1 | 1 | import {addons} from '@storybook/addons'
|
2 |
| -import {ThemeProvider, themeGet, theme, BaseStyles} from '../src' |
3 |
| -import styled, {createGlobalStyle} from 'styled-components' |
4 |
| -import {addDecorator} from '@storybook/react' |
5 | 2 | import {withPerformance} from 'storybook-addon-performance'
|
| 3 | +import {withThemeProvider, toolbarTypes} from '../src/utils/story-helpers' |
6 | 4 |
|
7 |
| -addDecorator(withPerformance) |
8 |
| - |
9 |
| -// set global theme styles for each story |
10 |
| -const GlobalStyle = createGlobalStyle` |
11 |
| - body { |
12 |
| - background-color: ${themeGet('colors.canvas.default')}; |
13 |
| - color: ${themeGet('colors.fg.default')}; |
14 |
| - } |
15 |
| -` |
16 |
| - |
17 |
| -// only remove padding for multi-theme view grid |
18 |
| -const GlobalStyleMultiTheme = createGlobalStyle` |
19 |
| - body { |
20 |
| - padding: 0 !important; |
21 |
| - } |
22 |
| -` |
23 |
| - |
24 |
| -// duo theme view, this can be extended for more themes |
25 |
| -const Wrapper = styled.div` |
26 |
| - display: grid; |
27 |
| - grid-template-columns: 1fr 1fr; |
28 |
| - grid-template-rows: 100vh; |
29 |
| -` |
30 |
| - |
31 |
| -// instead of global theme, only theme wrapper for each story |
32 |
| -const ThemedSectionStyle = styled.div` |
33 |
| - background-color: ${themeGet('colors.canvas.default')}; |
34 |
| - color: ${themeGet('colors.fg.default')}; |
35 |
| - padding: 1rem; |
36 |
| -` |
37 |
| - |
38 |
| -export const globalTypes = { |
39 |
| - colorMode: { |
40 |
| - name: 'Color mode', |
41 |
| - description: 'Color mode (day, night, auto, all)', |
42 |
| - defaultValue: 'day', |
43 |
| - toolbar: { |
44 |
| - icon: 'paintbrush', |
45 |
| - // array of colorMode items |
46 |
| - items: ['day', 'night', 'auto', 'all'], |
47 |
| - showName: true |
48 |
| - } |
49 |
| - }, |
50 |
| - dayScheme: { |
51 |
| - name: 'Day color scheme', |
52 |
| - description: 'Day color scheme', |
53 |
| - defaultValue: 'light', |
54 |
| - toolbar: { |
55 |
| - icon: 'circlehollow', |
56 |
| - items: Object.keys(theme.colorSchemes), |
57 |
| - showName: true |
58 |
| - } |
59 |
| - }, |
60 |
| - nightScheme: { |
61 |
| - name: 'Night color scheme', |
62 |
| - description: 'Night color scheme', |
63 |
| - defaultValue: 'dark', |
64 |
| - toolbar: { |
65 |
| - icon: 'circle', |
66 |
| - items: Object.keys(theme.colorSchemes), |
67 |
| - showName: true |
68 |
| - } |
69 |
| - } |
70 |
| -} |
71 |
| - |
72 |
| -// context.globals.X references items in globalTypes |
73 |
| -const withThemeProvider = (Story, context) => { |
74 |
| - // used for testing ThemeProvider.stories.tsx |
75 |
| - if (context.parameters.disableThemeDecorator) return <Story {...context} /> |
76 |
| - |
77 |
| - if (context.globals.colorMode === 'all') { |
78 |
| - return ( |
79 |
| - <Wrapper> |
80 |
| - <GlobalStyleMultiTheme /> |
81 |
| - <ThemeProvider colorMode="day" dayScheme={context.globals.dayScheme} nightScheme={context.globals.nightScheme}> |
82 |
| - <ThemedSectionStyle> |
83 |
| - <Story {...context} /> |
84 |
| - </ThemedSectionStyle> |
85 |
| - </ThemeProvider> |
86 |
| - <ThemeProvider |
87 |
| - colorMode="night" |
88 |
| - dayScheme={context.globals.dayScheme} |
89 |
| - nightScheme={context.globals.nightScheme} |
90 |
| - > |
91 |
| - <ThemedSectionStyle> |
92 |
| - <BaseStyles> |
93 |
| - <div id="html-addon-root"> |
94 |
| - <Story {...context} /> |
95 |
| - </div> |
96 |
| - </BaseStyles> |
97 |
| - </ThemedSectionStyle> |
98 |
| - </ThemeProvider> |
99 |
| - </Wrapper> |
100 |
| - ) |
101 |
| - } |
102 |
| - |
103 |
| - return ( |
104 |
| - <ThemeProvider |
105 |
| - colorMode={context.globals.colorMode} |
106 |
| - dayScheme={context.globals.dayScheme} |
107 |
| - nightScheme={context.globals.nightScheme} |
108 |
| - > |
109 |
| - <GlobalStyle /> |
110 |
| - <BaseStyles> |
111 |
| - <div id="html-addon-root"> |
112 |
| - <Story {...context} /> |
113 |
| - </div> |
114 |
| - </BaseStyles> |
115 |
| - </ThemeProvider> |
116 |
| - ) |
117 |
| -} |
118 |
| - |
| 5 | +export const globalTypes = toolbarTypes |
119 | 6 | export const decorators = [withThemeProvider, withPerformance]
|
120 | 7 |
|
121 | 8 | addons.setConfig({
|
|
0 commit comments