@khanacademy/perseus 0.4.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/.eslintrc.js +6 -1
  2. package/CHANGELOG.md +45 -0
  3. package/dist/es/index.css +15 -8
  4. package/dist/es/index.js +1214 -1404
  5. package/dist/es/index.js.map +1 -1
  6. package/dist/index.css +15 -8
  7. package/dist/index.js +1217 -1411
  8. package/dist/index.js.map +1 -1
  9. package/dist/strings.js +0 -4
  10. package/package.json +9 -8
  11. package/src/components/number-input.jsx +2 -2
  12. package/src/components/simple-keypad-input.jsx +18 -21
  13. package/src/index.js +1 -1
  14. package/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap +426 -135
  15. package/src/multi-items/__tests__/multi-renderer_test.js +9 -9
  16. package/src/perseus-api.jsx +10 -36
  17. package/src/perseus-types.js +18 -145
  18. package/src/styles/constants.js +0 -2
  19. package/src/styles/perseus-renderer.less +8 -2
  20. package/src/styles/variables.less +0 -2
  21. package/src/styles/widgets/passage.less +9 -5
  22. package/src/types.js +18 -35
  23. package/src/util/answer-types.js +2 -3
  24. package/src/util/math.js +3 -10
  25. package/src/util.js +0 -6
  26. package/src/version.js +1 -1
  27. package/src/widgets/__stories__/numeric-input.stories.jsx +43 -2
  28. package/src/widgets/__testdata__/base-radio_testdata.js +22 -0
  29. package/src/widgets/__tests__/__snapshots__/definition_test.js.snap +4 -4
  30. package/src/widgets/__tests__/__snapshots__/group_test.jsx.snap +291 -130
  31. package/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap +3293 -1415
  32. package/src/widgets/__tests__/group_test.jsx +4 -4
  33. package/src/widgets/__tests__/numeric-input_test.jsx +12 -8
  34. package/src/widgets/__tests__/passage_test.jsx +81 -0
  35. package/src/widgets/__tests__/radio/base-radio_test.jsx +291 -41
  36. package/src/widgets/__tests__/radio/choice-icon_test.jsx +67 -0
  37. package/src/widgets/__tests__/radio/choice_test.jsx +302 -0
  38. package/src/widgets/__tests__/radio/focus-ring_test.jsx +23 -0
  39. package/src/widgets/__tests__/radio/option-status_test.jsx +65 -0
  40. package/src/widgets/__tests__/radio_test.jsx +39 -15
  41. package/src/widgets/definition.jsx +1 -1
  42. package/src/widgets/group.jsx +84 -102
  43. package/src/widgets/input-number.jsx +6 -1
  44. package/src/widgets/numeric-input.jsx +87 -80
  45. package/src/widgets/passage/__tests__/passage-markdown_test.jsx +0 -9
  46. package/src/widgets/passage/get-line-height-for-node.js +4 -5
  47. package/src/widgets/passage/passage-markdown.jsx +176 -120
  48. package/src/widgets/passage.jsx +48 -46
  49. package/src/widgets/radio/__stories__/base-radio.stories.jsx +164 -17
  50. package/src/widgets/radio/__stories__/choice-icon.stories.jsx +202 -111
  51. package/src/widgets/radio/__stories__/choice-none-above.stories.jsx +21 -6
  52. package/src/widgets/radio/__stories__/choice.stories.jsx +138 -0
  53. package/src/widgets/radio/__stories__/focus-ring.stories.jsx +29 -23
  54. package/src/widgets/radio/__stories__/option-status.stories.jsx +93 -99
  55. package/src/widgets/radio/base-radio.jsx +485 -556
  56. package/src/widgets/radio/choice-a11y-text.js +62 -0
  57. package/src/widgets/radio/choice-icon/choice-icon.jsx +87 -0
  58. package/src/widgets/radio/choice-icon/cross-out-line.jsx +55 -0
  59. package/src/widgets/radio/choice-icon/library-choice-icon.jsx +214 -0
  60. package/src/widgets/radio/choice-icon/sat-choice-icon.jsx +120 -0
  61. package/src/widgets/radio/choice-icon/shared-styles.js +17 -0
  62. package/src/widgets/radio/choice-none-above.jsx +49 -40
  63. package/src/widgets/radio/choice.jsx +319 -347
  64. package/src/widgets/radio/choice.jsx.fixture.js +0 -18
  65. package/src/widgets/radio/focus-ring.jsx +29 -22
  66. package/src/widgets/radio/option-status.jsx +58 -36
  67. package/src/widgets/radio/widget.jsx +181 -136
  68. package/src/widgets/radio.jsx +16 -17
  69. package/src/widgets/radio/__stories__/cross-out-button.stories.jsx +0 -64
  70. package/src/widgets/radio/choice-icon.jsx +0 -469
  71. package/src/widgets/radio/cross-out-button.jsx +0 -134
@@ -136,7 +136,7 @@ describe("multi-item renderer", () => {
136
136
  // selected, a value is entered). You can see the result of this in the `choiceStates`
137
137
  // array in the captured state below where the choice at index 2 has
138
138
  // `"selected": true` (instead of false) and the input-number has a `currentValue`.
139
- userEvent.click(screen.getAllByRole("checkbox")[2]); // Correct
139
+ userEvent.click(screen.getAllByRole("radio")[2]); // Correct
140
140
  userEvent.paste(screen.getByRole("textbox"), "+42"); // Correct
141
141
 
142
142
  // Act
@@ -268,7 +268,7 @@ describe("multi-item renderer", () => {
268
268
  // Arrange
269
269
  const {renderer} = renderSimpleQuestion(question1);
270
270
 
271
- userEvent.click(screen.getAllByRole("checkbox")[2]);
271
+ userEvent.click(screen.getAllByRole("radio")[2]);
272
272
  userEvent.paste(screen.getByRole("textbox"), "99");
273
273
 
274
274
  // Act
@@ -525,11 +525,11 @@ describe("multi-item renderer", () => {
525
525
  renderer.restoreSerializedState(state);
526
526
 
527
527
  // Assert
528
- expect(screen.getAllByRole("checkbox")[0]).not.toBeChecked();
529
- expect(screen.getAllByRole("checkbox")[1]).not.toBeChecked();
530
- expect(screen.getAllByRole("checkbox")[2]).toBeChecked();
531
- expect(screen.getAllByRole("checkbox")[3]).not.toBeChecked();
532
- expect(screen.getAllByRole("checkbox")[4]).not.toBeChecked();
528
+ expect(screen.getAllByRole("radio")[0]).not.toBeChecked();
529
+ expect(screen.getAllByRole("radio")[1]).not.toBeChecked();
530
+ expect(screen.getAllByRole("radio")[2]).toBeChecked();
531
+ expect(screen.getAllByRole("radio")[3]).not.toBeChecked();
532
+ expect(screen.getAllByRole("radio")[4]).not.toBeChecked();
533
533
  expect(screen.getByRole("textbox")).toHaveValue("+42");
534
534
  });
535
535
 
@@ -586,7 +586,7 @@ describe("multi-item renderer", () => {
586
586
  // Arrange
587
587
  const {renderer} = renderSimpleQuestion(question1);
588
588
 
589
- userEvent.click(screen.getAllByRole("checkbox")[3]); // Correct
589
+ userEvent.click(screen.getAllByRole("radio")[3]); // Correct
590
590
  userEvent.paste(screen.getByRole("textbox"), "-42"); // Correct
591
591
 
592
592
  // Act
@@ -747,7 +747,7 @@ describe("multi-item renderer", () => {
747
747
  // Arrange
748
748
  const {renderer} = renderSimpleQuestion(question1);
749
749
 
750
- userEvent.click(screen.getAllByRole("checkbox")[3]); // Correct
750
+ userEvent.click(screen.getAllByRole("radio")[3]); // Correct
751
751
  userEvent.paste(screen.getByRole("textbox"), "-42"); // Correct
752
752
 
753
753
  // Act
@@ -123,38 +123,9 @@ export const ApiOptions = {
123
123
  // values. For now, though, you must either specify all fields
124
124
  // of `styling`, or omit the `styling` option entirely.
125
125
  styling: PropTypes.shape({
126
- // Which version of radio widget styles to use in non-SAT
127
- // contexts.
128
- //
129
- // "legacy" was the version of the widget display after XOM but
130
- // before we started adding MCR styles. It doesn't have support
131
- // for rationales. It has since been removed.
132
- //
133
- // "intermediate" is a design which adds several new additions
134
- // to the "legacy" styles such as:
135
- // 1. Using the XOM "desktop" styles (with a visible check icon
136
- // and lines in between choices) on mobile devices.
137
- // 2. Designs for rationales
138
- // 3. Using the single-select styles for multi-select styles
139
- //
140
- // "final" is a design which will build off of the
141
- // "intermediate" designs and adds some improved designs as well
142
- // as:
143
- // 1. a/b/c/d/etc. letters inside of the prompt check box
144
- // 2. New iconography and styles to indicate choice correctness
145
- //
146
- // The "legacy" and "intermediate" designs will be A/B tested
147
- // against each other to ensure that its changes don't cause
148
- // problems due to the new designs. Once the "intermediate"
149
- // designs are finished, they will be A/B tested against the
150
- // "final" designs.
151
- //
152
- // If no flag is provided, "legacy" styles will be shown.
153
- //
154
- // TODO(emily): Remove this by Aug 1, 2017, at which point all
155
- // callsites should have been switched to using the "final"
156
- // designs.
157
- radioStyleVersion: PropTypes.oneOf(["intermediate", "final"]),
126
+ // TODO(Nicole): Remove this after landing wonderblock-ifying
127
+ // the radio widget
128
+ primaryProductColor: PropTypes.string,
158
129
  }),
159
130
 
160
131
  // The color used for the hint progress indicator (eg. 1 / 3)
@@ -214,7 +185,12 @@ export const ApiOptions = {
214
185
  setDrawingAreaAvailable?: (...a: $ReadOnlyArray<any>) => mixed,
215
186
  showAlignmentOptions: boolean,
216
187
  staticRender: boolean,
217
- styling?: {radioStyleVersion?: "intermediate" | "final", ...},
188
+ styling?: {
189
+ // TODO(Nicole): Remove this after landing wonderblock-ifying
190
+ // the radio widget
191
+ primaryProductColor?: string,
192
+ ...
193
+ },
218
194
  trackInteraction?: (...a: $ReadOnlyArray<any>) => mixed,
219
195
  useDraftEditor?: boolean,
220
196
  widgetPlaceholder?: any,
@@ -241,9 +217,7 @@ export const ApiOptions = {
241
217
  },
242
218
  setDrawingAreaAvailable: function () {},
243
219
  useDraftEditor: false,
244
- styling: {
245
- radioStyleVersion: "final",
246
- },
220
+ styling: {},
247
221
  canScrollPage: false,
248
222
  inModal: false,
249
223
  crossOutEnabled: false,