Skip to content

Commit 302e0ed

Browse files
committed
Start building out EditorWithLayout
1 parent decd1bb commit 302e0ed

File tree

3 files changed

+424
-6
lines changed

3 files changed

+424
-6
lines changed
Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
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";
26

7+
import {EditorWithLayout} from "..";
8+
9+
import type {StyleType} from "@khanacademy/wonder-blocks-core";
310
import type {Meta, StoryObj} from "@storybook/react";
411

512
type Story = StoryObj<typeof EditorWithLayout>;
@@ -9,8 +16,78 @@ const meta: Meta<typeof EditorWithLayout> = {
916
component: EditorWithLayout,
1017
};
1118

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+
1245
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+
},
1491
};
1592

1693
export default meta;

0 commit comments

Comments
 (0)