@khanacademy/wonder-blocks-form 3.1.5 → 3.1.7

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/dist/index.js DELETED
@@ -1,1737 +0,0 @@
1
- module.exports =
2
- /******/ (function(modules) { // webpackBootstrap
3
- /******/ // The module cache
4
- /******/ var installedModules = {};
5
- /******/
6
- /******/ // The require function
7
- /******/ function __webpack_require__(moduleId) {
8
- /******/
9
- /******/ // Check if module is in cache
10
- /******/ if(installedModules[moduleId]) {
11
- /******/ return installedModules[moduleId].exports;
12
- /******/ }
13
- /******/ // Create a new module (and put it into the cache)
14
- /******/ var module = installedModules[moduleId] = {
15
- /******/ i: moduleId,
16
- /******/ l: false,
17
- /******/ exports: {}
18
- /******/ };
19
- /******/
20
- /******/ // Execute the module function
21
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
- /******/
23
- /******/ // Flag the module as loaded
24
- /******/ module.l = true;
25
- /******/
26
- /******/ // Return the exports of the module
27
- /******/ return module.exports;
28
- /******/ }
29
- /******/
30
- /******/
31
- /******/ // expose the modules object (__webpack_modules__)
32
- /******/ __webpack_require__.m = modules;
33
- /******/
34
- /******/ // expose the module cache
35
- /******/ __webpack_require__.c = installedModules;
36
- /******/
37
- /******/ // define getter function for harmony exports
38
- /******/ __webpack_require__.d = function(exports, name, getter) {
39
- /******/ if(!__webpack_require__.o(exports, name)) {
40
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41
- /******/ }
42
- /******/ };
43
- /******/
44
- /******/ // define __esModule on exports
45
- /******/ __webpack_require__.r = function(exports) {
46
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
- /******/ }
49
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
- /******/ };
51
- /******/
52
- /******/ // create a fake namespace object
53
- /******/ // mode & 1: value is a module id, require it
54
- /******/ // mode & 2: merge all properties of value into the ns
55
- /******/ // mode & 4: return value when already ns object
56
- /******/ // mode & 8|1: behave like require
57
- /******/ __webpack_require__.t = function(value, mode) {
58
- /******/ if(mode & 1) value = __webpack_require__(value);
59
- /******/ if(mode & 8) return value;
60
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61
- /******/ var ns = Object.create(null);
62
- /******/ __webpack_require__.r(ns);
63
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65
- /******/ return ns;
66
- /******/ };
67
- /******/
68
- /******/ // getDefaultExport function for compatibility with non-harmony modules
69
- /******/ __webpack_require__.n = function(module) {
70
- /******/ var getter = module && module.__esModule ?
71
- /******/ function getDefault() { return module['default']; } :
72
- /******/ function getModuleExports() { return module; };
73
- /******/ __webpack_require__.d(getter, 'a', getter);
74
- /******/ return getter;
75
- /******/ };
76
- /******/
77
- /******/ // Object.prototype.hasOwnProperty.call
78
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79
- /******/
80
- /******/ // __webpack_public_path__
81
- /******/ __webpack_require__.p = "";
82
- /******/
83
- /******/
84
- /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 22);
86
- /******/ })
87
- /************************************************************************/
88
- /******/ ([
89
- /* 0 */
90
- /***/ (function(module, exports) {
91
-
92
- module.exports = require("react");
93
-
94
- /***/ }),
95
- /* 1 */
96
- /***/ (function(module, exports) {
97
-
98
- module.exports = require("@khanacademy/wonder-blocks-color");
99
-
100
- /***/ }),
101
- /* 2 */
102
- /***/ (function(module, exports) {
103
-
104
- module.exports = require("@khanacademy/wonder-blocks-core");
105
-
106
- /***/ }),
107
- /* 3 */
108
- /***/ (function(module, exports) {
109
-
110
- module.exports = require("@khanacademy/wonder-blocks-spacing");
111
-
112
- /***/ }),
113
- /* 4 */
114
- /***/ (function(module, exports) {
115
-
116
- module.exports = require("@khanacademy/wonder-blocks-typography");
117
-
118
- /***/ }),
119
- /* 5 */
120
- /***/ (function(module, exports) {
121
-
122
- function _extends() {
123
- module.exports = _extends = Object.assign ? Object.assign.bind() : function (target) {
124
- for (var i = 1; i < arguments.length; i++) {
125
- var source = arguments[i];
126
- for (var key in source) {
127
- if (Object.prototype.hasOwnProperty.call(source, key)) {
128
- target[key] = source[key];
129
- }
130
- }
131
- }
132
- return target;
133
- }, module.exports.__esModule = true, module.exports["default"] = module.exports;
134
- return _extends.apply(this, arguments);
135
- }
136
- module.exports = _extends, module.exports.__esModule = true, module.exports["default"] = module.exports;
137
-
138
- /***/ }),
139
- /* 6 */
140
- /***/ (function(module, exports) {
141
-
142
- module.exports = require("aphrodite");
143
-
144
- /***/ }),
145
- /* 7 */
146
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
147
-
148
- "use strict";
149
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
150
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_0__);
151
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
152
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_1__);
153
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
154
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2__);
155
-
156
-
157
-
158
- const styles = aphrodite__WEBPACK_IMPORTED_MODULE_0__["StyleSheet"].create({
159
- fieldset: {
160
- border: "none",
161
- padding: 0,
162
- margin: 0
163
- },
164
- legend: {
165
- padding: 0
166
- },
167
- description: {
168
- marginTop: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.xxxSmall_4,
169
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_1___default.a.offBlack64
170
- },
171
- error: {
172
- marginTop: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.xxxSmall_4,
173
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_1___default.a.red
174
- },
175
- defaultLineGap: {
176
- marginTop: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.xSmall_8
177
- }
178
- });
179
- /* harmony default export */ __webpack_exports__["a"] = (styles);
180
-
181
- /***/ }),
182
- /* 8 */
183
- /***/ (function(module, exports) {
184
-
185
- module.exports = require("@khanacademy/wonder-blocks-layout");
186
-
187
- /***/ }),
188
- /* 9 */
189
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
190
-
191
- "use strict";
192
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Checkbox; });
193
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
194
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
195
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
196
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
197
- /* harmony import */ var _choice_internal_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
198
-
199
-
200
- // Keep synced with ChoiceComponentProps in ../util/types.js
201
-
202
- /**
203
- * ☑️ A nicely styled checkbox for all your checking needs. Can optionally take
204
- * label and description props.
205
- *
206
- * If used by itself, a checkbox provides two options - checked and unchecked.
207
- * A group of checkboxes can be used to allow a user to select multiple values
208
- * from a list of options.
209
- *
210
- * If you want a whole group of Checkbox[es] that are related, see the Choice
211
- * and CheckboxGroup components.
212
- *
213
- * ### Usage
214
- *
215
- * ```jsx
216
- * import {Checkbox} from "@khanacademy/wonder-blocks-form";
217
- *
218
- * const [checked, setChecked] = React.useState(false);
219
- *
220
- * <Checkbox checked={checked} onChange={setChecked} />
221
- * ```
222
- */
223
- class Checkbox extends react__WEBPACK_IMPORTED_MODULE_1__["Component"] {
224
- render() {
225
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_choice_internal_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"], _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({
226
- variant: "checkbox"
227
- }, this.props));
228
- }
229
-
230
- }
231
- Checkbox.defaultProps = {
232
- disabled: false,
233
- error: false
234
- };
235
-
236
- /***/ }),
237
- /* 10 */
238
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
239
-
240
- "use strict";
241
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
242
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
243
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
244
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
245
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
246
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_2__);
247
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1);
248
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__);
249
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(3);
250
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_4__);
251
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4);
252
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5__);
253
-
254
-
255
-
256
-
257
-
258
-
259
- const defaultErrorMessage = "This field is required.";
260
-
261
- // TODO(WB-1081): Change class name back to TextField after Styleguidist is gone.
262
-
263
- /**
264
- * A TextField is an element used to accept a single line of text from the user.
265
- */
266
- class TextFieldInternal extends react__WEBPACK_IMPORTED_MODULE_1__["Component"] {
267
- constructor(props) {
268
- super(props);
269
- this.state = {
270
- error: null,
271
- focused: false
272
- };
273
-
274
- this.maybeValidate = newValue => {
275
- const {
276
- validate,
277
- onValidate,
278
- required
279
- } = this.props;
280
-
281
- if (validate) {
282
- const maybeError = validate(newValue) || null;
283
- this.setState({
284
- error: maybeError
285
- }, () => {
286
- if (onValidate) {
287
- onValidate(maybeError);
288
- }
289
- });
290
- } else if (required) {
291
- const requiredString = typeof required === "string" ? required : defaultErrorMessage;
292
- const maybeError = newValue ? null : requiredString;
293
- this.setState({
294
- error: maybeError
295
- }, () => {
296
- if (onValidate) {
297
- onValidate(maybeError);
298
- }
299
- });
300
- }
301
- };
302
-
303
- this.handleChange = event => {
304
- const {
305
- onChange
306
- } = this.props;
307
- const newValue = event.target.value;
308
- this.maybeValidate(newValue);
309
- onChange(newValue);
310
- };
311
-
312
- this.handleFocus = event => {
313
- const {
314
- onFocus
315
- } = this.props;
316
- this.setState({
317
- focused: true
318
- }, () => {
319
- if (onFocus) {
320
- onFocus(event);
321
- }
322
- });
323
- };
324
-
325
- this.handleBlur = event => {
326
- const {
327
- onBlur
328
- } = this.props;
329
- this.setState({
330
- focused: false
331
- }, () => {
332
- if (onBlur) {
333
- onBlur(event);
334
- }
335
- });
336
- };
337
-
338
- if (props.validate && props.value !== "") {
339
- // Ensures error is updated on unmounted server-side renders
340
- this.state.error = props.validate(props.value) || null;
341
- }
342
- }
343
-
344
- componentDidMount() {
345
- if (this.props.value !== "") {
346
- this.maybeValidate(this.props.value);
347
- }
348
- }
349
-
350
- render() {
351
- const {
352
- id,
353
- type,
354
- value,
355
- disabled,
356
- onKeyDown,
357
- placeholder,
358
- light,
359
- style,
360
- testId,
361
- readOnly,
362
- autoComplete,
363
- forwardedRef,
364
- // The following props are being included here to avoid
365
- // passing them down to the otherProps spread
366
-
367
- /* eslint-disable no-unused-vars */
368
- onFocus,
369
- onBlur,
370
- onValidate,
371
- validate,
372
- onChange,
373
- required,
374
-
375
- /* eslint-enable no-unused-vars */
376
- // Should only include Aria related props
377
- ...otherProps
378
- } = this.props;
379
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"]("input", _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({
380
- className: Object(aphrodite__WEBPACK_IMPORTED_MODULE_2__["css"])([styles.input, _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5__["styles"].LabelMedium, styles.default, // Prioritizes disabled, then focused, then error (if any)
381
- disabled ? styles.disabled : this.state.focused ? [styles.focused, light && styles.defaultLight] : this.state.error && [styles.error, light && styles.errorLight], style && style]),
382
- id: id,
383
- type: type,
384
- placeholder: placeholder,
385
- value: value,
386
- disabled: disabled,
387
- onChange: this.handleChange,
388
- onKeyDown: onKeyDown,
389
- onFocus: this.handleFocus,
390
- onBlur: this.handleBlur,
391
- "data-test-id": testId,
392
- readOnly: readOnly,
393
- autoComplete: autoComplete,
394
- ref: forwardedRef
395
- }, otherProps));
396
- }
397
-
398
- }
399
-
400
- TextFieldInternal.defaultProps = {
401
- type: "text",
402
- disabled: false,
403
- light: false
404
- };
405
- const styles = aphrodite__WEBPACK_IMPORTED_MODULE_2__["StyleSheet"].create({
406
- input: {
407
- width: "100%",
408
- height: 40,
409
- borderRadius: 4,
410
- boxSizing: "border-box",
411
- paddingLeft: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_4___default.a.medium_16,
412
- margin: 0,
413
- outline: "none",
414
- boxShadow: "none"
415
- },
416
- default: {
417
- background: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.white,
418
- border: `1px solid ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack16}`,
419
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack,
420
- "::placeholder": {
421
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack64
422
- }
423
- },
424
- error: {
425
- background: `${Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["fade"])(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.red, 0.06), _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.white)}`,
426
- border: `1px solid ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.red}`,
427
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack,
428
- "::placeholder": {
429
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack64
430
- }
431
- },
432
- disabled: {
433
- background: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offWhite,
434
- border: `1px solid ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack16}`,
435
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack64,
436
- "::placeholder": {
437
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack32
438
- }
439
- },
440
- focused: {
441
- background: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.white,
442
- border: `1px solid ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.blue}`,
443
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack,
444
- "::placeholder": {
445
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack64
446
- }
447
- },
448
- defaultLight: {
449
- boxShadow: `0px 0px 0px 1px ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.blue}, 0px 0px 0px 2px ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.white}`
450
- },
451
- errorLight: {
452
- boxShadow: `0px 0px 0px 1px ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.red}, 0px 0px 0px 2px ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.white}`
453
- }
454
- });
455
-
456
- /**
457
- * A TextField is an element used to accept a single line of text from the user.
458
- *
459
- * ### Usage
460
- *
461
- * ```jsx
462
- * import {TextField} from "@khanacademy/wonder-blocks-form";
463
- *
464
- * const [value, setValue] = React.useState("");
465
- *
466
- * <TextField
467
- * id="some-unique-text-field-id"
468
- * value={value}
469
- * onChange={setValue}
470
- * />
471
- * ```
472
- */
473
- const TextField = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["forwardRef"]((props, ref) => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](TextFieldInternal, _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({}, props, {
474
- forwardedRef: ref
475
- })));
476
- /* harmony default export */ __webpack_exports__["a"] = (TextField);
477
-
478
- /***/ }),
479
- /* 11 */
480
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
481
-
482
- "use strict";
483
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ChoiceInternal; });
484
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
485
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
486
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
487
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
488
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
489
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_2__);
490
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1);
491
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__);
492
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2);
493
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__);
494
- /* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(16);
495
- /* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_5__);
496
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(8);
497
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_6__);
498
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(3);
499
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_7__);
500
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(4);
501
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_8__);
502
- /* harmony import */ var _checkbox_core_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(17);
503
- /* harmony import */ var _radio_core_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(19);
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
-
512
-
513
-
514
-
515
-
516
- /**
517
- * This is a potentially labeled 🔘 or ☑️ item. This is an internal component
518
- * that's wrapped by Checkbox and Radio. Choice is a wrapper for Checkbox and
519
- * Radio with many of its props auto-populated, to be used with CheckboxGroup
520
- * and RadioGroup. This design allows for more explicit prop typing. For
521
- * example, we can make onChange a required prop on Checkbox but not on Choice
522
- * (because for Choice, that prop would be auto-populated by CheckboxGroup).
523
- */
524
- class ChoiceInternal extends react__WEBPACK_IMPORTED_MODULE_1__["Component"] {
525
- constructor(...args) {
526
- super(...args);
527
-
528
- this.handleLabelClick = event => {
529
- // Browsers automatically use the for attribute to select the input,
530
- // but we use ClickableBehavior to handle this.
531
- event.preventDefault();
532
- };
533
-
534
- this.handleClick = () => {
535
- const {
536
- checked,
537
- onChange,
538
- variant
539
- } = this.props; // Radio buttons cannot be unchecked
540
-
541
- if (variant === "radio" && checked) {
542
- return;
543
- }
544
-
545
- onChange(!checked);
546
- };
547
- }
548
-
549
- getChoiceCoreComponent() {
550
- if (this.props.variant === "radio") {
551
- return _radio_core_js__WEBPACK_IMPORTED_MODULE_10__[/* default */ "a"];
552
- } else {
553
- return _checkbox_core_js__WEBPACK_IMPORTED_MODULE_9__[/* default */ "a"];
554
- }
555
- }
556
-
557
- getLabel() {
558
- const {
559
- disabled,
560
- id,
561
- label
562
- } = this.props;
563
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_8__["LabelMedium"], {
564
- style: [styles.label, disabled && styles.disabledLabel]
565
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"]("label", {
566
- htmlFor: id,
567
- onClick: this.handleLabelClick
568
- }, label));
569
- }
570
-
571
- getDescription(id) {
572
- const {
573
- description
574
- } = this.props;
575
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_8__["LabelSmall"], {
576
- style: styles.description,
577
- id: id
578
- }, description);
579
- }
580
-
581
- render() {
582
- const {
583
- label,
584
- description,
585
- // eslint-disable-next-line no-unused-vars
586
- onChange,
587
- style,
588
- className,
589
- variant,
590
- ...coreProps
591
- } = this.props;
592
- const ChoiceCore = this.getChoiceCoreComponent();
593
- const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_5__["getClickableBehavior"])();
594
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["UniqueIDProvider"], {
595
- mockOnFirstRender: true,
596
- scope: "choice"
597
- }, ids => {
598
- const descriptionId = description ? ids.get("description") : undefined;
599
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["View"], {
600
- style: style,
601
- className: className
602
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](ClickableBehavior, {
603
- disabled: coreProps.disabled,
604
- onClick: this.handleClick,
605
- role: variant
606
- }, (state, childrenProps) => {
607
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["View"], _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({
608
- style: styles.wrapper
609
- }, childrenProps, {
610
- // We are resetting the tabIndex=0 from handlers
611
- // because the ChoiceCore component will receive
612
- // focus on basis of it being an input element.
613
- tabIndex: -1
614
- }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](ChoiceCore, _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({}, coreProps, state, {
615
- "aria-describedby": descriptionId
616
- })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_6__["Strut"], {
617
- size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_7___default.a.xSmall_8
618
- }), label && this.getLabel());
619
- }), description && this.getDescription(descriptionId));
620
- });
621
- }
622
-
623
- }
624
- ChoiceInternal.defaultProps = {
625
- checked: false,
626
- disabled: false,
627
- error: false
628
- };
629
- const styles = aphrodite__WEBPACK_IMPORTED_MODULE_2__["StyleSheet"].create({
630
- wrapper: {
631
- flexDirection: "row",
632
- alignItems: "flex-start",
633
- outline: "none"
634
- },
635
- label: {
636
- userSelect: "none",
637
- // NOTE: The checkbox/radio button (height 16px) should be center
638
- // aligned with the first line of the label. However, LabelMedium has a
639
- // declared line height of 20px, so we need to adjust the top to get the
640
- // desired alignment.
641
- marginTop: -2
642
- },
643
- disabledLabel: {
644
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack32
645
- },
646
- description: {
647
- // 16 for icon + 8 for spacing strut
648
- marginLeft: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_7___default.a.medium_16 + _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_7___default.a.xSmall_8,
649
- marginTop: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_7___default.a.xxxSmall_4,
650
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack64
651
- }
652
- });
653
-
654
- /***/ }),
655
- /* 12 */
656
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
657
-
658
- "use strict";
659
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Choice; });
660
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
661
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
662
- /* harmony import */ var _checkbox_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
663
- /* harmony import */ var _radio_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20);
664
-
665
-
666
-
667
-
668
- /**
669
- * This is a labeled 🔘 or ☑️ item. Choice is meant to be used as children of
670
- * CheckboxGroup and RadioGroup because many of its props are auto-populated
671
- * and not shown in the documentation here. See those components for usage
672
- * examples.
673
- *
674
- * If you wish to use just a single field, use Checkbox or Radio with the
675
- * optional label and description props.
676
- *
677
- * ### Checkbox Usage
678
- *
679
- * ```jsx
680
- * import {Choice, CheckboxGroup} from "@khanacademy/wonder-blocks-form";
681
- *
682
- * const [selectedValues, setSelectedValues] = React.useState([]);
683
- *
684
- * // Checkbox usage
685
- * <CheckboxGroup
686
- * label="some-label"
687
- * description="some-description"
688
- * groupName="some-group-name"
689
- * onChange={setSelectedValues}
690
- * selectedValues={selectedValues}
691
- * />
692
- * // Add as many choices as necessary
693
- * <Choice
694
- * label="Choice 1"
695
- * value="some-choice-value"
696
- * description="Some choice description."
697
- * />
698
- * <Choice
699
- * label="Choice 2"
700
- * value="some-choice-value-2"
701
- * description="Some choice description."
702
- * />
703
- * </CheckboxGroup>
704
- * ```
705
- *
706
- * ### Radio Usage
707
- *
708
- * ```jsx
709
- * import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form";
710
- *
711
- * const [selectedValue, setSelectedValue] = React.useState("");
712
- *
713
- * <RadioGroup
714
- * label="some-label"
715
- * description="some-description"
716
- * groupName="some-group-name"
717
- * onChange={setSelectedValue}>
718
- * selectedValues={selectedValue}
719
- * />
720
- * // Add as many choices as necessary
721
- * <Choice
722
- * label="Choice 1"
723
- * value="some-choice-value"
724
- * description="Some choice description."
725
- * />
726
- * <Choice
727
- * label="Choice 2"
728
- * value="some-choice-value-2"
729
- * description="Some choice description."
730
- * />
731
- * </RadioGroup>
732
- * ```
733
- */
734
- class Choice extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
735
- getChoiceComponent(variant) {
736
- if (variant === "checkbox") {
737
- return _checkbox_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"];
738
- } else {
739
- return _radio_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"];
740
- }
741
- }
742
-
743
- render() {
744
- // we don't need this going into the ChoiceComponent
745
- // eslint-disable-next-line no-unused-vars
746
- const {
747
- value,
748
- variant,
749
- ...remainingProps
750
- } = this.props;
751
- const ChoiceComponent = this.getChoiceComponent(variant);
752
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ChoiceComponent, remainingProps);
753
- }
754
-
755
- }
756
- Choice.defaultProps = {
757
- checked: false,
758
- disabled: false,
759
- onChange: () => {}
760
- };
761
-
762
- /***/ }),
763
- /* 13 */
764
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
765
-
766
- "use strict";
767
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return CheckboxGroup; });
768
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
769
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
770
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
771
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
772
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
773
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2__);
774
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3);
775
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3__);
776
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4);
777
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__);
778
- /* harmony import */ var _group_styles_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7);
779
-
780
-
781
-
782
-
783
-
784
-
785
- const StyledFieldset = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["addStyle"])("fieldset");
786
- const StyledLegend = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["addStyle"])("legend");
787
- /**
788
- * A checkbox group allows multiple selection. This component auto-populates
789
- * many props for its children Choice components. The Choice component is
790
- * exposed for the user to apply custom styles or to indicate which choices are
791
- * disabled.
792
- *
793
- * ### Usage
794
- *
795
- * ```jsx
796
- * import {Choice, CheckboxGroup} from "@khanacademy/wonder-blocks-form";
797
- *
798
- * const [selectedValues, setSelectedValues] = React.useState([]);
799
- *
800
- * <CheckboxGroup
801
- * label="some-label"
802
- * description="some-description"
803
- * groupName="some-group-name"
804
- * onChange={setSelectedValues}
805
- * selectedValues={selectedValues}
806
- * >
807
- * // Add as many choices as necessary
808
- * <Choice
809
- * label="Choice 1"
810
- * value="some-choice-value"
811
- * />
812
- * <Choice
813
- * label="Choice 2"
814
- * value="some-choice-value-2"
815
- * description="Some choice description."
816
- * />
817
- * </CheckboxGroup>
818
- * ```
819
- */
820
-
821
- class CheckboxGroup extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
822
- handleChange(changedValue, originalCheckedState) {
823
- const {
824
- onChange,
825
- selectedValues
826
- } = this.props;
827
-
828
- if (originalCheckedState) {
829
- const index = selectedValues.indexOf(changedValue);
830
- const updatedSelection = [].concat(selectedValues.slice(0, index), selectedValues.slice(index + 1));
831
- onChange(updatedSelection);
832
- } else {
833
- onChange([].concat(selectedValues, [changedValue]));
834
- }
835
- }
836
-
837
- render() {
838
- const {
839
- children,
840
- label,
841
- description,
842
- errorMessage,
843
- groupName,
844
- selectedValues,
845
- style,
846
- testId
847
- } = this.props;
848
- const allChildren = react__WEBPACK_IMPORTED_MODULE_0__["Children"].toArray(children).filter(Boolean);
849
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledFieldset, {
850
- "data-test-id": testId,
851
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].fieldset
852
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["View"], {
853
- style: style
854
- }, label && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledLegend, {
855
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].legend
856
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelMedium"], null, label)), description && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelSmall"], {
857
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].description
858
- }, description), errorMessage && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelSmall"], {
859
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].error
860
- }, errorMessage), (label || description || errorMessage) && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2__["Strut"], {
861
- size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3___default.a.small_12
862
- }), allChildren.map((child, index) => {
863
- const {
864
- style,
865
- value
866
- } = child.props;
867
- const checked = selectedValues.includes(value);
868
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["cloneElement"](child, {
869
- checked: checked,
870
- error: !!errorMessage,
871
- groupName: groupName,
872
- id: `${groupName}-${value}`,
873
- key: value,
874
- onChange: () => this.handleChange(value, checked),
875
- style: [index > 0 && _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].defaultLineGap, style],
876
- variant: "checkbox"
877
- });
878
- })));
879
- }
880
-
881
- }
882
-
883
- /***/ }),
884
- /* 14 */
885
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
886
-
887
- "use strict";
888
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RadioGroup; });
889
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
890
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
891
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
892
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
893
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
894
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2__);
895
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3);
896
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3__);
897
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4);
898
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__);
899
- /* harmony import */ var _group_styles_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7);
900
-
901
-
902
-
903
-
904
-
905
-
906
- const StyledFieldset = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["addStyle"])("fieldset");
907
- const StyledLegend = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["addStyle"])("legend");
908
- /**
909
- * A radio group allows only single selection. Like CheckboxGroup, this
910
- * component auto-populates many props for its children Choice components. The
911
- * Choice component is exposed for the user to apply custom styles or to
912
- * indicate which choices are disabled. The use of the groupName prop is
913
- * important to maintain expected keyboard navigation behavior for
914
- * accessibility.
915
- *
916
- * ### Usage
917
- *
918
- * ```jsx
919
- * import {Choice, RadioGroup} from "@khanacademy/wonder-blocks-form";
920
- *
921
- * const [selectedValue, setSelectedValue] = React.useState("");
922
- *
923
- * <RadioGroup
924
- * label="some-label"
925
- * description="some-description"
926
- * groupName="some-group-name"
927
- * onChange={setSelectedValue}
928
- * selectedValue={selectedValue}
929
- * >
930
- * // Add as many choices as necessary
931
- * <Choice
932
- * label="Choice 1"
933
- * value="some-choice-value"
934
- * />
935
- * <Choice
936
- * label="Choice 2"
937
- * value="some-choice-value-2"
938
- * description="Some choice description."
939
- * />
940
- * </RadioGroup>
941
- * ```
942
- */
943
-
944
- class RadioGroup extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
945
- handleChange(changedValue) {
946
- this.props.onChange(changedValue);
947
- }
948
-
949
- render() {
950
- const {
951
- children,
952
- label,
953
- description,
954
- errorMessage,
955
- groupName,
956
- selectedValue,
957
- style,
958
- testId
959
- } = this.props;
960
- const allChildren = react__WEBPACK_IMPORTED_MODULE_0__["Children"].toArray(children).filter(Boolean);
961
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledFieldset, {
962
- "data-test-id": testId,
963
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].fieldset
964
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["View"], {
965
- style: style
966
- }, label && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledLegend, {
967
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].legend
968
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelMedium"], null, label)), description && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelSmall"], {
969
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].description
970
- }, description), errorMessage && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_4__["LabelSmall"], {
971
- style: _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].error
972
- }, errorMessage), (label || description || errorMessage) && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_2__["Strut"], {
973
- size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_3___default.a.small_12
974
- }), allChildren.map((child, index) => {
975
- const {
976
- style,
977
- value
978
- } = child.props;
979
- const checked = selectedValue === value;
980
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["cloneElement"](child, {
981
- checked: checked,
982
- error: !!errorMessage,
983
- groupName: groupName,
984
- id: `${groupName}-${value}`,
985
- key: value,
986
- onChange: () => this.handleChange(value),
987
- style: [index > 0 && _group_styles_js__WEBPACK_IMPORTED_MODULE_5__[/* default */ "a"].defaultLineGap, style],
988
- variant: "radio"
989
- });
990
- })));
991
- }
992
-
993
- }
994
-
995
- /***/ }),
996
- /* 15 */
997
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
998
-
999
- "use strict";
1000
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
1001
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
1002
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1003
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1004
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2);
1005
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2__);
1006
- /* harmony import */ var _field_heading_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(21);
1007
- /* harmony import */ var _text_field_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(10);
1008
-
1009
-
1010
-
1011
-
1012
-
1013
-
1014
- // TODO(WB-1081): Change class name back to LabeledTextField after Styleguidist is gone.
1015
-
1016
- /**
1017
- * A LabeledTextField is an element used to accept a single line of text
1018
- * from the user paired with a label, description, and error field elements.
1019
- */
1020
- class LabeledTextFieldInternal extends react__WEBPACK_IMPORTED_MODULE_1__["Component"] {
1021
- constructor(props) {
1022
- super(props);
1023
-
1024
- this.handleValidate = errorMessage => {
1025
- const {
1026
- onValidate
1027
- } = this.props;
1028
- this.setState({
1029
- error: errorMessage
1030
- }, () => {
1031
- if (onValidate) {
1032
- onValidate(errorMessage);
1033
- }
1034
- });
1035
- };
1036
-
1037
- this.handleFocus = event => {
1038
- const {
1039
- onFocus
1040
- } = this.props;
1041
- this.setState({
1042
- focused: true
1043
- }, () => {
1044
- if (onFocus) {
1045
- onFocus(event);
1046
- }
1047
- });
1048
- };
1049
-
1050
- this.handleBlur = event => {
1051
- const {
1052
- onBlur
1053
- } = this.props;
1054
- this.setState({
1055
- focused: false
1056
- }, () => {
1057
- if (onBlur) {
1058
- onBlur(event);
1059
- }
1060
- });
1061
- };
1062
-
1063
- this.state = {
1064
- error: null,
1065
- focused: false
1066
- };
1067
- }
1068
-
1069
- render() {
1070
- const {
1071
- id,
1072
- type,
1073
- label,
1074
- description,
1075
- value,
1076
- disabled,
1077
- required,
1078
- validate,
1079
- onChange,
1080
- onKeyDown,
1081
- placeholder,
1082
- light,
1083
- style,
1084
- testId,
1085
- readOnly,
1086
- autoComplete,
1087
- forwardedRef,
1088
- ariaDescribedby
1089
- } = this.props;
1090
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2__["IDProvider"], {
1091
- id: id,
1092
- scope: "labeled-text-field"
1093
- }, uniqueId => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_field_heading_js__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"], {
1094
- id: uniqueId,
1095
- testId: testId,
1096
- style: style,
1097
- field: /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_text_field_js__WEBPACK_IMPORTED_MODULE_4__[/* default */ "a"], {
1098
- id: `${uniqueId}-field`,
1099
- "aria-describedby": ariaDescribedby ? ariaDescribedby : `${uniqueId}-error`,
1100
- "aria-invalid": this.state.error ? "true" : "false",
1101
- "aria-required": required ? "true" : "false",
1102
- required: required,
1103
- testId: testId && `${testId}-field`,
1104
- type: type,
1105
- value: value,
1106
- placeholder: placeholder,
1107
- disabled: disabled,
1108
- validate: validate,
1109
- onValidate: this.handleValidate,
1110
- onChange: onChange,
1111
- onKeyDown: onKeyDown,
1112
- onFocus: this.handleFocus,
1113
- onBlur: this.handleBlur,
1114
- light: light,
1115
- readOnly: readOnly,
1116
- autoComplete: autoComplete,
1117
- ref: forwardedRef
1118
- }),
1119
- label: label,
1120
- description: description,
1121
- required: !!required,
1122
- error: !this.state.focused && this.state.error || ""
1123
- }));
1124
- }
1125
-
1126
- }
1127
-
1128
- LabeledTextFieldInternal.defaultProps = {
1129
- type: "text",
1130
- disabled: false,
1131
- light: false
1132
- };
1133
-
1134
- /**
1135
- * A LabeledTextField is an element used to accept a single line of text
1136
- * from the user paired with a label, description, and error field elements.
1137
- *
1138
- * ### Usage
1139
- *
1140
- * ```jsx
1141
- * import {LabeledTextField} from "@khanacademy/wonder-blocks-form";
1142
- *
1143
- * const [value, setValue] = React.useState("");
1144
- *
1145
- * <LabeledTextField
1146
- * label="Label"
1147
- * description="Hello, this is the description for this field"
1148
- * placeholder="Placeholder"
1149
- * value={value}
1150
- * onChange={setValue}
1151
- * />
1152
- * ```
1153
- */
1154
- const LabeledTextField = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["forwardRef"]((props, ref) => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](LabeledTextFieldInternal, _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({}, props, {
1155
- forwardedRef: ref
1156
- })));
1157
- /* harmony default export */ __webpack_exports__["a"] = (LabeledTextField);
1158
-
1159
- /***/ }),
1160
- /* 16 */
1161
- /***/ (function(module, exports) {
1162
-
1163
- module.exports = require("@khanacademy/wonder-blocks-clickable");
1164
-
1165
- /***/ }),
1166
- /* 17 */
1167
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1168
-
1169
- "use strict";
1170
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return CheckboxCore; });
1171
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
1172
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
1173
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1174
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1175
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
1176
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_2__);
1177
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1);
1178
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__);
1179
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2);
1180
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__);
1181
- /* harmony import */ var _khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(18);
1182
- /* harmony import */ var _khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_5__);
1183
-
1184
-
1185
-
1186
-
1187
-
1188
-
1189
- const {
1190
- blue,
1191
- red,
1192
- white,
1193
- offWhite,
1194
- offBlack16,
1195
- offBlack32,
1196
- offBlack50
1197
- } = _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a;
1198
- const StyledInput = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["addStyle"])("input");
1199
- const checkboxCheck = {
1200
- small: "M11.263 4.324a1 1 0 1 1 1.474 1.352l-5.5 6a1 1 0 0 1-1.505-.036l-2.5-3a1 1 0 1 1 1.536-1.28L6.536 9.48l4.727-5.157z"
1201
- };
1202
- /**
1203
- * The internal stateless ☑️ Checkbox
1204
- */
1205
-
1206
- class CheckboxCore extends react__WEBPACK_IMPORTED_MODULE_1__["Component"] {
1207
- constructor(...args) {
1208
- super(...args);
1209
-
1210
- this.handleChange = () => {
1211
- // Empty because change is handled by ClickableBehavior
1212
- return;
1213
- };
1214
- }
1215
-
1216
- render() {
1217
- const {
1218
- checked,
1219
- disabled,
1220
- error,
1221
- groupName,
1222
- id,
1223
- testId,
1224
- hovered,
1225
- focused,
1226
- pressed,
1227
- waiting: _,
1228
- ...sharedProps
1229
- } = this.props;
1230
-
1231
- const stateStyles = _generateStyles(checked, error);
1232
-
1233
- const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles.disabled];
1234
- const props = {
1235
- "data-test-id": testId
1236
- };
1237
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](react__WEBPACK_IMPORTED_MODULE_1__["Fragment"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](StyledInput, _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({}, sharedProps, {
1238
- type: "checkbox",
1239
- "aria-invalid": error,
1240
- checked: checked,
1241
- disabled: disabled,
1242
- id: id,
1243
- name: groupName // Need to specify because this is a controlled React form
1244
- // component, but we handle the click via ClickableBehavior
1245
- ,
1246
- onChange: this.handleChange,
1247
- style: defaultStyle
1248
- }, props)), checked && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_5___default.a, {
1249
- color: disabled ? offBlack32 : white,
1250
- icon: checkboxCheck,
1251
- size: "small",
1252
- style: sharedStyles.checkIcon
1253
- }));
1254
- }
1255
-
1256
- }
1257
- const size = 16;
1258
- const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_2__["StyleSheet"].create({
1259
- // Reset the default styled input element
1260
- inputReset: {
1261
- appearance: "none",
1262
- WebkitAppearance: "none",
1263
- MozAppearance: "none"
1264
- },
1265
- default: {
1266
- height: size,
1267
- width: size,
1268
- minHeight: size,
1269
- minWidth: size,
1270
- margin: 0,
1271
- outline: "none",
1272
- boxSizing: "border-box",
1273
- borderStyle: "solid",
1274
- borderWidth: 1,
1275
- borderRadius: 3
1276
- },
1277
- disabled: {
1278
- cursor: "auto",
1279
- backgroundColor: offWhite,
1280
- borderColor: offBlack16,
1281
- borderWidth: 1
1282
- },
1283
- checkIcon: {
1284
- position: "absolute",
1285
- pointerEvents: "none"
1286
- }
1287
- });
1288
- const fadedBlue = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["fade"])(blue, 0.16), white);
1289
- const activeBlue = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(offBlack32, blue);
1290
- const fadedRed = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["fade"])(red, 0.08), white);
1291
- const activeRed = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(offBlack32, red);
1292
- const colors = {
1293
- default: {
1294
- faded: fadedBlue,
1295
- base: blue,
1296
- active: activeBlue
1297
- },
1298
- error: {
1299
- faded: fadedRed,
1300
- base: red,
1301
- active: activeRed
1302
- }
1303
- };
1304
- const styles = {};
1305
-
1306
- const _generateStyles = (checked, error) => {
1307
- // "hash" the parameters
1308
- const styleKey = `${String(checked)}-${String(error)}`;
1309
-
1310
- if (styles[styleKey]) {
1311
- return styles[styleKey];
1312
- }
1313
-
1314
- const palette = error ? colors.error : colors.default;
1315
- let newStyles = {};
1316
-
1317
- if (checked) {
1318
- newStyles = {
1319
- default: {
1320
- backgroundColor: palette.base,
1321
- borderWidth: 0
1322
- },
1323
- focus: {
1324
- boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
1325
- },
1326
- active: {
1327
- boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.active}`,
1328
- background: palette.active
1329
- }
1330
- };
1331
- } else {
1332
- newStyles = {
1333
- default: {
1334
- backgroundColor: error ? fadedRed : white,
1335
- borderColor: error ? red : offBlack50
1336
- },
1337
- focus: {
1338
- backgroundColor: error ? fadedRed : white,
1339
- borderColor: palette.base,
1340
- borderWidth: 2
1341
- },
1342
- active: {
1343
- backgroundColor: palette.faded,
1344
- borderColor: error ? activeRed : blue,
1345
- borderWidth: 2
1346
- }
1347
- };
1348
- }
1349
-
1350
- styles[styleKey] = aphrodite__WEBPACK_IMPORTED_MODULE_2__["StyleSheet"].create(newStyles);
1351
- return styles[styleKey];
1352
- };
1353
-
1354
- /***/ }),
1355
- /* 18 */
1356
- /***/ (function(module, exports) {
1357
-
1358
- module.exports = require("@khanacademy/wonder-blocks-icon");
1359
-
1360
- /***/ }),
1361
- /* 19 */
1362
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1363
-
1364
- "use strict";
1365
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RadioCore; });
1366
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
1367
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
1368
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1369
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1370
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
1371
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_2__);
1372
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1);
1373
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__);
1374
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2);
1375
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__);
1376
-
1377
-
1378
-
1379
-
1380
-
1381
- const {
1382
- blue,
1383
- red,
1384
- white,
1385
- offWhite,
1386
- offBlack16,
1387
- offBlack32,
1388
- offBlack50
1389
- } = _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a;
1390
- const StyledInput = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["addStyle"])("input");
1391
- /**
1392
- * The internal stateless 🔘 Radio button
1393
- */
1394
-
1395
- class RadioCore extends react__WEBPACK_IMPORTED_MODULE_1__["Component"] {
1396
- constructor(...args) {
1397
- super(...args);
1398
-
1399
- this.handleChange = () => {
1400
- // Empty because change is handled by ClickableBehavior
1401
- return;
1402
- };
1403
- }
1404
-
1405
- render() {
1406
- const {
1407
- checked,
1408
- disabled,
1409
- error,
1410
- groupName,
1411
- id,
1412
- testId,
1413
- hovered,
1414
- focused,
1415
- pressed,
1416
- waiting: _,
1417
- ...sharedProps
1418
- } = this.props;
1419
-
1420
- const stateStyles = _generateStyles(checked, error);
1421
-
1422
- const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles.disabled];
1423
- const props = {
1424
- "data-test-id": testId
1425
- };
1426
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](react__WEBPACK_IMPORTED_MODULE_1__["Fragment"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](StyledInput, _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({}, sharedProps, {
1427
- type: "radio",
1428
- "aria-invalid": error,
1429
- checked: checked,
1430
- disabled: disabled,
1431
- id: id,
1432
- name: groupName // Need to specify because this is a controlled React form
1433
- // component, but we handle the click via ClickableBehavior
1434
- ,
1435
- onChange: this.handleChange,
1436
- style: defaultStyle
1437
- }, props)), disabled && checked && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"]("span", {
1438
- style: disabledChecked
1439
- }));
1440
- }
1441
-
1442
- }
1443
- const size = 16; // circle with a different color. Here, we add that center circle. // If the checkbox is disabled and selected, it has a border but also an inner
1444
-
1445
- const disabledChecked = {
1446
- position: "absolute",
1447
- top: size / 4,
1448
- left: size / 4,
1449
- height: size / 2,
1450
- width: size / 2,
1451
- borderRadius: "50%",
1452
- backgroundColor: offBlack32
1453
- };
1454
- const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_2__["StyleSheet"].create({
1455
- // Reset the default styled input element
1456
- inputReset: {
1457
- appearance: "none",
1458
- WebkitAppearance: "none",
1459
- MozAppearance: "none"
1460
- },
1461
- default: {
1462
- height: size,
1463
- width: size,
1464
- minHeight: size,
1465
- minWidth: size,
1466
- margin: 0,
1467
- outline: "none",
1468
- boxSizing: "border-box",
1469
- borderStyle: "solid",
1470
- borderWidth: 1,
1471
- borderRadius: "50%"
1472
- },
1473
- disabled: {
1474
- cursor: "auto",
1475
- backgroundColor: offWhite,
1476
- borderColor: offBlack16,
1477
- borderWidth: 1
1478
- }
1479
- });
1480
- const fadedBlue = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["fade"])(blue, 0.16), white);
1481
- const activeBlue = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(offBlack32, blue);
1482
- const fadedRed = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["fade"])(red, 0.08), white);
1483
- const activeRed = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__["mix"])(offBlack32, red);
1484
- const colors = {
1485
- default: {
1486
- faded: fadedBlue,
1487
- base: blue,
1488
- active: activeBlue
1489
- },
1490
- error: {
1491
- faded: fadedRed,
1492
- base: red,
1493
- active: activeRed
1494
- }
1495
- };
1496
- const styles = {};
1497
-
1498
- const _generateStyles = (checked, error) => {
1499
- // "hash" the parameters
1500
- const styleKey = `${String(checked)}-${String(error)}`;
1501
-
1502
- if (styles[styleKey]) {
1503
- return styles[styleKey];
1504
- }
1505
-
1506
- const palette = error ? colors.error : colors.default;
1507
- let newStyles = {};
1508
-
1509
- if (checked) {
1510
- newStyles = {
1511
- default: {
1512
- backgroundColor: white,
1513
- borderColor: palette.base,
1514
- borderWidth: size / 4
1515
- },
1516
- focus: {
1517
- boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.base}`
1518
- },
1519
- active: {
1520
- boxShadow: `0 0 0 1px ${white}, 0 0 0 3px ${palette.active}`,
1521
- borderColor: palette.active
1522
- }
1523
- };
1524
- } else {
1525
- newStyles = {
1526
- default: {
1527
- backgroundColor: error ? fadedRed : white,
1528
- borderColor: error ? red : offBlack50
1529
- },
1530
- focus: {
1531
- backgroundColor: error ? fadedRed : white,
1532
- borderColor: palette.base,
1533
- borderWidth: 2
1534
- },
1535
- active: {
1536
- backgroundColor: palette.faded,
1537
- borderColor: error ? activeRed : blue,
1538
- borderWidth: 2
1539
- }
1540
- };
1541
- }
1542
-
1543
- styles[styleKey] = aphrodite__WEBPACK_IMPORTED_MODULE_2__["StyleSheet"].create(newStyles);
1544
- return styles[styleKey];
1545
- };
1546
-
1547
- /***/ }),
1548
- /* 20 */
1549
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1550
-
1551
- "use strict";
1552
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Radio; });
1553
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
1554
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
1555
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1556
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1557
- /* harmony import */ var _choice_internal_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
1558
-
1559
-
1560
- // Keep synced with ChoiceComponentProps in ../util/types.js
1561
-
1562
- /**
1563
- * 🔘 A nicely styled radio button for all your non-AMFM radio button needs. Can
1564
- * optionally take label and description props.
1565
- *
1566
- * This component should not really be used by itself because radio buttons are
1567
- * often grouped together. See RadioGroup.
1568
- */
1569
- class Radio extends react__WEBPACK_IMPORTED_MODULE_1__["Component"] {
1570
- render() {
1571
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](_choice_internal_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"], _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({
1572
- variant: "radio"
1573
- }, this.props));
1574
- }
1575
-
1576
- }
1577
- Radio.defaultProps = {
1578
- disabled: false,
1579
- error: false
1580
- };
1581
-
1582
- /***/ }),
1583
- /* 21 */
1584
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1585
-
1586
- "use strict";
1587
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return FieldHeading; });
1588
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1589
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1590
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6);
1591
- /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_1__);
1592
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2);
1593
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2__);
1594
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1);
1595
- /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3__);
1596
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8);
1597
- /* harmony import */ var _khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_4__);
1598
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(3);
1599
- /* harmony import */ var _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_5__);
1600
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(4);
1601
- /* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_6__);
1602
-
1603
-
1604
-
1605
-
1606
-
1607
-
1608
-
1609
- const StyledSpan = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2__["addStyle"])("span");
1610
- /**
1611
- * A FieldHeading is an element that provides a label, description, and error element
1612
- * to present better context and hints to any type of form field component.
1613
- */
1614
-
1615
- class FieldHeading extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
1616
- renderLabel() {
1617
- const {
1618
- label,
1619
- id,
1620
- required,
1621
- testId
1622
- } = this.props;
1623
- const requiredIcon = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledSpan, {
1624
- style: styles.required,
1625
- "aria-hidden": true
1626
- }, " ", "*");
1627
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react__WEBPACK_IMPORTED_MODULE_0__["Fragment"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_6__["LabelMedium"], {
1628
- style: styles.label,
1629
- tag: "label",
1630
- htmlFor: id && `${id}-field`,
1631
- testId: testId && `${testId}-label`
1632
- }, label, required && requiredIcon), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_4__["Strut"], {
1633
- size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_5___default.a.xxxSmall_4
1634
- }));
1635
- }
1636
-
1637
- maybeRenderDescription() {
1638
- const {
1639
- description,
1640
- testId
1641
- } = this.props;
1642
-
1643
- if (!description) {
1644
- return null;
1645
- }
1646
-
1647
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react__WEBPACK_IMPORTED_MODULE_0__["Fragment"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_6__["LabelSmall"], {
1648
- style: styles.description,
1649
- testId: testId && `${testId}-description`
1650
- }, description), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_4__["Strut"], {
1651
- size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_5___default.a.xxxSmall_4
1652
- }));
1653
- }
1654
-
1655
- maybeRenderError() {
1656
- const {
1657
- error,
1658
- id,
1659
- testId
1660
- } = this.props;
1661
-
1662
- if (!error) {
1663
- return null;
1664
- }
1665
-
1666
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react__WEBPACK_IMPORTED_MODULE_0__["Fragment"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_4__["Strut"], {
1667
- size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_5___default.a.small_12
1668
- }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_6__["LabelSmall"], {
1669
- style: styles.error,
1670
- role: "alert",
1671
- id: id && `${id}-error`,
1672
- testId: testId && `${testId}-error`
1673
- }, error));
1674
- }
1675
-
1676
- render() {
1677
- const {
1678
- field,
1679
- style
1680
- } = this.props;
1681
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_2__["View"], {
1682
- style: style
1683
- }, this.renderLabel(), this.maybeRenderDescription(), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_4__["Strut"], {
1684
- size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_5___default.a.xSmall_8
1685
- }), field, this.maybeRenderError());
1686
- }
1687
-
1688
- }
1689
- const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
1690
- label: {
1691
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack
1692
- },
1693
- description: {
1694
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.offBlack64
1695
- },
1696
- error: {
1697
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.red
1698
- },
1699
- required: {
1700
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_3___default.a.red
1701
- }
1702
- });
1703
-
1704
- /***/ }),
1705
- /* 22 */
1706
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1707
-
1708
- "use strict";
1709
- __webpack_require__.r(__webpack_exports__);
1710
- /* harmony import */ var _components_checkbox_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9);
1711
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Checkbox", function() { return _components_checkbox_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
1712
-
1713
- /* harmony import */ var _components_choice_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
1714
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Choice", function() { return _components_choice_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
1715
-
1716
- /* harmony import */ var _components_checkbox_group_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13);
1717
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CheckboxGroup", function() { return _components_checkbox_group_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
1718
-
1719
- /* harmony import */ var _components_radio_group_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(14);
1720
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RadioGroup", function() { return _components_radio_group_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
1721
-
1722
- /* harmony import */ var _components_text_field_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(10);
1723
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TextField", function() { return _components_text_field_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
1724
-
1725
- /* harmony import */ var _components_labeled_text_field_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(15);
1726
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LabeledTextField", function() { return _components_labeled_text_field_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
1727
-
1728
-
1729
-
1730
-
1731
-
1732
-
1733
-
1734
-
1735
-
1736
- /***/ })
1737
- /******/ ]);