@khanacademy/perseus 0.3.3 → 0.4.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.
- package/CHANGELOG.md +31 -0
- package/dist/es/index.js +8247 -5609
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +17900 -15265
- package/dist/index.js.map +1 -1
- package/dist/strings.js +0 -1
- package/package.json +9 -8
- package/src/__tests__/__snapshots__/item-renderer_test.jsx.snap +2 -3
- package/src/__tests__/__snapshots__/server-item-renderer_test.jsx.snap +2 -3
- package/src/__tests__/renderer-api_test.jsx +3 -27
- package/src/components/__stories__/svg-image.stories.jsx +11 -0
- package/src/components/fixed-to-responsive.jsx +1 -0
- package/src/components/highlighting/ui/util.js +2 -2
- package/src/components/input-with-examples.jsx +3 -1
- package/src/components/svg-image.jsx +10 -7
- package/src/components/text-input.jsx +65 -16
- package/src/definition-context.js +59 -0
- package/src/index.js +5 -1
- package/src/interaction-tracker.js +2 -2
- package/src/item-renderer.jsx +1 -1
- package/src/mixins/provide-keypad.jsx +1 -1
- package/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap +438 -523
- package/src/multi-items/__tests__/multi-renderer_test.js +9 -9
- package/src/renderer.jsx +15 -8
- package/src/server-item-renderer.jsx +1 -1
- package/src/types.js +3 -4
- package/src/util/scroll-utils.js +2 -2
- package/src/widgets/__stories__/definition.stories.jsx +44 -0
- package/src/widgets/__tests__/__snapshots__/categorizer_test.jsx.snap +76 -8
- package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt_test.jsx.snap +6 -9
- package/src/widgets/__tests__/__snapshots__/graded-group-set_test.jsx.snap +2 -3
- package/src/widgets/__tests__/__snapshots__/grapher_test.jsx.snap +19 -2
- package/src/widgets/__tests__/__snapshots__/group_test.jsx.snap +338 -390
- package/src/widgets/__tests__/__snapshots__/image_test.jsx.snap +38 -4
- package/src/widgets/__tests__/__snapshots__/interactive-graph_test.jsx.snap +114 -12
- package/src/widgets/__tests__/__snapshots__/matrix_test.jsx.snap +120 -48
- package/src/widgets/__tests__/__snapshots__/numeric-input_test.jsx.snap +8 -12
- package/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap +3615 -4517
- package/src/widgets/__tests__/graded-group-set-jipt_test.jsx +0 -1
- package/src/widgets/__tests__/grapher.cypress.jsx +236 -176
- package/src/widgets/__tests__/group_test.jsx +4 -4
- package/src/widgets/__tests__/interactive-graph.cypress.jsx +371 -291
- package/src/widgets/__tests__/radio_test.jsx +73 -114
- package/src/widgets/definition.jsx +34 -32
- package/src/widgets/interactive-graph.jsx +4 -4
- package/src/widgets/label-image/answer-choices.jsx +1 -1
- package/src/widgets/label-image.jsx +1 -1
- package/src/widgets/molecule/molecule-drawing.jsx +1 -1
- package/src/widgets/numeric-input.jsx +2 -15
- package/src/widgets/radio/base-radio.jsx +1 -1
- package/src/widgets/radio/choice-icon.jsx +11 -10
- package/src/widgets/radio/choice.jsx +164 -396
- package/src/widgets/radio/cross-out-button.jsx +3 -5
- package/src/widgets/radio/option-status.jsx +4 -5
- package/src/widgets/radio/__stories__/cross-out-menu.stories.jsx +0 -59
- package/src/widgets/radio/__stories__/cross-out-tooltip.stories.jsx +0 -59
- package/src/widgets/radio/__stories__/toggleable-radio-button.stories.jsx +0 -28
- package/src/widgets/radio/cross-out-menu-wrapper.jsx +0 -492
- package/src/widgets/radio/cross-out-tooltip.jsx +0 -129
- package/src/widgets/radio/toggleable-radio-button.jsx +0 -133
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import _ from "underscore";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A radio button that can be unchecked by clicking it again.
|
|
8
|
-
*
|
|
9
|
-
* This component behaves much like a checkbox in that when you click it again
|
|
10
|
-
* (or hit space bar or select it in some other way), it will become unchecked.
|
|
11
|
-
* (Hopefully) it behaves exactly like a radio button in every other way though
|
|
12
|
-
* (arrow keys can still be used to select it within a group for example).
|
|
13
|
-
*
|
|
14
|
-
* Here's a summary of which of our event handlers fire for each way to select
|
|
15
|
-
* or deselect the button:
|
|
16
|
-
*
|
|
17
|
-
* - Clicking a button: handleClick, handleChange
|
|
18
|
-
* - Pressing spacebar with button focussed: handleKeyDown, handleKeyUp (we
|
|
19
|
-
* suppress the default behavior of some browsers to synthesize a click event
|
|
20
|
-
* here).
|
|
21
|
-
* - When radio button A is selected, pressing down arrow to select B:
|
|
22
|
-
* handleKeyDown (A), handleClick (B), handleChange (B), handleKeyUp (B)
|
|
23
|
-
* - Clicking with mac screenreader: handleClick, handleChange
|
|
24
|
-
*/
|
|
25
|
-
class ToggleableRadioButton extends React.Component<$FlowFixMe, $FlowFixMe> {
|
|
26
|
-
_inputElement: ?HTMLInputElement;
|
|
27
|
-
|
|
28
|
-
static propTypes = {
|
|
29
|
-
// Whether the radio button should be checked or unchecked (this is a
|
|
30
|
-
// controlled component).
|
|
31
|
-
checked: PropTypes.bool.isRequired,
|
|
32
|
-
|
|
33
|
-
// A ref function to attach to the <input> element.
|
|
34
|
-
inputRef: PropTypes.func,
|
|
35
|
-
|
|
36
|
-
// A function that will be called whenever the radio button is checked
|
|
37
|
-
// or unchecked. It's possible for this to be called twice for a single
|
|
38
|
-
// checking or unchecking.
|
|
39
|
-
onChecked: PropTypes.func.isRequired,
|
|
40
|
-
|
|
41
|
-
// Callbacks for when the user presses the up/left arrow or down/right
|
|
42
|
-
// arrow (respectively) to navigate between choices. When called, the
|
|
43
|
-
// parent finds the prev/next choice, focuses the input, and checks the
|
|
44
|
-
// radio button if appropriate. (The reason we have custom behavior is
|
|
45
|
-
// that we actually _don't_ want to auto-select crossed-out choices!)
|
|
46
|
-
goToPrevChoice: PropTypes.func.isRequired,
|
|
47
|
-
goToNextChoice: PropTypes.func.isRequired,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
handleClick: (SyntheticMouseEvent<>) => void = (event) => {
|
|
51
|
-
this.props.onChecked(!this.props.checked);
|
|
52
|
-
|
|
53
|
-
// NOTE(johnsullivan): Preventing default would make sense to do here
|
|
54
|
-
// because we're fully controlling the state of the check box and
|
|
55
|
-
// don't really want it to be (un)checked accidently. React
|
|
56
|
-
// requires that we *don't* call preventDefault from the onClick or
|
|
57
|
-
// onChecked handlers of a controlled component though.
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
handleKeyUp: (SyntheticKeyboardEvent<>) => void = (event) => {
|
|
61
|
-
// Make hitting the spacebar with the element selected equivalent to
|
|
62
|
-
// clicking it. Some browsers do this as part of the radio button's
|
|
63
|
-
// default behavior, but since some browsers don't we normalize the
|
|
64
|
-
// behavior here.
|
|
65
|
-
if (event.key === " ") {
|
|
66
|
-
this.props.onChecked(!this.props.checked);
|
|
67
|
-
event.preventDefault();
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
handleChange: (SyntheticInputEvent<>) => void = (event) => {
|
|
72
|
-
// If the checkbox is going from unchecked to checked, we'll handle it
|
|
73
|
-
// here.
|
|
74
|
-
// NOTE(johnsullivan): The onClick/onKeyUp handler most likely *also*
|
|
75
|
-
// handled this, but we're being defensive against browsers/devices
|
|
76
|
-
// that might not call those handlers like we'd expect. It's
|
|
77
|
-
// unclear to me whether this is strictly necessary.
|
|
78
|
-
if (!this.props.checked && event.target.checked) {
|
|
79
|
-
this.props.onChecked(true);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
handleKeyDown: (SyntheticKeyboardEvent<>) => void = (event) => {
|
|
84
|
-
// This is necessary in order to prevent IE9 from creating a duplicate
|
|
85
|
-
// click event on the radio button when the space bar is hit.
|
|
86
|
-
if (event.key === " ") {
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
} else if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
|
|
89
|
-
this.props.goToPrevChoice();
|
|
90
|
-
event.preventDefault();
|
|
91
|
-
} else if (event.key === "ArrowDown" || event.key === "ArrowRight") {
|
|
92
|
-
this.props.goToNextChoice();
|
|
93
|
-
event.preventDefault();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* We keep a reference to the input element ourselves, and provide it to
|
|
99
|
-
* the parent, too.
|
|
100
|
-
*/
|
|
101
|
-
handleRef: (HTMLInputElement) => void = (inputElement) => {
|
|
102
|
-
this._inputElement = inputElement;
|
|
103
|
-
this.props.inputRef && this.props.inputRef(inputElement);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
render(): React.Node {
|
|
107
|
-
const {
|
|
108
|
-
// eslint-disable-next-line no-unused-vars
|
|
109
|
-
inputRef,
|
|
110
|
-
// eslint-disable-next-line no-unused-vars
|
|
111
|
-
onChecked,
|
|
112
|
-
// eslint-disable-next-line no-unused-vars
|
|
113
|
-
goToPrevChoice,
|
|
114
|
-
// eslint-disable-next-line no-unused-vars
|
|
115
|
-
goToNextChoice,
|
|
116
|
-
...otherProps
|
|
117
|
-
} = this.props;
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<input
|
|
121
|
-
{...otherProps}
|
|
122
|
-
type="radio"
|
|
123
|
-
onChange={this.handleChange}
|
|
124
|
-
onClick={this.handleClick}
|
|
125
|
-
onKeyDown={this.handleKeyDown}
|
|
126
|
-
onKeyUp={this.handleKeyUp}
|
|
127
|
-
ref={this.handleRef}
|
|
128
|
-
/>
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export default ToggleableRadioButton;
|