@thecb/components 10.9.0-beta.10 → 10.9.0-beta.12

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.cjs.js CHANGED
@@ -26638,34 +26638,45 @@ function _extends$2() {
26638
26638
  _extends$2 = Object.assign || function (target) {
26639
26639
  for (var i = 1; i < arguments.length; i++) {
26640
26640
  var source = arguments[i];
26641
+
26641
26642
  for (var key in source) {
26642
26643
  if (Object.prototype.hasOwnProperty.call(source, key)) {
26643
26644
  target[key] = source[key];
26644
26645
  }
26645
26646
  }
26646
26647
  }
26648
+
26647
26649
  return target;
26648
26650
  };
26651
+
26649
26652
  return _extends$2.apply(this, arguments);
26650
26653
  }
26654
+
26651
26655
  function _objectWithoutPropertiesLoose$1(source, excluded) {
26652
26656
  if (source == null) return {};
26653
26657
  var target = {};
26654
26658
  var sourceKeys = Object.keys(source);
26655
26659
  var key, i;
26660
+
26656
26661
  for (i = 0; i < sourceKeys.length; i++) {
26657
26662
  key = sourceKeys[i];
26658
26663
  if (excluded.indexOf(key) >= 0) continue;
26659
26664
  target[key] = source[key];
26660
26665
  }
26666
+
26661
26667
  return target;
26662
26668
  }
26669
+
26663
26670
  function _objectWithoutProperties$1(source, excluded) {
26664
26671
  if (source == null) return {};
26672
+
26665
26673
  var target = _objectWithoutPropertiesLoose$1(source, excluded);
26674
+
26666
26675
  var key, i;
26676
+
26667
26677
  if (Object.getOwnPropertySymbols) {
26668
26678
  var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
26679
+
26669
26680
  for (i = 0; i < sourceSymbolKeys.length; i++) {
26670
26681
  key = sourceSymbolKeys[i];
26671
26682
  if (excluded.indexOf(key) >= 0) continue;
@@ -26673,37 +26684,48 @@ function _objectWithoutProperties$1(source, excluded) {
26673
26684
  target[key] = source[key];
26674
26685
  }
26675
26686
  }
26687
+
26676
26688
  return target;
26677
26689
  }
26690
+
26678
26691
  function _slicedToArray$1(arr, i) {
26679
26692
  return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _nonIterableRest$1();
26680
26693
  }
26694
+
26681
26695
  function _toConsumableArray$1(arr) {
26682
26696
  return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
26683
26697
  }
26698
+
26684
26699
  function _arrayWithoutHoles$1(arr) {
26685
26700
  if (Array.isArray(arr)) {
26686
26701
  for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
26702
+
26687
26703
  return arr2;
26688
26704
  }
26689
26705
  }
26706
+
26690
26707
  function _arrayWithHoles$1(arr) {
26691
26708
  if (Array.isArray(arr)) return arr;
26692
26709
  }
26710
+
26693
26711
  function _iterableToArray$1(iter) {
26694
26712
  if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
26695
26713
  }
26714
+
26696
26715
  function _iterableToArrayLimit$1(arr, i) {
26697
26716
  if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
26698
26717
  return;
26699
26718
  }
26719
+
26700
26720
  var _arr = [];
26701
26721
  var _n = true;
26702
26722
  var _d = false;
26703
26723
  var _e = undefined;
26724
+
26704
26725
  try {
26705
26726
  for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
26706
26727
  _arr.push(_s.value);
26728
+
26707
26729
  if (i && _arr.length === i) break;
26708
26730
  }
26709
26731
  } catch (err) {
@@ -26716,23 +26738,29 @@ function _iterableToArrayLimit$1(arr, i) {
26716
26738
  if (_d) throw _e;
26717
26739
  }
26718
26740
  }
26741
+
26719
26742
  return _arr;
26720
26743
  }
26744
+
26721
26745
  function _nonIterableSpread$1() {
26722
26746
  throw new TypeError("Invalid attempt to spread non-iterable instance");
26723
26747
  }
26748
+
26724
26749
  function _nonIterableRest$1() {
26725
26750
  throw new TypeError("Invalid attempt to destructure non-iterable instance");
26726
26751
  }
26752
+
26727
26753
  var getUniqueFormatDelimiters = function getUniqueFormatDelimiters(formats, formatChar) {
26728
26754
  return _toConsumableArray$1(new Set(formats.join("").split(formatChar).join("").split("")));
26729
26755
  };
26730
26756
  var format$1 = function format(formatter) {
26731
26757
  return function (value) {
26732
26758
  var usedFormat = formatter.formats[value.length];
26759
+
26733
26760
  if (!usedFormat) {
26734
26761
  return value;
26735
26762
  }
26763
+
26736
26764
  var formatPieces = usedFormat.split(formatter.formatChar);
26737
26765
  var valuePieces = value.split("");
26738
26766
  var zipped = formatPieces.map(function (v, i) {
@@ -26741,6 +26769,7 @@ var format$1 = function format(formatter) {
26741
26769
  return zipped.join("");
26742
26770
  };
26743
26771
  };
26772
+
26744
26773
  var countDelims = function countDelims(formatter, index) {
26745
26774
  var count = 0;
26746
26775
  var format = formatter.formats[index];
@@ -26750,11 +26779,13 @@ var countDelims = function countDelims(formatter, index) {
26750
26779
  });
26751
26780
  return count;
26752
26781
  };
26782
+
26753
26783
  var unformat = function unformat(formatter) {
26754
26784
  return function (formattedValue, formatIndex) {
26755
26785
  if (formatIndex >= formatter.formats.length) {
26756
26786
  return formattedValue;
26757
26787
  }
26788
+
26758
26789
  var format = formatter.formats[formatIndex];
26759
26790
  return formattedValue.split("").filter(function (_, i) {
26760
26791
  return !(format[i] != formatter.formatChar);
@@ -26768,6 +26799,7 @@ var inject = function inject(baseString) {
26768
26799
  };
26769
26800
  var formattedToUnformattedIndex = function formattedToUnformattedIndex(formattedIndex, rawValue, formatter) {
26770
26801
  var maxFormatExceeded = rawValue.length >= formatter.formats.length;
26802
+
26771
26803
  if (maxFormatExceeded) {
26772
26804
  return formattedIndex;
26773
26805
  } else {
@@ -26792,6 +26824,7 @@ var unformattedToFormattedIndex = function unformattedToFormattedIndex(rawIndex,
26792
26824
  }, 0) + rawIndex;
26793
26825
  }
26794
26826
  };
26827
+
26795
26828
  var createFormat = function createFormat(formats, formatChar) {
26796
26829
  return {
26797
26830
  uniqueDelimiters: getUniqueFormatDelimiters(formats, formatChar),
@@ -26799,15 +26832,18 @@ var createFormat = function createFormat(formats, formatChar) {
26799
26832
  formatChar: formatChar
26800
26833
  };
26801
26834
  };
26835
+
26802
26836
  var FormattedInput = function FormattedInput(_ref) {
26803
26837
  var value = _ref.value,
26804
- formatter = _ref.formatter,
26805
- onChange = _ref.onChange,
26806
- props = _objectWithoutProperties$1(_ref, ["value", "formatter", "onChange"]);
26838
+ formatter = _ref.formatter,
26839
+ onChange = _ref.onChange,
26840
+ props = _objectWithoutProperties$1(_ref, ["value", "formatter", "onChange"]);
26841
+
26807
26842
  var _useState = React.useState(format$1(formatter)(value)),
26808
- _useState2 = _slicedToArray$1(_useState, 2),
26809
- formattedValue = _useState2[0],
26810
- setFormattedValue = _useState2[1];
26843
+ _useState2 = _slicedToArray$1(_useState, 2),
26844
+ formattedValue = _useState2[0],
26845
+ setFormattedValue = _useState2[1];
26846
+
26811
26847
  var inputEl = React.useRef(null);
26812
26848
  var stateRefs = React.useRef({
26813
26849
  selectionStart: 0,
@@ -26821,9 +26857,11 @@ var FormattedInput = function FormattedInput(_ref) {
26821
26857
  inputEl.current.setSelectionRange(stateRefs.current.selectionStart, stateRefs.current.selectionEnd);
26822
26858
  }
26823
26859
  }, [stateRefs]);
26860
+
26824
26861
  var handleChange = function handleChange(event) {
26825
26862
  var deleteKeyPressed = stateRefs.current.isDelete;
26826
26863
  var maxFormatExceeded = stateRefs.current.rawValue.length >= formatter.formats.length - 1;
26864
+
26827
26865
  if (maxFormatExceeded && !deleteKeyPressed) {
26828
26866
  return;
26829
26867
  }
@@ -26834,6 +26872,7 @@ var FormattedInput = function FormattedInput(_ref) {
26834
26872
  * old unformatted value.
26835
26873
  */
26836
26874
 
26875
+
26837
26876
  var injectionLength = event.target.value.length - formattedValue.length;
26838
26877
  var end = stateRefs.current.selectionStart === stateRefs.current.selectionEnd ? stateRefs.current.selectionStart + injectionLength : stateRefs.current.selectionEnd - 1;
26839
26878
  var injection = event.target.value.substring(stateRefs.current.selectionStart, end); // Injection is the new unformatted piece of the input
@@ -26860,7 +26899,8 @@ var FormattedInput = function FormattedInput(_ref) {
26860
26899
  onChange(unformattedNewValue);
26861
26900
  }
26862
26901
  };
26863
- return /*#__PURE__*/React__default.createElement("input", _extends$2({}, props, {
26902
+
26903
+ return React__default.createElement("input", _extends$2({}, props, {
26864
26904
  ref: inputEl,
26865
26905
  value: format$1(formatter)(value),
26866
26906
  onKeyDown: function onKeyDown(event) {
@@ -41742,6 +41782,13 @@ var EmailForm = function EmailForm(_ref) {
41742
41782
  }, []);
41743
41783
  }
41744
41784
  var emailFieldErrorMessages = _defineProperty(_defineProperty({}, required.error, "Email address is required"), isProbablyEmail.error, "Invalid email address");
41785
+ React.useEffect(function () {
41786
+ if (isRequired) {
41787
+ actions.fields.email.addValidator(required());
41788
+ } else {
41789
+ actions.fields.email.removeValidator(required());
41790
+ }
41791
+ }, [isRequired]);
41745
41792
  return /*#__PURE__*/React__default.createElement(FormContainer$1, {
41746
41793
  variant: variant,
41747
41794
  role: "form",
@@ -41772,7 +41819,7 @@ var EmailForm = function EmailForm(_ref) {
41772
41819
 
41773
41820
  var formConfig$3 = {
41774
41821
  email: {
41775
- validators: [required(), isProbablyEmail()]
41822
+ validators: [isProbablyEmail()] // 'required' validator is conditionally added based on `isRequired` prop
41776
41823
  }
41777
41824
  };
41778
41825
  var _createFormState$3 = createFormState(formConfig$3),
@@ -48969,6 +49016,7 @@ var PhoneForm = function PhoneForm(_ref) {
48969
49016
  walletCheckboxMarked = _ref.walletCheckboxMarked,
48970
49017
  _ref$isRequired = _ref.isRequired,
48971
49018
  isRequired = _ref$isRequired === void 0 ? false : _ref$isRequired;
49019
+ console.log("🚀 ~ isRequired:", isRequired);
48972
49020
  if (clearOnDismount) {
48973
49021
  React.useEffect(function () {
48974
49022
  return function () {
@@ -48977,6 +49025,19 @@ var PhoneForm = function PhoneForm(_ref) {
48977
49025
  }, []);
48978
49026
  }
48979
49027
  var phoneErrorMessage = _defineProperty(_defineProperty({}, required.error, "Phone number is required"), hasLength.error, "Phone number must be 10 digits");
49028
+ React.useEffect(function () {
49029
+ if (isRequired) {
49030
+ console.log('adding validator');
49031
+ actions.fields.phone.addValidator(required());
49032
+ } else {
49033
+ console.log('removing validator');
49034
+ actions.fields.phone.removeValidator(required());
49035
+ }
49036
+ return function () {
49037
+ console.log('removing validator');
49038
+ actions.fields.phone.removeValidator(required());
49039
+ };
49040
+ }, [isRequired]);
48980
49041
  return /*#__PURE__*/React__default.createElement(FormContainer$1, {
48981
49042
  variant: variant,
48982
49043
  role: "form",
@@ -49005,7 +49066,8 @@ var PhoneForm = function PhoneForm(_ref) {
49005
49066
 
49006
49067
  var formConfig$8 = {
49007
49068
  phone: {
49008
- validators: [required(), hasLength(10, 10)],
49069
+ validators: [hasLength(10, 10)],
49070
+ // 'required' validator is conditionally added based on `isRequired` prop
49009
49071
  constraints: [onlyIntegers(), hasLength(0, 10)]
49010
49072
  }
49011
49073
  };