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

Update spacing in locked figure settings #1231

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/honest-pens-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
---

Adjust spacing in locked point and locked line settings
49 changes: 49 additions & 0 deletions packages/perseus-editor/src/__stories__/editor-page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {action} from "@storybook/addon-actions";
import * as React from "react";

import {EditorPage} from "..";
import {segmentWithLockedFigures} from "../../../perseus/src/widgets/__testdata__/interactive-graph.testdata";
import {registerAllWidgetsAndEditorsForTesting} from "../util/register-all-widgets-and-editors-for-testing";

import {flags} from "./flags-for-api-options";
Expand Down Expand Up @@ -68,3 +69,51 @@ export const Demo = (): React.ReactElement => {
/>
);
};

export const MafsWithLockedFigures = (): React.ReactElement => {
const [previewDevice, setPreviewDevice] =
React.useState<DeviceType>("phone");
const [jsonMode, setJsonMode] = React.useState<boolean | undefined>(false);
const [answerArea, setAnswerArea] = React.useState<
PerseusAnswerArea | undefined | null
>();
const [question, setQuestion] = React.useState<PerseusRenderer | undefined>(
segmentWithLockedFigures,
);
const [hints, setHints] = React.useState<ReadonlyArray<Hint> | undefined>();

return (
<EditorPage
apiOptions={{
isMobile: false,
flags,
}}
previewDevice={previewDevice}
onPreviewDeviceChange={(newDevice) => setPreviewDevice(newDevice)}
developerMode={true}
jsonMode={jsonMode}
answerArea={answerArea}
question={question}
hints={hints}
frameSource="about:blank"
previewURL="about:blank"
Comment on lines +98 to +99
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢 no change needed, but this preview system (and lack of it in Storybook) just makes me sad.

itemId="1"
onChange={(props) => {
onChangeAction(props);

if ("jsonMode" in props) {
setJsonMode(props.jsonMode);
}
if ("answerArea" in props) {
setAnswerArea(props.answerArea);
}
if ("question" in props) {
setQuestion(props.question);
}
if ("hints" in props) {
setHints(props.hints);
}
}}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {View} from "@khanacademy/wonder-blocks-core";
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
import {StyleSheet} from "aphrodite";
import * as React from "react";

import LockedFiguresSection from "../locked-figures-section";
import {getDefaultFigureForType} from "../util";

import type {Meta, StoryObj} from "@storybook/react";

export default {
title: "Perseus Editor/Components/Locked Figures Section",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Perseus Editor part of this can't include spaces. I recently discovered that things were not grouped correctly because of the spaces we had in the title here. I think spaces later on are fine, but for top-level areas, it needs to be PerseusEditor/...

component: LockedFiguresSection,
} as Meta<typeof LockedFiguresSection>;

export const Default = (args): React.ReactElement => {
return <LockedFiguresSection {...args} />;
};

type StoryComponentType = StoryObj<typeof LockedFiguresSection>;

// Set the default values in the control panel.
Default.args = {};

export const Controlled: StoryComponentType = {
render: function Render() {
const [figures, setFigures] = React.useState([]);

const handlePropsUpdate = (newProps) => {
setFigures(newProps.lockedFigures);
};

return (
<LockedFiguresSection
figures={figures}
onChange={handlePropsUpdate}
/>
);
},
};

export const WithProdWidth: StoryComponentType = {
render: function Render() {
const [figures, setFigures] = React.useState([
getDefaultFigureForType("point"),
getDefaultFigureForType("line"),
]);

const handlePropsUpdate = (newProps) => {
setFigures(newProps.lockedFigures);
};

return (
<View style={styles.prodSizeContainer}>
<LockedFiguresSection
figures={figures}
onChange={handlePropsUpdate}
/>
</View>
);
},
};

const contentSize = 310;
const padding = 10;
// Padding on each side
const containerSize = contentSize + 2 * padding;

const styles = StyleSheet.create({
prodSizeContainer: {
width: containerSize,
padding: padding,
marginInlineStart: spacing.medium_16,
border: `1px solid ${color.offBlack32}`,
borderRadius: spacing.xxxSmall_4,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("LockedPointSettings", () => {
{wrapper: RenderStateRoot},
);

const toggleSwitch = screen.getByLabelText("Show point on graph");
const toggleSwitch = screen.getByLabelText("show point on graph");

// Assert
expect(toggleSwitch).toBeInTheDocument();
Expand All @@ -82,7 +82,7 @@ describe("LockedPointSettings", () => {
{wrapper: RenderStateRoot},
);

const toggleSwitch = screen.getByLabelText("Show point on graph");
const toggleSwitch = screen.getByLabelText("show point on graph");

// Assert
expect(toggleSwitch).toBeChecked();
Expand All @@ -102,7 +102,7 @@ describe("LockedPointSettings", () => {
{wrapper: RenderStateRoot},
);

const toggleSwitch = screen.getByLabelText("Show point on graph");
const toggleSwitch = screen.getByLabelText("show point on graph");

// Assert
expect(toggleSwitch).not.toBeChecked();
Expand All @@ -122,8 +122,8 @@ describe("LockedPointSettings", () => {
{wrapper: RenderStateRoot},
);

const colorSelect = screen.getByLabelText("Color");
const openCheckbox = screen.getByLabelText("Open point");
const colorSelect = screen.getByLabelText("color");
const openCheckbox = screen.getByLabelText("open point");

// Assert
expect(colorSelect).toBeInTheDocument();
Expand Down
10 changes: 6 additions & 4 deletions packages/perseus-editor/src/components/color-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ import * as React from "react";
import ColorSwatch from "./color-swatch";

import type {LockedFigureColor} from "@khanacademy/perseus";
import type {StyleType} from "@khanacademy/wonder-blocks-core";

const possibleColors = Object.keys(lockedFigureColors) as LockedFigureColor[];

type Props = {
// Required ID so that the label can be associated with the select.
id: string;
selectedValue: LockedFigureColor;
style?: StyleType;
onChange: (newValue: string) => void;
};

const ColorSelect = (props: Props) => {
const {id, selectedValue, onChange} = props;
const {id, selectedValue, style, onChange} = props;

return (
<View style={styles.row}>
<View style={[styles.row, style]}>
<LabelMedium htmlFor={id} style={styles.label} tag="label">
Color
color
</LabelMedium>
<SingleSelect
id={id}
Expand Down Expand Up @@ -57,7 +59,7 @@ const styles = StyleSheet.create({
alignItems: "center",
},
label: {
marginInlineEnd: spacing.xSmall_8,
marginInlineEnd: spacing.xxxSmall_4,
},
});

Expand Down
42 changes: 42 additions & 0 deletions packages/perseus-editor/src/components/labeled-switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {View, useUniqueIdWithMock} from "@khanacademy/wonder-blocks-core";
import {Strut} from "@khanacademy/wonder-blocks-layout";
import Switch from "@khanacademy/wonder-blocks-switch";
import {spacing} from "@khanacademy/wonder-blocks-tokens";
import {LabelMedium} from "@khanacademy/wonder-blocks-typography";
import {StyleSheet} from "aphrodite";
import * as React from "react";

import type {StyleType} from "@khanacademy/wonder-blocks-core";

type Props = {
label: string;
checked: boolean;
style?: StyleType;
onChange: (newValue: boolean) => void;
};

const LabeledSwitch = (props: Props) => {
const {checked, label, style, onChange} = props;

const ids = useUniqueIdWithMock();
const switchId = ids.get("switch");

return (
<View style={[styles.row, style]}>
<Switch id={switchId} checked={checked} onChange={onChange} />
<Strut size={spacing.xSmall_8} />
<LabelMedium tag="label" htmlFor={switchId}>
{label}
</LabelMedium>
</View>
);
};

const styles = StyleSheet.create({
row: {
flexDirection: "row",
alignItems: "center",
},
});

export default LabeledSwitch;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const LockedFigureSelect = (props: Props) => {

const styles = StyleSheet.create({
container: {
marginTop: spacing.xxxSmall_4,
marginTop: spacing.xSmall_8,
},
addElementSelect: {
backgroundColor: color.fadedBlue8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const styles = StyleSheet.create({
width: "100%",
flexDirection: "row",
alignItems: "center",
marginTop: spacing.xxxSmall_4,
},
deleteButton: {
// Line up the delete icon with the rest of the content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* the dropdown for adding figures as well as the settings for each figure.
*/
import {View, useUniqueIdWithMock} from "@khanacademy/wonder-blocks-core";
import {spacing} from "@khanacademy/wonder-blocks-tokens";
import {StyleSheet} from "aphrodite";
import * as React from "react";

import LockedFigureSelect from "./locked-figure-select";
Expand Down Expand Up @@ -69,7 +67,7 @@ const LockedFiguresSection = (props: Props) => {
}

return (
<View style={styles.container}>
<View>
{figures?.map((figure, index) => (
<LockedFigureSettings
key={`${uniqueId}-locked-${figure}-${index}`}
Expand All @@ -86,10 +84,4 @@ const LockedFiguresSection = (props: Props) => {
);
};

const styles = StyleSheet.create({
container: {
paddingTop: spacing.large_24,
},
});

export default LockedFiguresSection;