1
- import EditorWithLayout from "../editor-with-layout" ;
1
+ import { View } from "@khanacademy/wonder-blocks-core" ;
2
+ import { color , spacing } from "@khanacademy/wonder-blocks-tokens" ;
3
+ import { HeadingSmall } from "@khanacademy/wonder-blocks-typography" ;
4
+ import { action } from "@storybook/addon-actions" ;
5
+ import * as React from "react" ;
2
6
7
+ import { EditorWithLayout } from ".." ;
8
+
9
+ import type { StyleType } from "@khanacademy/wonder-blocks-core" ;
3
10
import type { Meta , StoryObj } from "@storybook/react" ;
4
11
5
12
type Story = StoryObj < typeof EditorWithLayout > ;
@@ -9,8 +16,78 @@ const meta: Meta<typeof EditorWithLayout> = {
9
16
component : EditorWithLayout ,
10
17
} ;
11
18
19
+ function Section (
20
+ props : React . PropsWithChildren < { title : string ; style ?: StyleType } > ,
21
+ ) {
22
+ return (
23
+ < View
24
+ style = { {
25
+ borderWidth : "1px" ,
26
+ borderRadius : spacing . xxxSmall_4 ,
27
+ ...props . style ,
28
+ } }
29
+ >
30
+ < HeadingSmall
31
+ style = { {
32
+ backgroundColor : color . darkBlue ,
33
+ color : color . offWhite ,
34
+ padding : spacing . xxSmall_6 ,
35
+ marginBottom : spacing . xxSmall_6 ,
36
+ } }
37
+ >
38
+ { props . title }
39
+ </ HeadingSmall >
40
+ < View style = { { padding : spacing . xxxSmall_4 } } > { props . children } </ View >
41
+ </ View >
42
+ ) ;
43
+ }
44
+
12
45
export const Default : Story = {
13
- args : { } ,
46
+ render ( props , context ) {
47
+ return (
48
+ < EditorWithLayout { ...props } >
49
+ { ( items ) => < View > { items . jsonModeEditor } </ View > }
50
+ </ EditorWithLayout >
51
+ ) ;
52
+ } ,
53
+ } ;
54
+
55
+ export const Controlled : Story = {
56
+ args : {
57
+ onChange : action ( "onChange" ) ,
58
+ } ,
59
+ render ( props , context ) {
60
+ // eslint-disable-next-line react-hooks/rules-of-hooks
61
+ const [ state , setState ] = React . useState ( props ) ;
62
+
63
+ return (
64
+ < EditorWithLayout
65
+ { ...state }
66
+ onChange = { ( updatedProps ) =>
67
+ setState ( { ...state , ...updatedProps } )
68
+ }
69
+ >
70
+ { ( items ) => (
71
+ < View style = { { gap : spacing . xSmall_8 } } >
72
+ < Section title = "JSON Mode Editor" >
73
+ { items . jsonModeEditor }
74
+ </ Section >
75
+
76
+ < Section
77
+ title = "JSON Editor"
78
+ style = { { width : 50 , height : 300 } }
79
+ >
80
+ < items . JsonEditor style = { { height : 100 } } />
81
+ </ Section >
82
+
83
+ < Section title = "Heads-up Display (HUD)" >
84
+ { items . hudElement }
85
+ </ Section >
86
+ </ View >
87
+ ) }
88
+ </ EditorWithLayout >
89
+ ) ;
90
+ } ,
14
91
} ;
15
92
16
93
export default meta ;
0 commit comments