1
1
import * as React from "react" ;
2
2
import { color } from "@khanacademy/wonder-blocks-tokens" ;
3
3
import { RenderStateRoot } from "@khanacademy/wonder-blocks-core" ;
4
+ import { ThemeSwitcher } from "@khanacademy/wonder-blocks-theming" ;
4
5
5
6
import {
6
7
setDependencies ,
@@ -17,35 +18,75 @@ import "./reset.css";
17
18
// Import the Wonder Blocks CSS variables
18
19
import "@khanacademy/wonder-blocks-tokens/styles.css" ;
19
20
20
- import type { Preview } from "@storybook/react-vite" ;
21
+ import type { Decorator , Preview } from "@storybook/react-vite" ;
21
22
22
23
// IMPORTANT: This code runs ONCE per story file, not per story within that file.
23
24
// If you want code to run once per story, see `StorybookWrapper`.
24
25
25
26
setDependencies ( storybookTestDependencies ) ;
26
27
28
+ const withPerseusDecorator : Decorator = ( Story ) => {
29
+ return (
30
+ < RenderStateRoot >
31
+ < DependenciesContext . Provider value = { storybookDependenciesV2 } >
32
+ { /* Most of our components have an expectation to be rendered
33
+ inside of a .framework-perseus container. We want to make sure
34
+ we can include it here, since it can also affect the styling.
35
+
36
+ Include box-sizing-border-box-reset to reflect the global styles
37
+ from prod.
38
+ */ }
39
+ < div className = "framework-perseus box-sizing-border-box-reset" >
40
+ < Story />
41
+ </ div >
42
+ </ DependenciesContext . Provider >
43
+ </ RenderStateRoot >
44
+ ) ;
45
+ } ;
46
+
47
+ const withThemeSwitcher : Decorator = ( Story , context ) => {
48
+ const theme = context . globals . theme ;
49
+
50
+ return (
51
+ < ThemeSwitcher theme = { theme } >
52
+ < Story />
53
+ </ ThemeSwitcher >
54
+ ) ;
55
+ } ;
56
+
57
+ const supportedThemes = {
58
+ description : "Global theme for components" ,
59
+ toolbar : {
60
+ // The label to show for this toolbar item
61
+ title : "Theme" ,
62
+ icon : "switchalt" ,
63
+ // Array of plain string values or MenuItem shape (see below)
64
+ items : [
65
+ {
66
+ value : "default" ,
67
+ icon : "circlehollow" ,
68
+ title : "Wonder Blocks (default)" ,
69
+ } ,
70
+ {
71
+ value : "thunderblocks" ,
72
+ icon : "lightning" ,
73
+ title : "Shape Your Learning (Thunder Blocks)" ,
74
+ } ,
75
+ ] ,
76
+ // Change title based on selected value
77
+ dynamicTitle : true ,
78
+ } ,
79
+ } ;
80
+
27
81
const preview : Preview = {
28
82
// These decorators apply to all stories, both inside and outside the
29
83
// fixture framework.
30
- decorators : [
31
- ( Story ) => (
32
- < RenderStateRoot >
33
- < DependenciesContext . Provider value = { storybookDependenciesV2 } >
34
- { /* Most of our components have an expectation to be
35
- rendered inside of a .framework-perseus container.
36
- We want to make sure we can include it here, since it
37
- can also affect the styling.
38
-
39
- Include box-sizing-border-box-reset to reflect
40
- the global styles from prod.
41
- */ }
42
- < div className = "framework-perseus box-sizing-border-box-reset" >
43
- < Story />
44
- </ div >
45
- </ DependenciesContext . Provider >
46
- </ RenderStateRoot >
47
- ) ,
48
- ] ,
84
+ decorators : [ withPerseusDecorator , withThemeSwitcher ] ,
85
+ globalTypes : {
86
+ // Added theme globalTypes to be consistent with WonderBlocks supported
87
+ // themes, that will allow the user to select a theme from the toolbar.
88
+ theme : supportedThemes ,
89
+ } ,
49
90
// These parameters apply to all stories, both inside and outside the fixture
50
91
// framework.
51
92
parameters : {
0 commit comments