@thecb/components 10.9.0-beta.13 → 10.9.0-beta.14
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 +16 -34
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.esm.js +16 -34
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/email-form/EmailForm.js +7 -17
- package/src/components/molecules/phone-form/PhoneForm.js +8 -18
- package/src/hooks/index.js +1 -0
- package/src/hooks/use-conditionally-add-validator/index.js +6 -19
package/dist/index.d.ts
CHANGED
|
@@ -491,15 +491,34 @@ declare function useToastNotification(
|
|
|
491
491
|
options?: UseToastOptions
|
|
492
492
|
): UseToastResult;
|
|
493
493
|
|
|
494
|
+
declare function useConditionallyAddValidator(
|
|
495
|
+
condition,
|
|
496
|
+
validatorFn,
|
|
497
|
+
addValidator,
|
|
498
|
+
removeValidator
|
|
499
|
+
) {
|
|
500
|
+
useEffect(() => {
|
|
501
|
+
if (condition) {
|
|
502
|
+
addValidator(validatorFn());
|
|
503
|
+
}
|
|
504
|
+
return () => {
|
|
505
|
+
// Remove validator when component unmounts
|
|
506
|
+
removeValidator(validatorFn());
|
|
507
|
+
};
|
|
508
|
+
}, [condition, addValidator, removeValidator]);
|
|
509
|
+
}
|
|
510
|
+
|
|
494
511
|
|
|
495
512
|
|
|
496
513
|
declare const index_useScrollTo: typeof useScrollTo;
|
|
497
514
|
declare const index_useToastNotification: typeof useToastNotification;
|
|
515
|
+
declare const index_useConditionallyAddValidator: typeof useConditionallyAddValidator;
|
|
498
516
|
declare namespace index {
|
|
499
517
|
export {
|
|
500
518
|
useOutsideClickHook as useOutsideClick,
|
|
501
519
|
index_useScrollTo as useScrollTo,
|
|
502
520
|
index_useToastNotification as useToastNotification,
|
|
521
|
+
index_useConditionallyAddValidator as useConditionallyAddValidator,
|
|
503
522
|
};
|
|
504
523
|
}
|
|
505
524
|
|
package/dist/index.esm.js
CHANGED
|
@@ -26395,13 +26395,26 @@ var useToastNotification = function useToastNotification() {
|
|
|
26395
26395
|
};
|
|
26396
26396
|
};
|
|
26397
26397
|
|
|
26398
|
+
function useConditionallyAddValidator(condition, validatorFn, addValidator, removeValidator) {
|
|
26399
|
+
useEffect$1(function () {
|
|
26400
|
+
if (condition) {
|
|
26401
|
+
addValidator(validatorFn());
|
|
26402
|
+
}
|
|
26403
|
+
return function () {
|
|
26404
|
+
// Remove validator when component unmounts
|
|
26405
|
+
removeValidator(validatorFn());
|
|
26406
|
+
};
|
|
26407
|
+
}, [condition, addValidator, removeValidator]);
|
|
26408
|
+
}
|
|
26409
|
+
|
|
26398
26410
|
|
|
26399
26411
|
|
|
26400
26412
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
26401
26413
|
__proto__: null,
|
|
26402
26414
|
useOutsideClick: useOutsideClickHook,
|
|
26403
26415
|
useScrollTo: useScrollTo,
|
|
26404
|
-
useToastNotification: useToastNotification
|
|
26416
|
+
useToastNotification: useToastNotification,
|
|
26417
|
+
useConditionallyAddValidator: useConditionallyAddValidator
|
|
26405
26418
|
});
|
|
26406
26419
|
|
|
26407
26420
|
var hoverColor$4 = "#116285";
|
|
@@ -41766,7 +41779,6 @@ var EmailForm = function EmailForm(_ref) {
|
|
|
41766
41779
|
walletCheckboxMarked = _ref.walletCheckboxMarked,
|
|
41767
41780
|
_ref$isRequired = _ref.isRequired,
|
|
41768
41781
|
isRequired = _ref$isRequired === void 0 ? false : _ref$isRequired;
|
|
41769
|
-
console.log("🚀 ~ isRequired:", isRequired);
|
|
41770
41782
|
if (clearOnDismount) {
|
|
41771
41783
|
useEffect$1(function () {
|
|
41772
41784
|
return function () {
|
|
@@ -41774,23 +41786,8 @@ var EmailForm = function EmailForm(_ref) {
|
|
|
41774
41786
|
};
|
|
41775
41787
|
}, []);
|
|
41776
41788
|
}
|
|
41789
|
+
useConditionallyAddValidator(isRequired, required, actions.fields.email.addValidator, actions.fields.email.removeValidator);
|
|
41777
41790
|
var emailFieldErrorMessages = _defineProperty(_defineProperty({}, required.error, "Email address is required"), isProbablyEmail.error, "Invalid email address");
|
|
41778
|
-
useEffect$1(function () {
|
|
41779
|
-
debugger;
|
|
41780
|
-
if (isRequired) {
|
|
41781
|
-
console.log('adding email validator');
|
|
41782
|
-
actions.fields.email.addValidator(required());
|
|
41783
|
-
}
|
|
41784
|
-
// else {
|
|
41785
|
-
// console.log('removing email validator')
|
|
41786
|
-
// actions.fields.email.removeValidator(required());
|
|
41787
|
-
// }
|
|
41788
|
-
return function () {
|
|
41789
|
-
console.log('removing email validator');
|
|
41790
|
-
// If the form is not rendered it should not be required.
|
|
41791
|
-
actions.fields.email.removeValidator(required());
|
|
41792
|
-
};
|
|
41793
|
-
}, [isRequired]);
|
|
41794
41791
|
return /*#__PURE__*/React.createElement(FormContainer$1, {
|
|
41795
41792
|
variant: variant,
|
|
41796
41793
|
role: "form",
|
|
@@ -49025,23 +49022,8 @@ var PhoneForm = function PhoneForm(_ref) {
|
|
|
49025
49022
|
};
|
|
49026
49023
|
}, []);
|
|
49027
49024
|
}
|
|
49025
|
+
useConditionallyAddValidator(isRequired, required, actions.fields.phone.addValidator, actions.fields.phone.removeValidator);
|
|
49028
49026
|
var phoneErrorMessage = _defineProperty(_defineProperty({}, required.error, "Phone number is required"), hasLength.error, "Phone number must be 10 digits");
|
|
49029
|
-
useEffect$1(function () {
|
|
49030
|
-
if (isRequired) {
|
|
49031
|
-
console.log("adding phone validator");
|
|
49032
|
-
actions.fields.phone.addValidator(required());
|
|
49033
|
-
}
|
|
49034
|
-
// else {
|
|
49035
|
-
// debugger;
|
|
49036
|
-
// console.log('removing phone validator 1')
|
|
49037
|
-
// actions.fields.phone.removeValidator(required());
|
|
49038
|
-
// }
|
|
49039
|
-
return function () {
|
|
49040
|
-
console.log("removing phone validator 2");
|
|
49041
|
-
// If the form is not rendered it should not be required.
|
|
49042
|
-
actions.fields.phone.removeValidator(required());
|
|
49043
|
-
};
|
|
49044
|
-
}, [isRequired]);
|
|
49045
49027
|
return /*#__PURE__*/React.createElement(FormContainer$1, {
|
|
49046
49028
|
variant: variant,
|
|
49047
49029
|
role: "form",
|