|
| 1 | +import {components} from "@khanacademy/perseus"; |
| 2 | +import {View} from "@khanacademy/wonder-blocks-core"; |
| 3 | +import {OptionItem, SingleSelect} from "@khanacademy/wonder-blocks-dropdown"; |
| 4 | +import {Checkbox} from "@khanacademy/wonder-blocks-form"; |
| 5 | +import {LabelSmall} from "@khanacademy/wonder-blocks-typography"; |
| 6 | +import * as React from "react"; |
| 7 | +import invariant from "tiny-invariant"; |
| 8 | + |
| 9 | +import styles from "../interactive-graph-editor.module.css"; |
| 10 | +import LabeledRow from "../locked-figures/labeled-row"; |
| 11 | + |
| 12 | +import type {Props as EditorProps} from "../interactive-graph-editor"; |
| 13 | +import type { |
| 14 | + PerseusGraphType, |
| 15 | + PerseusGraphTypeAngle, |
| 16 | +} from "@khanacademy/perseus-core"; |
| 17 | + |
| 18 | +const {InfoTip} = components; |
| 19 | + |
| 20 | +interface Props { |
| 21 | + correct: PerseusGraphTypeAngle; |
| 22 | + graph: PerseusGraphType | undefined; |
| 23 | + onChange: (props: Partial<EditorProps>) => void; |
| 24 | +} |
| 25 | + |
| 26 | +export default function AngleAnswerOptions({correct, graph, onChange}: Props) { |
| 27 | + return ( |
| 28 | + <> |
| 29 | + <View className={styles.row}> |
| 30 | + <Checkbox |
| 31 | + label={<LabelSmall>Show angle measures</LabelSmall>} |
| 32 | + checked={ |
| 33 | + // Don't show indeterminate checkbox state |
| 34 | + !!correct?.showAngles |
| 35 | + } |
| 36 | + onChange={(newValue) => { |
| 37 | + if (graph?.type === "angle") { |
| 38 | + invariant( |
| 39 | + correct.type === "angle", |
| 40 | + `Expected graph type to be angle, but got ${correct.type}`, |
| 41 | + ); |
| 42 | + onChange({ |
| 43 | + correct: { |
| 44 | + ...correct, |
| 45 | + showAngles: newValue, |
| 46 | + }, |
| 47 | + graph: { |
| 48 | + ...graph, |
| 49 | + showAngles: newValue, |
| 50 | + }, |
| 51 | + }); |
| 52 | + } |
| 53 | + }} |
| 54 | + /> |
| 55 | + <InfoTip> |
| 56 | + <p>Displays the interior angle measures.</p> |
| 57 | + </InfoTip> |
| 58 | + </View> |
| 59 | + <View className={styles.row}> |
| 60 | + <Checkbox |
| 61 | + label={<LabelSmall>Allow reflex angles</LabelSmall>} |
| 62 | + checked={ |
| 63 | + // Don't show indeterminate checkbox state |
| 64 | + !!correct?.allowReflexAngles |
| 65 | + } |
| 66 | + onChange={(newValue) => { |
| 67 | + invariant( |
| 68 | + correct.type === "angle", |
| 69 | + `Expected graph type to be angle, but got ${correct.type}`, |
| 70 | + ); |
| 71 | + invariant( |
| 72 | + graph?.type === "angle", |
| 73 | + `Expected graph type to be angle, but got ${graph?.type}`, |
| 74 | + ); |
| 75 | + |
| 76 | + const update = { |
| 77 | + allowReflexAngles: newValue, |
| 78 | + }; |
| 79 | + |
| 80 | + onChange({ |
| 81 | + correct: { |
| 82 | + ...correct, |
| 83 | + ...update, |
| 84 | + }, |
| 85 | + graph: { |
| 86 | + ...graph, |
| 87 | + ...update, |
| 88 | + }, |
| 89 | + }); |
| 90 | + }} |
| 91 | + /> |
| 92 | + <InfoTip> |
| 93 | + <p>Allow students to be able to create reflex angles.</p> |
| 94 | + </InfoTip> |
| 95 | + </View> |
| 96 | + <LabeledRow label="Student answer must"> |
| 97 | + <SingleSelect |
| 98 | + selectedValue={correct.match || "exact"} |
| 99 | + onChange={(newValue) => { |
| 100 | + invariant( |
| 101 | + correct.type === "angle", |
| 102 | + `Expected graph type to be angle, but got ${correct.type}`, |
| 103 | + ); |
| 104 | + onChange({ |
| 105 | + correct: { |
| 106 | + ...correct, |
| 107 | + // TODO(benchristel): this cast is necessary |
| 108 | + // because "exact" is not actually a valid |
| 109 | + // value for `match`; a value of undefined |
| 110 | + // means exact matching. The code happens |
| 111 | + // to work because "exact" falls through |
| 112 | + // to the correct else branch when scoring |
| 113 | + match: newValue as PerseusGraphTypeAngle["match"], |
| 114 | + }, |
| 115 | + }); |
| 116 | + }} |
| 117 | + // Never uses placeholder, always has value |
| 118 | + placeholder="" |
| 119 | + className={styles.singleSelectShort} |
| 120 | + > |
| 121 | + <OptionItem value="exact" label="match exactly" /> |
| 122 | + <OptionItem value="congruent" label="be congruent" /> |
| 123 | + </SingleSelect> |
| 124 | + <InfoTip> |
| 125 | + <p> |
| 126 | + Congruency requires only that the angle measures are the |
| 127 | + same. An exact match implies congruency, but also |
| 128 | + requires that the angles have the same orientation and |
| 129 | + that the vertices are in the same position. |
| 130 | + </p> |
| 131 | + </InfoTip> |
| 132 | + </LabeledRow> |
| 133 | + </> |
| 134 | + ); |
| 135 | +} |
0 commit comments