@khanacademy/wonder-blocks-form 3.1.11 → 3.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/components/checkbox-core.d.ts +16 -0
- package/dist/components/checkbox-core.js.flow +26 -0
- package/dist/components/checkbox-group.d.ts +84 -0
- package/dist/components/checkbox-group.js.flow +103 -0
- package/dist/components/checkbox.d.ts +83 -0
- package/dist/components/checkbox.js.flow +106 -0
- package/dist/components/choice-internal.d.ts +63 -0
- package/dist/components/choice-internal.js.flow +100 -0
- package/dist/components/choice.d.ts +127 -0
- package/dist/components/choice.js.flow +161 -0
- package/dist/components/field-heading.d.ts +50 -0
- package/dist/components/field-heading.js.flow +64 -0
- package/dist/components/group-styles.d.ts +3 -0
- package/dist/components/group-styles.js.flow +10 -0
- package/dist/components/labeled-text-field.d.ts +169 -0
- package/dist/components/labeled-text-field.js.flow +211 -0
- package/dist/components/radio-core.d.ts +15 -0
- package/dist/components/radio-core.js.flow +26 -0
- package/dist/components/radio-group.d.ts +85 -0
- package/dist/components/radio-group.js.flow +104 -0
- package/dist/components/radio.d.ts +68 -0
- package/dist/components/radio.js.flow +92 -0
- package/dist/components/text-field.d.ts +146 -0
- package/dist/components/text-field.js.flow +186 -0
- package/dist/es/index.js +258 -224
- package/dist/index.d.ts +7 -0
- package/dist/index.js +281 -249
- package/dist/index.js.flow +21 -2
- package/dist/util/types.d.ts +62 -0
- package/dist/util/types.js.flow +138 -0
- package/package.json +10 -10
- package/src/__tests__/{custom-snapshot.test.js → custom-snapshot.test.tsx} +8 -9
- package/src/components/__tests__/{checkbox-group.test.js → checkbox-group.test.tsx} +5 -5
- package/src/components/__tests__/{field-heading.test.js → field-heading.test.tsx} +0 -1
- package/src/components/__tests__/{labeled-text-field.test.js → labeled-text-field.test.tsx} +4 -5
- package/src/components/__tests__/{radio-group.test.js → radio-group.test.tsx} +8 -8
- package/src/components/__tests__/{text-field.test.js → text-field.test.tsx} +22 -18
- package/src/components/{checkbox-core.js → checkbox-core.tsx} +12 -15
- package/src/components/{checkbox-group.js → checkbox-group.tsx} +20 -23
- package/src/components/{checkbox.js → checkbox.tsx} +18 -32
- package/src/components/{choice-internal.js → choice-internal.tsx} +25 -39
- package/src/components/{choice.js → choice.tsx} +24 -37
- package/src/components/{field-heading.js → field-heading.tsx} +16 -23
- package/src/components/{group-styles.js → group-styles.ts} +0 -1
- package/src/components/{labeled-text-field.js → labeled-text-field.tsx} +54 -69
- package/src/components/{radio-core.js → radio-core.tsx} +13 -16
- package/src/components/{radio-group.js → radio-group.tsx} +20 -23
- package/src/components/{radio.js → radio.tsx} +18 -32
- package/src/components/{text-field.js → text-field.tsx} +53 -64
- package/src/{index.js → index.ts} +0 -1
- package/src/util/{types.js → types.ts} +32 -35
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -15
- package/src/components/__docs__/checkbox-accessibility.stories.mdx +0 -147
- package/src/components/__docs__/checkbox-group.stories.js +0 -300
- package/src/components/__docs__/checkbox.stories.js +0 -167
- package/src/components/__docs__/choice.stories.js +0 -86
- package/src/components/__docs__/labeled-text-field.argtypes.js +0 -248
- package/src/components/__docs__/labeled-text-field.stories.js +0 -709
- package/src/components/__docs__/radio-group.stories.js +0 -217
- package/src/components/__docs__/radio.stories.js +0 -161
- package/src/components/__docs__/text-field.argtypes.js +0 -206
- package/src/components/__docs__/text-field.stories.js +0 -780
- /package/src/__tests__/__snapshots__/{custom-snapshot.test.js.snap → custom-snapshot.test.tsx.snap} +0 -0
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
2
1
|
import * as React from 'react';
|
|
3
|
-
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
4
2
|
import { StyleSheet, css } from 'aphrodite';
|
|
5
3
|
import Color, { mix, fade } from '@khanacademy/wonder-blocks-color';
|
|
6
4
|
import { addStyle, UniqueIDProvider, View, IDProvider } from '@khanacademy/wonder-blocks-core';
|
|
@@ -10,6 +8,48 @@ import Spacing from '@khanacademy/wonder-blocks-spacing';
|
|
|
10
8
|
import { LabelMedium, LabelSmall, styles as styles$6 } from '@khanacademy/wonder-blocks-typography';
|
|
11
9
|
import Icon from '@khanacademy/wonder-blocks-icon';
|
|
12
10
|
|
|
11
|
+
function _extends() {
|
|
12
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
13
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
14
|
+
var source = arguments[i];
|
|
15
|
+
for (var key in source) {
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
17
|
+
target[key] = source[key];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return target;
|
|
22
|
+
};
|
|
23
|
+
return _extends.apply(this, arguments);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function _setPrototypeOf(o, p) {
|
|
27
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
28
|
+
o.__proto__ = p;
|
|
29
|
+
return o;
|
|
30
|
+
};
|
|
31
|
+
return _setPrototypeOf(o, p);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _inheritsLoose(subClass, superClass) {
|
|
35
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
36
|
+
subClass.prototype.constructor = subClass;
|
|
37
|
+
_setPrototypeOf(subClass, superClass);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
41
|
+
if (source == null) return {};
|
|
42
|
+
var target = {};
|
|
43
|
+
var sourceKeys = Object.keys(source);
|
|
44
|
+
var key, i;
|
|
45
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
46
|
+
key = sourceKeys[i];
|
|
47
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
48
|
+
target[key] = source[key];
|
|
49
|
+
}
|
|
50
|
+
return target;
|
|
51
|
+
}
|
|
52
|
+
|
|
13
53
|
const _excluded$4 = ["checked", "disabled", "error", "groupName", "id", "testId", "hovered", "focused", "pressed", "waiting"];
|
|
14
54
|
const {
|
|
15
55
|
blue: blue$1,
|
|
@@ -24,32 +64,32 @@ const StyledInput$1 = addStyle("input");
|
|
|
24
64
|
const checkboxCheck = {
|
|
25
65
|
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"
|
|
26
66
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
67
|
+
let CheckboxCore = function (_React$Component) {
|
|
68
|
+
_inheritsLoose(CheckboxCore, _React$Component);
|
|
69
|
+
function CheckboxCore(...args) {
|
|
70
|
+
var _this;
|
|
71
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
72
|
+
_this.handleChange = () => {
|
|
32
73
|
return;
|
|
33
74
|
};
|
|
75
|
+
return _this;
|
|
34
76
|
}
|
|
35
|
-
|
|
36
|
-
render() {
|
|
77
|
+
var _proto = CheckboxCore.prototype;
|
|
78
|
+
_proto.render = function render() {
|
|
37
79
|
const _this$props = this.props,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
{
|
|
81
|
+
checked,
|
|
82
|
+
disabled,
|
|
83
|
+
error,
|
|
84
|
+
groupName,
|
|
85
|
+
id,
|
|
86
|
+
testId,
|
|
87
|
+
hovered,
|
|
88
|
+
focused,
|
|
89
|
+
pressed
|
|
90
|
+
} = _this$props,
|
|
91
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$4);
|
|
51
92
|
const stateStyles = _generateStyles$1(checked, error);
|
|
52
|
-
|
|
53
93
|
const defaultStyle = [sharedStyles$1.inputReset, sharedStyles$1.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles$1.disabled];
|
|
54
94
|
const props = {
|
|
55
95
|
"data-test-id": testId
|
|
@@ -69,9 +109,9 @@ class CheckboxCore extends React.Component {
|
|
|
69
109
|
size: "small",
|
|
70
110
|
style: sharedStyles$1.checkIcon
|
|
71
111
|
}));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}
|
|
112
|
+
};
|
|
113
|
+
return CheckboxCore;
|
|
114
|
+
}(React.Component);
|
|
75
115
|
const size$1 = 16;
|
|
76
116
|
const sharedStyles$1 = StyleSheet.create({
|
|
77
117
|
inputReset: {
|
|
@@ -119,17 +159,13 @@ const colors$1 = {
|
|
|
119
159
|
}
|
|
120
160
|
};
|
|
121
161
|
const styles$5 = {};
|
|
122
|
-
|
|
123
162
|
const _generateStyles$1 = (checked, error) => {
|
|
124
163
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
125
|
-
|
|
126
164
|
if (styles$5[styleKey]) {
|
|
127
165
|
return styles$5[styleKey];
|
|
128
166
|
}
|
|
129
|
-
|
|
130
167
|
const palette = error ? colors$1.error : colors$1.default;
|
|
131
168
|
let newStyles = {};
|
|
132
|
-
|
|
133
169
|
if (checked) {
|
|
134
170
|
newStyles = {
|
|
135
171
|
default: {
|
|
@@ -162,7 +198,6 @@ const _generateStyles$1 = (checked, error) => {
|
|
|
162
198
|
}
|
|
163
199
|
};
|
|
164
200
|
}
|
|
165
|
-
|
|
166
201
|
styles$5[styleKey] = StyleSheet.create(newStyles);
|
|
167
202
|
return styles$5[styleKey];
|
|
168
203
|
};
|
|
@@ -178,32 +213,32 @@ const {
|
|
|
178
213
|
offBlack50
|
|
179
214
|
} = Color;
|
|
180
215
|
const StyledInput = addStyle("input");
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
216
|
+
let RadioCore = function (_React$Component) {
|
|
217
|
+
_inheritsLoose(RadioCore, _React$Component);
|
|
218
|
+
function RadioCore(...args) {
|
|
219
|
+
var _this;
|
|
220
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
221
|
+
_this.handleChange = () => {
|
|
186
222
|
return;
|
|
187
223
|
};
|
|
224
|
+
return _this;
|
|
188
225
|
}
|
|
189
|
-
|
|
190
|
-
render() {
|
|
226
|
+
var _proto = RadioCore.prototype;
|
|
227
|
+
_proto.render = function render() {
|
|
191
228
|
const _this$props = this.props,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
229
|
+
{
|
|
230
|
+
checked,
|
|
231
|
+
disabled,
|
|
232
|
+
error,
|
|
233
|
+
groupName,
|
|
234
|
+
id,
|
|
235
|
+
testId,
|
|
236
|
+
hovered,
|
|
237
|
+
focused,
|
|
238
|
+
pressed
|
|
239
|
+
} = _this$props,
|
|
240
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$3);
|
|
205
241
|
const stateStyles = _generateStyles(checked, error);
|
|
206
|
-
|
|
207
242
|
const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, stateStyles.default, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus), disabled && sharedStyles.disabled];
|
|
208
243
|
const props = {
|
|
209
244
|
"data-test-id": testId
|
|
@@ -220,9 +255,9 @@ class RadioCore extends React.Component {
|
|
|
220
255
|
}, props)), disabled && checked && React.createElement("span", {
|
|
221
256
|
style: disabledChecked
|
|
222
257
|
}));
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
}
|
|
258
|
+
};
|
|
259
|
+
return RadioCore;
|
|
260
|
+
}(React.Component);
|
|
226
261
|
const size = 16;
|
|
227
262
|
const disabledChecked = {
|
|
228
263
|
position: "absolute",
|
|
@@ -275,17 +310,13 @@ const colors = {
|
|
|
275
310
|
}
|
|
276
311
|
};
|
|
277
312
|
const styles$4 = {};
|
|
278
|
-
|
|
279
313
|
const _generateStyles = (checked, error) => {
|
|
280
314
|
const styleKey = `${String(checked)}-${String(error)}`;
|
|
281
|
-
|
|
282
315
|
if (styles$4[styleKey]) {
|
|
283
316
|
return styles$4[styleKey];
|
|
284
317
|
}
|
|
285
|
-
|
|
286
318
|
const palette = error ? colors.error : colors.default;
|
|
287
319
|
let newStyles = {};
|
|
288
|
-
|
|
289
320
|
if (checked) {
|
|
290
321
|
newStyles = {
|
|
291
322
|
default: {
|
|
@@ -319,44 +350,41 @@ const _generateStyles = (checked, error) => {
|
|
|
319
350
|
}
|
|
320
351
|
};
|
|
321
352
|
}
|
|
322
|
-
|
|
323
353
|
styles$4[styleKey] = StyleSheet.create(newStyles);
|
|
324
354
|
return styles$4[styleKey];
|
|
325
355
|
};
|
|
326
356
|
|
|
327
357
|
const _excluded$2 = ["label", "description", "onChange", "style", "className", "variant"];
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
358
|
+
let ChoiceInternal = function (_React$Component) {
|
|
359
|
+
_inheritsLoose(ChoiceInternal, _React$Component);
|
|
360
|
+
function ChoiceInternal(...args) {
|
|
361
|
+
var _this;
|
|
362
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
363
|
+
_this.handleLabelClick = event => {
|
|
333
364
|
event.preventDefault();
|
|
334
365
|
};
|
|
335
|
-
|
|
336
|
-
this.handleClick = () => {
|
|
366
|
+
_this.handleClick = () => {
|
|
337
367
|
const {
|
|
338
368
|
checked,
|
|
339
369
|
onChange,
|
|
340
370
|
variant
|
|
341
|
-
} =
|
|
342
|
-
|
|
371
|
+
} = _this.props;
|
|
343
372
|
if (variant === "radio" && checked) {
|
|
344
373
|
return;
|
|
345
374
|
}
|
|
346
|
-
|
|
347
375
|
onChange(!checked);
|
|
348
376
|
};
|
|
377
|
+
return _this;
|
|
349
378
|
}
|
|
350
|
-
|
|
351
|
-
getChoiceCoreComponent() {
|
|
379
|
+
var _proto = ChoiceInternal.prototype;
|
|
380
|
+
_proto.getChoiceCoreComponent = function getChoiceCoreComponent() {
|
|
352
381
|
if (this.props.variant === "radio") {
|
|
353
382
|
return RadioCore;
|
|
354
383
|
} else {
|
|
355
384
|
return CheckboxCore;
|
|
356
385
|
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
getLabel() {
|
|
386
|
+
};
|
|
387
|
+
_proto.getLabel = function getLabel() {
|
|
360
388
|
const {
|
|
361
389
|
disabled,
|
|
362
390
|
id,
|
|
@@ -368,9 +396,8 @@ class ChoiceInternal extends React.Component {
|
|
|
368
396
|
htmlFor: id,
|
|
369
397
|
onClick: this.handleLabelClick
|
|
370
398
|
}, label));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
getDescription(id) {
|
|
399
|
+
};
|
|
400
|
+
_proto.getDescription = function getDescription(id) {
|
|
374
401
|
const {
|
|
375
402
|
description
|
|
376
403
|
} = this.props;
|
|
@@ -378,19 +405,17 @@ class ChoiceInternal extends React.Component {
|
|
|
378
405
|
style: styles$3.description,
|
|
379
406
|
id: id
|
|
380
407
|
}, description);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
render() {
|
|
408
|
+
};
|
|
409
|
+
_proto.render = function render() {
|
|
384
410
|
const _this$props = this.props,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
411
|
+
{
|
|
412
|
+
label,
|
|
413
|
+
description,
|
|
414
|
+
style,
|
|
415
|
+
className,
|
|
416
|
+
variant
|
|
417
|
+
} = _this$props,
|
|
418
|
+
coreProps = _objectWithoutPropertiesLoose(_this$props, _excluded$2);
|
|
394
419
|
const ChoiceCore = this.getChoiceCoreComponent();
|
|
395
420
|
const ClickableBehavior = getClickableBehavior();
|
|
396
421
|
return React.createElement(UniqueIDProvider, {
|
|
@@ -417,9 +442,9 @@ class ChoiceInternal extends React.Component {
|
|
|
417
442
|
}), label && this.getLabel());
|
|
418
443
|
}), description && this.getDescription(descriptionId));
|
|
419
444
|
});
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
}
|
|
445
|
+
};
|
|
446
|
+
return ChoiceInternal;
|
|
447
|
+
}(React.Component);
|
|
423
448
|
ChoiceInternal.defaultProps = {
|
|
424
449
|
checked: false,
|
|
425
450
|
disabled: false,
|
|
@@ -445,54 +470,67 @@ const styles$3 = StyleSheet.create({
|
|
|
445
470
|
}
|
|
446
471
|
});
|
|
447
472
|
|
|
448
|
-
|
|
449
|
-
|
|
473
|
+
let Checkbox = function (_React$Component) {
|
|
474
|
+
_inheritsLoose(Checkbox, _React$Component);
|
|
475
|
+
function Checkbox() {
|
|
476
|
+
return _React$Component.apply(this, arguments) || this;
|
|
477
|
+
}
|
|
478
|
+
var _proto = Checkbox.prototype;
|
|
479
|
+
_proto.render = function render() {
|
|
450
480
|
return React.createElement(ChoiceInternal, _extends({
|
|
451
481
|
variant: "checkbox"
|
|
452
482
|
}, this.props));
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
}
|
|
483
|
+
};
|
|
484
|
+
return Checkbox;
|
|
485
|
+
}(React.Component);
|
|
456
486
|
Checkbox.defaultProps = {
|
|
457
487
|
disabled: false,
|
|
458
488
|
error: false
|
|
459
489
|
};
|
|
460
490
|
|
|
461
|
-
|
|
462
|
-
|
|
491
|
+
let Radio = function (_React$Component) {
|
|
492
|
+
_inheritsLoose(Radio, _React$Component);
|
|
493
|
+
function Radio() {
|
|
494
|
+
return _React$Component.apply(this, arguments) || this;
|
|
495
|
+
}
|
|
496
|
+
var _proto = Radio.prototype;
|
|
497
|
+
_proto.render = function render() {
|
|
463
498
|
return React.createElement(ChoiceInternal, _extends({
|
|
464
499
|
variant: "radio"
|
|
465
500
|
}, this.props));
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
}
|
|
501
|
+
};
|
|
502
|
+
return Radio;
|
|
503
|
+
}(React.Component);
|
|
469
504
|
Radio.defaultProps = {
|
|
470
505
|
disabled: false,
|
|
471
506
|
error: false
|
|
472
507
|
};
|
|
473
508
|
|
|
474
509
|
const _excluded$1 = ["value", "variant"];
|
|
475
|
-
|
|
476
|
-
|
|
510
|
+
let Choice = function (_React$Component) {
|
|
511
|
+
_inheritsLoose(Choice, _React$Component);
|
|
512
|
+
function Choice() {
|
|
513
|
+
return _React$Component.apply(this, arguments) || this;
|
|
514
|
+
}
|
|
515
|
+
var _proto = Choice.prototype;
|
|
516
|
+
_proto.getChoiceComponent = function getChoiceComponent(variant) {
|
|
477
517
|
if (variant === "checkbox") {
|
|
478
518
|
return Checkbox;
|
|
479
519
|
} else {
|
|
480
520
|
return Radio;
|
|
481
521
|
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
render() {
|
|
522
|
+
};
|
|
523
|
+
_proto.render = function render() {
|
|
485
524
|
const _this$props = this.props,
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
525
|
+
{
|
|
526
|
+
variant
|
|
527
|
+
} = _this$props,
|
|
528
|
+
remainingProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
491
529
|
const ChoiceComponent = this.getChoiceComponent(variant);
|
|
492
530
|
return React.createElement(ChoiceComponent, remainingProps);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
}
|
|
531
|
+
};
|
|
532
|
+
return Choice;
|
|
533
|
+
}(React.Component);
|
|
496
534
|
Choice.defaultProps = {
|
|
497
535
|
checked: false,
|
|
498
536
|
disabled: false,
|
|
@@ -523,13 +561,17 @@ const styles$2 = StyleSheet.create({
|
|
|
523
561
|
|
|
524
562
|
const StyledFieldset$1 = addStyle("fieldset");
|
|
525
563
|
const StyledLegend$1 = addStyle("legend");
|
|
526
|
-
|
|
527
|
-
|
|
564
|
+
let CheckboxGroup = function (_React$Component) {
|
|
565
|
+
_inheritsLoose(CheckboxGroup, _React$Component);
|
|
566
|
+
function CheckboxGroup() {
|
|
567
|
+
return _React$Component.apply(this, arguments) || this;
|
|
568
|
+
}
|
|
569
|
+
var _proto = CheckboxGroup.prototype;
|
|
570
|
+
_proto.handleChange = function handleChange(changedValue, originalCheckedState) {
|
|
528
571
|
const {
|
|
529
572
|
onChange,
|
|
530
573
|
selectedValues
|
|
531
574
|
} = this.props;
|
|
532
|
-
|
|
533
575
|
if (originalCheckedState) {
|
|
534
576
|
const index = selectedValues.indexOf(changedValue);
|
|
535
577
|
const updatedSelection = [].concat(selectedValues.slice(0, index), selectedValues.slice(index + 1));
|
|
@@ -537,9 +579,8 @@ class CheckboxGroup extends React.Component {
|
|
|
537
579
|
} else {
|
|
538
580
|
onChange([].concat(selectedValues, [changedValue]));
|
|
539
581
|
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
render() {
|
|
582
|
+
};
|
|
583
|
+
_proto.render = function render() {
|
|
543
584
|
const {
|
|
544
585
|
children,
|
|
545
586
|
label,
|
|
@@ -581,18 +622,22 @@ class CheckboxGroup extends React.Component {
|
|
|
581
622
|
variant: "checkbox"
|
|
582
623
|
});
|
|
583
624
|
})));
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
}
|
|
625
|
+
};
|
|
626
|
+
return CheckboxGroup;
|
|
627
|
+
}(React.Component);
|
|
587
628
|
|
|
588
629
|
const StyledFieldset = addStyle("fieldset");
|
|
589
630
|
const StyledLegend = addStyle("legend");
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
631
|
+
let RadioGroup = function (_React$Component) {
|
|
632
|
+
_inheritsLoose(RadioGroup, _React$Component);
|
|
633
|
+
function RadioGroup() {
|
|
634
|
+
return _React$Component.apply(this, arguments) || this;
|
|
593
635
|
}
|
|
594
|
-
|
|
595
|
-
|
|
636
|
+
var _proto = RadioGroup.prototype;
|
|
637
|
+
_proto.handleChange = function handleChange(changedValue) {
|
|
638
|
+
this.props.onChange(changedValue);
|
|
639
|
+
};
|
|
640
|
+
_proto.render = function render() {
|
|
596
641
|
const {
|
|
597
642
|
children,
|
|
598
643
|
label,
|
|
@@ -634,31 +679,30 @@ class RadioGroup extends React.Component {
|
|
|
634
679
|
variant: "radio"
|
|
635
680
|
});
|
|
636
681
|
})));
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
}
|
|
682
|
+
};
|
|
683
|
+
return RadioGroup;
|
|
684
|
+
}(React.Component);
|
|
640
685
|
|
|
641
686
|
const _excluded = ["id", "type", "value", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
|
|
642
687
|
const defaultErrorMessage = "This field is required.";
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
688
|
+
let TextField = function (_React$Component) {
|
|
689
|
+
_inheritsLoose(TextField, _React$Component);
|
|
690
|
+
function TextField(props) {
|
|
691
|
+
var _this;
|
|
692
|
+
_this = _React$Component.call(this, props) || this;
|
|
693
|
+
_this.state = {
|
|
648
694
|
error: null,
|
|
649
695
|
focused: false
|
|
650
696
|
};
|
|
651
|
-
|
|
652
|
-
this.maybeValidate = newValue => {
|
|
697
|
+
_this.maybeValidate = newValue => {
|
|
653
698
|
const {
|
|
654
699
|
validate,
|
|
655
700
|
onValidate,
|
|
656
701
|
required
|
|
657
|
-
} =
|
|
658
|
-
|
|
702
|
+
} = _this.props;
|
|
659
703
|
if (validate) {
|
|
660
704
|
const maybeError = validate(newValue) || null;
|
|
661
|
-
|
|
705
|
+
_this.setState({
|
|
662
706
|
error: maybeError
|
|
663
707
|
}, () => {
|
|
664
708
|
if (onValidate) {
|
|
@@ -668,7 +712,7 @@ class TextField extends React.Component {
|
|
|
668
712
|
} else if (required) {
|
|
669
713
|
const requiredString = typeof required === "string" ? required : defaultErrorMessage;
|
|
670
714
|
const maybeError = newValue ? null : requiredString;
|
|
671
|
-
|
|
715
|
+
_this.setState({
|
|
672
716
|
error: maybeError
|
|
673
717
|
}, () => {
|
|
674
718
|
if (onValidate) {
|
|
@@ -677,21 +721,19 @@ class TextField extends React.Component {
|
|
|
677
721
|
});
|
|
678
722
|
}
|
|
679
723
|
};
|
|
680
|
-
|
|
681
|
-
this.handleChange = event => {
|
|
724
|
+
_this.handleChange = event => {
|
|
682
725
|
const {
|
|
683
726
|
onChange
|
|
684
|
-
} =
|
|
727
|
+
} = _this.props;
|
|
685
728
|
const newValue = event.target.value;
|
|
686
|
-
|
|
729
|
+
_this.maybeValidate(newValue);
|
|
687
730
|
onChange(newValue);
|
|
688
731
|
};
|
|
689
|
-
|
|
690
|
-
this.handleFocus = event => {
|
|
732
|
+
_this.handleFocus = event => {
|
|
691
733
|
const {
|
|
692
734
|
onFocus
|
|
693
|
-
} =
|
|
694
|
-
|
|
735
|
+
} = _this.props;
|
|
736
|
+
_this.setState({
|
|
695
737
|
focused: true
|
|
696
738
|
}, () => {
|
|
697
739
|
if (onFocus) {
|
|
@@ -699,12 +741,11 @@ class TextField extends React.Component {
|
|
|
699
741
|
}
|
|
700
742
|
});
|
|
701
743
|
};
|
|
702
|
-
|
|
703
|
-
this.handleBlur = event => {
|
|
744
|
+
_this.handleBlur = event => {
|
|
704
745
|
const {
|
|
705
746
|
onBlur
|
|
706
|
-
} =
|
|
707
|
-
|
|
747
|
+
} = _this.props;
|
|
748
|
+
_this.setState({
|
|
708
749
|
focused: false
|
|
709
750
|
}, () => {
|
|
710
751
|
if (onBlur) {
|
|
@@ -712,36 +753,34 @@ class TextField extends React.Component {
|
|
|
712
753
|
}
|
|
713
754
|
});
|
|
714
755
|
};
|
|
715
|
-
|
|
716
756
|
if (props.validate && props.value !== "") {
|
|
717
|
-
|
|
757
|
+
_this.state.error = props.validate(props.value) || null;
|
|
718
758
|
}
|
|
759
|
+
return _this;
|
|
719
760
|
}
|
|
720
|
-
|
|
721
|
-
componentDidMount() {
|
|
761
|
+
var _proto = TextField.prototype;
|
|
762
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
722
763
|
if (this.props.value !== "") {
|
|
723
764
|
this.maybeValidate(this.props.value);
|
|
724
765
|
}
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
render() {
|
|
766
|
+
};
|
|
767
|
+
_proto.render = function render() {
|
|
728
768
|
const _this$props = this.props,
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
769
|
+
{
|
|
770
|
+
id,
|
|
771
|
+
type,
|
|
772
|
+
value,
|
|
773
|
+
disabled,
|
|
774
|
+
onKeyDown,
|
|
775
|
+
placeholder,
|
|
776
|
+
light,
|
|
777
|
+
style,
|
|
778
|
+
testId,
|
|
779
|
+
readOnly,
|
|
780
|
+
autoComplete,
|
|
781
|
+
forwardedRef
|
|
782
|
+
} = _this$props,
|
|
783
|
+
otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
745
784
|
return React.createElement("input", _extends({
|
|
746
785
|
className: css([styles$1.input, styles$6.LabelMedium, styles$1.default, disabled ? styles$1.disabled : this.state.focused ? [styles$1.focused, light && styles$1.defaultLight] : this.state.error && [styles$1.error, light && styles$1.errorLight], style && style]),
|
|
747
786
|
id: id,
|
|
@@ -758,10 +797,9 @@ class TextField extends React.Component {
|
|
|
758
797
|
autoComplete: autoComplete,
|
|
759
798
|
ref: forwardedRef
|
|
760
799
|
}, otherProps));
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
}
|
|
764
|
-
|
|
800
|
+
};
|
|
801
|
+
return TextField;
|
|
802
|
+
}(React.Component);
|
|
765
803
|
TextField.defaultProps = {
|
|
766
804
|
type: "text",
|
|
767
805
|
disabled: false,
|
|
@@ -822,8 +860,13 @@ var TextField$1 = React.forwardRef((props, ref) => React.createElement(TextField
|
|
|
822
860
|
})));
|
|
823
861
|
|
|
824
862
|
const StyledSpan = addStyle("span");
|
|
825
|
-
|
|
826
|
-
|
|
863
|
+
let FieldHeading = function (_React$Component) {
|
|
864
|
+
_inheritsLoose(FieldHeading, _React$Component);
|
|
865
|
+
function FieldHeading() {
|
|
866
|
+
return _React$Component.apply(this, arguments) || this;
|
|
867
|
+
}
|
|
868
|
+
var _proto = FieldHeading.prototype;
|
|
869
|
+
_proto.renderLabel = function renderLabel() {
|
|
827
870
|
const {
|
|
828
871
|
label,
|
|
829
872
|
id,
|
|
@@ -842,37 +885,31 @@ class FieldHeading extends React.Component {
|
|
|
842
885
|
}, label, required && requiredIcon), React.createElement(Strut, {
|
|
843
886
|
size: Spacing.xxxSmall_4
|
|
844
887
|
}));
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
maybeRenderDescription() {
|
|
888
|
+
};
|
|
889
|
+
_proto.maybeRenderDescription = function maybeRenderDescription() {
|
|
848
890
|
const {
|
|
849
891
|
description,
|
|
850
892
|
testId
|
|
851
893
|
} = this.props;
|
|
852
|
-
|
|
853
894
|
if (!description) {
|
|
854
895
|
return null;
|
|
855
896
|
}
|
|
856
|
-
|
|
857
897
|
return React.createElement(React.Fragment, null, React.createElement(LabelSmall, {
|
|
858
898
|
style: styles.description,
|
|
859
899
|
testId: testId && `${testId}-description`
|
|
860
900
|
}, description), React.createElement(Strut, {
|
|
861
901
|
size: Spacing.xxxSmall_4
|
|
862
902
|
}));
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
maybeRenderError() {
|
|
903
|
+
};
|
|
904
|
+
_proto.maybeRenderError = function maybeRenderError() {
|
|
866
905
|
const {
|
|
867
906
|
error,
|
|
868
907
|
id,
|
|
869
908
|
testId
|
|
870
909
|
} = this.props;
|
|
871
|
-
|
|
872
910
|
if (!error) {
|
|
873
911
|
return null;
|
|
874
912
|
}
|
|
875
|
-
|
|
876
913
|
return React.createElement(React.Fragment, null, React.createElement(Strut, {
|
|
877
914
|
size: Spacing.small_12
|
|
878
915
|
}), React.createElement(LabelSmall, {
|
|
@@ -881,9 +918,8 @@ class FieldHeading extends React.Component {
|
|
|
881
918
|
id: id && `${id}-error`,
|
|
882
919
|
testId: testId && `${testId}-error`
|
|
883
920
|
}, error));
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
render() {
|
|
921
|
+
};
|
|
922
|
+
_proto.render = function render() {
|
|
887
923
|
const {
|
|
888
924
|
field,
|
|
889
925
|
style
|
|
@@ -893,9 +929,9 @@ class FieldHeading extends React.Component {
|
|
|
893
929
|
}, this.renderLabel(), this.maybeRenderDescription(), React.createElement(Strut, {
|
|
894
930
|
size: Spacing.xSmall_8
|
|
895
931
|
}), field, this.maybeRenderError());
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
}
|
|
932
|
+
};
|
|
933
|
+
return FieldHeading;
|
|
934
|
+
}(React.Component);
|
|
899
935
|
const styles = StyleSheet.create({
|
|
900
936
|
label: {
|
|
901
937
|
color: Color.offBlack
|
|
@@ -911,15 +947,16 @@ const styles = StyleSheet.create({
|
|
|
911
947
|
}
|
|
912
948
|
});
|
|
913
949
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
950
|
+
let LabeledTextField = function (_React$Component) {
|
|
951
|
+
_inheritsLoose(LabeledTextField, _React$Component);
|
|
952
|
+
function LabeledTextField(props) {
|
|
953
|
+
var _this;
|
|
954
|
+
_this = _React$Component.call(this, props) || this;
|
|
955
|
+
_this.handleValidate = errorMessage => {
|
|
919
956
|
const {
|
|
920
957
|
onValidate
|
|
921
|
-
} =
|
|
922
|
-
|
|
958
|
+
} = _this.props;
|
|
959
|
+
_this.setState({
|
|
923
960
|
error: errorMessage
|
|
924
961
|
}, () => {
|
|
925
962
|
if (onValidate) {
|
|
@@ -927,12 +964,11 @@ class LabeledTextField extends React.Component {
|
|
|
927
964
|
}
|
|
928
965
|
});
|
|
929
966
|
};
|
|
930
|
-
|
|
931
|
-
this.handleFocus = event => {
|
|
967
|
+
_this.handleFocus = event => {
|
|
932
968
|
const {
|
|
933
969
|
onFocus
|
|
934
|
-
} =
|
|
935
|
-
|
|
970
|
+
} = _this.props;
|
|
971
|
+
_this.setState({
|
|
936
972
|
focused: true
|
|
937
973
|
}, () => {
|
|
938
974
|
if (onFocus) {
|
|
@@ -940,12 +976,11 @@ class LabeledTextField extends React.Component {
|
|
|
940
976
|
}
|
|
941
977
|
});
|
|
942
978
|
};
|
|
943
|
-
|
|
944
|
-
this.handleBlur = event => {
|
|
979
|
+
_this.handleBlur = event => {
|
|
945
980
|
const {
|
|
946
981
|
onBlur
|
|
947
|
-
} =
|
|
948
|
-
|
|
982
|
+
} = _this.props;
|
|
983
|
+
_this.setState({
|
|
949
984
|
focused: false
|
|
950
985
|
}, () => {
|
|
951
986
|
if (onBlur) {
|
|
@@ -953,14 +988,14 @@ class LabeledTextField extends React.Component {
|
|
|
953
988
|
}
|
|
954
989
|
});
|
|
955
990
|
};
|
|
956
|
-
|
|
957
|
-
this.state = {
|
|
991
|
+
_this.state = {
|
|
958
992
|
error: null,
|
|
959
993
|
focused: false
|
|
960
994
|
};
|
|
995
|
+
return _this;
|
|
961
996
|
}
|
|
962
|
-
|
|
963
|
-
render() {
|
|
997
|
+
var _proto = LabeledTextField.prototype;
|
|
998
|
+
_proto.render = function render() {
|
|
964
999
|
const {
|
|
965
1000
|
id,
|
|
966
1001
|
type,
|
|
@@ -1015,10 +1050,9 @@ class LabeledTextField extends React.Component {
|
|
|
1015
1050
|
required: !!required,
|
|
1016
1051
|
error: !this.state.focused && this.state.error || ""
|
|
1017
1052
|
}));
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1053
|
+
};
|
|
1054
|
+
return LabeledTextField;
|
|
1055
|
+
}(React.Component);
|
|
1022
1056
|
LabeledTextField.defaultProps = {
|
|
1023
1057
|
type: "text",
|
|
1024
1058
|
disabled: false,
|