@khanacademy/perseus 2.0.1 → 3.0.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 +17 -0
- package/dist/es/index.css +2 -66
- package/dist/es/index.js +18698 -18817
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +2 -66
- package/dist/index.js +18750 -18869
- package/dist/index.js.map +1 -1
- package/package.json +34 -34
- package/src/components/graph.jsx +0 -2
- package/src/components/math-input.jsx +163 -152
- package/src/components/tex-buttons.jsx +7 -9
- package/src/components/tooltip.jsx +0 -3
- package/src/components/zoomable.jsx +0 -10
- package/src/hint-renderer.jsx +4 -7
- package/src/interactive2/movable-point.jsx +0 -4
- package/src/interactive2/wrapped-ellipse.js +0 -1
- package/src/perseus-api.jsx +0 -7
- package/src/styles/articles.less +0 -4
- package/src/styles/khan-exercise.css +1 -33
- package/src/styles/perseus-renderer.less +1 -10
- package/src/styles/widgets/expression.less +0 -2
- package/src/styles/widgets/orderer.less +1 -1
- package/src/styles/widgets/plotter.less +0 -4
- package/src/styles/widgets/sortable.less +0 -14
- package/src/types.js +0 -6
- package/src/widgets/__stories__/unit.stories.jsx +0 -16
- package/src/widgets/__tests__/__snapshots__/input-number_test.jsx.snap +0 -481
- package/src/widgets/__tests__/__snapshots__/number-line_test.jsx.snap +1 -1
- package/src/widgets/__tests__/__snapshots__/unit_test.jsx.snap +20 -0
- package/src/widgets/__tests__/__snapshots__/video_test.jsx.snap +2 -2
- package/src/widgets/__tests__/expression_test.jsx +0 -10
- package/src/widgets/__tests__/input-number_test.jsx +0 -8
- package/src/widgets/__tests__/numeric-input_test.jsx +0 -11
- package/src/widgets/__tests__/unit_test.jsx +146 -121
- package/src/widgets/expression.jsx +2 -25
- package/src/widgets/input-number.jsx +2 -12
- package/src/widgets/matrix.jsx +4 -20
- package/src/widgets/number-line.jsx +0 -3
- package/src/widgets/numeric-input.jsx +1 -8
- package/src/widgets/radio/choice.jsx +2 -11
- package/src/widgets/simulator.jsx +2 -8
- package/src/widgets/table.jsx +0 -8
- package/src/widgets/transformer.jsx +0 -4
- package/src/widgets/unit.jsx +36 -51
- package/src/widgets/__tests__/__snapshots__/expression_test.jsx.snap +0 -38
|
@@ -1,144 +1,169 @@
|
|
|
1
1
|
// @flow
|
|
2
|
+
import "@testing-library/jest-dom";
|
|
3
|
+
import {render} from "@testing-library/react";
|
|
4
|
+
import React from "react";
|
|
5
|
+
|
|
2
6
|
import Unit, {countSigfigs, sigfigPrint} from "../unit.jsx";
|
|
3
7
|
|
|
4
8
|
const {widget} = Unit;
|
|
5
9
|
const UnitWidget = widget;
|
|
6
10
|
|
|
7
|
-
describe("
|
|
8
|
-
it("
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
11
|
+
describe("Unit Widget", () => {
|
|
12
|
+
it("renders", () => {
|
|
13
|
+
// Arrange
|
|
14
|
+
const props = {
|
|
15
|
+
onBlur: () => {},
|
|
16
|
+
onFocus: () => {},
|
|
17
|
+
onChange: () => {},
|
|
18
|
+
};
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
expect(
|
|
22
|
-
expect(sigfigPrint(50, 2)).toEqual("50.");
|
|
20
|
+
// Act
|
|
21
|
+
const {container} = render(<Unit.widget {...props} />);
|
|
22
|
+
|
|
23
|
+
// Assert
|
|
24
|
+
expect(container).toMatchSnapshot("initial render");
|
|
23
25
|
});
|
|
24
|
-
});
|
|
25
26
|
|
|
26
|
-
describe("
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
describe("countSigfigs", () => {
|
|
28
|
+
it("gets a few simple cases right", () => {
|
|
29
|
+
expect(countSigfigs("5")).toEqual(1);
|
|
30
|
+
expect(countSigfigs("500")).toEqual(1);
|
|
31
|
+
expect(countSigfigs("5.00")).toEqual(3);
|
|
32
|
+
expect(countSigfigs("5.01")).toEqual(3);
|
|
33
|
+
expect(countSigfigs("05.01")).toEqual(3);
|
|
32
34
|
});
|
|
33
|
-
if (maybeValid.type === "invalid") {
|
|
34
|
-
throw new Error("invalid unit");
|
|
35
|
-
}
|
|
36
|
-
expect(maybeValid.earned).toEqual(1);
|
|
37
|
-
|
|
38
|
-
maybeValid = UnitWidget.validate("0.0739 L", {
|
|
39
|
-
value: "5.00 tbsp",
|
|
40
|
-
accepting: "all",
|
|
41
|
-
sigfigs: 3,
|
|
42
|
-
});
|
|
43
|
-
if (maybeValid.type === "invalid") {
|
|
44
|
-
throw new Error("invalid unit");
|
|
45
|
-
}
|
|
46
|
-
expect(maybeValid.earned).toEqual(1);
|
|
47
|
-
|
|
48
|
-
maybeValid = UnitWidget.validate("5.00 tbsp", {
|
|
49
|
-
value: "0.0739 L",
|
|
50
|
-
accepting: "all",
|
|
51
|
-
sigfigs: 3,
|
|
52
|
-
});
|
|
53
|
-
if (maybeValid.type === "invalid") {
|
|
54
|
-
throw new Error("invalid unit");
|
|
55
|
-
}
|
|
56
|
-
expect(maybeValid.earned).toEqual(1);
|
|
57
|
-
|
|
58
|
-
maybeValid = UnitWidget.validate("1124 lb", {
|
|
59
|
-
value: "5000 N",
|
|
60
|
-
accepting: "all",
|
|
61
|
-
sigfigs: 4,
|
|
62
|
-
});
|
|
63
|
-
if (maybeValid.type === "invalid") {
|
|
64
|
-
throw new Error("invalid unit");
|
|
65
|
-
}
|
|
66
|
-
expect(maybeValid.earned).toEqual(1);
|
|
67
|
-
|
|
68
|
-
maybeValid = UnitWidget.validate("1124 lb", {
|
|
69
|
-
value: "5000 N",
|
|
70
|
-
accepting: "some",
|
|
71
|
-
acceptingUnits: ["lb"],
|
|
72
|
-
sigfigs: 4,
|
|
73
|
-
});
|
|
74
|
-
if (maybeValid.type === "invalid") {
|
|
75
|
-
throw new Error("invalid unit");
|
|
76
|
-
}
|
|
77
|
-
expect(maybeValid.earned).toEqual(1);
|
|
78
35
|
});
|
|
79
36
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
37
|
+
describe("displaySigFigs", () => {
|
|
38
|
+
it("gets a few simple cases right", () => {
|
|
39
|
+
expect(sigfigPrint(150, 3)).toEqual("150.");
|
|
40
|
+
expect(sigfigPrint(0.0005, 2)).toEqual("5.0 x 10^-4");
|
|
41
|
+
expect(sigfigPrint(15000, 2)).toEqual("1.5 x 10^4");
|
|
42
|
+
expect(sigfigPrint(50, 2)).toEqual("50.");
|
|
86
43
|
});
|
|
87
|
-
if (maybeValid.type === "invalid") {
|
|
88
|
-
throw new Error("invalid unit");
|
|
89
|
-
}
|
|
90
|
-
expect(maybeValid.earned).toEqual(1);
|
|
91
44
|
});
|
|
92
45
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
46
|
+
describe("Unit Widget Grading", () => {
|
|
47
|
+
it("accepts correct answers", () => {
|
|
48
|
+
let maybeValid = UnitWidget.validate("5 tbsp", {
|
|
49
|
+
value: "5 tbsp",
|
|
50
|
+
accepting: "all",
|
|
51
|
+
sigfigs: 1,
|
|
52
|
+
});
|
|
53
|
+
if (maybeValid.type === "invalid") {
|
|
54
|
+
throw new Error("invalid unit");
|
|
55
|
+
}
|
|
56
|
+
expect(maybeValid.earned).toEqual(1);
|
|
57
|
+
|
|
58
|
+
maybeValid = UnitWidget.validate("0.0739 L", {
|
|
59
|
+
value: "5.00 tbsp",
|
|
60
|
+
accepting: "all",
|
|
61
|
+
sigfigs: 3,
|
|
62
|
+
});
|
|
63
|
+
if (maybeValid.type === "invalid") {
|
|
64
|
+
throw new Error("invalid unit");
|
|
65
|
+
}
|
|
66
|
+
expect(maybeValid.earned).toEqual(1);
|
|
67
|
+
|
|
68
|
+
maybeValid = UnitWidget.validate("5.00 tbsp", {
|
|
69
|
+
value: "0.0739 L",
|
|
70
|
+
accepting: "all",
|
|
71
|
+
sigfigs: 3,
|
|
72
|
+
});
|
|
73
|
+
if (maybeValid.type === "invalid") {
|
|
74
|
+
throw new Error("invalid unit");
|
|
75
|
+
}
|
|
76
|
+
expect(maybeValid.earned).toEqual(1);
|
|
77
|
+
|
|
78
|
+
maybeValid = UnitWidget.validate("1124 lb", {
|
|
79
|
+
value: "5000 N",
|
|
80
|
+
accepting: "all",
|
|
81
|
+
sigfigs: 4,
|
|
82
|
+
});
|
|
83
|
+
if (maybeValid.type === "invalid") {
|
|
84
|
+
throw new Error("invalid unit");
|
|
85
|
+
}
|
|
86
|
+
expect(maybeValid.earned).toEqual(1);
|
|
87
|
+
|
|
88
|
+
maybeValid = UnitWidget.validate("1124 lb", {
|
|
89
|
+
value: "5000 N",
|
|
90
|
+
accepting: "some",
|
|
91
|
+
acceptingUnits: ["lb"],
|
|
92
|
+
sigfigs: 4,
|
|
93
|
+
});
|
|
94
|
+
if (maybeValid.type === "invalid") {
|
|
95
|
+
throw new Error("invalid unit");
|
|
96
|
+
}
|
|
97
|
+
expect(maybeValid.earned).toEqual(1);
|
|
98
98
|
});
|
|
99
|
-
if (maybeValid.type === "invalid") {
|
|
100
|
-
throw new Error("invalid unit");
|
|
101
|
-
}
|
|
102
|
-
expect(maybeValid.earned).toEqual(0);
|
|
103
|
-
expect(maybeValid.message).toEqual("Check your units.");
|
|
104
|
-
});
|
|
105
99
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
it("handles loss of precision gracefully", () => {
|
|
101
|
+
const maybeValid = UnitWidget.validate("1.12 lb", {
|
|
102
|
+
value: "5 N",
|
|
103
|
+
accepting: "some",
|
|
104
|
+
acceptingUnits: ["lb"],
|
|
105
|
+
sigfigs: 3,
|
|
106
|
+
});
|
|
107
|
+
if (maybeValid.type === "invalid") {
|
|
108
|
+
throw new Error("invalid unit");
|
|
109
|
+
}
|
|
110
|
+
expect(maybeValid.earned).toEqual(1);
|
|
111
111
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
112
|
+
|
|
113
|
+
it("flags incorrect units", () => {
|
|
114
|
+
const maybeValid = UnitWidget.validate("5 tbsp", {
|
|
115
|
+
value: "5 m",
|
|
116
|
+
accepting: "all",
|
|
117
|
+
sigfigs: 1,
|
|
118
|
+
});
|
|
119
|
+
if (maybeValid.type === "invalid") {
|
|
120
|
+
throw new Error("invalid unit");
|
|
121
|
+
}
|
|
122
|
+
expect(maybeValid.earned).toEqual(0);
|
|
123
|
+
expect(maybeValid.message).toEqual("Check your units.");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("flags incorrect sigfigs", () => {
|
|
127
|
+
let maybeValid = UnitWidget.validate("5.0 tbsp", {
|
|
128
|
+
value: "5 tbsp",
|
|
129
|
+
accepting: "all",
|
|
130
|
+
sigfigs: 1,
|
|
131
|
+
});
|
|
132
|
+
if (maybeValid.type === "invalid") {
|
|
133
|
+
throw new Error("invalid unit");
|
|
134
|
+
}
|
|
135
|
+
expect(maybeValid.earned).toEqual(0);
|
|
136
|
+
expect(maybeValid.message).toEqual(
|
|
137
|
+
"Check your significant figures.",
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
maybeValid = UnitWidget.validate("5 tbsp", {
|
|
141
|
+
value: "5.0 tbsp",
|
|
142
|
+
accepting: "all",
|
|
143
|
+
sigfigs: 2,
|
|
144
|
+
});
|
|
145
|
+
if (maybeValid.type === "invalid") {
|
|
146
|
+
throw new Error("invalid unit");
|
|
147
|
+
}
|
|
148
|
+
expect(maybeValid.earned).toEqual(0);
|
|
149
|
+
expect(maybeValid.message).toEqual(
|
|
150
|
+
"Check your significant figures.",
|
|
151
|
+
);
|
|
122
152
|
});
|
|
123
|
-
if (maybeValid.type === "invalid") {
|
|
124
|
-
throw new Error("invalid unit");
|
|
125
|
-
}
|
|
126
|
-
expect(maybeValid.earned).toEqual(0);
|
|
127
|
-
expect(maybeValid.message).toEqual("Check your significant figures.");
|
|
128
|
-
});
|
|
129
153
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
154
|
+
it("flags numerically incorrect answers", () => {
|
|
155
|
+
const maybeValid = UnitWidget.validate("8.1 tbsp", {
|
|
156
|
+
value: "5.0 tbsp",
|
|
157
|
+
accepting: "all",
|
|
158
|
+
sigfigs: 2,
|
|
159
|
+
});
|
|
160
|
+
if (maybeValid.type === "invalid") {
|
|
161
|
+
throw new Error("invalid unit");
|
|
162
|
+
}
|
|
163
|
+
expect(maybeValid.earned).toEqual(0);
|
|
164
|
+
expect(maybeValid.message).toEqual(
|
|
165
|
+
"That answer is numerically incorrect.",
|
|
166
|
+
);
|
|
135
167
|
});
|
|
136
|
-
if (maybeValid.type === "invalid") {
|
|
137
|
-
throw new Error("invalid unit");
|
|
138
|
-
}
|
|
139
|
-
expect(maybeValid.earned).toEqual(0);
|
|
140
|
-
expect(maybeValid.message).toEqual(
|
|
141
|
-
"That answer is numerically incorrect.",
|
|
142
|
-
);
|
|
143
168
|
});
|
|
144
169
|
});
|
|
@@ -9,7 +9,6 @@ import * as React from "react";
|
|
|
9
9
|
import _ from "underscore";
|
|
10
10
|
|
|
11
11
|
import InlineIcon from "../components/inline-icon.jsx";
|
|
12
|
-
import InputWithExamples from "../components/input-with-examples.jsx";
|
|
13
12
|
import MathInput from "../components/math-input.jsx";
|
|
14
13
|
import Tooltip from "../components/tooltip.jsx";
|
|
15
14
|
import {iconExclamationSign} from "../icon-paths.js";
|
|
@@ -398,10 +397,8 @@ export class Expression extends React.Component<Props, ExpressionState> {
|
|
|
398
397
|
|
|
399
398
|
// HACK(joel)
|
|
400
399
|
insert: (text: string) => void = (text: string) => {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
this.refs.input.insert(text);
|
|
404
|
-
}
|
|
400
|
+
// eslint-disable-next-line react/no-string-refs
|
|
401
|
+
this.refs.input.insert(text);
|
|
405
402
|
};
|
|
406
403
|
|
|
407
404
|
getInputPaths: () => $ReadOnlyArray<$ReadOnlyArray<any>> = () => {
|
|
@@ -458,26 +455,6 @@ export class Expression extends React.Component<Props, ExpressionState> {
|
|
|
458
455
|
/>
|
|
459
456
|
);
|
|
460
457
|
}
|
|
461
|
-
if (this.props.apiOptions.staticRender) {
|
|
462
|
-
// To make things slightly easier, we just use an InputWithExamples
|
|
463
|
-
// component to handle the static rendering, which is the same
|
|
464
|
-
// component used by InputNumber and NumericInput
|
|
465
|
-
return (
|
|
466
|
-
<InputWithExamples
|
|
467
|
-
// eslint-disable-next-line react/no-string-refs
|
|
468
|
-
ref="input"
|
|
469
|
-
value={this.props.value}
|
|
470
|
-
type="tex"
|
|
471
|
-
examples={[]}
|
|
472
|
-
shouldShowExamples={false}
|
|
473
|
-
onChange={this.changeAndTrack}
|
|
474
|
-
onFocus={this._handleFocus}
|
|
475
|
-
onBlur={this._handleBlur}
|
|
476
|
-
id={this.props.widgetId}
|
|
477
|
-
linterContext={this.props.linterContext}
|
|
478
|
-
/>
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
458
|
// TODO(alex): Style this tooltip to be more consistent with other
|
|
482
459
|
// tooltips on the site; align to left middle (once possible)
|
|
483
460
|
const errorTooltip = (
|
|
@@ -136,10 +136,7 @@ class InputNumber extends React.Component<Props> {
|
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
shouldShowExamples: () => boolean = () => {
|
|
139
|
-
return
|
|
140
|
-
this.props.answerType !== "number" &&
|
|
141
|
-
!this.props.apiOptions.staticRender
|
|
142
|
-
);
|
|
139
|
+
return this.props.answerType !== "number";
|
|
143
140
|
};
|
|
144
141
|
|
|
145
142
|
render(): React.Node {
|
|
@@ -188,7 +185,7 @@ class InputNumber extends React.Component<Props> {
|
|
|
188
185
|
value={this.props.currentValue}
|
|
189
186
|
onChange={this.handleChange}
|
|
190
187
|
style={inputStyles}
|
|
191
|
-
type=
|
|
188
|
+
type="text"
|
|
192
189
|
examples={this.examples()}
|
|
193
190
|
shouldShowExamples={this.shouldShowExamples()}
|
|
194
191
|
onFocus={this._handleFocus}
|
|
@@ -204,13 +201,6 @@ class InputNumber extends React.Component<Props> {
|
|
|
204
201
|
this.props.onChange({currentValue: newValue}, cb);
|
|
205
202
|
};
|
|
206
203
|
|
|
207
|
-
_getInputType: () => "tex" | "text" = () => {
|
|
208
|
-
if (this.props.apiOptions.staticRender) {
|
|
209
|
-
return "tex";
|
|
210
|
-
}
|
|
211
|
-
return "text";
|
|
212
|
-
};
|
|
213
|
-
|
|
214
204
|
_handleFocus: () => void = () => {
|
|
215
205
|
this.props.onFocus([]);
|
|
216
206
|
// HACK(kevinb): We want to dismiss the feedback popover that webapp
|
package/src/widgets/matrix.jsx
CHANGED
|
@@ -9,7 +9,6 @@ import * as React from "react";
|
|
|
9
9
|
import ReactDOM from "react-dom";
|
|
10
10
|
import _ from "underscore";
|
|
11
11
|
|
|
12
|
-
import MathOutput from "../components/math-output.jsx";
|
|
13
12
|
import NumberInput from "../components/number-input.jsx";
|
|
14
13
|
import SimpleKeypadInput from "../components/simple-keypad-input.jsx";
|
|
15
14
|
import TextInput from "../components/text-input.jsx";
|
|
@@ -26,19 +25,12 @@ import type {WidgetExports, WidgetProps} from "../types.js";
|
|
|
26
25
|
const {assert} = InteractiveUtil;
|
|
27
26
|
const {stringArrayOfSize} = Util;
|
|
28
27
|
|
|
29
|
-
// We store
|
|
30
|
-
// inputs, which vary in formatting: (1) the
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
// and mobile web. The first two sets of dimensions come from `matrix.less`;
|
|
28
|
+
// We store two sets of dimensions for the brackets, for our two types of
|
|
29
|
+
// inputs, which vary in formatting: (1) the normal inputs rendered on
|
|
30
|
+
// desktop and (2) the keypad-based inputs newly rendered for the mobile apps
|
|
31
|
+
// and mobile web. These sets of dimensions come from `matrix.less`;
|
|
34
32
|
// the keypad-based input's dimensions are provided to the component itself,
|
|
35
33
|
// below.
|
|
36
|
-
const STATIC_INPUT_DIMENSIONS = {
|
|
37
|
-
INPUT_MARGIN: 4,
|
|
38
|
-
INPUT_HEIGHT: 38,
|
|
39
|
-
INPUT_WIDTH: 82,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
34
|
const NORMAL_DIMENSIONS = {
|
|
43
35
|
INPUT_MARGIN: 3,
|
|
44
36
|
INPUT_HEIGHT: 30,
|
|
@@ -162,8 +154,6 @@ class Matrix extends React.Component<Props, State> {
|
|
|
162
154
|
let dimensions;
|
|
163
155
|
if (this.props.apiOptions.customKeypad) {
|
|
164
156
|
dimensions = KEYPAD_INPUT_DIMENSIONS;
|
|
165
|
-
} else if (this.props.apiOptions.staticRender) {
|
|
166
|
-
dimensions = STATIC_INPUT_DIMENSIONS;
|
|
167
157
|
} else {
|
|
168
158
|
dimensions = NORMAL_DIMENSIONS;
|
|
169
159
|
}
|
|
@@ -314,12 +304,6 @@ class Matrix extends React.Component<Props, State> {
|
|
|
314
304
|
}
|
|
315
305
|
/>
|
|
316
306
|
);
|
|
317
|
-
} else if (
|
|
318
|
-
this.props.apiOptions.staticRender
|
|
319
|
-
) {
|
|
320
|
-
MatrixInput = (
|
|
321
|
-
<MathOutput {...inputProps} />
|
|
322
|
-
);
|
|
323
307
|
} else if (this.props.numericInput) {
|
|
324
308
|
MatrixInput = (
|
|
325
309
|
<NumberInput {...inputProps} />
|
|
@@ -6,7 +6,6 @@ import ReactDOM from "react-dom";
|
|
|
6
6
|
import _ from "underscore";
|
|
7
7
|
|
|
8
8
|
import Graphie from "../components/graphie.jsx";
|
|
9
|
-
import MathOutput from "../components/math-output.jsx";
|
|
10
9
|
import NumberInput from "../components/number-input.jsx";
|
|
11
10
|
import SimpleKeypadInput from "../components/simple-keypad-input.jsx";
|
|
12
11
|
import InteractiveUtil from "../interactive2/interactive-util.js";
|
|
@@ -656,8 +655,6 @@ class NumberLine extends React.Component<Props, State> {
|
|
|
656
655
|
let Input;
|
|
657
656
|
if (this.props.apiOptions.customKeypad) {
|
|
658
657
|
Input = SimpleKeypadInput;
|
|
659
|
-
} else if (this.props.apiOptions.staticRender) {
|
|
660
|
-
Input = MathOutput;
|
|
661
658
|
} else {
|
|
662
659
|
Input = NumberInput;
|
|
663
660
|
}
|
|
@@ -348,13 +348,6 @@ export class NumericInput extends React.Component<Props, State> {
|
|
|
348
348
|
this.props.trackInteraction();
|
|
349
349
|
};
|
|
350
350
|
|
|
351
|
-
_getInputType: () => "tex" | "text" = () => {
|
|
352
|
-
if (this.props.apiOptions.staticRender) {
|
|
353
|
-
return "tex";
|
|
354
|
-
}
|
|
355
|
-
return "text";
|
|
356
|
-
};
|
|
357
|
-
|
|
358
351
|
_handleFocus: () => void = () => {
|
|
359
352
|
this.props.onFocus([]);
|
|
360
353
|
// HACK(kevinb): We want to dismiss the feedback popover that webapp
|
|
@@ -418,7 +411,7 @@ export class NumericInput extends React.Component<Props, State> {
|
|
|
418
411
|
value={this.props.currentValue}
|
|
419
412
|
onChange={this.handleChange}
|
|
420
413
|
labelText={labelText}
|
|
421
|
-
type=
|
|
414
|
+
type="text"
|
|
422
415
|
examples={this.examples()}
|
|
423
416
|
shouldShowExamples={this.shouldShowExamples()}
|
|
424
417
|
onFocus={this._handleFocus}
|
|
@@ -180,11 +180,7 @@ function Choice(props: ChoicePropsWithForwardRef): React.Node {
|
|
|
180
180
|
});
|
|
181
181
|
}}
|
|
182
182
|
onChange={() => {}}
|
|
183
|
-
disabled={
|
|
184
|
-
disabled ||
|
|
185
|
-
apiOptions.staticRender ||
|
|
186
|
-
apiOptions.readOnly
|
|
187
|
-
}
|
|
183
|
+
disabled={disabled || apiOptions.readOnly}
|
|
188
184
|
tabIndex={-1}
|
|
189
185
|
className={ClassNames.RADIO.OPTION_CONTENT}
|
|
190
186
|
/>
|
|
@@ -201,11 +197,7 @@ function Choice(props: ChoicePropsWithForwardRef): React.Node {
|
|
|
201
197
|
crossedOut: false,
|
|
202
198
|
});
|
|
203
199
|
}}
|
|
204
|
-
disabled={
|
|
205
|
-
disabled ||
|
|
206
|
-
apiOptions.staticRender ||
|
|
207
|
-
apiOptions.readOnly
|
|
208
|
-
}
|
|
200
|
+
disabled={disabled || apiOptions.readOnly}
|
|
209
201
|
style={{flex: 1, color: Color.offBlack, userSelect: "text"}}
|
|
210
202
|
ref={(forwardedRef: any)}
|
|
211
203
|
aria-hidden="true"
|
|
@@ -311,7 +303,6 @@ function Choice(props: ChoicePropsWithForwardRef): React.Node {
|
|
|
311
303
|
aria-label={`Open menu for Choice ${getChoiceLetter(
|
|
312
304
|
pos,
|
|
313
305
|
)}`}
|
|
314
|
-
disabled={apiOptions.staticRender}
|
|
315
306
|
style={{
|
|
316
307
|
alignSelf: "center",
|
|
317
308
|
padding: "5px",
|
|
@@ -448,8 +448,6 @@ class Simulator extends React.Component<$FlowFixMe, $FlowFixMe> {
|
|
|
448
448
|
|
|
449
449
|
const highlight = "0px 0px 0px 2px rgba(255, 165, 0, 1)";
|
|
450
450
|
const highlightStyle = _.extend({}, inputStyle, {
|
|
451
|
-
WebkitBoxShadow: highlight,
|
|
452
|
-
MozBoxShadow: highlight,
|
|
453
451
|
boxShadow: highlight,
|
|
454
452
|
transition: "all 0.15s",
|
|
455
453
|
});
|
|
@@ -460,13 +458,9 @@ class Simulator extends React.Component<$FlowFixMe, $FlowFixMe> {
|
|
|
460
458
|
? highlightStyle
|
|
461
459
|
: unhighlightStyle;
|
|
462
460
|
|
|
463
|
-
const InputComponent = this.props.apiOptions.staticRender
|
|
464
|
-
? MathOutput
|
|
465
|
-
: NumberInput;
|
|
466
|
-
|
|
467
461
|
const proportionInput = (
|
|
468
462
|
<div>
|
|
469
|
-
<
|
|
463
|
+
<NumberInput
|
|
470
464
|
// eslint-disable-next-line react/no-string-refs
|
|
471
465
|
ref="userProportion"
|
|
472
466
|
style={style}
|
|
@@ -489,7 +483,7 @@ class Simulator extends React.Component<$FlowFixMe, $FlowFixMe> {
|
|
|
489
483
|
|
|
490
484
|
const sampleSizeInput = (
|
|
491
485
|
<div>
|
|
492
|
-
<
|
|
486
|
+
<NumberInput
|
|
493
487
|
// eslint-disable-next-line react/no-string-refs
|
|
494
488
|
ref="sampleSize"
|
|
495
489
|
style={style}
|
package/src/widgets/table.jsx
CHANGED
|
@@ -10,7 +10,6 @@ import * as React from "react";
|
|
|
10
10
|
import ReactDOM from "react-dom";
|
|
11
11
|
import _ from "underscore";
|
|
12
12
|
|
|
13
|
-
import MathOutput from "../components/math-output.jsx";
|
|
14
13
|
import SimpleKeypadInput from "../components/simple-keypad-input.jsx";
|
|
15
14
|
import InteractiveUtil from "../interactive2/interactive-util.js";
|
|
16
15
|
import {ApiOptions} from "../perseus-api.jsx";
|
|
@@ -102,9 +101,6 @@ class Table extends React.Component<$FlowFixMe> {
|
|
|
102
101
|
// input in table.less. Those values should be kept in-sync.
|
|
103
102
|
inputStyle = {width: 80};
|
|
104
103
|
extraInputProps.keypadElement = this.props.keypadElement;
|
|
105
|
-
} else if (this.props.apiOptions.staticRender) {
|
|
106
|
-
InputComponent = MathOutput;
|
|
107
|
-
inputStyle = {};
|
|
108
104
|
} else {
|
|
109
105
|
InputComponent = "input";
|
|
110
106
|
inputStyle = {};
|
|
@@ -241,8 +237,6 @@ class Table extends React.Component<$FlowFixMe> {
|
|
|
241
237
|
const inputComponent = this.refs[inputID];
|
|
242
238
|
if (this.props.apiOptions.customKeypad) {
|
|
243
239
|
inputComponent.focus();
|
|
244
|
-
} else if (this.props.apiOptions.staticRender) {
|
|
245
|
-
inputComponent.focus();
|
|
246
240
|
} else {
|
|
247
241
|
// $FlowFixMe[prop-missing]
|
|
248
242
|
// $FlowFixMe[incompatible-use]
|
|
@@ -256,8 +250,6 @@ class Table extends React.Component<$FlowFixMe> {
|
|
|
256
250
|
const inputComponent = this.refs[inputID];
|
|
257
251
|
if (this.props.apiOptions.customKeypad) {
|
|
258
252
|
inputComponent.blur();
|
|
259
|
-
} else if (this.props.apiOptions.staticRender) {
|
|
260
|
-
inputComponent.blur();
|
|
261
253
|
} else {
|
|
262
254
|
// $FlowFixMe[prop-missing]
|
|
263
255
|
// $FlowFixMe[incompatible-use]
|
|
@@ -30,7 +30,6 @@ import _ from "underscore";
|
|
|
30
30
|
|
|
31
31
|
import Graph from "../components/graph.jsx";
|
|
32
32
|
import InlineIcon from "../components/inline-icon.jsx";
|
|
33
|
-
import MathOutput from "../components/math-output.jsx";
|
|
34
33
|
import NumberInput from "../components/number-input.jsx";
|
|
35
34
|
import SimpleKeypadInput from "../components/simple-keypad-input.jsx";
|
|
36
35
|
import {getDependencies} from "../dependencies.js";
|
|
@@ -260,9 +259,6 @@ const inputComponentForApiOptions = (apiOptions) => {
|
|
|
260
259
|
if (apiOptions.customKeypad) {
|
|
261
260
|
return SimpleKeypadInput;
|
|
262
261
|
}
|
|
263
|
-
if (apiOptions.staticRender) {
|
|
264
|
-
return MathOutput;
|
|
265
|
-
}
|
|
266
262
|
return NumberInput;
|
|
267
263
|
};
|
|
268
264
|
|