Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOT READY FOR REVIEW!!] Introduce EditorWithLayout #1257

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
116 changes: 116 additions & 0 deletions packages/perseus-editor/src/__stories__/editor-with-layout.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import {View} from "@khanacademy/wonder-blocks-core";
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
import {HeadingSmall} from "@khanacademy/wonder-blocks-typography";
import {action} from "@storybook/addon-actions";
import * as React from "react";

import {EditorWithLayout} from "..";

import type {StyleType} from "@khanacademy/wonder-blocks-core";
import type {Meta, StoryObj} from "@storybook/react";

type Story = StoryObj<typeof EditorWithLayout>;

const meta: Meta<typeof EditorWithLayout> = {
title: "PerseusEditor/EditorWithLayout",
component: EditorWithLayout,
};

function Section(
props: React.PropsWithChildren<{title: string; style?: StyleType}>,
) {
return (
<View
style={{
borderWidth: "1px",
borderRadius: spacing.xxxSmall_4,
...props.style,
}}
>
<HeadingSmall
style={{
backgroundColor: color.darkBlue,
color: color.offWhite,
padding: spacing.xxSmall_6,
marginBottom: spacing.xxSmall_6,
}}
>
{props.title}
</HeadingSmall>
<View style={{padding: spacing.xxxSmall_4}}>{props.children}</View>
</View>
);
}

export const Default: Story = {
render(props, context) {
return (
<EditorWithLayout {...props}>
{(items) => <View>{items.jsonModeEditor}</View>}
</EditorWithLayout>
);
},
};

export const Controlled: Story = {
args: {
onChange: action("onChange"),
},
render(props, context) {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [state, setState] = React.useState(props);

return (
<EditorWithLayout
{...state}
onChange={(updatedProps) =>
setState({...state, ...updatedProps})
}
>
{(items) => (
<View style={{gap: spacing.xSmall_8}}>
<View
style={{
flexDirection: "row",
gap: spacing.xSmall_8,
}}
>
<Section title="Viewport Resizer">
{items.viewportResizerElement}
</Section>

<Section title="Heads-up Display (HUD)">
{items.hudElement}
</Section>

<Section title="JSON Mode Editor">
{items.jsonModeEditor}
</Section>

<Section title="Question Extras">
{items.questionExtras}
</Section>
</View>

<Section title="Item Editor">
{items.itemEditor}
</Section>

<Section
title="JSON Editor"
style={{width: "100%", height: 300}}
>
<items.JsonEditor style={{height: 100}} />
</Section>

<Section title="Hints Editor">
{items.hintsEditor}
</Section>
</View>
)}
</EditorWithLayout>
);
},
};

export default meta;
3 changes: 2 additions & 1 deletion packages/perseus-editor/src/editor-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import CombinedHintsEditor from "./hint-editor";
import ItemEditor from "./item-editor";

import type {SerializeOptions} from "./types";
import type {
APIOptions,
APIOptionsWithDefaults,
Expand Down Expand Up @@ -193,7 +194,7 @@
return issues1.concat(issues2);
}

serialize(options?: {keepDeletedWidgets?: boolean}): any | PerseusItem {
serialize(options?: SerializeOptions): PerseusItem {

Check warning on line 197 in packages/perseus-editor/src/editor-page.tsx

View check run for this annotation

Codecov / codecov/patch

packages/perseus-editor/src/editor-page.tsx#L197

Added line #L197 was not covered by tests
if (this.props.jsonMode) {
return this.state.json;
}
Expand Down
Loading
Loading