@pie-lib/mask-markup 1.13.47-next.1 → 1.13.47-next.1639

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 (60) hide show
  1. package/CHANGELOG.json +1 -871
  2. package/CHANGELOG.md +170 -17
  3. package/NEXT.CHANGELOG.json +1 -0
  4. package/lib/choices/choice.js +80 -17
  5. package/lib/choices/choice.js.map +1 -1
  6. package/lib/choices/index.js +11 -3
  7. package/lib/choices/index.js.map +1 -1
  8. package/lib/components/blank.js +146 -34
  9. package/lib/components/blank.js.map +1 -1
  10. package/lib/components/correct-input.js +8 -3
  11. package/lib/components/correct-input.js.map +1 -1
  12. package/lib/components/dropdown.js +340 -58
  13. package/lib/components/dropdown.js.map +1 -1
  14. package/lib/constructed-response.js +87 -23
  15. package/lib/constructed-response.js.map +1 -1
  16. package/lib/customizable.js +48 -0
  17. package/lib/customizable.js.map +1 -0
  18. package/lib/drag-in-the-blank.js +34 -8
  19. package/lib/drag-in-the-blank.js.map +1 -1
  20. package/lib/index.js +8 -0
  21. package/lib/index.js.map +1 -1
  22. package/lib/inline-dropdown.js +3 -1
  23. package/lib/inline-dropdown.js.map +1 -1
  24. package/lib/mask.js +45 -6
  25. package/lib/mask.js.map +1 -1
  26. package/lib/with-mask.js +34 -2
  27. package/lib/with-mask.js.map +1 -1
  28. package/package.json +10 -6
  29. package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +316 -0
  30. package/src/__tests__/__snapshots__/mask.test.js.snap +55 -0
  31. package/src/__tests__/__snapshots__/with-mask.test.js.snap +62 -0
  32. package/src/__tests__/drag-in-the-blank.test.js +71 -0
  33. package/src/__tests__/index.test.js +39 -0
  34. package/src/__tests__/mask.test.js +152 -0
  35. package/src/__tests__/serialization.test.js +54 -0
  36. package/src/__tests__/utils.js +1 -0
  37. package/src/__tests__/with-mask.test.js +51 -0
  38. package/src/choices/__tests__/__snapshots__/index.test.js.snap +209 -0
  39. package/src/choices/__tests__/index.test.js +62 -0
  40. package/src/choices/choice.jsx +60 -6
  41. package/src/choices/index.jsx +2 -2
  42. package/src/components/__tests__/__snapshots__/blank.test.js.snap +111 -0
  43. package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +64 -0
  44. package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +136 -0
  45. package/src/components/__tests__/__snapshots__/input.test.js.snap +34 -0
  46. package/src/components/__tests__/blank.test.js +202 -0
  47. package/src/components/__tests__/correct-input.test.js +49 -0
  48. package/src/components/__tests__/dropdown.test.js +51 -0
  49. package/src/components/__tests__/input.test.js +50 -0
  50. package/src/components/blank.jsx +139 -28
  51. package/src/components/correct-input.jsx +6 -1
  52. package/src/components/dropdown.jsx +313 -79
  53. package/src/constructed-response.jsx +76 -18
  54. package/src/customizable.jsx +35 -0
  55. package/src/drag-in-the-blank.jsx +26 -3
  56. package/src/index.js +10 -1
  57. package/src/inline-dropdown.jsx +2 -0
  58. package/src/mask.jsx +30 -5
  59. package/src/with-mask.jsx +39 -2
  60. package/README.md +0 -14
@@ -25,16 +25,34 @@ var _react = _interopRequireDefault(require("react"));
25
25
 
26
26
  var _propTypes = _interopRequireDefault(require("prop-types"));
27
27
 
28
- var _Select = _interopRequireDefault(require("@material-ui/core/Select"));
28
+ var _Button = _interopRequireDefault(require("@material-ui/core/Button"));
29
+
30
+ var _InputLabel = _interopRequireDefault(require("@material-ui/core/InputLabel"));
31
+
32
+ var _Menu = _interopRequireDefault(require("@material-ui/core/Menu"));
29
33
 
30
34
  var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));
31
35
 
32
- var _correctInput = _interopRequireDefault(require("./correct-input"));
36
+ var _ArrowDropDown = _interopRequireDefault(require("@material-ui/icons/ArrowDropDown"));
37
+
38
+ var _ArrowDropUp = _interopRequireDefault(require("@material-ui/icons/ArrowDropUp"));
39
+
40
+ var _Close = _interopRequireDefault(require("@material-ui/icons/Close"));
41
+
42
+ var _Check = _interopRequireDefault(require("@material-ui/icons/Check"));
33
43
 
34
44
  var _styles = require("@material-ui/core/styles");
35
45
 
46
+ var _classnames = _interopRequireDefault(require("classnames"));
47
+
36
48
  var _renderUi = require("@pie-lib/render-ui");
37
49
 
50
+ var _mathRendering = require("@pie-lib/math-rendering");
51
+
52
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
53
+
54
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
55
+
38
56
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
39
57
 
40
58
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
@@ -49,82 +67,291 @@ var Dropdown = /*#__PURE__*/function (_React$Component) {
49
67
 
50
68
  (0, _classCallCheck2["default"])(this, Dropdown);
51
69
  _this = _super.call(this, props);
52
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "showCheckmarkAndOpen", function () {
53
- _this.setState({
54
- showCheckmark: true,
55
- open: true
70
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function (event) {
71
+ return _this.setState({
72
+ anchorEl: event.currentTarget
56
73
  });
57
74
  });
58
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "hideCheckmarkAndClose", function () {
75
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClose", function () {
76
+ var value = _this.props.value;
77
+
78
+ _this.setState({
79
+ anchorEl: null,
80
+ previewValue: null,
81
+ highlightedOptionId: null
82
+ }); // clear displayed preview if no selection
83
+
84
+
85
+ if (!value && _this.previewRef.current) {
86
+ _this.previewRef.current.innerHTML = '';
87
+ }
88
+ });
89
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleHighlight", function (index) {
90
+ var highlightedOptionId = "dropdown-option-".concat(_this.props.id, "-").concat(index); // preview on hover if nothing selected
91
+
92
+ var stateUpdate = {
93
+ highlightedOptionId: highlightedOptionId
94
+ };
95
+
96
+ if (!_this.props.value) {
97
+ stateUpdate.previewValue = _this.props.choices[index].value;
98
+ }
99
+
100
+ _this.setState(stateUpdate);
101
+ });
102
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleSelect", function (value, index) {
103
+ _this.props.onChange(_this.props.id, value);
104
+
105
+ _this.handleHighlight(index);
106
+
107
+ _this.handleClose();
108
+ });
109
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleHover", function (index) {
110
+ var selectedValue = _this.props.value;
111
+ if (selectedValue) return;
112
+ var highlightedOptionId = "dropdown-option-".concat(_this.props.id, "-").concat(index);
113
+ var previewValue = _this.state.previewValue;
114
+
59
115
  _this.setState({
60
- showCheckmark: false,
61
- open: false
116
+ highlightedOptionId: highlightedOptionId,
117
+ previewValue: previewValue
118
+ }, function () {
119
+ // On hover, preview the math-rendered content inside the button if no value is selected.
120
+ var ref = _this.elementRefs[index];
121
+ var preview = _this.previewRef.current;
122
+
123
+ if (ref && preview) {
124
+ preview.innerHTML = ref.innerHTML;
125
+ }
62
126
  });
63
127
  });
64
128
  _this.state = {
65
- showCheckmark: false,
66
- open: false
129
+ anchorEl: null,
130
+ highlightedOptionId: null,
131
+ menuWidth: null,
132
+ previewValue: null
67
133
  };
134
+ _this.hiddenRef = /*#__PURE__*/_react["default"].createRef();
135
+ _this.buttonRef = /*#__PURE__*/_react["default"].createRef();
136
+ _this.previewRef = /*#__PURE__*/_react["default"].createRef();
137
+ _this.elementRefs = [];
68
138
  return _this;
69
139
  }
70
140
 
71
141
  (0, _createClass2["default"])(Dropdown, [{
142
+ key: "componentDidMount",
143
+ value: function componentDidMount() {
144
+ // measure hidden menu width once
145
+ if (this.hiddenRef.current && this.state.menuWidth === null) {
146
+ this.setState({
147
+ menuWidth: this.hiddenRef.current.clientWidth
148
+ });
149
+ }
150
+ }
151
+ }, {
152
+ key: "componentDidUpdate",
153
+ value: function componentDidUpdate(prevProps, prevState) {
154
+ var hiddenEl = this.hiddenRef.current;
155
+ var dropdownJustOpened = !prevState.anchorEl && this.state.anchorEl;
156
+
157
+ if (dropdownJustOpened) {
158
+ this.elementRefs.forEach(function (ref) {
159
+ if (!ref) return;
160
+ var containsLatex = ref.querySelector('[data-latex], [data-raw]');
161
+ var hasMathJax = ref.querySelector('mjx-container');
162
+ var mathHandled = ref.querySelector('[data-math-handled="true"]');
163
+
164
+ if (containsLatex && (!mathHandled || !hasMathJax)) {
165
+ (0, _mathRendering.renderMath)(ref);
166
+ }
167
+ });
168
+ }
169
+
170
+ if (hiddenEl) {
171
+ var newWidth = hiddenEl.clientWidth;
172
+
173
+ if (newWidth !== this.state.menuWidth) {
174
+ this.elementRefs.forEach(function (ref) {
175
+ if (ref) (0, _mathRendering.renderMath)(ref);
176
+ });
177
+ (0, _mathRendering.renderMath)(hiddenEl);
178
+ this.setState({
179
+ menuWidth: newWidth
180
+ });
181
+ }
182
+ }
183
+ }
184
+ }, {
185
+ key: "getLabel",
186
+ value: function getLabel(choices, value) {
187
+ var found = (choices || []).find(function (choice) {
188
+ return choice.value === value;
189
+ });
190
+ return found ? found.label.trim() : undefined;
191
+ }
192
+ }, {
72
193
  key: "render",
73
194
  value: function render() {
195
+ var _this2 = this;
196
+
74
197
  var _this$props = this.props,
75
198
  classes = _this$props.classes,
76
199
  id = _this$props.id,
77
200
  correct = _this$props.correct,
78
201
  disabled = _this$props.disabled,
79
202
  value = _this$props.value,
80
- _onChange = _this$props.onChange,
81
203
  choices = _this$props.choices,
82
- showCorrectAnswer = _this$props.showCorrectAnswer;
83
- var _this$state = this.state,
84
- showCheckmark = _this$state.showCheckmark,
85
- open = _this$state.open;
86
- return /*#__PURE__*/_react["default"].createElement(_Select["default"], {
204
+ showCorrectAnswer = _this$props.showCorrectAnswer,
205
+ singleQuery = _this$props.singleQuery,
206
+ correctValue = _this$props.correctValue;
207
+ var anchorEl = this.state.anchorEl;
208
+ var open = Boolean(anchorEl);
209
+ var buttonId = "dropdown-button-".concat(id);
210
+ var menuId = "dropdown-menu-".concat(id);
211
+ var valueDisplayId = "dropdown-value-".concat(id); // Determine the class for disabled state, view mode and evaluate mode
212
+
213
+ var disabledClass; // Reset elementRefs before each render to avoid stale references
214
+
215
+ this.elementRefs = [];
216
+
217
+ if (disabled && correct !== undefined) {
218
+ disabledClass = correct || showCorrectAnswer ? classes.disabledCorrect : classes.disabledIncorrect;
219
+ } // Create distinct, visually hidden labels for each dropdown
220
+
221
+
222
+ var incrementedId = parseInt(id, 10) + 1;
223
+ var labelId = singleQuery ? 'Query-label' : "Query-label-".concat(incrementedId);
224
+ var labelText = singleQuery ? 'Query' : "Query ".concat(incrementedId); // 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.
225
+
226
+ var correctnessIcon = null;
227
+
228
+ if (disabled && correct !== undefined) {
229
+ correctnessIcon = correct || showCorrectAnswer ? /*#__PURE__*/_react["default"].createElement(_Check["default"], {
230
+ className: (0, _classnames["default"])(classes.correctnessIndicatorIcon, classes.correctIcon)
231
+ }) : /*#__PURE__*/_react["default"].createElement(_Close["default"], {
232
+ className: (0, _classnames["default"])(classes.correctnessIndicatorIcon, classes.incorrectIcon)
233
+ });
234
+ }
235
+
236
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
237
+ ref: this.hiddenRef,
238
+ style: {
239
+ position: 'absolute',
240
+ visibility: 'hidden',
241
+ top: 0,
242
+ left: 0
243
+ },
244
+ tabIndex: -1,
245
+ "aria-hidden": "true"
246
+ }, (choices || []).map(function (c, index) {
247
+ return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
248
+ key: index,
249
+ classes: {
250
+ root: classes.menuRoot,
251
+ selected: classes.selected
252
+ },
253
+ tabIndex: -1,
254
+ "aria-hidden": "true"
255
+ }, /*#__PURE__*/_react["default"].createElement("span", {
256
+ className: classes.label,
257
+ dangerouslySetInnerHTML: {
258
+ __html: c.label
259
+ }
260
+ }));
261
+ })), /*#__PURE__*/_react["default"].createElement(_InputLabel["default"], {
262
+ className: classes.srOnly,
263
+ id: labelId,
264
+ tabIndex: -1,
265
+ "aria-hidden": "true"
266
+ }, labelText), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
267
+ ref: this.buttonRef,
268
+ style: _objectSpread(_objectSpread({}, this.state.menuWidth && {
269
+ minWidth: "calc(".concat(this.state.menuWidth, "px + 8px)")
270
+ }), {}, {
271
+ borderWidth: open ? '2px' : '1px',
272
+ transition: 'border-width 0.2s ease-in-out'
273
+ }),
274
+ "aria-controls": open ? menuId : undefined,
275
+ "aria-haspopup": "listbox",
276
+ "aria-expanded": open ? 'true' : undefined,
277
+ "aria-activedescendant": this.state.highlightedOptionId,
278
+ onClick: this.handleClick,
87
279
  classes: {
88
280
  root: classes.root,
89
- icon: classes.icon,
90
- selectMenu: classes.selectMenu,
91
- select: classes.select
281
+ disabled: disabledClass
92
282
  },
93
283
  disabled: disabled,
94
- value: value || '',
95
- onOpen: this.showCheckmarkAndOpen,
96
- onClose: this.hideCheckmarkAndClose,
284
+ id: buttonId,
285
+ role: "combobox",
286
+ "aria-label": "Select an option for ".concat(labelText),
287
+ "aria-labelledby": valueDisplayId
288
+ }, correctnessIcon, /*#__PURE__*/_react["default"].createElement("span", {
289
+ id: valueDisplayId,
290
+ ref: this.previewRef,
291
+ className: classes.label,
292
+ dangerouslySetInnerHTML: {
293
+ __html: correctValue ? correctValue : open && this.state.previewValue ? this.getLabel(choices, this.state.previewValue) : this.getLabel(choices, value) || ''
294
+ }
295
+ }), open ? /*#__PURE__*/_react["default"].createElement(_ArrowDropUp["default"], null) : /*#__PURE__*/_react["default"].createElement(_ArrowDropDown["default"], null)), /*#__PURE__*/_react["default"].createElement(_Menu["default"], {
296
+ id: menuId,
297
+ anchorEl: anchorEl,
298
+ className: classes.selectMenu,
299
+ keepMounted: true,
97
300
  open: open,
98
- input: /*#__PURE__*/_react["default"].createElement(_correctInput["default"], {
99
- correct: showCorrectAnswer || correct
100
- }),
101
- MenuProps: {
102
- keepMounted: true,
103
- disablePortal: true
301
+ onClose: this.handleClose,
302
+ getContentAnchorEl: null,
303
+ anchorOrigin: {
304
+ vertical: 'bottom',
305
+ horizontal: 'left'
306
+ },
307
+ transformOrigin: {
308
+ vertical: 'top',
309
+ horizontal: 'left'
104
310
  },
105
- onChange: function onChange(e) {
106
- _onChange(id, e.target.value);
311
+ PaperProps: this.state.menuWidth ? {
312
+ style: {
313
+ minWidth: this.state.menuWidth,
314
+ padding: '4px'
315
+ }
316
+ } : undefined,
317
+ MenuListProps: {
318
+ 'aria-labelledby': buttonId,
319
+ role: 'listbox',
320
+ disablePadding: true
107
321
  }
108
322
  }, (choices || []).map(function (c, index) {
323
+ var optionId = "dropdown-option-".concat(id, "-").concat(index);
109
324
  return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
325
+ id: optionId,
110
326
  classes: {
111
327
  root: classes.menuRoot,
112
328
  selected: classes.selected
113
329
  },
114
330
  key: "".concat(c.label, "-").concat(index),
115
- value: c.value
331
+ value: c.value,
332
+ onClick: function onClick() {
333
+ return _this2.handleSelect(c.value, index);
334
+ },
335
+ role: "option",
336
+ "aria-selected": _this2.state.highlightedOptionId === optionId ? 'true' : undefined,
337
+ onMouseOver: function onMouseOver() {
338
+ return _this2.handleHover(index);
339
+ }
116
340
  }, /*#__PURE__*/_react["default"].createElement("span", {
341
+ ref: function ref(_ref) {
342
+ return _this2.elementRefs[index] = _ref;
343
+ },
117
344
  className: classes.label,
118
345
  dangerouslySetInnerHTML: {
119
346
  __html: c.label
120
347
  }
121
- }), showCheckmark && /*#__PURE__*/_react["default"].createElement("span", {
122
- className: classes.label,
348
+ }), /*#__PURE__*/_react["default"].createElement("span", {
349
+ className: classes.selectedIndicator,
123
350
  dangerouslySetInnerHTML: {
124
351
  __html: c.value === value ? ' &check;' : ''
125
352
  }
126
353
  }));
127
- }));
354
+ })));
128
355
  }
129
356
  }]);
130
357
  return Dropdown;
@@ -141,71 +368,126 @@ var Dropdown = /*#__PURE__*/function (_React$Component) {
141
368
  value: _propTypes["default"].string,
142
369
  label: _propTypes["default"].string
143
370
  })),
144
- showCorrectAnswer: _propTypes["default"].bool
371
+ showCorrectAnswer: _propTypes["default"].bool,
372
+ singleQuery: _propTypes["default"].bool,
373
+ correctValue: _propTypes["default"].string
145
374
  });
146
375
 
147
376
  var styles = function styles() {
148
377
  return {
149
378
  root: {
150
379
  color: _renderUi.color.text(),
380
+ border: "1px solid ".concat(_renderUi.color.borderGray()),
381
+ borderRadius: '4px',
382
+ justifyContent: 'space-between',
151
383
  backgroundColor: _renderUi.color.background(),
152
- borderColor: _renderUi.color.secondaryLight(),
153
- '& ul': {
154
- paddingTop: 0,
155
- paddingBottom: 0,
156
- border: "1px solid ".concat(_renderUi.color.text()),
157
- borderRadius: '5px',
384
+ position: 'relative',
385
+ height: '45px',
386
+ width: 'fit-content',
387
+ margin: '2px',
388
+ textTransform: 'none',
389
+ '& span': {
390
+ paddingRight: '5px'
391
+ },
392
+ '& svg': {
393
+ position: 'absolute',
394
+ right: 0,
395
+ top: 'calc(50% - 12px)',
396
+ pointerEvents: 'none',
158
397
  color: _renderUi.color.text(),
159
- backgroundColor: _renderUi.color.background()
398
+ marginLeft: '5px'
399
+ },
400
+ '&:focus, &:focus-visible': {
401
+ outline: "3px solid ".concat(_renderUi.color.tertiary()),
402
+ outlineOffset: '2px',
403
+ borderWidth: '3px'
160
404
  }
161
405
  },
162
- select: {
163
- '&:focus': {
164
- borderRadius: '4px'
165
- }
406
+ disabledCorrect: {
407
+ borderWidth: '2px',
408
+ borderColor: _renderUi.color.correct(),
409
+ color: "".concat(_renderUi.color.text(), " !important")
410
+ },
411
+ disabledIncorrect: {
412
+ borderWidth: '2px',
413
+ borderColor: _renderUi.color.incorrectWithIcon(),
414
+ color: "".concat(_renderUi.color.text(), " !important")
166
415
  },
167
416
  selectMenu: {
168
417
  backgroundColor: _renderUi.color.background(),
418
+ border: "1px solid ".concat(_renderUi.color.correct(), " !important"),
169
419
  '&:hover': {
420
+ border: "1px solid ".concat(_renderUi.color.text(), " "),
170
421
  borderColor: 'initial'
171
422
  },
172
423
  '&:focus': {
424
+ border: "1px solid ".concat(_renderUi.color.text()),
173
425
  borderColor: 'initial'
426
+ },
427
+ // remove default padding on the inner list
428
+ '& .MuiList-root': {
429
+ padding: 0
174
430
  }
175
431
  },
176
- icon: {
177
- color: _renderUi.color.text()
178
- },
179
432
  selected: {
180
433
  color: "".concat(_renderUi.color.text(), " !important"),
181
434
  backgroundColor: "".concat(_renderUi.color.background(), " !important"),
182
435
  '&:hover': {
183
436
  color: _renderUi.color.text(),
184
- backgroundColor: "".concat(_renderUi.color.secondaryLight(), " !important")
437
+ backgroundColor: "".concat(_renderUi.color.dropdownBackground(), " !important")
185
438
  }
186
439
  },
187
440
  menuRoot: {
188
441
  color: _renderUi.color.text(),
189
442
  backgroundColor: _renderUi.color.background(),
443
+ '&:focus, &:focus-visible': {
444
+ outline: "3px solid ".concat(_renderUi.color.tertiary()),
445
+ outlineOffset: '-1px' // keeps it inside the item
446
+
447
+ },
190
448
  '&:focus': {
191
449
  color: _renderUi.color.text(),
192
450
  backgroundColor: _renderUi.color.background()
193
451
  },
194
452
  '&:hover': {
195
453
  color: _renderUi.color.text(),
196
- backgroundColor: _renderUi.color.secondaryLight()
454
+ backgroundColor: _renderUi.color.dropdownBackground()
197
455
  },
198
456
  boxSizing: 'border-box',
199
457
  padding: '25px',
200
- '&:first-of-type': {
201
- borderRadius: '3px 3px 0 0'
202
- },
203
- '&:last-of-type': {
204
- borderRadius: '0 0 3px 3px'
205
- }
458
+ borderRadius: '4px'
206
459
  },
207
460
  label: {
208
461
  fontSize: 'max(1rem, 14px)'
462
+ },
463
+ selectedIndicator: {
464
+ fontSize: 'max(1rem, 14px)',
465
+ position: 'absolute',
466
+ right: '10px'
467
+ },
468
+ srOnly: {
469
+ position: 'absolute',
470
+ left: '-10000px',
471
+ top: 'auto',
472
+ width: '1px',
473
+ height: '1px',
474
+ overflow: 'hidden'
475
+ },
476
+ correctnessIndicatorIcon: {
477
+ color: "".concat(_renderUi.color.white(), " !important"),
478
+ position: 'absolute',
479
+ top: '-8px !important',
480
+ left: '-8px',
481
+ marginLeft: '0 !important',
482
+ borderRadius: '50%',
483
+ fontSize: '16px',
484
+ padding: '2px'
485
+ },
486
+ correctIcon: {
487
+ backgroundColor: _renderUi.color.correct()
488
+ },
489
+ incorrectIcon: {
490
+ backgroundColor: _renderUi.color.incorrectWithIcon()
209
491
  }
210
492
  };
211
493
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/dropdown.jsx"],"names":["Dropdown","props","setState","showCheckmark","open","state","classes","id","correct","disabled","value","onChange","choices","showCorrectAnswer","root","icon","selectMenu","select","showCheckmarkAndOpen","hideCheckmarkAndClose","keepMounted","disablePortal","e","target","map","c","index","menuRoot","selected","label","__html","React","Component","PropTypes","string","bool","func","object","arrayOf","shape","styles","color","text","backgroundColor","background","borderColor","secondaryLight","paddingTop","paddingBottom","border","borderRadius","boxSizing","padding","fontSize"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;IAEMA,Q;;;;;AAYJ,oBAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,6GASI,YAAM;AAC3B,YAAKC,QAAL,CAAc;AACZC,QAAAA,aAAa,EAAE,IADH;AAEZC,QAAAA,IAAI,EAAE;AAFM,OAAd;AAID,KAdkB;AAAA,8GAgBK,YAAM;AAC5B,YAAKF,QAAL,CAAc;AACZC,QAAAA,aAAa,EAAE,KADH;AAEZC,QAAAA,IAAI,EAAE;AAFM,OAAd;AAID,KArBkB;AAGjB,UAAKC,KAAL,GAAa;AACXF,MAAAA,aAAa,EAAE,KADJ;AAEXC,MAAAA,IAAI,EAAE;AAFK,KAAb;AAHiB;AAOlB;;;;WAgBD,kBAAS;AACP,wBAAwF,KAAKH,KAA7F;AAAA,UAAQK,OAAR,eAAQA,OAAR;AAAA,UAAiBC,EAAjB,eAAiBA,EAAjB;AAAA,UAAqBC,OAArB,eAAqBA,OAArB;AAAA,UAA8BC,QAA9B,eAA8BA,QAA9B;AAAA,UAAwCC,KAAxC,eAAwCA,KAAxC;AAAA,UAA+CC,SAA/C,eAA+CA,QAA/C;AAAA,UAAyDC,OAAzD,eAAyDA,OAAzD;AAAA,UAAkEC,iBAAlE,eAAkEA,iBAAlE;AAEA,wBAAgC,KAAKR,KAArC;AAAA,UAAQF,aAAR,eAAQA,aAAR;AAAA,UAAuBC,IAAvB,eAAuBA,IAAvB;AAEA,0BACE,gCAAC,kBAAD;AACE,QAAA,OAAO,EAAE;AACPU,UAAAA,IAAI,EAAER,OAAO,CAACQ,IADP;AAEPC,UAAAA,I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\nimport Select from '@material-ui/core/Select';\nimport MenuItem from '@material-ui/core/MenuItem';\nimport CorrectInput from './correct-input';\nimport { withStyles } from '@material-ui/core/styles';\nimport { color } from '@pie-lib/render-ui';\n\nclass Dropdown extends React.Component {\n static propTypes = {\n id: PropTypes.string,\n value: PropTypes.string,\n disabled: PropTypes.bool,\n onChange: PropTypes.func,\n classes: PropTypes.object,\n correct: PropTypes.bool,\n choices: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string, label: PropTypes.string })),\n showCorrectAnswer: PropTypes.bool,\n };\n\n constructor(props) {\n super(props);\n\n this.state = {\n showCheckmark: false,\n open: false,\n };\n }\n\n showCheckmarkAndOpen = () => {\n this.setState({\n showCheckmark: true,\n open: true,\n });\n };\n\n hideCheckmarkAndClose = () => {\n this.setState({\n showCheckmark: false,\n open: false,\n });\n };\n\n render() {\n const { classes, id, correct, disabled, value, onChange, choices, showCorrectAnswer } = this.props;\n\n const { showCheckmark, open } = this.state;\n\n return (\n <Select\n classes={{\n root: classes.root,\n icon: classes.icon,\n selectMenu: classes.selectMenu,\n select: classes.select,\n }}\n disabled={disabled}\n value={value || ''}\n onOpen={this.showCheckmarkAndOpen}\n onClose={this.hideCheckmarkAndClose}\n open={open}\n input={<CorrectInput correct={showCorrectAnswer || correct} />}\n MenuProps={{\n keepMounted: true,\n disablePortal: true,\n }}\n onChange={(e) => {\n onChange(id, e.target.value);\n }}\n >\n {(choices || []).map((c, index) => (\n <MenuItem\n classes={{ root: classes.menuRoot, selected: classes.selected }}\n key={`${c.label}-${index}`}\n value={c.value}\n >\n <span\n className={classes.label}\n dangerouslySetInnerHTML={{\n __html: c.label,\n }}\n />\n {showCheckmark && (\n <span\n className={classes.label}\n dangerouslySetInnerHTML={{ __html: c.value === value ? ' &check;' : '' }}\n />\n )}\n </MenuItem>\n ))}\n </Select>\n );\n }\n}\n\nconst styles = () => ({\n root: {\n color: color.text(),\n backgroundColor: color.background(),\n borderColor: color.secondaryLight(),\n '& ul': {\n paddingTop: 0,\n paddingBottom: 0,\n border: `1px solid ${color.text()}`,\n borderRadius: '5px',\n color: color.text(),\n backgroundColor: color.background(),\n },\n },\n select: {\n '&:focus': {\n borderRadius: '4px',\n },\n },\n selectMenu: {\n backgroundColor: color.background(),\n '&:hover': {\n borderColor: 'initial',\n },\n '&:focus': {\n borderColor: 'initial',\n },\n },\n icon: {\n color: color.text(),\n },\n selected: {\n color: `${color.text()} !important`,\n backgroundColor: `${color.background()} !important`,\n '&:hover': {\n color: color.text(),\n backgroundColor: `${color.secondaryLight()} !important`,\n },\n },\n menuRoot: {\n color: color.text(),\n backgroundColor: color.background(),\n '&:focus': {\n color: color.text(),\n backgroundColor: color.background(),\n },\n '&:hover': {\n color: color.text(),\n backgroundColor: color.secondaryLight(),\n },\n boxSizing: 'border-box',\n padding: '25px',\n '&:first-of-type': {\n borderRadius: '3px 3px 0 0',\n },\n '&:last-of-type': {\n borderRadius: '0 0 3px 3px',\n },\n },\n label: {\n fontSize: 'max(1rem, 14px)',\n },\n});\n\nexport default withStyles(styles)(Dropdown);\n"],"file":"dropdown.js"}
1
+ {"version":3,"sources":["../../src/components/dropdown.jsx"],"names":["Dropdown","props","event","setState","anchorEl","currentTarget","value","previewValue","highlightedOptionId","previewRef","current","innerHTML","index","id","stateUpdate","choices","onChange","handleHighlight","handleClose","selectedValue","state","ref","elementRefs","preview","menuWidth","hiddenRef","React","createRef","buttonRef","clientWidth","prevProps","prevState","hiddenEl","dropdownJustOpened","forEach","containsLatex","querySelector","hasMathJax","mathHandled","newWidth","found","find","choice","label","trim","undefined","classes","correct","disabled","showCorrectAnswer","singleQuery","correctValue","open","Boolean","buttonId","menuId","valueDisplayId","disabledClass","disabledCorrect","disabledIncorrect","incrementedId","parseInt","labelId","labelText","correctnessIcon","correctnessIndicatorIcon","correctIcon","incorrectIcon","position","visibility","top","left","map","c","root","menuRoot","selected","__html","srOnly","minWidth","borderWidth","transition","handleClick","getLabel","selectMenu","vertical","horizontal","style","padding","role","disablePadding","optionId","handleSelect","handleHover","selectedIndicator","Component","PropTypes","string","bool","func","object","arrayOf","shape","styles","color","text","border","borderGray","borderRadius","justifyContent","backgroundColor","background","height","width","margin","textTransform","paddingRight","right","pointerEvents","marginLeft","outline","tertiary","outlineOffset","borderColor","incorrectWithIcon","dropdownBackground","boxSizing","fontSize","overflow","white"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;;;IAEMA,Q;;;;;AAcJ,oBAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,oGAqDL,UAACC,KAAD;AAAA,aAAW,MAAKC,QAAL,CAAc;AAAEC,QAAAA,QAAQ,EAAEF,KAAK,CAACG;AAAlB,OAAd,CAAX;AAAA,KArDK;AAAA,oGAuDL,YAAM;AAClB,UAAQC,KAAR,GAAkB,MAAKL,KAAvB,CAAQK,KAAR;;AACA,YAAKH,QAAL,CAAc;AAAEC,QAAAA,QAAQ,EAAE,IAAZ;AAAkBG,QAAAA,YAAY,EAAE,IAAhC;AAAsCC,QAAAA,mBAAmB,EAAE;AAA3D,OAAd,EAFkB,CAGlB;;;AACA,UAAI,CAACF,KAAD,IAAU,MAAKG,UAAL,CAAgBC,OAA9B,EAAuC;AACrC,cAAKD,UAAL,CAAgBC,OAAhB,CAAwBC,SAAxB,GAAoC,EAApC;AACD;AACF,KA9DkB;AAAA,wGAgED,UAACC,KAAD,EAAW;AAC3B,UAAMJ,mBAAmB,6BAAsB,MAAKP,KAAL,CAAWY,EAAjC,cAAuCD,KAAvC,CAAzB,CAD2B,CAG3B;;AACA,UAAME,WAAW,GAAG;AAAEN,QAAAA,mBAAmB,EAAnBA;AAAF,OAApB;;AACA,UAAI,CAAC,MAAKP,KAAL,CAAWK,KAAhB,EAAuB;AACrBQ,QAAAA,WAAW,CAACP,YAAZ,GAA2B,MAAKN,KAAL,C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BC,MAAAA,IAAI,EAAE,MAJkB;AAKxBgD,MAAAA,UAAU,EAAE,cALY;AAMxBX,MAAAA,YAAY,EAAE,KANU;AAOxBmB,MAAAA,QAAQ,EAAE,MAPc;AAQxBvC,MAAAA,OAAO,EAAE;AARe,KAlGN;AA4GpBtB,IAAAA,WAAW,EAAE;AACX4C,MAAAA,eAAe,EAAEN,gBAAMzD,OAAN;AADN,KA5GO;AA+GpBoB,IAAAA,aAAa,EAAE;AACb2C,MAAAA,eAAe,EAAEN,gBAAMoB,iBAAN;AADJ;AA/GK,GAAP;AAAA,CAAf;;eAoHe,wBAAWrB,MAAX,EAAmBvG,QAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Button from '@material-ui/core/Button';\nimport InputLabel from '@material-ui/core/InputLabel';\nimport Menu from '@material-ui/core/Menu';\nimport MenuItem from '@material-ui/core/MenuItem';\nimport ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';\nimport ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';\nimport Close from '@material-ui/icons/Close';\nimport Check from '@material-ui/icons/Check';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\n\nimport { color } from '@pie-lib/render-ui';\nimport { renderMath } from '@pie-lib/math-rendering';\n\nclass Dropdown extends React.Component {\n static propTypes = {\n id: PropTypes.string,\n value: PropTypes.string,\n disabled: PropTypes.bool,\n onChange: PropTypes.func,\n classes: PropTypes.object,\n correct: PropTypes.bool,\n choices: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string, label: PropTypes.string })),\n showCorrectAnswer: PropTypes.bool,\n singleQuery: PropTypes.bool,\n correctValue: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n\n this.state = {\n anchorEl: null,\n highlightedOptionId: null,\n menuWidth: null,\n previewValue: null,\n };\n this.hiddenRef = React.createRef();\n this.buttonRef = React.createRef();\n this.previewRef = React.createRef();\n this.elementRefs = [];\n }\n\n componentDidMount() {\n // measure hidden menu width once\n if (this.hiddenRef.current && this.state.menuWidth === null) {\n this.setState({ menuWidth: this.hiddenRef.current.clientWidth });\n }\n }\n\n componentDidUpdate(prevProps, prevState) {\n const hiddenEl = this.hiddenRef.current;\n\n const dropdownJustOpened = !prevState.anchorEl && this.state.anchorEl;\n if (dropdownJustOpened) {\n this.elementRefs.forEach((ref) => {\n if (!ref) return;\n\n const containsLatex = ref.querySelector('[data-latex], [data-raw]');\n const hasMathJax = ref.querySelector('mjx-container');\n const mathHandled = ref.querySelector('[data-math-handled=\"true\"]');\n\n if (containsLatex && (!mathHandled || !hasMathJax)) {\n renderMath(ref);\n }\n });\n }\n\n if (hiddenEl) {\n const newWidth = hiddenEl.clientWidth;\n if (newWidth !== this.state.menuWidth) {\n this.elementRefs.forEach((ref) => {\n if (ref) renderMath(ref);\n });\n\n renderMath(hiddenEl);\n this.setState({ menuWidth: newWidth });\n }\n }\n }\n\n handleClick = (event) => this.setState({ anchorEl: event.currentTarget });\n\n handleClose = () => {\n const { value } = this.props;\n this.setState({ anchorEl: null, previewValue: null, highlightedOptionId: null });\n // clear displayed preview if no selection\n if (!value && this.previewRef.current) {\n this.previewRef.current.innerHTML = '';\n }\n };\n\n handleHighlight = (index) => {\n const highlightedOptionId = `dropdown-option-${this.props.id}-${index}`;\n\n // preview on hover if nothing selected\n const stateUpdate = { highlightedOptionId };\n if (!this.props.value) {\n stateUpdate.previewValue = this.props.choices[index].value;\n }\n this.setState(stateUpdate);\n };\n\n handleSelect = (value, index) => {\n this.props.onChange(this.props.id, value);\n this.handleHighlight(index);\n this.handleClose();\n };\n\n handleHover = (index) => {\n const selectedValue = this.props.value;\n\n if (selectedValue) return;\n\n const highlightedOptionId = `dropdown-option-${this.props.id}-${index}`;\n const previewValue = this.state.previewValue;\n\n this.setState({ highlightedOptionId, previewValue }, () => {\n // On hover, preview the math-rendered content inside the button if no value is selected.\n const ref = this.elementRefs[index];\n const preview = this.previewRef.current;\n\n if (ref && preview) {\n preview.innerHTML = ref.innerHTML;\n }\n });\n };\n\n getLabel(choices, value) {\n const found = (choices || []).find((choice) => choice.value === value);\n\n return found ? found.label.trim() : undefined;\n }\n\n render() {\n const { classes, id, correct, disabled, value, choices, showCorrectAnswer, singleQuery, correctValue } = this.props;\n const { anchorEl } = this.state;\n const open = Boolean(anchorEl);\n const buttonId = `dropdown-button-${id}`;\n const menuId = `dropdown-menu-${id}`;\n const valueDisplayId = `dropdown-value-${id}`;\n\n // Determine the class for disabled state, view mode and evaluate mode\n let disabledClass;\n // Reset elementRefs before each render to avoid stale references\n this.elementRefs = [];\n\n if (disabled && correct !== undefined) {\n disabledClass = correct || showCorrectAnswer ? classes.disabledCorrect : classes.disabledIncorrect;\n }\n\n // Create distinct, visually hidden labels for each dropdown\n const incrementedId = parseInt(id, 10) + 1;\n const labelId = singleQuery ? 'Query-label' : `Query-label-${incrementedId}`;\n const labelText = singleQuery ? 'Query' : `Query ${incrementedId}`;\n\n // 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.\n let correctnessIcon = null;\n if (disabled && correct !== undefined) {\n correctnessIcon =\n correct || showCorrectAnswer ? (\n <Check className={classNames(classes.correctnessIndicatorIcon, classes.correctIcon)} />\n ) : (\n <Close className={classNames(classes.correctnessIndicatorIcon, classes.incorrectIcon)} />\n );\n }\n\n return (\n <>\n <div\n ref={this.hiddenRef}\n style={{ position: 'absolute', visibility: 'hidden', top: 0, left: 0 }}\n tabIndex={-1}\n aria-hidden=\"true\"\n >\n {(choices || []).map((c, index) => (\n <MenuItem\n key={index}\n classes={{ root: classes.menuRoot, selected: classes.selected }}\n tabIndex={-1}\n aria-hidden=\"true\"\n >\n <span className={classes.label} dangerouslySetInnerHTML={{ __html: c.label }} />\n </MenuItem>\n ))}\n </div>\n <InputLabel className={classes.srOnly} id={labelId} tabIndex={-1} aria-hidden=\"true\">\n {labelText}\n </InputLabel>\n <Button\n ref={this.buttonRef}\n style={{\n ...(this.state.menuWidth && { minWidth: `calc(${this.state.menuWidth}px + 8px)` }),\n borderWidth: open ? '2px' : '1px',\n transition: 'border-width 0.2s ease-in-out',\n }}\n aria-controls={open ? menuId : undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={open ? 'true' : undefined}\n aria-activedescendant={this.state.highlightedOptionId}\n onClick={this.handleClick}\n classes={{\n root: classes.root,\n disabled: disabledClass,\n }}\n disabled={disabled}\n id={buttonId}\n role=\"combobox\"\n aria-label={`Select an option for ${labelText}`}\n aria-labelledby={valueDisplayId}\n >\n {correctnessIcon}\n <span\n id={valueDisplayId}\n ref={this.previewRef}\n className={classes.label}\n dangerouslySetInnerHTML={{\n __html: correctValue\n ? correctValue\n : open && this.state.previewValue\n ? this.getLabel(choices, this.state.previewValue)\n : this.getLabel(choices, value) || '',\n }}\n />\n {open ? <ArrowDropUpIcon /> : <ArrowDropDownIcon />}\n </Button>\n <Menu\n id={menuId}\n anchorEl={anchorEl}\n className={classes.selectMenu}\n keepMounted\n open={open}\n onClose={this.handleClose}\n getContentAnchorEl={null}\n anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}\n transformOrigin={{ vertical: 'top', horizontal: 'left' }}\n PaperProps={this.state.menuWidth ? { style: { minWidth: this.state.menuWidth, padding: '4px' } } : undefined}\n MenuListProps={{\n 'aria-labelledby': buttonId,\n role: 'listbox',\n disablePadding: true,\n }}\n >\n {(choices || []).map((c, index) => {\n const optionId = `dropdown-option-${id}-${index}`;\n\n return (\n <MenuItem\n id={optionId}\n classes={{ root: classes.menuRoot, selected: classes.selected }}\n key={`${c.label}-${index}`}\n value={c.value}\n onClick={() => this.handleSelect(c.value, index)}\n role=\"option\"\n aria-selected={this.state.highlightedOptionId === optionId ? 'true' : undefined}\n onMouseOver={() => this.handleHover(index)}\n >\n <span\n ref={(ref) => (this.elementRefs[index] = ref)}\n className={classes.label}\n dangerouslySetInnerHTML={{ __html: c.label }}\n />\n <span\n className={classes.selectedIndicator}\n dangerouslySetInnerHTML={{ __html: c.value === value ? ' &check;' : '' }}\n />\n </MenuItem>\n );\n })}\n </Menu>\n </>\n );\n }\n}\n\nconst styles = () => ({\n root: {\n color: color.text(),\n border: `1px solid ${color.borderGray()}`,\n borderRadius: '4px',\n justifyContent: 'space-between',\n backgroundColor: color.background(),\n position: 'relative',\n height: '45px',\n width: 'fit-content',\n margin: '2px',\n textTransform: 'none',\n '& span': {\n paddingRight: '5px',\n },\n '& svg': {\n position: 'absolute',\n right: 0,\n top: 'calc(50% - 12px)',\n pointerEvents: 'none',\n color: color.text(),\n marginLeft: '5px',\n },\n '&:focus, &:focus-visible': {\n outline: `3px solid ${color.tertiary()}`,\n outlineOffset: '2px',\n borderWidth: '3px',\n },\n },\n disabledCorrect: {\n borderWidth: '2px',\n borderColor: color.correct(),\n color: `${color.text()} !important`,\n },\n disabledIncorrect: {\n borderWidth: '2px',\n borderColor: color.incorrectWithIcon(),\n color: `${color.text()} !important`,\n },\n selectMenu: {\n backgroundColor: color.background(),\n border: `1px solid ${color.correct()} !important`,\n '&:hover': {\n border: `1px solid ${color.text()} `,\n borderColor: 'initial',\n },\n '&:focus': {\n border: `1px solid ${color.text()}`,\n borderColor: 'initial',\n },\n // remove default padding on the inner list\n '& .MuiList-root': {\n padding: 0,\n },\n },\n selected: {\n color: `${color.text()} !important`,\n backgroundColor: `${color.background()} !important`,\n '&:hover': {\n color: color.text(),\n backgroundColor: `${color.dropdownBackground()} !important`,\n },\n },\n menuRoot: {\n color: color.text(),\n backgroundColor: color.background(),\n '&:focus, &:focus-visible': {\n outline: `3px solid ${color.tertiary()}`,\n outlineOffset: '-1px', // keeps it inside the item\n },\n '&:focus': {\n color: color.text(),\n backgroundColor: color.background(),\n },\n '&:hover': {\n color: color.text(),\n backgroundColor: color.dropdownBackground(),\n },\n boxSizing: 'border-box',\n padding: '25px',\n borderRadius: '4px',\n },\n label: {\n fontSize: 'max(1rem, 14px)',\n },\n selectedIndicator: {\n fontSize: 'max(1rem, 14px)',\n position: 'absolute',\n right: '10px',\n },\n srOnly: {\n position: 'absolute',\n left: '-10000px',\n top: 'auto',\n width: '1px',\n height: '1px',\n overflow: 'hidden',\n },\n correctnessIndicatorIcon: {\n color: `${color.white()} !important`,\n position: 'absolute',\n top: '-8px !important',\n left: '-8px',\n marginLeft: '0 !important',\n borderRadius: '50%',\n fontSize: '16px',\n padding: '2px',\n },\n correctIcon: {\n backgroundColor: color.correct(),\n },\n incorrectIcon: {\n backgroundColor: color.incorrectWithIcon(),\n },\n});\n\nexport default withStyles(styles)(Dropdown);\n"],"file":"dropdown.js"}