@ttoss/forms 0.23.0 → 0.23.2
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/Brazil/index.d.mts +2 -1
- package/dist/Brazil/index.d.ts +2 -1
- package/dist/Brazil/index.js +54 -6
- package/dist/MultistepForm/index.d.mts +1 -0
- package/dist/MultistepForm/index.d.ts +1 -0
- package/dist/MultistepForm/index.js +177 -124
- package/dist/esm/Brazil/index.js +8 -39
- package/dist/esm/MultistepForm/index.js +1 -1
- package/dist/esm/{chunk-5SH4STWG.js → chunk-J6VGD2RH.js} +141 -60
- package/dist/esm/index.js +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +130 -77
- package/dist/typings.d-KteERiXO.d.mts +12 -0
- package/dist/typings.d-KteERiXO.d.ts +12 -0
- package/package.json +12 -12
- package/src/Brazil/FormFieldCNPJ.tsx +56 -0
- package/src/Brazil/index.ts +1 -0
- package/src/index.ts +1 -3
- package/src/yup/schema.ts +12 -0
- package/src/yup/typings.d.ts +14 -0
- package/src/yup/yup.ts +4 -0
- /package/src/{i18n.ts → yup/i18n.ts} +0 -0
package/dist/Brazil/index.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ type FormFieldCNPJProps = {
|
|
|
6
6
|
label: string;
|
|
7
7
|
name: string;
|
|
8
8
|
} & Partial<PatternFormatProps>;
|
|
9
|
+
declare const isCnpjValid: (cnpj: any) => boolean;
|
|
9
10
|
declare const FormFieldCNPJ: ({ label, name, ...patternFormatProps }: FormFieldCNPJProps) => react_jsx_runtime.JSX.Element;
|
|
10
11
|
|
|
11
12
|
type FormFieldPhoneProps = {
|
|
@@ -20,4 +21,4 @@ type FormFieldCEPProps = {
|
|
|
20
21
|
} & Partial<FormFieldPatternFormatProps>;
|
|
21
22
|
declare const FormFieldCEP: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCEPProps) => react_jsx_runtime.JSX.Element;
|
|
22
23
|
|
|
23
|
-
export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone };
|
|
24
|
+
export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone, isCnpjValid };
|
package/dist/Brazil/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ type FormFieldCNPJProps = {
|
|
|
6
6
|
label: string;
|
|
7
7
|
name: string;
|
|
8
8
|
} & Partial<PatternFormatProps>;
|
|
9
|
+
declare const isCnpjValid: (cnpj: any) => boolean;
|
|
9
10
|
declare const FormFieldCNPJ: ({ label, name, ...patternFormatProps }: FormFieldCNPJProps) => react_jsx_runtime.JSX.Element;
|
|
10
11
|
|
|
11
12
|
type FormFieldPhoneProps = {
|
|
@@ -20,4 +21,4 @@ type FormFieldCEPProps = {
|
|
|
20
21
|
} & Partial<FormFieldPatternFormatProps>;
|
|
21
22
|
declare const FormFieldCEP: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCEPProps) => react_jsx_runtime.JSX.Element;
|
|
22
23
|
|
|
23
|
-
export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone };
|
|
24
|
+
export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone, isCnpjValid };
|
package/dist/Brazil/index.js
CHANGED
|
@@ -41,7 +41,8 @@ var Brazil_exports = {};
|
|
|
41
41
|
__export(Brazil_exports, {
|
|
42
42
|
FormFieldCEP: () => FormFieldCEP,
|
|
43
43
|
FormFieldCNPJ: () => FormFieldCNPJ,
|
|
44
|
-
FormFieldPhone: () => FormFieldPhone
|
|
44
|
+
FormFieldPhone: () => FormFieldPhone,
|
|
45
|
+
isCnpjValid: () => isCnpjValid
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(Brazil_exports);
|
|
47
48
|
|
|
@@ -70,11 +71,12 @@ __export(src_exports, {
|
|
|
70
71
|
useFormGroup: () => useFormGroup,
|
|
71
72
|
useFormState: () => import_react_hook_form6.useFormState,
|
|
72
73
|
useWatch: () => import_react_hook_form6.useWatch,
|
|
73
|
-
yup: () =>
|
|
74
|
+
yup: () => yup2,
|
|
74
75
|
yupResolver: () => import_yup2.yupResolver
|
|
75
76
|
});
|
|
77
|
+
var import_yup2 = require("@hookform/resolvers/yup");
|
|
76
78
|
|
|
77
|
-
// src/i18n.ts
|
|
79
|
+
// src/yup/i18n.ts
|
|
78
80
|
var import_react_i18n = require("@ttoss/react-i18n");
|
|
79
81
|
var import_yup = require("yup");
|
|
80
82
|
(0, import_yup.setLocale)({
|
|
@@ -114,9 +116,16 @@ var import_yup = require("yup");
|
|
|
114
116
|
}
|
|
115
117
|
});
|
|
116
118
|
|
|
117
|
-
// src/
|
|
118
|
-
var import_yup2 = require("@hookform/resolvers/yup");
|
|
119
|
+
// src/yup/schema.ts
|
|
119
120
|
var yup = __toESM(require("yup"));
|
|
121
|
+
yup.addMethod(yup.string, "cnpj", function () {
|
|
122
|
+
return this.test("valid-cnpj", "Invalid CNPJ", value => {
|
|
123
|
+
return isCnpjValid(value);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// src/yup/yup.ts
|
|
128
|
+
var yup2 = __toESM(require("yup"));
|
|
120
129
|
|
|
121
130
|
// src/Form.tsx
|
|
122
131
|
var import_ui = require("@ttoss/ui");
|
|
@@ -698,6 +707,44 @@ __reExport(src_exports, require("react-hook-form"));
|
|
|
698
707
|
var import_ui13 = require("@ttoss/ui");
|
|
699
708
|
var import_react_number_format3 = require("react-number-format");
|
|
700
709
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
710
|
+
var isCnpjValid = cnpj => {
|
|
711
|
+
if (cnpj?.length != 14) {
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
if (cnpj == "00000000000000" || cnpj == "11111111111111" || cnpj == "22222222222222" || cnpj == "33333333333333" || cnpj == "44444444444444" || cnpj == "55555555555555" || cnpj == "66666666666666" || cnpj == "77777777777777" || cnpj == "88888888888888" || cnpj == "99999999999999") {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
let size = cnpj.length - 2;
|
|
718
|
+
let numbers = cnpj.substring(0, size);
|
|
719
|
+
const digits = cnpj.substring(size);
|
|
720
|
+
let soma = 0;
|
|
721
|
+
let pos = size - 7;
|
|
722
|
+
for (let i = size; i >= 1; i--) {
|
|
723
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
724
|
+
if (pos < 2) {
|
|
725
|
+
pos = 9;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
let result = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
|
729
|
+
if (result != digits.charAt(0)) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
size = size + 1;
|
|
733
|
+
numbers = cnpj.substring(0, size);
|
|
734
|
+
soma = 0;
|
|
735
|
+
pos = size - 7;
|
|
736
|
+
for (let i = size; i >= 1; i--) {
|
|
737
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
738
|
+
if (pos < 2) {
|
|
739
|
+
pos = 9;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
result = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
|
743
|
+
if (result != digits.charAt(1)) {
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
return true;
|
|
747
|
+
};
|
|
701
748
|
var FormFieldCNPJ = ({
|
|
702
749
|
label,
|
|
703
750
|
name,
|
|
@@ -776,5 +823,6 @@ var FormFieldCEP = ({
|
|
|
776
823
|
0 && (module.exports = {
|
|
777
824
|
FormFieldCEP,
|
|
778
825
|
FormFieldCNPJ,
|
|
779
|
-
FormFieldPhone
|
|
826
|
+
FormFieldPhone,
|
|
827
|
+
isCnpjValid
|
|
780
828
|
});
|