@pie-lib/mask-markup 2.0.0-beta.2 → 2.0.0-next.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.json +1 -871
- package/CHANGELOG.md +296 -2
- package/LICENSE.md +5 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/choices/choice.js +99 -118
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +23 -19
- package/lib/choices/index.js.map +1 -1
- package/lib/componentize.js +1 -2
- package/lib/componentize.js.map +1 -1
- package/lib/components/blank.js +315 -221
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +39 -42
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +393 -124
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +1 -2
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +82 -26
- package/lib/constructed-response.js.map +1 -1
- package/lib/customizable.js +44 -0
- package/lib/customizable.js.map +1 -0
- package/lib/drag-in-the-blank.js +154 -61
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +4 -3
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +89 -56
- package/lib/mask.js.map +1 -1
- package/lib/serialization.js +30 -42
- package/lib/serialization.js.map +1 -1
- package/lib/with-mask.js +48 -20
- package/lib/with-mask.js.map +1 -1
- package/package.json +26 -15
- package/src/__tests__/drag-in-the-blank.test.js +111 -0
- package/src/__tests__/index.test.js +39 -0
- package/src/__tests__/mask.test.js +187 -0
- package/src/__tests__/serialization.test.js +54 -0
- package/src/__tests__/utils.js +1 -0
- package/src/__tests__/with-mask.test.js +76 -0
- package/src/choices/__tests__/index.test.js +75 -0
- package/src/choices/choice.jsx +83 -96
- package/src/choices/index.jsx +11 -5
- package/src/components/__tests__/blank.test.js +138 -0
- package/src/components/__tests__/correct-input.test.js +90 -0
- package/src/components/__tests__/dropdown.test.js +93 -0
- package/src/components/__tests__/input.test.js +102 -0
- package/src/components/blank.jsx +316 -204
- package/src/components/correct-input.jsx +37 -38
- package/src/components/dropdown.jsx +371 -125
- package/src/constructed-response.jsx +80 -18
- package/src/customizable.jsx +35 -0
- package/src/drag-in-the-blank.jsx +152 -40
- package/src/index.js +10 -1
- package/src/inline-dropdown.jsx +2 -0
- package/src/mask.jsx +71 -25
- package/src/serialization.js +22 -34
- package/src/with-mask.jsx +43 -3
- package/README.md +0 -14
- package/lib/new-serialization.js +0 -267
- package/lib/new-serialization.js.map +0 -1
- package/lib/parse-html.js +0 -17
- package/lib/parse-html.js.map +0 -1
- package/lib/test-serializer.js +0 -164
- package/lib/test-serializer.js.map +0 -1
- package/src/new-serialization.jsx +0 -291
- package/src/parse-html.js +0 -8
- package/src/test-serializer.js +0 -163
|
@@ -7,184 +7,453 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
10
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
11
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
12
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
14
|
var _react = _interopRequireDefault(require("react"));
|
|
16
15
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
16
|
+
var _Button = _interopRequireDefault(require("@mui/material/Button"));
|
|
17
|
+
var _InputLabel = _interopRequireDefault(require("@mui/material/InputLabel"));
|
|
18
|
+
var _Menu = _interopRequireDefault(require("@mui/material/Menu"));
|
|
19
|
+
var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
|
|
20
|
+
var _ArrowDropDown = _interopRequireDefault(require("@mui/icons-material/ArrowDropDown"));
|
|
21
|
+
var _ArrowDropUp = _interopRequireDefault(require("@mui/icons-material/ArrowDropUp"));
|
|
22
|
+
var _Close = _interopRequireDefault(require("@mui/icons-material/Close"));
|
|
23
|
+
var _Check = _interopRequireDefault(require("@mui/icons-material/Check"));
|
|
24
|
+
var _styles = require("@mui/material/styles");
|
|
21
25
|
var _renderUi = require("@pie-lib/render-ui");
|
|
22
|
-
|
|
23
|
-
function
|
|
26
|
+
var _mathRendering = require("@pie-lib/math-rendering");
|
|
27
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
28
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
29
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
30
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
31
|
+
var StyledButton = (0, _styles.styled)(_Button["default"])(function () {
|
|
32
|
+
return {
|
|
33
|
+
color: _renderUi.color.text(),
|
|
34
|
+
border: "1px solid ".concat(_renderUi.color.borderGray()),
|
|
35
|
+
borderRadius: '4px',
|
|
36
|
+
justifyContent: 'space-between',
|
|
37
|
+
backgroundColor: _renderUi.color.background(),
|
|
38
|
+
position: 'relative',
|
|
39
|
+
height: '45px',
|
|
40
|
+
width: 'fit-content',
|
|
41
|
+
margin: '2px',
|
|
42
|
+
textTransform: 'none',
|
|
43
|
+
'& span': {
|
|
44
|
+
paddingRight: '5px'
|
|
45
|
+
},
|
|
46
|
+
'& svg': {
|
|
47
|
+
position: 'absolute',
|
|
48
|
+
right: 0,
|
|
49
|
+
top: 'calc(50% - 12px)',
|
|
50
|
+
pointerEvents: 'none',
|
|
51
|
+
color: _renderUi.color.text(),
|
|
52
|
+
marginLeft: '5px'
|
|
53
|
+
},
|
|
54
|
+
'&.Mui-focused': {
|
|
55
|
+
outline: "3px solid ".concat(_renderUi.color.tertiary()),
|
|
56
|
+
outlineOffset: '2px',
|
|
57
|
+
borderWidth: '3px'
|
|
58
|
+
},
|
|
59
|
+
'&.disabledCorrect': {
|
|
60
|
+
borderWidth: '2px',
|
|
61
|
+
borderColor: _renderUi.color.correct(),
|
|
62
|
+
color: "".concat(_renderUi.color.text(), " !important")
|
|
63
|
+
},
|
|
64
|
+
'&.disabledIncorrect': {
|
|
65
|
+
borderWidth: '2px',
|
|
66
|
+
borderColor: _renderUi.color.incorrectWithIcon(),
|
|
67
|
+
color: "".concat(_renderUi.color.text(), " !important")
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
var StyledMenu = (0, _styles.styled)(_Menu["default"])(function () {
|
|
72
|
+
return {
|
|
73
|
+
backgroundColor: _renderUi.color.background(),
|
|
74
|
+
border: "1px solid ".concat(_renderUi.color.correct(), " !important"),
|
|
75
|
+
'&:hover': {
|
|
76
|
+
border: "1px solid ".concat(_renderUi.color.text(), " "),
|
|
77
|
+
borderColor: 'initial'
|
|
78
|
+
},
|
|
79
|
+
'&:focus': {
|
|
80
|
+
border: "1px solid ".concat(_renderUi.color.text()),
|
|
81
|
+
borderColor: 'initial'
|
|
82
|
+
},
|
|
83
|
+
// remove default padding on the inner list
|
|
84
|
+
'& .MuiList-root': {
|
|
85
|
+
padding: 0
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
var StyledMenuItem = (0, _styles.styled)(_MenuItem["default"])(function () {
|
|
90
|
+
return {
|
|
91
|
+
color: _renderUi.color.text(),
|
|
92
|
+
backgroundColor: _renderUi.color.background(),
|
|
93
|
+
'&.Mui-focused': {
|
|
94
|
+
outline: "3px solid ".concat(_renderUi.color.tertiary()),
|
|
95
|
+
outlineOffset: '-1px',
|
|
96
|
+
// keeps it inside the item
|
|
97
|
+
color: _renderUi.color.text(),
|
|
98
|
+
backgroundColor: _renderUi.color.background()
|
|
99
|
+
},
|
|
100
|
+
'&:hover': {
|
|
101
|
+
color: _renderUi.color.text(),
|
|
102
|
+
backgroundColor: _renderUi.color.dropdownBackground()
|
|
103
|
+
},
|
|
104
|
+
boxSizing: 'border-box',
|
|
105
|
+
padding: '25px',
|
|
106
|
+
borderRadius: '4px',
|
|
107
|
+
'&.selected': {
|
|
108
|
+
color: "".concat(_renderUi.color.text(), " !important"),
|
|
109
|
+
backgroundColor: "".concat(_renderUi.color.background(), " !important"),
|
|
110
|
+
'&:hover': {
|
|
111
|
+
color: _renderUi.color.text(),
|
|
112
|
+
backgroundColor: "".concat(_renderUi.color.dropdownBackground(), " !important")
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
var StyledLabel = (0, _styles.styled)('span')(function () {
|
|
118
|
+
return {
|
|
119
|
+
fontSize: 'max(1rem, 14px)'
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
var StyledSelectedIndicator = (0, _styles.styled)('span')(function () {
|
|
123
|
+
return {
|
|
124
|
+
fontSize: 'max(1rem, 14px)',
|
|
125
|
+
position: 'absolute',
|
|
126
|
+
right: '10px'
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
var StyledInputLabel = (0, _styles.styled)(_InputLabel["default"])(function () {
|
|
130
|
+
return {
|
|
131
|
+
position: 'absolute',
|
|
132
|
+
left: '-10000px',
|
|
133
|
+
top: 'auto',
|
|
134
|
+
width: '1px',
|
|
135
|
+
height: '1px',
|
|
136
|
+
overflow: 'hidden'
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
var StyledCorrectnessIcon = (0, _styles.styled)(_Check["default"])(function () {
|
|
140
|
+
return {
|
|
141
|
+
color: "".concat(_renderUi.color.white(), " !important"),
|
|
142
|
+
position: 'absolute',
|
|
143
|
+
top: '-8px !important',
|
|
144
|
+
left: '-8px',
|
|
145
|
+
marginLeft: '0 !important',
|
|
146
|
+
borderRadius: '50%',
|
|
147
|
+
fontSize: '16px',
|
|
148
|
+
padding: '2px',
|
|
149
|
+
'&.correct': {
|
|
150
|
+
backgroundColor: _renderUi.color.correct()
|
|
151
|
+
},
|
|
152
|
+
'&.incorrect': {
|
|
153
|
+
backgroundColor: _renderUi.color.incorrectWithIcon()
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
var StyledIncorrectnessIcon = (0, _styles.styled)(_Close["default"])(function () {
|
|
158
|
+
return {
|
|
159
|
+
color: "".concat(_renderUi.color.white(), " !important"),
|
|
160
|
+
position: 'absolute',
|
|
161
|
+
top: '-8px !important',
|
|
162
|
+
left: '-8px',
|
|
163
|
+
marginLeft: '0 !important',
|
|
164
|
+
borderRadius: '50%',
|
|
165
|
+
fontSize: '16px',
|
|
166
|
+
padding: '2px',
|
|
167
|
+
'&.correct': {
|
|
168
|
+
backgroundColor: _renderUi.color.correct()
|
|
169
|
+
},
|
|
170
|
+
'&.incorrect': {
|
|
171
|
+
backgroundColor: _renderUi.color.incorrectWithIcon()
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
});
|
|
24
175
|
var Dropdown = /*#__PURE__*/function (_React$Component) {
|
|
25
|
-
(0, _inherits2["default"])(Dropdown, _React$Component);
|
|
26
|
-
var _super = _createSuper(Dropdown);
|
|
27
176
|
function Dropdown(props) {
|
|
28
177
|
var _this;
|
|
29
178
|
(0, _classCallCheck2["default"])(this, Dropdown);
|
|
30
|
-
_this =
|
|
31
|
-
(0, _defineProperty2["default"])(
|
|
179
|
+
_this = _callSuper(this, Dropdown, [props]);
|
|
180
|
+
(0, _defineProperty2["default"])(_this, "handleClick", function (event) {
|
|
181
|
+
return _this.setState({
|
|
182
|
+
anchorEl: event.currentTarget
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
(0, _defineProperty2["default"])(_this, "handleClose", function () {
|
|
186
|
+
var value = _this.props.value;
|
|
32
187
|
_this.setState({
|
|
33
|
-
|
|
34
|
-
|
|
188
|
+
anchorEl: null,
|
|
189
|
+
previewValue: null,
|
|
190
|
+
highlightedOptionId: null
|
|
35
191
|
});
|
|
192
|
+
// clear displayed preview if no selection
|
|
193
|
+
if (!value && _this.previewRef.current) {
|
|
194
|
+
_this.previewRef.current.innerHTML = '';
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
(0, _defineProperty2["default"])(_this, "handleHighlight", function (index) {
|
|
198
|
+
var highlightedOptionId = "dropdown-option-".concat(_this.props.id, "-").concat(index);
|
|
199
|
+
|
|
200
|
+
// preview on hover if nothing selected
|
|
201
|
+
var stateUpdate = {
|
|
202
|
+
highlightedOptionId: highlightedOptionId
|
|
203
|
+
};
|
|
204
|
+
if (!_this.props.value) {
|
|
205
|
+
stateUpdate.previewValue = _this.props.choices[index].value;
|
|
206
|
+
}
|
|
207
|
+
_this.setState(stateUpdate);
|
|
208
|
+
});
|
|
209
|
+
(0, _defineProperty2["default"])(_this, "handleSelect", function (value, index) {
|
|
210
|
+
_this.props.onChange(_this.props.id, value);
|
|
211
|
+
_this.handleHighlight(index);
|
|
212
|
+
_this.handleClose();
|
|
36
213
|
});
|
|
37
|
-
(0, _defineProperty2["default"])(
|
|
214
|
+
(0, _defineProperty2["default"])(_this, "handleHover", function (index) {
|
|
215
|
+
var selectedValue = _this.props.value;
|
|
216
|
+
if (selectedValue) return;
|
|
217
|
+
var highlightedOptionId = "dropdown-option-".concat(_this.props.id, "-").concat(index);
|
|
218
|
+
var previewValue = _this.state.previewValue;
|
|
38
219
|
_this.setState({
|
|
39
|
-
|
|
40
|
-
|
|
220
|
+
highlightedOptionId: highlightedOptionId,
|
|
221
|
+
previewValue: previewValue
|
|
222
|
+
}, function () {
|
|
223
|
+
// On hover, preview the math-rendered content inside the button if no value is selected.
|
|
224
|
+
var ref = _this.elementRefs[index];
|
|
225
|
+
var preview = _this.previewRef.current;
|
|
226
|
+
if (ref && preview) {
|
|
227
|
+
preview.innerHTML = ref.innerHTML;
|
|
228
|
+
}
|
|
41
229
|
});
|
|
42
230
|
});
|
|
43
231
|
_this.state = {
|
|
44
|
-
|
|
45
|
-
|
|
232
|
+
anchorEl: null,
|
|
233
|
+
highlightedOptionId: null,
|
|
234
|
+
menuWidth: null,
|
|
235
|
+
previewValue: null
|
|
46
236
|
};
|
|
237
|
+
_this.hiddenRef = /*#__PURE__*/_react["default"].createRef();
|
|
238
|
+
_this.buttonRef = /*#__PURE__*/_react["default"].createRef();
|
|
239
|
+
_this.previewRef = /*#__PURE__*/_react["default"].createRef();
|
|
240
|
+
_this.elementRefs = [];
|
|
47
241
|
return _this;
|
|
48
242
|
}
|
|
49
|
-
(0,
|
|
243
|
+
(0, _inherits2["default"])(Dropdown, _React$Component);
|
|
244
|
+
return (0, _createClass2["default"])(Dropdown, [{
|
|
245
|
+
key: "componentDidMount",
|
|
246
|
+
value: function componentDidMount() {
|
|
247
|
+
// measure hidden menu width once
|
|
248
|
+
if (this.hiddenRef.current && this.state.menuWidth === null) {
|
|
249
|
+
this.setState({
|
|
250
|
+
menuWidth: this.hiddenRef.current.clientWidth
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
key: "componentDidUpdate",
|
|
256
|
+
value: function componentDidUpdate(prevProps, prevState) {
|
|
257
|
+
var hiddenEl = this.hiddenRef.current;
|
|
258
|
+
var dropdownJustOpened = !prevState.anchorEl && this.state.anchorEl;
|
|
259
|
+
if (dropdownJustOpened) {
|
|
260
|
+
this.elementRefs.forEach(function (ref) {
|
|
261
|
+
if (!ref) return;
|
|
262
|
+
var containsLatex = ref.querySelector('[data-latex], [data-raw]');
|
|
263
|
+
var hasMathJax = ref.querySelector('mjx-container');
|
|
264
|
+
var mathHandled = ref.querySelector('[data-math-handled="true"]');
|
|
265
|
+
if (containsLatex && (!mathHandled || !hasMathJax)) {
|
|
266
|
+
(0, _mathRendering.renderMath)(ref);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (hiddenEl) {
|
|
271
|
+
var newWidth = hiddenEl.clientWidth;
|
|
272
|
+
if (newWidth !== this.state.menuWidth) {
|
|
273
|
+
this.elementRefs.forEach(function (ref) {
|
|
274
|
+
if (ref) (0, _mathRendering.renderMath)(ref);
|
|
275
|
+
});
|
|
276
|
+
(0, _mathRendering.renderMath)(hiddenEl);
|
|
277
|
+
this.setState({
|
|
278
|
+
menuWidth: newWidth
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}, {
|
|
284
|
+
key: "getLabel",
|
|
285
|
+
value: function getLabel(choices, value) {
|
|
286
|
+
var found = (choices || []).find(function (choice) {
|
|
287
|
+
return choice.value === value;
|
|
288
|
+
});
|
|
289
|
+
return found ? found.label.trim() : undefined;
|
|
290
|
+
}
|
|
291
|
+
}, {
|
|
50
292
|
key: "render",
|
|
51
293
|
value: function render() {
|
|
294
|
+
var _this2 = this;
|
|
52
295
|
var _this$props = this.props,
|
|
53
|
-
classes = _this$props.classes,
|
|
54
296
|
id = _this$props.id,
|
|
55
297
|
correct = _this$props.correct,
|
|
56
298
|
disabled = _this$props.disabled,
|
|
57
299
|
value = _this$props.value,
|
|
58
|
-
_onChange = _this$props.onChange,
|
|
59
300
|
choices = _this$props.choices,
|
|
60
|
-
showCorrectAnswer = _this$props.showCorrectAnswer
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
301
|
+
showCorrectAnswer = _this$props.showCorrectAnswer,
|
|
302
|
+
singleQuery = _this$props.singleQuery,
|
|
303
|
+
correctValue = _this$props.correctValue;
|
|
304
|
+
var anchorEl = this.state.anchorEl;
|
|
305
|
+
var open = Boolean(anchorEl);
|
|
306
|
+
var buttonId = "dropdown-button-".concat(id);
|
|
307
|
+
var menuId = "dropdown-menu-".concat(id);
|
|
308
|
+
var valueDisplayId = "dropdown-value-".concat(id);
|
|
309
|
+
|
|
310
|
+
// Determine the class for disabled state, view mode and evaluate mode
|
|
311
|
+
var disabledClass;
|
|
312
|
+
// Reset elementRefs before each render to avoid stale references
|
|
313
|
+
this.elementRefs = [];
|
|
314
|
+
if (disabled && correct !== undefined) {
|
|
315
|
+
disabledClass = correct || showCorrectAnswer ? 'disabledCorrect' : 'disabledIncorrect';
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Create distinct, visually hidden labels for each dropdown
|
|
319
|
+
var incrementedId = parseInt(id, 10) + 1;
|
|
320
|
+
var labelId = singleQuery ? 'Query-label' : "Query-label-".concat(incrementedId);
|
|
321
|
+
var labelText = singleQuery ? 'Query' : "Query ".concat(incrementedId);
|
|
322
|
+
|
|
323
|
+
// Changed from Select to Button for dropdown to enhance accessibility. This modification offers explicit control over aria attributes and focuses management, ensuring the dropdown is compliant with accessibility standards. The use of Button and Menu components allows for better handling of keyboard interactions and provides accessible labels and menus, aligning with WCAG guidelines and improving usability for assistive technology users.
|
|
324
|
+
var correctnessIcon = null;
|
|
325
|
+
if (disabled && correct !== undefined) {
|
|
326
|
+
correctnessIcon = correct || showCorrectAnswer ? /*#__PURE__*/_react["default"].createElement(StyledCorrectnessIcon, {
|
|
327
|
+
className: "correct"
|
|
328
|
+
}) : /*#__PURE__*/_react["default"].createElement(StyledIncorrectnessIcon, {
|
|
329
|
+
className: "incorrect"
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
|
|
333
|
+
ref: this.hiddenRef,
|
|
334
|
+
style: {
|
|
335
|
+
position: 'absolute',
|
|
336
|
+
visibility: 'hidden',
|
|
337
|
+
top: 0,
|
|
338
|
+
left: 0
|
|
70
339
|
},
|
|
340
|
+
tabIndex: -1,
|
|
341
|
+
"aria-hidden": "true"
|
|
342
|
+
}, (choices || []).map(function (c, index) {
|
|
343
|
+
return /*#__PURE__*/_react["default"].createElement(StyledMenuItem, {
|
|
344
|
+
key: index,
|
|
345
|
+
tabIndex: -1,
|
|
346
|
+
"aria-hidden": "true"
|
|
347
|
+
}, /*#__PURE__*/_react["default"].createElement(StyledLabel, {
|
|
348
|
+
dangerouslySetInnerHTML: {
|
|
349
|
+
__html: c.label
|
|
350
|
+
}
|
|
351
|
+
}));
|
|
352
|
+
})), /*#__PURE__*/_react["default"].createElement(StyledInputLabel, {
|
|
353
|
+
id: labelId,
|
|
354
|
+
tabIndex: -1,
|
|
355
|
+
"aria-hidden": "true"
|
|
356
|
+
}, labelText), /*#__PURE__*/_react["default"].createElement(StyledButton, {
|
|
357
|
+
ref: this.buttonRef,
|
|
358
|
+
style: _objectSpread(_objectSpread({}, this.state.menuWidth && {
|
|
359
|
+
minWidth: "calc(".concat(this.state.menuWidth, "px + 8px)")
|
|
360
|
+
}), {}, {
|
|
361
|
+
borderWidth: open ? '2px' : '1px',
|
|
362
|
+
transition: 'border-width 0.2s ease-in-out'
|
|
363
|
+
}),
|
|
364
|
+
"aria-controls": open ? menuId : undefined,
|
|
365
|
+
"aria-haspopup": "listbox",
|
|
366
|
+
"aria-expanded": open ? 'true' : undefined,
|
|
367
|
+
"aria-activedescendant": this.state.highlightedOptionId,
|
|
368
|
+
onClick: this.handleClick,
|
|
369
|
+
className: disabledClass,
|
|
71
370
|
disabled: disabled,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
371
|
+
id: buttonId,
|
|
372
|
+
role: "combobox",
|
|
373
|
+
"aria-label": "Select an option for ".concat(labelText),
|
|
374
|
+
"aria-labelledby": valueDisplayId
|
|
375
|
+
}, correctnessIcon, /*#__PURE__*/_react["default"].createElement(StyledLabel, {
|
|
376
|
+
id: valueDisplayId,
|
|
377
|
+
ref: this.previewRef,
|
|
378
|
+
dangerouslySetInnerHTML: {
|
|
379
|
+
__html: correctValue ? correctValue : open && this.state.previewValue ? this.getLabel(choices, this.state.previewValue) : this.getLabel(choices, value) || ''
|
|
380
|
+
}
|
|
381
|
+
}), open ? /*#__PURE__*/_react["default"].createElement(_ArrowDropUp["default"], null) : /*#__PURE__*/_react["default"].createElement(_ArrowDropDown["default"], null)), /*#__PURE__*/_react["default"].createElement(StyledMenu, {
|
|
382
|
+
id: menuId,
|
|
383
|
+
anchorEl: anchorEl,
|
|
384
|
+
keepMounted: true,
|
|
75
385
|
open: open,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
386
|
+
onClose: this.handleClose,
|
|
387
|
+
getContentAnchorEl: null,
|
|
388
|
+
anchorOrigin: {
|
|
389
|
+
vertical: 'bottom',
|
|
390
|
+
horizontal: 'left'
|
|
391
|
+
},
|
|
392
|
+
transformOrigin: {
|
|
393
|
+
vertical: 'top',
|
|
394
|
+
horizontal: 'left'
|
|
82
395
|
},
|
|
83
|
-
|
|
84
|
-
|
|
396
|
+
transitionDuration: {
|
|
397
|
+
enter: 225,
|
|
398
|
+
exit: 195
|
|
399
|
+
},
|
|
400
|
+
slotProps: {
|
|
401
|
+
paper: this.state.menuWidth ? {
|
|
402
|
+
style: {
|
|
403
|
+
minWidth: this.state.menuWidth,
|
|
404
|
+
padding: '4px'
|
|
405
|
+
}
|
|
406
|
+
} : undefined,
|
|
407
|
+
list: {
|
|
408
|
+
'aria-labelledby': buttonId,
|
|
409
|
+
role: 'listbox',
|
|
410
|
+
disablePadding: true
|
|
411
|
+
}
|
|
85
412
|
}
|
|
86
413
|
}, (choices || []).map(function (c, index) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
414
|
+
var optionId = "dropdown-option-".concat(id, "-").concat(index);
|
|
415
|
+
return /*#__PURE__*/_react["default"].createElement(StyledMenuItem, {
|
|
416
|
+
id: optionId,
|
|
417
|
+
className: c.value === value ? 'selected' : '',
|
|
92
418
|
key: "".concat(c.label, "-").concat(index),
|
|
93
|
-
value: c.value
|
|
94
|
-
|
|
95
|
-
|
|
419
|
+
value: c.value,
|
|
420
|
+
onClick: function onClick() {
|
|
421
|
+
return _this2.handleSelect(c.value, index);
|
|
422
|
+
},
|
|
423
|
+
role: "option",
|
|
424
|
+
"aria-selected": _this2.state.highlightedOptionId === optionId ? 'true' : undefined,
|
|
425
|
+
onMouseOver: function onMouseOver() {
|
|
426
|
+
return _this2.handleHover(index);
|
|
427
|
+
}
|
|
428
|
+
}, /*#__PURE__*/_react["default"].createElement(StyledLabel, {
|
|
429
|
+
ref: function ref(_ref) {
|
|
430
|
+
return _this2.elementRefs[index] = _ref;
|
|
431
|
+
},
|
|
96
432
|
dangerouslySetInnerHTML: {
|
|
97
433
|
__html: c.label
|
|
98
434
|
}
|
|
99
|
-
}),
|
|
100
|
-
className: classes.label,
|
|
435
|
+
}), /*#__PURE__*/_react["default"].createElement(StyledSelectedIndicator, {
|
|
101
436
|
dangerouslySetInnerHTML: {
|
|
102
437
|
__html: c.value === value ? ' ✓' : ''
|
|
103
438
|
}
|
|
104
439
|
}));
|
|
105
|
-
}));
|
|
440
|
+
})));
|
|
106
441
|
}
|
|
107
442
|
}]);
|
|
108
|
-
return Dropdown;
|
|
109
443
|
}(_react["default"].Component);
|
|
110
444
|
(0, _defineProperty2["default"])(Dropdown, "propTypes", {
|
|
111
445
|
id: _propTypes["default"].string,
|
|
112
446
|
value: _propTypes["default"].string,
|
|
113
447
|
disabled: _propTypes["default"].bool,
|
|
114
448
|
onChange: _propTypes["default"].func,
|
|
115
|
-
classes: _propTypes["default"].object,
|
|
116
449
|
correct: _propTypes["default"].bool,
|
|
117
450
|
choices: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
118
451
|
value: _propTypes["default"].string,
|
|
119
452
|
label: _propTypes["default"].string
|
|
120
453
|
})),
|
|
121
|
-
showCorrectAnswer: _propTypes["default"].bool
|
|
454
|
+
showCorrectAnswer: _propTypes["default"].bool,
|
|
455
|
+
singleQuery: _propTypes["default"].bool,
|
|
456
|
+
correctValue: _propTypes["default"].string
|
|
122
457
|
});
|
|
123
|
-
var
|
|
124
|
-
return {
|
|
125
|
-
root: {
|
|
126
|
-
color: _renderUi.color.text(),
|
|
127
|
-
backgroundColor: _renderUi.color.background(),
|
|
128
|
-
borderColor: _renderUi.color.secondaryLight(),
|
|
129
|
-
'& ul': {
|
|
130
|
-
paddingTop: 0,
|
|
131
|
-
paddingBottom: 0,
|
|
132
|
-
border: "1px solid ".concat(_renderUi.color.text()),
|
|
133
|
-
borderRadius: '5px',
|
|
134
|
-
color: _renderUi.color.text(),
|
|
135
|
-
backgroundColor: _renderUi.color.background()
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
select: {
|
|
139
|
-
'&:focus': {
|
|
140
|
-
borderRadius: '4px'
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
selectMenu: {
|
|
144
|
-
backgroundColor: _renderUi.color.background(),
|
|
145
|
-
'&:hover': {
|
|
146
|
-
borderColor: 'initial'
|
|
147
|
-
},
|
|
148
|
-
'&:focus': {
|
|
149
|
-
borderColor: 'initial'
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
icon: {
|
|
153
|
-
color: _renderUi.color.text()
|
|
154
|
-
},
|
|
155
|
-
selected: {
|
|
156
|
-
color: "".concat(_renderUi.color.text(), " !important"),
|
|
157
|
-
backgroundColor: "".concat(_renderUi.color.background(), " !important"),
|
|
158
|
-
'&:hover': {
|
|
159
|
-
color: _renderUi.color.text(),
|
|
160
|
-
backgroundColor: "".concat(_renderUi.color.secondaryLight(), " !important")
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
menuRoot: {
|
|
164
|
-
color: _renderUi.color.text(),
|
|
165
|
-
backgroundColor: _renderUi.color.background(),
|
|
166
|
-
'&:focus': {
|
|
167
|
-
color: _renderUi.color.text(),
|
|
168
|
-
backgroundColor: _renderUi.color.background()
|
|
169
|
-
},
|
|
170
|
-
'&:hover': {
|
|
171
|
-
color: _renderUi.color.text(),
|
|
172
|
-
backgroundColor: _renderUi.color.secondaryLight()
|
|
173
|
-
},
|
|
174
|
-
boxSizing: 'border-box',
|
|
175
|
-
padding: '25px',
|
|
176
|
-
'&:first-of-type': {
|
|
177
|
-
borderRadius: '3px 3px 0 0'
|
|
178
|
-
},
|
|
179
|
-
'&:last-of-type': {
|
|
180
|
-
borderRadius: '0 0 3px 3px'
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
label: {
|
|
184
|
-
fontSize: 'max(1rem, 14px)'
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
|
-
var _default = (0, _styles.withStyles)(styles)(Dropdown);
|
|
189
|
-
exports["default"] = _default;
|
|
458
|
+
var _default = exports["default"] = Dropdown;
|
|
190
459
|
//# sourceMappingURL=dropdown.js.map
|