@khanacademy/wonder-blocks-form 4.7.4 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _extends = require('@babel/runtime/helpers/extends');
5
6
  var React = require('react');
7
+ var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
6
8
  var aphrodite = require('aphrodite');
7
9
  var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
8
10
  var wonderBlocksLayout = require('@khanacademy/wonder-blocks-layout');
@@ -15,56 +17,30 @@ var minusIcon = require('@phosphor-icons/core/bold/minus-bold.svg');
15
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
18
 
17
19
  function _interopNamespace(e) {
18
- if (e && e.__esModule) return e;
19
- var n = Object.create(null);
20
- if (e) {
21
- Object.keys(e).forEach(function (k) {
22
- if (k !== 'default') {
23
- var d = Object.getOwnPropertyDescriptor(e, k);
24
- Object.defineProperty(n, k, d.get ? d : {
25
- enumerable: true,
26
- get: function () { return e[k]; }
20
+ if (e && e.__esModule) return e;
21
+ var n = Object.create(null);
22
+ if (e) {
23
+ Object.keys(e).forEach(function (k) {
24
+ if (k !== 'default') {
25
+ var d = Object.getOwnPropertyDescriptor(e, k);
26
+ Object.defineProperty(n, k, d.get ? d : {
27
+ enumerable: true,
28
+ get: function () { return e[k]; }
29
+ });
30
+ }
27
31
  });
28
- }
29
- });
30
- }
31
- n["default"] = e;
32
- return Object.freeze(n);
32
+ }
33
+ n["default"] = e;
34
+ return Object.freeze(n);
33
35
  }
34
36
 
37
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
35
38
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
+ var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
36
40
  var checkIcon__default = /*#__PURE__*/_interopDefaultLegacy(checkIcon);
37
41
  var minusIcon__default = /*#__PURE__*/_interopDefaultLegacy(minusIcon);
38
42
 
39
- function _extends() {
40
- _extends = Object.assign ? Object.assign.bind() : function (target) {
41
- for (var i = 1; i < arguments.length; i++) {
42
- var source = arguments[i];
43
- for (var key in source) {
44
- if (Object.prototype.hasOwnProperty.call(source, key)) {
45
- target[key] = source[key];
46
- }
47
- }
48
- }
49
- return target;
50
- };
51
- return _extends.apply(this, arguments);
52
- }
53
-
54
- function _objectWithoutPropertiesLoose(source, excluded) {
55
- if (source == null) return {};
56
- var target = {};
57
- var sourceKeys = Object.keys(source);
58
- var key, i;
59
- for (i = 0; i < sourceKeys.length; i++) {
60
- key = sourceKeys[i];
61
- if (excluded.indexOf(key) >= 0) continue;
62
- target[key] = source[key];
63
- }
64
- return target;
65
- }
66
-
67
- const _excluded$6 = ["checked", "disabled", "error", "groupName", "id", "testId"];
43
+ const _excluded$7 = ["checked", "disabled", "error", "groupName", "id", "testId"];
68
44
  function mapCheckedToAriaChecked(value) {
69
45
  switch (value) {
70
46
  case true:
@@ -96,7 +72,7 @@ const CheckboxCore = React__namespace.forwardRef(function CheckboxCore(props, re
96
72
  id,
97
73
  testId
98
74
  } = props,
99
- sharedProps = _objectWithoutPropertiesLoose(props, _excluded$6);
75
+ sharedProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$7);
100
76
  const innerRef = React__namespace.useRef(null);
101
77
  React__namespace.useEffect(() => {
102
78
  if (innerRef.current != null) {
@@ -118,7 +94,7 @@ const CheckboxCore = React__namespace.forwardRef(function CheckboxCore(props, re
118
94
  }]
119
95
  });
120
96
  const ariaChecked = mapCheckedToAriaChecked(checked);
121
- return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$2, _extends({}, sharedProps, {
97
+ return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$2, _extends__default["default"]({}, sharedProps, {
122
98
  ref: node => {
123
99
  innerRef.current = node;
124
100
  if (typeof ref === "function") {
@@ -185,11 +161,11 @@ const colors$1 = {
185
161
  active: activeRed
186
162
  }
187
163
  };
188
- const styles$5 = {};
164
+ const styles$6 = {};
189
165
  const _generateStyles$1 = (checked, error) => {
190
166
  const styleKey = `${String(checked)}-${String(error)}`;
191
- if (styles$5[styleKey]) {
192
- return styles$5[styleKey];
167
+ if (styles$6[styleKey]) {
168
+ return styles$6[styleKey];
193
169
  }
194
170
  const palette = error ? colors$1.error : colors$1.default;
195
171
  let newStyles = {};
@@ -233,11 +209,11 @@ const _generateStyles$1 = (checked, error) => {
233
209
  }
234
210
  };
235
211
  }
236
- styles$5[styleKey] = aphrodite.StyleSheet.create(newStyles);
237
- return styles$5[styleKey];
212
+ styles$6[styleKey] = aphrodite.StyleSheet.create(newStyles);
213
+ return styles$6[styleKey];
238
214
  };
239
215
 
240
- const _excluded$5 = ["checked", "disabled", "error", "groupName", "id", "testId"];
216
+ const _excluded$6 = ["checked", "disabled", "error", "groupName", "id", "testId"];
241
217
  const {
242
218
  blue,
243
219
  red,
@@ -260,10 +236,10 @@ const RadioCore = React__namespace.forwardRef(function RadioCore(props, ref) {
260
236
  id,
261
237
  testId
262
238
  } = props,
263
- sharedProps = _objectWithoutPropertiesLoose(props, _excluded$5);
239
+ sharedProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$6);
264
240
  const stateStyles = _generateStyles(checked, error);
265
241
  const defaultStyle = [sharedStyles.inputReset, sharedStyles.default, !disabled && stateStyles.default, disabled && sharedStyles.disabled];
266
- return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$1, _extends({}, sharedProps, {
242
+ return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(StyledInput$1, _extends__default["default"]({}, sharedProps, {
267
243
  type: "radio",
268
244
  "aria-invalid": error,
269
245
  checked: checked != null ? checked : undefined,
@@ -327,11 +303,11 @@ const colors = {
327
303
  active: wonderBlocksTokens.color.activeRed
328
304
  }
329
305
  };
330
- const styles$4 = {};
306
+ const styles$5 = {};
331
307
  const _generateStyles = (checked, error) => {
332
308
  const styleKey = `${String(checked)}-${String(error)}`;
333
- if (styles$4[styleKey]) {
334
- return styles$4[styleKey];
309
+ if (styles$5[styleKey]) {
310
+ return styles$5[styleKey];
335
311
  }
336
312
  const palette = error ? colors.error : colors.default;
337
313
  let newStyles = {};
@@ -376,11 +352,11 @@ const _generateStyles = (checked, error) => {
376
352
  }
377
353
  };
378
354
  }
379
- styles$4[styleKey] = aphrodite.StyleSheet.create(newStyles);
380
- return styles$4[styleKey];
355
+ styles$5[styleKey] = aphrodite.StyleSheet.create(newStyles);
356
+ return styles$5[styleKey];
381
357
  };
382
358
 
383
- const _excluded$4 = ["checked", "description", "disabled", "error", "id", "label", "onChange", "style", "className", "variant"];
359
+ const _excluded$5 = ["checked", "description", "disabled", "error", "id", "label", "onChange", "style", "className", "variant"];
384
360
  const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props, ref) {
385
361
  const {
386
362
  checked,
@@ -394,7 +370,7 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
394
370
  className,
395
371
  variant
396
372
  } = props,
397
- coreProps = _objectWithoutPropertiesLoose(props, _excluded$4);
373
+ coreProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$5);
398
374
  const handleClick = () => {
399
375
  if (variant === "radio" && checked) {
400
376
  return;
@@ -410,14 +386,14 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
410
386
  };
411
387
  const getLabel = id => {
412
388
  return React__namespace.createElement(wonderBlocksTypography.LabelMedium, {
413
- style: [styles$3.label, disabled && styles$3.disabledLabel]
389
+ style: [styles$4.label, disabled && styles$4.disabledLabel]
414
390
  }, React__namespace.createElement("label", {
415
391
  htmlFor: id
416
392
  }, label));
417
393
  };
418
394
  const getDescription = id => {
419
395
  return React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
420
- style: styles$3.description,
396
+ style: styles$4.description,
421
397
  id: id
422
398
  }, description);
423
399
  };
@@ -432,9 +408,9 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
432
408
  style: style,
433
409
  className: className
434
410
  }, React__namespace.createElement(wonderBlocksCore.View, {
435
- style: styles$3.wrapper,
411
+ style: styles$4.wrapper,
436
412
  tabIndex: -1
437
- }, React__namespace.createElement(ChoiceCore, _extends({}, coreProps, {
413
+ }, React__namespace.createElement(ChoiceCore, _extends__default["default"]({}, coreProps, {
438
414
  id: uniqueId,
439
415
  checked: checked,
440
416
  "aria-describedby": descriptionId,
@@ -447,7 +423,7 @@ const ChoiceInternal = React__namespace.forwardRef(function ChoiceInternal(props
447
423
  }), label && getLabel(uniqueId)), description && getDescription(descriptionId));
448
424
  });
449
425
  });
450
- const styles$3 = aphrodite.StyleSheet.create({
426
+ const styles$4 = aphrodite.StyleSheet.create({
451
427
  wrapper: {
452
428
  flexDirection: "row",
453
429
  alignItems: "flex-start",
@@ -471,7 +447,7 @@ const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
471
447
  disabled = false,
472
448
  error = false
473
449
  } = props;
474
- return React__namespace.createElement(ChoiceInternal, _extends({}, props, {
450
+ return React__namespace.createElement(ChoiceInternal, _extends__default["default"]({}, props, {
475
451
  variant: "checkbox",
476
452
  disabled: disabled,
477
453
  error: error,
@@ -479,14 +455,14 @@ const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
479
455
  }));
480
456
  });
481
457
 
482
- const _excluded$3 = ["disabled", "error"];
458
+ const _excluded$4 = ["disabled", "error"];
483
459
  const Radio = React__namespace.forwardRef(function Radio(props, ref) {
484
460
  const {
485
461
  disabled = false,
486
462
  error = false
487
463
  } = props,
488
- otherProps = _objectWithoutPropertiesLoose(props, _excluded$3);
489
- return React__namespace.createElement(ChoiceInternal, _extends({}, otherProps, {
464
+ otherProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$4);
465
+ return React__namespace.createElement(ChoiceInternal, _extends__default["default"]({}, otherProps, {
490
466
  variant: "radio",
491
467
  disabled: disabled,
492
468
  error: error,
@@ -494,7 +470,7 @@ const Radio = React__namespace.forwardRef(function Radio(props, ref) {
494
470
  }));
495
471
  });
496
472
 
497
- const _excluded$2 = ["checked", "disabled", "onChange", "value", "variant"];
473
+ const _excluded$3 = ["checked", "disabled", "onChange", "value", "variant"];
498
474
  const Choice = React__namespace.forwardRef(function Choice(props, ref) {
499
475
  const {
500
476
  checked = false,
@@ -502,7 +478,7 @@ const Choice = React__namespace.forwardRef(function Choice(props, ref) {
502
478
  onChange = () => {},
503
479
  variant
504
480
  } = props,
505
- remainingProps = _objectWithoutPropertiesLoose(props, _excluded$2);
481
+ remainingProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded$3);
506
482
  const getChoiceComponent = variant => {
507
483
  if (variant === "checkbox") {
508
484
  return Checkbox;
@@ -511,7 +487,7 @@ const Choice = React__namespace.forwardRef(function Choice(props, ref) {
511
487
  }
512
488
  };
513
489
  const ChoiceComponent = getChoiceComponent(variant);
514
- return React__namespace.createElement(ChoiceComponent, _extends({}, remainingProps, {
490
+ return React__namespace.createElement(ChoiceComponent, _extends__default["default"]({}, remainingProps, {
515
491
  checked: checked,
516
492
  disabled: disabled,
517
493
  onChange: onChange,
@@ -519,7 +495,7 @@ const Choice = React__namespace.forwardRef(function Choice(props, ref) {
519
495
  }));
520
496
  });
521
497
 
522
- const styles$2 = aphrodite.StyleSheet.create({
498
+ const styles$3 = aphrodite.StyleSheet.create({
523
499
  fieldset: {
524
500
  border: "none",
525
501
  padding: 0,
@@ -567,16 +543,16 @@ const CheckboxGroup = React__namespace.forwardRef(function CheckboxGroup(props,
567
543
  const allChildren = React__namespace.Children.toArray(children).filter(Boolean);
568
544
  return React__namespace.createElement(StyledFieldset$1, {
569
545
  "data-testid": testId,
570
- style: styles$2.fieldset,
546
+ style: styles$3.fieldset,
571
547
  ref: ref
572
548
  }, React__namespace.createElement(wonderBlocksCore.View, {
573
549
  style: style
574
550
  }, label && React__namespace.createElement(StyledLegend$1, {
575
- style: styles$2.legend
551
+ style: styles$3.legend
576
552
  }, React__namespace.createElement(wonderBlocksTypography.LabelMedium, null, label)), description && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
577
- style: styles$2.description
553
+ style: styles$3.description
578
554
  }, description), errorMessage && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
579
- style: styles$2.error
555
+ style: styles$3.error
580
556
  }, errorMessage), (label || description || errorMessage) && React__namespace.createElement(wonderBlocksLayout.Strut, {
581
557
  size: wonderBlocksTokens.spacing.small_12
582
558
  }), allChildren.map((child, index) => {
@@ -592,7 +568,7 @@ const CheckboxGroup = React__namespace.forwardRef(function CheckboxGroup(props,
592
568
  id: `${groupName}-${value}`,
593
569
  key: value,
594
570
  onChange: () => handleChange(value, checked),
595
- style: [index > 0 && styles$2.defaultLineGap, style],
571
+ style: [index > 0 && styles$3.defaultLineGap, style],
596
572
  variant: "checkbox"
597
573
  });
598
574
  })));
@@ -615,16 +591,16 @@ const RadioGroup = React__namespace.forwardRef(function RadioGroup(props, ref) {
615
591
  const allChildren = React__namespace.Children.toArray(children).filter(Boolean);
616
592
  return React__namespace.createElement(StyledFieldset, {
617
593
  "data-testid": testId,
618
- style: styles$2.fieldset,
594
+ style: styles$3.fieldset,
619
595
  ref: ref
620
596
  }, React__namespace.createElement(wonderBlocksCore.View, {
621
597
  style: style
622
598
  }, label && React__namespace.createElement(StyledLegend, {
623
- style: styles$2.legend
599
+ style: styles$3.legend
624
600
  }, React__namespace.createElement(wonderBlocksTypography.LabelMedium, null, label)), description && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
625
- style: styles$2.description
601
+ style: styles$3.description
626
602
  }, description), errorMessage && React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
627
- style: styles$2.error
603
+ style: styles$3.error
628
604
  }, errorMessage), (label || description || errorMessage) && React__namespace.createElement(wonderBlocksLayout.Strut, {
629
605
  size: wonderBlocksTokens.spacing.small_12
630
606
  }), allChildren.map((child, index) => {
@@ -640,14 +616,14 @@ const RadioGroup = React__namespace.forwardRef(function RadioGroup(props, ref) {
640
616
  id: `${groupName}-${value}`,
641
617
  key: value,
642
618
  onChange: () => onChange(value),
643
- style: [index > 0 && styles$2.defaultLineGap, style],
619
+ style: [index > 0 && styles$3.defaultLineGap, style],
644
620
  variant: "radio"
645
621
  });
646
622
  })));
647
623
  });
648
624
 
649
- const _excluded$1 = ["id", "type", "value", "name", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoFocus", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
650
- const defaultErrorMessage = "This field is required.";
625
+ const _excluded$2 = ["id", "type", "value", "name", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoFocus", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
626
+ const defaultErrorMessage$1 = "This field is required.";
651
627
  const StyledInput = wonderBlocksCore.addStyle("input");
652
628
  class TextField extends React__namespace.Component {
653
629
  constructor(props) {
@@ -672,7 +648,7 @@ class TextField extends React__namespace.Component {
672
648
  }
673
649
  });
674
650
  } else if (required) {
675
- const requiredString = typeof required === "string" ? required : defaultErrorMessage;
651
+ const requiredString = typeof required === "string" ? required : defaultErrorMessage$1;
676
652
  const maybeError = newValue ? null : requiredString;
677
653
  this.setState({
678
654
  error: maybeError
@@ -742,12 +718,12 @@ class TextField extends React__namespace.Component {
742
718
  autoComplete,
743
719
  forwardedRef
744
720
  } = _this$props,
745
- otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
721
+ otherProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$2);
746
722
  return React__namespace.createElement(wonderBlocksCore.IDProvider, {
747
723
  id: id,
748
724
  scope: "text-field"
749
- }, uniqueId => React__namespace.createElement(StyledInput, _extends({
750
- style: [styles$1.input, wonderBlocksTypography.styles.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], !!this.state.error && styles$1.error, style && style],
725
+ }, uniqueId => React__namespace.createElement(StyledInput, _extends__default["default"]({
726
+ style: [styles$2.input, wonderBlocksTypography.styles.LabelMedium, styles$2.default, disabled ? styles$2.disabled : this.state.focused ? [styles$2.focused, light && styles$2.defaultLight] : !!this.state.error && [styles$2.error, light && styles$2.errorLight], !!this.state.error && styles$2.error, style && style],
751
727
  id: uniqueId,
752
728
  type: type,
753
729
  placeholder: placeholder,
@@ -773,7 +749,7 @@ TextField.defaultProps = {
773
749
  disabled: false,
774
750
  light: false
775
751
  };
776
- const styles$1 = aphrodite.StyleSheet.create({
752
+ const styles$2 = aphrodite.StyleSheet.create({
777
753
  input: {
778
754
  width: "100%",
779
755
  height: 40,
@@ -823,7 +799,7 @@ const styles$1 = aphrodite.StyleSheet.create({
823
799
  boxShadow: `0px 0px 0px 1px ${wonderBlocksTokens.color.red}, 0px 0px 0px 2px ${wonderBlocksTokens.color.white}`
824
800
  }
825
801
  });
826
- var TextField$1 = React__namespace.forwardRef((props, ref) => React__namespace.createElement(TextField, _extends({}, props, {
802
+ var TextField$1 = React__namespace.forwardRef((props, ref) => React__namespace.createElement(TextField, _extends__default["default"]({}, props, {
827
803
  forwardedRef: ref
828
804
  })));
829
805
 
@@ -837,11 +813,11 @@ class FieldHeading extends React__namespace.Component {
837
813
  testId
838
814
  } = this.props;
839
815
  const requiredIcon = React__namespace.createElement(StyledSpan, {
840
- style: styles.required,
816
+ style: styles$1.required,
841
817
  "aria-hidden": true
842
818
  }, " ", "*");
843
819
  return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksTypography.LabelMedium, {
844
- style: styles.label,
820
+ style: styles$1.label,
845
821
  tag: "label",
846
822
  htmlFor: id && `${id}-field`,
847
823
  testId: testId && `${testId}-label`
@@ -858,7 +834,7 @@ class FieldHeading extends React__namespace.Component {
858
834
  return null;
859
835
  }
860
836
  return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
861
- style: styles.description,
837
+ style: styles$1.description,
862
838
  testId: testId && `${testId}-description`
863
839
  }, description), React__namespace.createElement(wonderBlocksLayout.Strut, {
864
840
  size: wonderBlocksTokens.spacing.xxxSmall_4
@@ -876,7 +852,7 @@ class FieldHeading extends React__namespace.Component {
876
852
  return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksLayout.Strut, {
877
853
  size: wonderBlocksTokens.spacing.small_12
878
854
  }), React__namespace.createElement(wonderBlocksTypography.LabelSmall, {
879
- style: styles.error,
855
+ style: styles$1.error,
880
856
  role: "alert",
881
857
  id: id && `${id}-error`,
882
858
  testId: testId && `${testId}-error`
@@ -894,7 +870,7 @@ class FieldHeading extends React__namespace.Component {
894
870
  }), field, this.maybeRenderError());
895
871
  }
896
872
  }
897
- const styles = aphrodite.StyleSheet.create({
873
+ const styles$1 = aphrodite.StyleSheet.create({
898
874
  label: {
899
875
  color: wonderBlocksTokens.color.offBlack
900
876
  },
@@ -909,7 +885,7 @@ const styles = aphrodite.StyleSheet.create({
909
885
  }
910
886
  });
911
887
 
912
- const _excluded = ["id", "type", "label", "description", "value", "disabled", "required", "validate", "onChange", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "ariaDescribedby", "onValidate", "onFocus", "onBlur"];
888
+ const _excluded$1 = ["id", "type", "label", "description", "value", "disabled", "required", "validate", "onChange", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "ariaDescribedby", "onValidate", "onFocus", "onBlur"];
913
889
  class LabeledTextField extends React__namespace.Component {
914
890
  constructor(props) {
915
891
  super(props);
@@ -976,7 +952,7 @@ class LabeledTextField extends React__namespace.Component {
976
952
  forwardedRef,
977
953
  ariaDescribedby
978
954
  } = _this$props,
979
- otherProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
955
+ otherProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$1);
980
956
  return React__namespace.createElement(wonderBlocksCore.IDProvider, {
981
957
  id: id,
982
958
  scope: "labeled-text-field"
@@ -984,7 +960,7 @@ class LabeledTextField extends React__namespace.Component {
984
960
  id: uniqueId,
985
961
  testId: testId,
986
962
  style: style,
987
- field: React__namespace.createElement(TextField$1, _extends({
963
+ field: React__namespace.createElement(TextField$1, _extends__default["default"]({
988
964
  id: `${uniqueId}-field`,
989
965
  "aria-describedby": ariaDescribedby ? ariaDescribedby : `${uniqueId}-error`,
990
966
  "aria-required": required ? "true" : "false",
@@ -1017,13 +993,214 @@ LabeledTextField.defaultProps = {
1017
993
  disabled: false,
1018
994
  light: false
1019
995
  };
1020
- var labeledTextField = React__namespace.forwardRef((props, ref) => React__namespace.createElement(LabeledTextField, _extends({}, props, {
996
+ var labeledTextField = React__namespace.forwardRef((props, ref) => React__namespace.createElement(LabeledTextField, _extends__default["default"]({}, props, {
1021
997
  forwardedRef: ref
1022
998
  })));
1023
999
 
1000
+ const _excluded = ["onChange", "value", "placeholder", "disabled", "id", "testId", "style", "readOnly", "autoComplete", "name", "className", "autoFocus", "rows", "spellCheck", "wrap", "minLength", "maxLength", "onClick", "onKeyDown", "onKeyUp", "onFocus", "onBlur", "validate", "onValidate", "required", "resizeType", "light"];
1001
+ const defaultErrorMessage = "This field is required.";
1002
+ const StyledTextArea = wonderBlocksCore.addStyle("textarea");
1003
+ const TextArea = React__namespace.forwardRef(function TextArea(props, ref) {
1004
+ const {
1005
+ onChange,
1006
+ value,
1007
+ placeholder,
1008
+ disabled,
1009
+ id,
1010
+ testId,
1011
+ style,
1012
+ readOnly,
1013
+ autoComplete,
1014
+ name,
1015
+ className,
1016
+ autoFocus,
1017
+ rows,
1018
+ spellCheck,
1019
+ wrap,
1020
+ minLength,
1021
+ maxLength,
1022
+ onClick,
1023
+ onKeyDown,
1024
+ onKeyUp,
1025
+ onFocus,
1026
+ onBlur,
1027
+ validate,
1028
+ onValidate,
1029
+ required,
1030
+ resizeType,
1031
+ light
1032
+ } = props,
1033
+ otherProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded);
1034
+ const [error, setError] = React__namespace.useState(null);
1035
+ const ids = wonderBlocksCore.useUniqueIdWithMock("text-area");
1036
+ const uniqueId = id != null ? id : ids.get("id");
1037
+ const handleChange = event => {
1038
+ const newValue = event.target.value;
1039
+ onChange(newValue);
1040
+ handleValidation(newValue);
1041
+ };
1042
+ const handleValidation = newValue => {
1043
+ if (validate) {
1044
+ const error = validate(newValue) || null;
1045
+ setError(error);
1046
+ if (onValidate) {
1047
+ onValidate(error);
1048
+ }
1049
+ } else if (required) {
1050
+ const requiredString = typeof required === "string" ? required : defaultErrorMessage;
1051
+ const error = newValue ? null : requiredString;
1052
+ setError(error);
1053
+ if (onValidate) {
1054
+ onValidate(error);
1055
+ }
1056
+ }
1057
+ };
1058
+ wonderBlocksCore.useOnMountEffect(() => {
1059
+ if (value !== "") {
1060
+ handleValidation(value);
1061
+ }
1062
+ });
1063
+ const getStyles = () => {
1064
+ const baseStyles = [styles.textarea, wonderBlocksTypography.styles.LabelMedium, resizeType && resizeStyles[resizeType]];
1065
+ const defaultStyles = [styles.default, !disabled && styles.defaultFocus, disabled && styles.disabled, !!error && styles.error];
1066
+ const lightStyles = [styles.light, !disabled && styles.lightFocus, disabled && styles.lightDisabled, !!error && styles.lightError];
1067
+ return [...baseStyles, ...(light ? lightStyles : defaultStyles)];
1068
+ };
1069
+ return React__namespace.createElement(wonderBlocksCore.View, {
1070
+ style: {
1071
+ width: "100%"
1072
+ }
1073
+ }, React__namespace.createElement(StyledTextArea, _extends__default["default"]({
1074
+ id: uniqueId,
1075
+ "data-testid": testId,
1076
+ ref: ref,
1077
+ className: className,
1078
+ style: [...getStyles(), style],
1079
+ value: value,
1080
+ onChange: handleChange,
1081
+ placeholder: placeholder,
1082
+ disabled: disabled,
1083
+ readOnly: readOnly,
1084
+ autoComplete: autoComplete,
1085
+ name: name,
1086
+ autoFocus: autoFocus,
1087
+ rows: rows,
1088
+ spellCheck: spellCheck,
1089
+ wrap: wrap,
1090
+ minLength: minLength,
1091
+ maxLength: maxLength,
1092
+ onClick: onClick,
1093
+ onKeyDown: onKeyDown,
1094
+ onKeyUp: onKeyUp,
1095
+ onFocus: onFocus,
1096
+ onBlur: onBlur,
1097
+ required: !!required
1098
+ }, otherProps, {
1099
+ "aria-invalid": !!error
1100
+ })));
1101
+ });
1102
+ const styles = aphrodite.StyleSheet.create({
1103
+ textarea: {
1104
+ borderRadius: wonderBlocksTokens.border.radius.medium_4,
1105
+ boxSizing: "border-box",
1106
+ padding: `10px ${wonderBlocksTokens.spacing.medium_16}px`,
1107
+ minHeight: "1em"
1108
+ },
1109
+ default: {
1110
+ background: wonderBlocksTokens.color.white,
1111
+ border: `1px solid ${wonderBlocksTokens.color.offBlack50}`,
1112
+ color: wonderBlocksTokens.color.offBlack,
1113
+ "::placeholder": {
1114
+ color: wonderBlocksTokens.color.offBlack64
1115
+ }
1116
+ },
1117
+ defaultFocus: {
1118
+ ":focus-visible": {
1119
+ borderColor: wonderBlocksTokens.color.blue,
1120
+ outline: `1px solid ${wonderBlocksTokens.color.blue}`,
1121
+ outlineOffset: 0
1122
+ }
1123
+ },
1124
+ disabled: {
1125
+ background: wonderBlocksTokens.color.offWhite,
1126
+ border: `1px solid ${wonderBlocksTokens.color.offBlack16}`,
1127
+ color: wonderBlocksTokens.color.offBlack64,
1128
+ "::placeholder": {
1129
+ color: wonderBlocksTokens.color.offBlack64
1130
+ },
1131
+ cursor: "not-allowed"
1132
+ },
1133
+ error: {
1134
+ background: wonderBlocksTokens.color.fadedRed8,
1135
+ border: `1px solid ${wonderBlocksTokens.color.red}`,
1136
+ color: wonderBlocksTokens.color.offBlack,
1137
+ "::placeholder": {
1138
+ color: wonderBlocksTokens.color.offBlack64
1139
+ },
1140
+ ":focus-visible": {
1141
+ outlineColor: wonderBlocksTokens.color.red,
1142
+ borderColor: wonderBlocksTokens.color.red
1143
+ }
1144
+ },
1145
+ light: {
1146
+ background: wonderBlocksTokens.color.white,
1147
+ border: `1px solid ${wonderBlocksTokens.color.offBlack16}`,
1148
+ color: wonderBlocksTokens.color.offBlack,
1149
+ "::placeholder": {
1150
+ color: wonderBlocksTokens.color.offBlack64
1151
+ }
1152
+ },
1153
+ lightFocus: {
1154
+ ":focus-visible": {
1155
+ outline: `1px solid ${wonderBlocksTokens.color.blue}`,
1156
+ outlineOffset: 0,
1157
+ borderColor: wonderBlocksTokens.color.blue,
1158
+ boxShadow: `0px 0px 0px 2px ${wonderBlocksTokens.color.blue}, 0px 0px 0px 3px ${wonderBlocksTokens.color.white}`
1159
+ }
1160
+ },
1161
+ lightDisabled: {
1162
+ backgroundColor: "transparent",
1163
+ border: `1px solid ${wonderBlocksTokens.color.white32}`,
1164
+ color: wonderBlocksTokens.color.white64,
1165
+ "::placeholder": {
1166
+ color: wonderBlocksTokens.color.white64
1167
+ },
1168
+ cursor: "not-allowed"
1169
+ },
1170
+ lightError: {
1171
+ background: wonderBlocksTokens.color.fadedRed8,
1172
+ border: `1px solid ${wonderBlocksTokens.color.red}`,
1173
+ boxShadow: `0px 0px 0px 1px ${wonderBlocksTokens.color.red}, 0px 0px 0px 2px ${wonderBlocksTokens.color.white}`,
1174
+ color: wonderBlocksTokens.color.offBlack,
1175
+ "::placeholder": {
1176
+ color: wonderBlocksTokens.color.offBlack64
1177
+ },
1178
+ ":focus-visible": {
1179
+ outlineColor: wonderBlocksTokens.color.red,
1180
+ borderColor: wonderBlocksTokens.color.red,
1181
+ boxShadow: `0px 0px 0px 2px ${wonderBlocksTokens.color.red}, 0px 0px 0px 3px ${wonderBlocksTokens.color.white}`
1182
+ }
1183
+ }
1184
+ });
1185
+ const resizeStyles = aphrodite.StyleSheet.create({
1186
+ both: {
1187
+ resize: "both"
1188
+ },
1189
+ none: {
1190
+ resize: "none"
1191
+ },
1192
+ horizontal: {
1193
+ resize: "horizontal"
1194
+ },
1195
+ vertical: {
1196
+ resize: "vertical"
1197
+ }
1198
+ });
1199
+
1024
1200
  exports.Checkbox = Checkbox;
1025
1201
  exports.CheckboxGroup = CheckboxGroup;
1026
1202
  exports.Choice = Choice;
1027
1203
  exports.LabeledTextField = labeledTextField;
1028
1204
  exports.RadioGroup = RadioGroup;
1205
+ exports.TextArea = TextArea;
1029
1206
  exports.TextField = TextField$1;