diff --git a/.changeset/four-windows-retire.md b/.changeset/four-windows-retire.md new file mode 100644 index 0000000000..cf95d50f3e --- /dev/null +++ b/.changeset/four-windows-retire.md @@ -0,0 +1,6 @@ +--- +"@khanacademy/perseus": major +"@khanacademy/perseus-editor": patch +--- + +Remove PropCheckBox component from Perseus; use WB instead diff --git a/packages/perseus-editor/src/components/graph-settings.tsx b/packages/perseus-editor/src/components/graph-settings.tsx index 17ee3c5f85..b65498183f 100644 --- a/packages/perseus-editor/src/components/graph-settings.tsx +++ b/packages/perseus-editor/src/components/graph-settings.tsx @@ -10,13 +10,14 @@ import { KhanMath, Util, } from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import createReactClass from "create-react-class"; import PropTypes from "prop-types"; import * as React from "react"; import ReactDOM from "react-dom"; import _ from "underscore"; -const {ButtonGroup, InfoTip, PropCheckBox, RangeInput} = components; +const {ButtonGroup, InfoTip, RangeInput} = components; const defaultBackgroundImage = { url: null, @@ -521,10 +522,12 @@ const GraphSettings = createReactClass({ />
- { + this.change({showTooltips: value}); + }} />
@@ -566,17 +569,21 @@ const GraphSettings = createReactClass({
- { + this.change({showRuler: value}); + }} />
- { + this.change({showProtractor: value}); + }} />
diff --git a/packages/perseus-editor/src/components/interactive-graph-settings.tsx b/packages/perseus-editor/src/components/interactive-graph-settings.tsx index 4af8a5d37f..7d957f7fec 100644 --- a/packages/perseus-editor/src/components/interactive-graph-settings.tsx +++ b/packages/perseus-editor/src/components/interactive-graph-settings.tsx @@ -10,6 +10,7 @@ import { } from "@khanacademy/perseus"; import Banner from "@khanacademy/wonder-blocks-banner"; import {View} from "@khanacademy/wonder-blocks-core"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import {color, spacing} from "@khanacademy/wonder-blocks-tokens"; import {css, StyleSheet} from "aphrodite"; import * as React from "react"; @@ -20,7 +21,7 @@ import Heading from "./heading"; import type {PerseusImageBackground} from "@khanacademy/perseus"; -const {ButtonGroup, InfoTip, PropCheckBox, RangeInput} = components; +const {ButtonGroup, InfoTip, RangeInput} = components; const defaultBackgroundImage = { url: null, @@ -547,10 +548,12 @@ class InteractiveGraphSettings extends React.Component {
- { + this.change({showTooltips: value}); + }} />
@@ -585,10 +588,12 @@ class InteractiveGraphSettings extends React.Component { - { + this.change({showProtractor: value}); + }} style={styles.resetSpaceTop} /> diff --git a/packages/perseus-editor/src/widgets/__tests__/numeric-input-editor.test.tsx b/packages/perseus-editor/src/widgets/__tests__/numeric-input-editor.test.tsx index 738f5beeea..0858fdc222 100644 --- a/packages/perseus-editor/src/widgets/__tests__/numeric-input-editor.test.tsx +++ b/packages/perseus-editor/src/widgets/__tests__/numeric-input-editor.test.tsx @@ -84,6 +84,33 @@ describe("numeric-input-editor", () => { expect(onChangeMock).toBeCalledWith({coefficient: true}); }); + it("should be possible to select strictly match only these formats", async () => { + const onChangeMock = jest.fn(); + + render(); + + await userEvent.click(screen.getByLabelText("Toggle options")); + await userEvent.click( + screen.getByRole("checkbox", { + name: "Strictly match only these formats", + }), + ); + + expect(onChangeMock).toBeCalledWith({ + answers: [ + { + answerForms: [], + maxError: null, + message: "", + simplify: "required", + status: "correct", + strict: true, + value: null, + }, + ], + }); + }); + it("should be possible to update label text", async () => { const onChangeMock = jest.fn(); diff --git a/packages/perseus-editor/src/widgets/categorizer-editor.tsx b/packages/perseus-editor/src/widgets/categorizer-editor.tsx index 37d029f3d1..d2425ffaff 100644 --- a/packages/perseus-editor/src/widgets/categorizer-editor.tsx +++ b/packages/perseus-editor/src/widgets/categorizer-editor.tsx @@ -5,11 +5,12 @@ import { Changeable, EditorJsonify, } from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; -const {PropCheckBox, TextListEditor} = components; +const {TextListEditor} = components; const Categorizer = CategorizerWidget.widget; type Props = any; @@ -45,11 +46,12 @@ class CategorizerEditor extends React.Component { return (
- { + this.props.onChange({randomizeItems: value}); + }} />
Categories: diff --git a/packages/perseus-editor/src/widgets/cs-program-editor.tsx b/packages/perseus-editor/src/widgets/cs-program-editor.tsx index 384fa89418..adf4dd4369 100644 --- a/packages/perseus-editor/src/widgets/cs-program-editor.tsx +++ b/packages/perseus-editor/src/widgets/cs-program-editor.tsx @@ -11,6 +11,7 @@ import { Log, } from "@khanacademy/perseus"; import {Errors} from "@khanacademy/perseus-core"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import $ from "jquery"; import PropTypes from "prop-types"; import * as React from "react"; @@ -18,7 +19,7 @@ import _ from "underscore"; import BlurInput from "../components/blur-input"; -const {InfoTip, PropCheckBox} = components; +const {InfoTip} = components; const DEFAULT_WIDTH = 400; const DEFAULT_HEIGHT = 400; @@ -220,20 +221,24 @@ class CSProgramEditor extends React.Component { />
- { + this.props.onChange({showEditor: value}); + }} /> If you show the editor, you should use the "full-width" alignment to make room for the width of the editor.
- { + this.props.onChange({showButtons: value}); + }} />
- { + this.props.onChange({times: value}); + }} />

@@ -542,11 +543,12 @@ class AnswerOption extends React.Component<

- { + this.props.onChange({form: value}); + }} />

@@ -558,12 +560,12 @@ class AnswerOption extends React.Component<

- { + this.props.onChange({simplify: value}); + }} />

diff --git a/packages/perseus-editor/src/widgets/iframe-editor.tsx b/packages/perseus-editor/src/widgets/iframe-editor.tsx index ad95bb5d74..de45b219b9 100644 --- a/packages/perseus-editor/src/widgets/iframe-editor.tsx +++ b/packages/perseus-editor/src/widgets/iframe-editor.tsx @@ -1,14 +1,13 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ /* eslint-disable react/sort-comp */ -import {components, Changeable, EditorJsonify} from "@khanacademy/perseus"; +import {Changeable, EditorJsonify} from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; import BlurInput from "../components/blur-input"; -const {PropCheckBox} = components; - type PairEditorProps = any; /** @@ -174,16 +173,20 @@ class IframeEditor extends React.Component { onChange={this.change("height")} /> - { + this.props.onChange({allowFullScreen: value}); + }} />
- { + this.props.onChange({allowTopNavigation: value}); + }} />

); diff --git a/packages/perseus-editor/src/widgets/matcher-editor.tsx b/packages/perseus-editor/src/widgets/matcher-editor.tsx index 9a2ba16c39..81cc35ed3d 100644 --- a/packages/perseus-editor/src/widgets/matcher-editor.tsx +++ b/packages/perseus-editor/src/widgets/matcher-editor.tsx @@ -1,10 +1,11 @@ /* eslint-disable react/forbid-prop-types, react/sort-comp */ import {components} from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; -const {InfoTip, PropCheckBox, TextListEditor} = components; +const {InfoTip, TextListEditor} = components; type Props = any; @@ -79,10 +80,12 @@ class MatcherEditor extends React.Component { />
- { + this.props.onChange({orderMatters: value}); + }} />

@@ -100,10 +103,12 @@ class MatcherEditor extends React.Component {

- { + this.props.onChange({padding: value}); + }} />

diff --git a/packages/perseus-editor/src/widgets/measurer-editor.tsx b/packages/perseus-editor/src/widgets/measurer-editor.tsx index 1b4060c9ea..67251326b5 100644 --- a/packages/perseus-editor/src/widgets/measurer-editor.tsx +++ b/packages/perseus-editor/src/widgets/measurer-editor.tsx @@ -1,11 +1,12 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ /* eslint-disable react/sort-comp */ import {components, Changeable, EditorJsonify} from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; -const {InfoTip, NumberInput, PropCheckBox, RangeInput} = components; +const {InfoTip, NumberInput, RangeInput} = components; const defaultImage = { url: null, @@ -103,17 +104,21 @@ class MeasurerEditor extends React.Component {

- { + this.props.onChange({showRuler: value}); + }} />
- { + this.props.onChange({showProtractor: value}); + }} />
diff --git a/packages/perseus-editor/src/widgets/number-line-editor.tsx b/packages/perseus-editor/src/widgets/number-line-editor.tsx index 088b612b08..b8575da54f 100644 --- a/packages/perseus-editor/src/widgets/number-line-editor.tsx +++ b/packages/perseus-editor/src/widgets/number-line-editor.tsx @@ -1,12 +1,12 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ import {number as knumber} from "@khanacademy/kmath"; import {components, EditorJsonify} from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; -const {ButtonGroup, InfoTip, NumberInput, PropCheckBox, RangeInput} = - components; +const {ButtonGroup, InfoTip, NumberInput, RangeInput} = components; type Range = [number, number]; @@ -365,28 +365,34 @@ class NumberLineEditor extends React.Component {
{!this.props.static && (
- { + this.props.onChange({isTickCtrl: value}); + }} />
)}
- { + this.props.onChange({labelTicks: value}); + }} />
{!this.props.static && ( - { + this.props.onChange({showTooltips: value}); + }} /> )}
diff --git a/packages/perseus-editor/src/widgets/numeric-input-editor.tsx b/packages/perseus-editor/src/widgets/numeric-input-editor.tsx index 3c655d1db0..8fb01b35cb 100644 --- a/packages/perseus-editor/src/widgets/numeric-input-editor.tsx +++ b/packages/perseus-editor/src/widgets/numeric-input-editor.tsx @@ -7,6 +7,7 @@ import { Util, PerseusI18nContext, } from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import * as React from "react"; import _ from "underscore"; @@ -20,7 +21,6 @@ const { InlineIcon, MultiButtonGroup, NumberInput, - PropCheckBox, TextInput, } = components; const {iconGear, iconTrash} = icons; @@ -197,11 +197,12 @@ class NumericInputEditor extends React.Component {
- { + this.updateAnswer.bind(this, i)({strict: value}); + }} />
@@ -245,10 +246,12 @@ class NumericInputEditor extends React.Component { const rightAlign = (
- { + this.props.onChange({rightAlign: value}); + }} />
); @@ -274,10 +277,12 @@ class NumericInputEditor extends React.Component { const coefficientCheck = (
- { + this.props.onChange({coefficient: value}); + }} />

diff --git a/packages/perseus-editor/src/widgets/passage-editor.tsx b/packages/perseus-editor/src/widgets/passage-editor.tsx index f2d913b34d..c0755a1b32 100644 --- a/packages/perseus-editor/src/widgets/passage-editor.tsx +++ b/packages/perseus-editor/src/widgets/passage-editor.tsx @@ -1,11 +1,12 @@ import {components, Changeable, EditorJsonify} from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; import Editor from "../editor"; -const {InfoTip, PropCheckBox} = components; +const {InfoTip} = components; type Props = any; @@ -68,11 +69,12 @@ class PassageEditor extends React.Component { return (

- { + this.props.onChange({showLineNumbers: value}); + }} />
diff --git a/packages/perseus-editor/src/widgets/radio/editor.tsx b/packages/perseus-editor/src/widgets/radio/editor.tsx index f106d66c9b..fc50cefad7 100644 --- a/packages/perseus-editor/src/widgets/radio/editor.tsx +++ b/packages/perseus-editor/src/widgets/radio/editor.tsx @@ -6,13 +6,14 @@ import { BaseRadio, Changeable, } from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; import Editor from "../../editor"; -const {InlineIcon, PropCheckBox} = components; +const {InlineIcon} = components; const {iconPlus, iconTrash} = icons; class ChoiceEditor extends React.Component { @@ -150,28 +151,35 @@ class RadioEditor extends React.Component {
- { + this.onMultipleSelectChange({ + multipleSelect: value, + }); + }} />
- { + this.props.onChange({randomize: value}); + }} />
{this.props.multipleSelect && (
- { + this.onCountChoicesChange({ + countChoices: value, + }); + }} />
)} diff --git a/packages/perseus-editor/src/widgets/sorter-editor.tsx b/packages/perseus-editor/src/widgets/sorter-editor.tsx index 4aed056341..6840b62243 100644 --- a/packages/perseus-editor/src/widgets/sorter-editor.tsx +++ b/packages/perseus-editor/src/widgets/sorter-editor.tsx @@ -1,11 +1,12 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ /* eslint-disable react/forbid-prop-types */ import {components} from "@khanacademy/perseus"; +import {Checkbox} from "@khanacademy/wonder-blocks-form"; import PropTypes from "prop-types"; import * as React from "react"; import _ from "underscore"; -const {InfoTip, PropCheckBox, TextListEditor} = components; +const {InfoTip, TextListEditor} = components; const HORIZONTAL = "horizontal"; const VERTICAL = "vertical"; @@ -84,10 +85,12 @@ class SorterEditor extends React.Component {
- { + this.props.onChange({padding: value}); + }} />

diff --git a/packages/perseus/src/components.ts b/packages/perseus/src/components.ts index 9c529c7159..ca12de1252 100644 --- a/packages/perseus/src/components.ts +++ b/packages/perseus/src/components.ts @@ -8,7 +8,6 @@ export {default as InlineIcon} from "./components/inline-icon"; export {default as MathInput} from "./components/math-input"; export {default as MultiButtonGroup} from "./components/multi-button-group"; export {default as NumberInput} from "./components/number-input"; -export {default as PropCheckBox} from "./components/prop-check-box"; export {default as RangeInput} from "./components/range-input"; export {default as SvgImage} from "./components/svg-image"; export {default as TextInput} from "./components/text-input"; diff --git a/packages/perseus/src/components/__stories__/prop-check-box.stories.tsx b/packages/perseus/src/components/__stories__/prop-check-box.stories.tsx deleted file mode 100644 index 09eed8aa89..0000000000 --- a/packages/perseus/src/components/__stories__/prop-check-box.stories.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import * as React from "react"; - -import PropCheckBox from "../prop-check-box"; - -type StoryArgs = Record; - -type Story = { - title: string; -}; - -export default { - title: "Perseus/Components/Prop Check Box", -} as Story; - -export const TestLabelWithCheckedObject = ( - args: StoryArgs, -): React.ReactElement => { - return ( - {}} - labelAlignment="left" - /> - ); -}; - -export const TestLabelWithUncheckedObject = ( - args: StoryArgs, -): React.ReactElement => { - return ( - {}} - labelAlignment="left" - /> - ); -}; - -export const TestLabelWithCheckedObjectLabelOnTheRight = ( - args: StoryArgs, -): React.ReactElement => { - return ( - {}} - labelAlignment="right" - /> - ); -}; - -export const TestLabelWithUncheckedObjectLabelOnTheRight = ( - args: StoryArgs, -): React.ReactElement => { - return ( - {}} - labelAlignment="right" - /> - ); -}; diff --git a/packages/perseus/src/components/prop-check-box.tsx b/packages/perseus/src/components/prop-check-box.tsx deleted file mode 100644 index 13380aef6d..0000000000 --- a/packages/perseus/src/components/prop-check-box.tsx +++ /dev/null @@ -1,91 +0,0 @@ -/* eslint-disable @babel/no-invalid-this */ -/* eslint-disable react/sort-comp */ -import {Errors, PerseusError} from "@khanacademy/perseus-core"; -import {Checkbox} from "@khanacademy/wonder-blocks-form"; -import {LabelSmall} from "@khanacademy/wonder-blocks-typography"; -import {css, StyleSheet} from "aphrodite"; -import createReactClass from "create-react-class"; -import PropTypes from "prop-types"; -import * as React from "react"; -import _ from "underscore"; - -/* A checkbox that syncs its value to props using the - * renderer's onChange method, and gets the prop name - * dynamically from its props list - */ -const PropCheckBox: any = createReactClass({ - displayName: "PropCheckBox", - - propTypes: { - labelAlignment: PropTypes.oneOf(["left", "right"]), - }, - - DEFAULT_PROPS: { - label: null, - onChange: null, - labelAlignment: "left", - }, - - getDefaultProps: function () { - return this.DEFAULT_PROPS; - }, - - propName: function () { - const propName = _.find( - _.keys(this.props), - function (localPropName) { - // @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation. - return !_.has(this.DEFAULT_PROPS, localPropName); - }, - this, - ); - - if (!propName) { - throw new PerseusError( - "Attempted to create a PropCheckBox with no prop!", - Errors.InvalidInput, - ); - } - - return propName; - }, - - _labelAlignLeft: function () { - return this.props.labelAlignment === "left"; - }, - - render: function () { - const propName = this.propName(); - return ( - - ); - }, - - toggle: function () { - const propName = this.propName(); - const changes: Record = {}; - changes[propName] = !this.props[propName]; - this.props.onChange(changes); - }, -}); - -export const styles = StyleSheet.create({ - labeledCheckbox: { - display: "flex", - flexDirection: "row", - alignItems: "center", - }, -}); - -export default PropCheckBox;