1
+ import React from 'react' ;
1
2
import { Preview } from '@storybook/react' ;
2
3
import { themes } from '@storybook/theming' ;
3
- import React from 'react' ;
4
- import { RedesignedColors } from '../src/essentials/Colors/globalStyles' ;
4
+ import { ClassicColors , ModernColors } from '../src/essentials/Colors/globalStyles' ;
5
+
6
+ const THEMES = {
7
+ classic : ClassicColors ,
8
+ modern : ModernColors
9
+ } as const ;
10
+
11
+ export const withTheme = ( Story , context ) => {
12
+ const Theme = THEMES [ context . globals . theme ] ;
13
+ return (
14
+ < >
15
+ < Theme />
16
+ < Story { ...context } />
17
+ </ >
18
+ ) ;
19
+ } ;
5
20
6
21
export const preview : Preview = {
7
- decorators : [
8
- Story => (
9
- < >
10
- < RedesignedColors />
11
- < Story />
12
- </ >
13
- )
14
- ] ,
22
+ decorators : [ withTheme ] ,
15
23
parameters : {
16
24
actions : { argTypesRegex : '^on[A-Z].*' } ,
17
25
viewMode : 'docs' ,
@@ -22,6 +30,11 @@ export const preview: Preview = {
22
30
date : / D a t e $ /
23
31
}
24
32
} ,
33
+ options : {
34
+ storySort : {
35
+ order : [ 'Welcome' , 'Get Started' , 'Essentials' , 'Components' , 'Form Elements' ]
36
+ }
37
+ } ,
25
38
docs : {
26
39
theme : themes . light
27
40
} ,
@@ -75,10 +88,17 @@ export const preview: Preview = {
75
88
type : 'desktop'
76
89
}
77
90
}
78
- } ,
79
- options : {
80
- storySort : {
81
- order : [ 'Welcome' , 'Get Started' , 'Essentials' , 'Components' , 'Form Elements' ]
91
+ }
92
+ } ,
93
+ globalTypes : {
94
+ theme : {
95
+ description : 'Global theme for components' ,
96
+ defaultValue : 'modern' ,
97
+ toolbar : {
98
+ title : 'Theme' ,
99
+ icon : 'paintbrush' ,
100
+ items : [ 'modern' , 'classic' ] ,
101
+ dynamicTitle : true
82
102
}
83
103
}
84
104
}
0 commit comments