@khanacademy/wonder-blocks-form 4.0.4 → 4.0.6

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
@@ -52,20 +52,6 @@ function _extends() {
52
52
  return _extends.apply(this, arguments);
53
53
  }
54
54
 
55
- function _setPrototypeOf(o, p) {
56
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
57
- o.__proto__ = p;
58
- return o;
59
- };
60
- return _setPrototypeOf(o, p);
61
- }
62
-
63
- function _inheritsLoose(subClass, superClass) {
64
- subClass.prototype = Object.create(superClass.prototype);
65
- subClass.prototype.constructor = subClass;
66
- _setPrototypeOf(subClass, superClass);
67
- }
68
-
69
55
  function _objectWithoutPropertiesLoose(source, excluded) {
70
56
  if (source == null) return {};
71
57
  var target = {};
@@ -93,18 +79,14 @@ const StyledInput$1 = wonderBlocksCore.addStyle("input");
93
79
  const checkboxCheck = {
94
80
  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"
95
81
  };
96
- let CheckboxCore = function (_React$Component) {
97
- _inheritsLoose(CheckboxCore, _React$Component);
98
- function CheckboxCore(...args) {
99
- var _this;
100
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
101
- _this.handleChange = () => {
82
+ class CheckboxCore extends React__namespace.Component {
83
+ constructor(...args) {
84
+ super(...args);
85
+ this.handleChange = () => {
102
86
  return;
103
87
  };
104
- return _this;
105
88
  }
106
- var _proto = CheckboxCore.prototype;
107
- _proto.render = function render() {
89
+ render() {
108
90
  const _this$props = this.props,
109
91
  {
110
92
  checked,
@@ -138,9 +120,8 @@ let CheckboxCore = function (_React$Component) {
138
120
  size: "small",
139
121
  style: sharedStyles$1.checkIcon
140
122
  }));
141
- };
142
- return CheckboxCore;
143
- }(React__namespace.Component);
123
+ }
124
+ }
144
125
  const size$1 = 16;
145
126
  const sharedStyles$1 = aphrodite.StyleSheet.create({
146
127
  inputReset: {
@@ -242,18 +223,14 @@ const {
242
223
  offBlack50
243
224
  } = Color__default["default"];
244
225
  const StyledInput = wonderBlocksCore.addStyle("input");
245
- let RadioCore = function (_React$Component) {
246
- _inheritsLoose(RadioCore, _React$Component);
247
- function RadioCore(...args) {
248
- var _this;
249
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
250
- _this.handleChange = () => {
226
+ class RadioCore extends React__namespace.Component {
227
+ constructor(...args) {
228
+ super(...args);
229
+ this.handleChange = () => {
251
230
  return;
252
231
  };
253
- return _this;
254
232
  }
255
- var _proto = RadioCore.prototype;
256
- _proto.render = function render() {
233
+ render() {
257
234
  const _this$props = this.props,
258
235
  {
259
236
  checked,
@@ -284,9 +261,8 @@ let RadioCore = function (_React$Component) {
284
261
  }, props)), disabled && checked && React__namespace.createElement("span", {
285
262
  style: disabledChecked
286
263
  }));
287
- };
288
- return RadioCore;
289
- }(React__namespace.Component);
264
+ }
265
+ }
290
266
  const size = 16;
291
267
  const disabledChecked = {
292
268
  position: "absolute",
@@ -384,36 +360,32 @@ const _generateStyles = (checked, error) => {
384
360
  };
385
361
 
386
362
  const _excluded$2 = ["label", "description", "onChange", "style", "className", "variant"];
387
- let ChoiceInternal = function (_React$Component) {
388
- _inheritsLoose(ChoiceInternal, _React$Component);
389
- function ChoiceInternal(...args) {
390
- var _this;
391
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
392
- _this.handleLabelClick = event => {
363
+ class ChoiceInternal extends React__namespace.Component {
364
+ constructor(...args) {
365
+ super(...args);
366
+ this.handleLabelClick = event => {
393
367
  event.preventDefault();
394
368
  };
395
- _this.handleClick = () => {
369
+ this.handleClick = () => {
396
370
  const {
397
371
  checked,
398
372
  onChange,
399
373
  variant
400
- } = _this.props;
374
+ } = this.props;
401
375
  if (variant === "radio" && checked) {
402
376
  return;
403
377
  }
404
378
  onChange(!checked);
405
379
  };
406
- return _this;
407
380
  }
408
- var _proto = ChoiceInternal.prototype;
409
- _proto.getChoiceCoreComponent = function getChoiceCoreComponent() {
381
+ getChoiceCoreComponent() {
410
382
  if (this.props.variant === "radio") {
411
383
  return RadioCore;
412
384
  } else {
413
385
  return CheckboxCore;
414
386
  }
415
- };
416
- _proto.getLabel = function getLabel() {
387
+ }
388
+ getLabel() {
417
389
  const {
418
390
  disabled,
419
391
  id,
@@ -425,8 +397,8 @@ let ChoiceInternal = function (_React$Component) {
425
397
  htmlFor: id,
426
398
  onClick: this.handleLabelClick
427
399
  }, label));
428
- };
429
- _proto.getDescription = function getDescription(id) {
400
+ }
401
+ getDescription(id) {
430
402
  const {
431
403
  description
432
404
  } = this.props;
@@ -434,8 +406,8 @@ let ChoiceInternal = function (_React$Component) {
434
406
  style: styles$3.description,
435
407
  id: id
436
408
  }, description);
437
- };
438
- _proto.render = function render() {
409
+ }
410
+ render() {
439
411
  const _this$props = this.props,
440
412
  {
441
413
  label,
@@ -471,9 +443,8 @@ let ChoiceInternal = function (_React$Component) {
471
443
  }), label && this.getLabel());
472
444
  }), description && this.getDescription(descriptionId));
473
445
  });
474
- };
475
- return ChoiceInternal;
476
- }(React__namespace.Component);
446
+ }
447
+ }
477
448
  ChoiceInternal.defaultProps = {
478
449
  checked: false,
479
450
  disabled: false,
@@ -499,57 +470,40 @@ const styles$3 = aphrodite.StyleSheet.create({
499
470
  }
500
471
  });
501
472
 
502
- let Checkbox = function (_React$Component) {
503
- _inheritsLoose(Checkbox, _React$Component);
504
- function Checkbox() {
505
- return _React$Component.apply(this, arguments) || this;
506
- }
507
- var _proto = Checkbox.prototype;
508
- _proto.render = function render() {
473
+ class Checkbox extends React__namespace.Component {
474
+ render() {
509
475
  return React__namespace.createElement(ChoiceInternal, _extends({
510
476
  variant: "checkbox"
511
477
  }, this.props));
512
- };
513
- return Checkbox;
514
- }(React__namespace.Component);
478
+ }
479
+ }
515
480
  Checkbox.defaultProps = {
516
481
  disabled: false,
517
482
  error: false
518
483
  };
519
484
 
520
- let Radio = function (_React$Component) {
521
- _inheritsLoose(Radio, _React$Component);
522
- function Radio() {
523
- return _React$Component.apply(this, arguments) || this;
524
- }
525
- var _proto = Radio.prototype;
526
- _proto.render = function render() {
485
+ class Radio extends React__namespace.Component {
486
+ render() {
527
487
  return React__namespace.createElement(ChoiceInternal, _extends({
528
488
  variant: "radio"
529
489
  }, this.props));
530
- };
531
- return Radio;
532
- }(React__namespace.Component);
490
+ }
491
+ }
533
492
  Radio.defaultProps = {
534
493
  disabled: false,
535
494
  error: false
536
495
  };
537
496
 
538
497
  const _excluded$1 = ["value", "variant"];
539
- let Choice = function (_React$Component) {
540
- _inheritsLoose(Choice, _React$Component);
541
- function Choice() {
542
- return _React$Component.apply(this, arguments) || this;
543
- }
544
- var _proto = Choice.prototype;
545
- _proto.getChoiceComponent = function getChoiceComponent(variant) {
498
+ class Choice extends React__namespace.Component {
499
+ getChoiceComponent(variant) {
546
500
  if (variant === "checkbox") {
547
501
  return Checkbox;
548
502
  } else {
549
503
  return Radio;
550
504
  }
551
- };
552
- _proto.render = function render() {
505
+ }
506
+ render() {
553
507
  const _this$props = this.props,
554
508
  {
555
509
  variant
@@ -557,9 +511,8 @@ let Choice = function (_React$Component) {
557
511
  remainingProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
558
512
  const ChoiceComponent = this.getChoiceComponent(variant);
559
513
  return React__namespace.createElement(ChoiceComponent, remainingProps);
560
- };
561
- return Choice;
562
- }(React__namespace.Component);
514
+ }
515
+ }
563
516
  Choice.defaultProps = {
564
517
  checked: false,
565
518
  disabled: false,
@@ -590,26 +543,21 @@ const styles$2 = aphrodite.StyleSheet.create({
590
543
 
591
544
  const StyledFieldset$1 = wonderBlocksCore.addStyle("fieldset");
592
545
  const StyledLegend$1 = wonderBlocksCore.addStyle("legend");
593
- let CheckboxGroup = function (_React$Component) {
594
- _inheritsLoose(CheckboxGroup, _React$Component);
595
- function CheckboxGroup() {
596
- return _React$Component.apply(this, arguments) || this;
597
- }
598
- var _proto = CheckboxGroup.prototype;
599
- _proto.handleChange = function handleChange(changedValue, originalCheckedState) {
546
+ class CheckboxGroup extends React__namespace.Component {
547
+ handleChange(changedValue, originalCheckedState) {
600
548
  const {
601
549
  onChange,
602
550
  selectedValues
603
551
  } = this.props;
604
552
  if (originalCheckedState) {
605
553
  const index = selectedValues.indexOf(changedValue);
606
- const updatedSelection = [].concat(selectedValues.slice(0, index), selectedValues.slice(index + 1));
554
+ const updatedSelection = [...selectedValues.slice(0, index), ...selectedValues.slice(index + 1)];
607
555
  onChange(updatedSelection);
608
556
  } else {
609
- onChange([].concat(selectedValues, [changedValue]));
557
+ onChange([...selectedValues, changedValue]);
610
558
  }
611
- };
612
- _proto.render = function render() {
559
+ }
560
+ render() {
613
561
  const {
614
562
  children,
615
563
  label,
@@ -651,22 +599,16 @@ let CheckboxGroup = function (_React$Component) {
651
599
  variant: "checkbox"
652
600
  });
653
601
  })));
654
- };
655
- return CheckboxGroup;
656
- }(React__namespace.Component);
602
+ }
603
+ }
657
604
 
658
605
  const StyledFieldset = wonderBlocksCore.addStyle("fieldset");
659
606
  const StyledLegend = wonderBlocksCore.addStyle("legend");
660
- let RadioGroup = function (_React$Component) {
661
- _inheritsLoose(RadioGroup, _React$Component);
662
- function RadioGroup() {
663
- return _React$Component.apply(this, arguments) || this;
664
- }
665
- var _proto = RadioGroup.prototype;
666
- _proto.handleChange = function handleChange(changedValue) {
607
+ class RadioGroup extends React__namespace.Component {
608
+ handleChange(changedValue) {
667
609
  this.props.onChange(changedValue);
668
- };
669
- _proto.render = function render() {
610
+ }
611
+ render() {
670
612
  const {
671
613
  children,
672
614
  label,
@@ -708,30 +650,27 @@ let RadioGroup = function (_React$Component) {
708
650
  variant: "radio"
709
651
  });
710
652
  })));
711
- };
712
- return RadioGroup;
713
- }(React__namespace.Component);
653
+ }
654
+ }
714
655
 
715
656
  const _excluded = ["id", "type", "value", "disabled", "onKeyDown", "placeholder", "light", "style", "testId", "readOnly", "autoComplete", "forwardedRef", "onFocus", "onBlur", "onValidate", "validate", "onChange", "required"];
716
657
  const defaultErrorMessage = "This field is required.";
717
- let TextField = function (_React$Component) {
718
- _inheritsLoose(TextField, _React$Component);
719
- function TextField(props) {
720
- var _this;
721
- _this = _React$Component.call(this, props) || this;
722
- _this.state = {
658
+ class TextField extends React__namespace.Component {
659
+ constructor(props) {
660
+ super(props);
661
+ this.state = {
723
662
  error: null,
724
663
  focused: false
725
664
  };
726
- _this.maybeValidate = newValue => {
665
+ this.maybeValidate = newValue => {
727
666
  const {
728
667
  validate,
729
668
  onValidate,
730
669
  required
731
- } = _this.props;
670
+ } = this.props;
732
671
  if (validate) {
733
672
  const maybeError = validate(newValue) || null;
734
- _this.setState({
673
+ this.setState({
735
674
  error: maybeError
736
675
  }, () => {
737
676
  if (onValidate) {
@@ -741,7 +680,7 @@ let TextField = function (_React$Component) {
741
680
  } else if (required) {
742
681
  const requiredString = typeof required === "string" ? required : defaultErrorMessage;
743
682
  const maybeError = newValue ? null : requiredString;
744
- _this.setState({
683
+ this.setState({
745
684
  error: maybeError
746
685
  }, () => {
747
686
  if (onValidate) {
@@ -750,19 +689,19 @@ let TextField = function (_React$Component) {
750
689
  });
751
690
  }
752
691
  };
753
- _this.handleChange = event => {
692
+ this.handleChange = event => {
754
693
  const {
755
694
  onChange
756
- } = _this.props;
695
+ } = this.props;
757
696
  const newValue = event.target.value;
758
- _this.maybeValidate(newValue);
697
+ this.maybeValidate(newValue);
759
698
  onChange(newValue);
760
699
  };
761
- _this.handleFocus = event => {
700
+ this.handleFocus = event => {
762
701
  const {
763
702
  onFocus
764
- } = _this.props;
765
- _this.setState({
703
+ } = this.props;
704
+ this.setState({
766
705
  focused: true
767
706
  }, () => {
768
707
  if (onFocus) {
@@ -770,11 +709,11 @@ let TextField = function (_React$Component) {
770
709
  }
771
710
  });
772
711
  };
773
- _this.handleBlur = event => {
712
+ this.handleBlur = event => {
774
713
  const {
775
714
  onBlur
776
- } = _this.props;
777
- _this.setState({
715
+ } = this.props;
716
+ this.setState({
778
717
  focused: false
779
718
  }, () => {
780
719
  if (onBlur) {
@@ -783,17 +722,15 @@ let TextField = function (_React$Component) {
783
722
  });
784
723
  };
785
724
  if (props.validate && props.value !== "") {
786
- _this.state.error = props.validate(props.value) || null;
725
+ this.state.error = props.validate(props.value) || null;
787
726
  }
788
- return _this;
789
727
  }
790
- var _proto = TextField.prototype;
791
- _proto.componentDidMount = function componentDidMount() {
728
+ componentDidMount() {
792
729
  if (this.props.value !== "") {
793
730
  this.maybeValidate(this.props.value);
794
731
  }
795
- };
796
- _proto.render = function render() {
732
+ }
733
+ render() {
797
734
  const _this$props = this.props,
798
735
  {
799
736
  id,
@@ -826,9 +763,8 @@ let TextField = function (_React$Component) {
826
763
  autoComplete: autoComplete,
827
764
  ref: forwardedRef
828
765
  }, otherProps));
829
- };
830
- return TextField;
831
- }(React__namespace.Component);
766
+ }
767
+ }
832
768
  TextField.defaultProps = {
833
769
  type: "text",
834
770
  disabled: false,
@@ -889,13 +825,8 @@ var TextField$1 = React__namespace.forwardRef((props, ref) => React__namespace.c
889
825
  })));
890
826
 
891
827
  const StyledSpan = wonderBlocksCore.addStyle("span");
892
- let FieldHeading = function (_React$Component) {
893
- _inheritsLoose(FieldHeading, _React$Component);
894
- function FieldHeading() {
895
- return _React$Component.apply(this, arguments) || this;
896
- }
897
- var _proto = FieldHeading.prototype;
898
- _proto.renderLabel = function renderLabel() {
828
+ class FieldHeading extends React__namespace.Component {
829
+ renderLabel() {
899
830
  const {
900
831
  label,
901
832
  id,
@@ -914,8 +845,8 @@ let FieldHeading = function (_React$Component) {
914
845
  }, label, required && requiredIcon), React__namespace.createElement(wonderBlocksLayout.Strut, {
915
846
  size: Spacing__default["default"].xxxSmall_4
916
847
  }));
917
- };
918
- _proto.maybeRenderDescription = function maybeRenderDescription() {
848
+ }
849
+ maybeRenderDescription() {
919
850
  const {
920
851
  description,
921
852
  testId
@@ -929,8 +860,8 @@ let FieldHeading = function (_React$Component) {
929
860
  }, description), React__namespace.createElement(wonderBlocksLayout.Strut, {
930
861
  size: Spacing__default["default"].xxxSmall_4
931
862
  }));
932
- };
933
- _proto.maybeRenderError = function maybeRenderError() {
863
+ }
864
+ maybeRenderError() {
934
865
  const {
935
866
  error,
936
867
  id,
@@ -947,8 +878,8 @@ let FieldHeading = function (_React$Component) {
947
878
  id: id && `${id}-error`,
948
879
  testId: testId && `${testId}-error`
949
880
  }, error));
950
- };
951
- _proto.render = function render() {
881
+ }
882
+ render() {
952
883
  const {
953
884
  field,
954
885
  style
@@ -958,9 +889,8 @@ let FieldHeading = function (_React$Component) {
958
889
  }, this.renderLabel(), this.maybeRenderDescription(), React__namespace.createElement(wonderBlocksLayout.Strut, {
959
890
  size: Spacing__default["default"].xSmall_8
960
891
  }), field, this.maybeRenderError());
961
- };
962
- return FieldHeading;
963
- }(React__namespace.Component);
892
+ }
893
+ }
964
894
  const styles = aphrodite.StyleSheet.create({
965
895
  label: {
966
896
  color: Color__default["default"].offBlack
@@ -976,16 +906,14 @@ const styles = aphrodite.StyleSheet.create({
976
906
  }
977
907
  });
978
908
 
979
- let LabeledTextField = function (_React$Component) {
980
- _inheritsLoose(LabeledTextField, _React$Component);
981
- function LabeledTextField(props) {
982
- var _this;
983
- _this = _React$Component.call(this, props) || this;
984
- _this.handleValidate = errorMessage => {
909
+ class LabeledTextField extends React__namespace.Component {
910
+ constructor(props) {
911
+ super(props);
912
+ this.handleValidate = errorMessage => {
985
913
  const {
986
914
  onValidate
987
- } = _this.props;
988
- _this.setState({
915
+ } = this.props;
916
+ this.setState({
989
917
  error: errorMessage
990
918
  }, () => {
991
919
  if (onValidate) {
@@ -993,11 +921,11 @@ let LabeledTextField = function (_React$Component) {
993
921
  }
994
922
  });
995
923
  };
996
- _this.handleFocus = event => {
924
+ this.handleFocus = event => {
997
925
  const {
998
926
  onFocus
999
- } = _this.props;
1000
- _this.setState({
927
+ } = this.props;
928
+ this.setState({
1001
929
  focused: true
1002
930
  }, () => {
1003
931
  if (onFocus) {
@@ -1005,11 +933,11 @@ let LabeledTextField = function (_React$Component) {
1005
933
  }
1006
934
  });
1007
935
  };
1008
- _this.handleBlur = event => {
936
+ this.handleBlur = event => {
1009
937
  const {
1010
938
  onBlur
1011
- } = _this.props;
1012
- _this.setState({
939
+ } = this.props;
940
+ this.setState({
1013
941
  focused: false
1014
942
  }, () => {
1015
943
  if (onBlur) {
@@ -1017,14 +945,12 @@ let LabeledTextField = function (_React$Component) {
1017
945
  }
1018
946
  });
1019
947
  };
1020
- _this.state = {
948
+ this.state = {
1021
949
  error: null,
1022
950
  focused: false
1023
951
  };
1024
- return _this;
1025
952
  }
1026
- var _proto = LabeledTextField.prototype;
1027
- _proto.render = function render() {
953
+ render() {
1028
954
  const {
1029
955
  id,
1030
956
  type,
@@ -1079,9 +1005,8 @@ let LabeledTextField = function (_React$Component) {
1079
1005
  required: !!required,
1080
1006
  error: !this.state.focused && this.state.error || ""
1081
1007
  }));
1082
- };
1083
- return LabeledTextField;
1084
- }(React__namespace.Component);
1008
+ }
1009
+ }
1085
1010
  LabeledTextField.defaultProps = {
1086
1011
  type: "text",
1087
1012
  disabled: false,
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for index
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import Checkbox from "./components/checkbox";
9
8
  import Choice from "./components/choice";
10
9
  import CheckboxGroup from "./components/checkbox-group";
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for types
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
9
8
  import Choice from "../components/choice";
10
9
  export type ChoiceCoreProps = {|
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-form",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "design": "v1",
5
5
  "description": "Form components for Wonder Blocks.",
6
6
  "main": "dist/index.js",
@@ -16,19 +16,19 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-clickable": "^3.0.4",
19
+ "@khanacademy/wonder-blocks-clickable": "^3.0.6",
20
20
  "@khanacademy/wonder-blocks-color": "^2.0.1",
21
- "@khanacademy/wonder-blocks-core": "^5.0.3",
22
- "@khanacademy/wonder-blocks-icon": "^2.0.4",
23
- "@khanacademy/wonder-blocks-layout": "^2.0.4",
21
+ "@khanacademy/wonder-blocks-core": "^5.0.4",
22
+ "@khanacademy/wonder-blocks-icon": "^2.0.6",
23
+ "@khanacademy/wonder-blocks-layout": "^2.0.6",
24
24
  "@khanacademy/wonder-blocks-spacing": "^4.0.1",
25
- "@khanacademy/wonder-blocks-typography": "^2.0.4"
25
+ "@khanacademy/wonder-blocks-typography": "^2.0.6"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "aphrodite": "^1.2.5",
29
29
  "react": "16.14.0"
30
30
  },
31
31
  "devDependencies": {
32
- "wb-dev-build-settings": "^0.9.3"
32
+ "wb-dev-build-settings": "^0.9.5"
33
33
  }
34
34
  }