@ttoss/forms 0.35.0 → 0.35.1

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.
@@ -1,18 +1,25 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { FieldValues, FieldPath } from 'react-hook-form';
3
- import { PatternFormatProps } from 'react-number-format';
4
- import { F as FormFieldProps, a as FormFieldPatternFormatProps } from '../FormFieldPatternFormat-D5CI6eUA.js';
3
+ import { a as FormFieldPatternFormatProps, F as FormFieldProps } from '../FormFieldPatternFormat-D5CI6eUA.js';
4
+ import { PatternFormatProps, NumberFormatBaseProps } from 'react-number-format';
5
5
  import '@ttoss/ui';
6
6
  import 'react';
7
7
 
8
+ type FormFieldCEPProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<FormFieldPatternFormatProps<TFieldValues, TName>, 'format'>;
9
+ declare const FormFieldCEP: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ placeholder, ...formFieldPatternFormatProps }: FormFieldCEPProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
10
+
8
11
  type FormFieldCNPJProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<PatternFormatProps, 'name' | 'format'>;
9
12
  declare const isCnpjValid: (cnpj: any) => boolean;
10
13
  declare const FormFieldCNPJ: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldCNPJProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
11
14
 
15
+ type FormFieldCPFProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<PatternFormatProps, 'name' | 'format'>;
16
+ declare const isCpfValid: (cpf: any) => boolean;
17
+ declare const FormFieldCPF: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldCPFProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
18
+
19
+ type FormFieldCPFOrCNPJProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<NumberFormatBaseProps, 'name' | 'format'>;
20
+ declare const FormFieldCPFOrCNPJ: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldCPFOrCNPJProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
21
+
12
22
  type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<PatternFormatProps, 'name' | 'format'>;
13
23
  declare const FormFieldPhone: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldPhoneProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
14
24
 
15
- type FormFieldCEPProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<FormFieldPatternFormatProps<TFieldValues, TName>, 'format'>;
16
- declare const FormFieldCEP: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ placeholder, ...formFieldPatternFormatProps }: FormFieldCEPProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
17
-
18
- export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone, isCnpjValid };
25
+ export { FormFieldCEP, FormFieldCNPJ, FormFieldCPF, FormFieldCPFOrCNPJ, FormFieldPhone, isCnpjValid, isCpfValid };
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import '../typings.d-HZBqJJjn.js';
3
+ import '../typings.d-BZ6kUiQ4.js';
4
4
  import * as yup from 'yup';
5
5
  import { IconType } from '@ttoss/react-icons';
6
6
 
@@ -1,9 +1,79 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  import * as React from 'react';
3
- import { FormField, FormFieldCNPJ, FormFieldPatternFormat, __name, isCnpjValid } from "../chunk-EA4K5JAO.js";
3
+ import { FormField, FormFieldCNPJ, FormFieldCPF, FormFieldPatternFormat, __name, isCnpjValid, isCpfValid } from "../chunk-QJQFXN4B.js";
4
4
 
5
- // src/Brazil/FormFieldPhone.tsx
5
+ // src/Brazil/FormFieldCEP.tsx
6
+ var FormFieldCEP = /* @__PURE__ */__name(({
7
+ placeholder = "12345-678",
8
+ ...formFieldPatternFormatProps
9
+ }) => {
10
+ return /* @__PURE__ */React.createElement(FormFieldPatternFormat, {
11
+ format: "#####-###",
12
+ placeholder,
13
+ ...formFieldPatternFormatProps
14
+ });
15
+ }, "FormFieldCEP");
16
+
17
+ // src/Brazil/FormFieldCPFOrCNPJ.tsx
6
18
  import { Input } from "@ttoss/ui";
19
+ import { NumberFormatBase } from "react-number-format";
20
+ var formatCPFOrCNPJ = /* @__PURE__ */__name(value => {
21
+ const numericValue = value.replace(/\D/g, "");
22
+ if (numericValue.length <= 11) {
23
+ return numericValue.replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d{1,2})$/, "$1-$2");
24
+ } else {
25
+ return numericValue.substring(0, 14).replace(/(\d{2})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1/$2").replace(/(\d{4})(\d{1,2})$/, "$1-$2");
26
+ }
27
+ }, "formatCPFOrCNPJ");
28
+ var FormFieldCPFOrCNPJ = /* @__PURE__ */__name(({
29
+ disabled,
30
+ ...props
31
+ }) => {
32
+ const {
33
+ label,
34
+ name,
35
+ labelTooltip,
36
+ warning,
37
+ sx,
38
+ css,
39
+ rules,
40
+ id,
41
+ defaultValue,
42
+ placeholder = "123.456.789-00 or 12.345.678/0000-00",
43
+ ...formatProps
44
+ } = props;
45
+ return /* @__PURE__ */React.createElement(FormField, {
46
+ id,
47
+ label,
48
+ name,
49
+ labelTooltip,
50
+ warning,
51
+ sx,
52
+ css,
53
+ defaultValue,
54
+ rules,
55
+ disabled,
56
+ render: /* @__PURE__ */__name(({
57
+ field
58
+ }) => {
59
+ return /* @__PURE__ */React.createElement(NumberFormatBase, {
60
+ ...formatProps,
61
+ value: field.value,
62
+ onBlur: field.onBlur,
63
+ onValueChange: /* @__PURE__ */__name(values => {
64
+ field.onChange(values.value);
65
+ }, "onValueChange"),
66
+ format: formatCPFOrCNPJ,
67
+ customInput: Input,
68
+ placeholder,
69
+ disabled: disabled ?? field.disabled
70
+ });
71
+ }, "render")
72
+ });
73
+ }, "FormFieldCPFOrCNPJ");
74
+
75
+ // src/Brazil/FormFieldPhone.tsx
76
+ import { Input as Input2 } from "@ttoss/ui";
7
77
  import { PatternFormat } from "react-number-format";
8
78
  var FormFieldPhone = /* @__PURE__ */__name(({
9
79
  disabled,
@@ -48,23 +118,11 @@ var FormFieldPhone = /* @__PURE__ */__name(({
48
118
  field.onChange(values.value);
49
119
  }, "onValueChange"),
50
120
  format,
51
- customInput: Input,
121
+ customInput: Input2,
52
122
  placeholder,
53
123
  disabled: disabled ?? field.disabled
54
124
  });
55
125
  }, "render")
56
126
  });
57
127
  }, "FormFieldPhone");
58
-
59
- // src/Brazil/FormFieldCEP.tsx
60
- var FormFieldCEP = /* @__PURE__ */__name(({
61
- placeholder = "12345-678",
62
- ...formFieldPatternFormatProps
63
- }) => {
64
- return /* @__PURE__ */React.createElement(FormFieldPatternFormat, {
65
- format: "#####-###",
66
- placeholder,
67
- ...formFieldPatternFormatProps
68
- });
69
- }, "FormFieldCEP");
70
- export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone, isCnpjValid };
128
+ export { FormFieldCEP, FormFieldCNPJ, FormFieldCPF, FormFieldCPFOrCNPJ, FormFieldPhone, isCnpjValid, isCpfValid };
@@ -1,7 +1,7 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  import * as React from 'react';
3
- import { Form, useForm, yupResolver } from "../chunk-X2A7XW2U.js";
4
- import { __name } from "../chunk-EA4K5JAO.js";
3
+ import { Form, useForm, yupResolver } from "../chunk-O7FR42EI.js";
4
+ import { __name } from "../chunk-QJQFXN4B.js";
5
5
 
6
6
  // src/MultistepForm/MultistepForm.tsx
7
7
  import { Flex as Flex6 } from "@ttoss/ui";
@@ -1,6 +1,6 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  import * as React from 'react';
3
- import { FormErrorMessage, FormField, FormFieldPatternFormat, __name, isCnpjValid } from "./chunk-EA4K5JAO.js";
3
+ import { FormErrorMessage, FormField, FormFieldPatternFormat, __name, isCnpjValid, isCpfValid } from "./chunk-QJQFXN4B.js";
4
4
 
5
5
  // src/Form.tsx
6
6
  import { Box } from "@ttoss/ui";
@@ -901,6 +901,11 @@ yup.addMethod(yup.string, "cnpj", function () {
901
901
  return isCnpjValid(value);
902
902
  });
903
903
  });
904
+ yup.addMethod(yup.string, "cpf", function () {
905
+ return this.test("valid-cpf", "Invalid CPF", value => {
906
+ return isCpfValid(value);
907
+ });
908
+ });
904
909
  yup.addMethod(yup.string, "password", function ({
905
910
  required
906
911
  } = {}) {
@@ -357,4 +357,86 @@ var FormFieldCNPJ = /* @__PURE__ */__name(({
357
357
  }, "render")
358
358
  });
359
359
  }, "FormFieldCNPJ");
360
- export { __name, FormErrorMessage, FormField, FormFieldPatternFormat, isCnpjValid, FormFieldCNPJ };
360
+
361
+ // src/Brazil/FormFieldCPF.tsx
362
+ import { Input as Input3 } from "@ttoss/ui";
363
+ import { PatternFormat as PatternFormat3 } from "react-number-format";
364
+ var isCpfValid = /* @__PURE__ */__name(cpf => {
365
+ if (cpf?.length != 11) {
366
+ return false;
367
+ }
368
+ if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
369
+ return false;
370
+ }
371
+ let soma = 0;
372
+ for (let i = 0; i < 9; i++) {
373
+ soma += parseInt(cpf.charAt(i)) * (10 - i);
374
+ }
375
+ let resto = soma * 10 % 11;
376
+ if (resto === 10 || resto === 11) {
377
+ resto = 0;
378
+ }
379
+ if (resto != parseInt(cpf.charAt(9))) {
380
+ return false;
381
+ }
382
+ soma = 0;
383
+ for (let i = 0; i < 10; i++) {
384
+ soma += parseInt(cpf.charAt(i)) * (11 - i);
385
+ }
386
+ resto = soma * 10 % 11;
387
+ if (resto === 10 || resto === 11) {
388
+ resto = 0;
389
+ }
390
+ if (resto != parseInt(cpf.charAt(10))) {
391
+ return false;
392
+ }
393
+ return true;
394
+ }, "isCpfValid");
395
+ var FormFieldCPF = /* @__PURE__ */__name(({
396
+ disabled,
397
+ ...props
398
+ }) => {
399
+ const {
400
+ label,
401
+ name,
402
+ labelTooltip,
403
+ warning,
404
+ sx,
405
+ css,
406
+ rules,
407
+ id,
408
+ defaultValue,
409
+ placeholder = "123.456.789-00",
410
+ ...patternFormatProps
411
+ } = props;
412
+ return /* @__PURE__ */React.createElement(FormField, {
413
+ id,
414
+ label,
415
+ name,
416
+ labelTooltip,
417
+ warning,
418
+ sx,
419
+ css,
420
+ defaultValue,
421
+ rules,
422
+ disabled,
423
+ render: /* @__PURE__ */__name(({
424
+ field
425
+ }) => {
426
+ return /* @__PURE__ */React.createElement(PatternFormat3, {
427
+ ...patternFormatProps,
428
+ name: field.name,
429
+ value: field.value,
430
+ onBlur: field.onBlur,
431
+ onValueChange: /* @__PURE__ */__name(values => {
432
+ field.onChange(values.value);
433
+ }, "onValueChange"),
434
+ format: "###.###.###-##",
435
+ customInput: Input3,
436
+ placeholder,
437
+ disabled: disabled ?? field.disabled
438
+ });
439
+ }, "render")
440
+ });
441
+ }, "FormFieldCPF");
442
+ export { __name, FormErrorMessage, FormField, FormFieldPatternFormat, isCnpjValid, FormFieldCNPJ, isCpfValid, FormFieldCPF };
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Controller, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-X2A7XW2U.js";
3
- import { FormErrorMessage, FormField, FormFieldPatternFormat } from "./chunk-EA4K5JAO.js";
2
+ import { Controller, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-O7FR42EI.js";
3
+ import { FormErrorMessage, FormField, FormFieldPatternFormat } from "./chunk-QJQFXN4B.js";
4
4
  export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver };
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { Controller, FormProvider, useController, useFieldArray, useForm, useFor
7
7
  import { F as FormFieldProps, a as FormFieldPatternFormatProps } from './FormFieldPatternFormat-D5CI6eUA.js';
8
8
  export { b as FormField, c as FormFieldPatternFormat } from './FormFieldPatternFormat-D5CI6eUA.js';
9
9
  import { NumericFormatProps } from 'react-number-format';
10
- import './typings.d-HZBqJJjn.js';
10
+ import './typings.d-BZ6kUiQ4.js';
11
11
  import * as yup from 'yup';
12
12
  export { yup };
13
13
  export { yupResolver } from '@hookform/resolvers/yup';
@@ -8,5 +8,6 @@ declare module 'yup' {
8
8
  TFlags extends Flags = '',
9
9
  > extends Schema<TType, TContext, TDefault, TFlags> {
10
10
  cnpj(): this;
11
+ cpf(): this;
11
12
  }
12
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.35.0",
3
+ "version": "0.35.1",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -51,11 +51,11 @@
51
51
  "tsup": "^8.5.1",
52
52
  "yup": "^1.7.1",
53
53
  "@ttoss/config": "^1.35.12",
54
- "@ttoss/react-i18n": "^2.0.24",
55
54
  "@ttoss/react-icons": "^0.5.5",
56
- "@ttoss/i18n-cli": "^0.7.38",
57
55
  "@ttoss/test-utils": "^4.0.1",
58
- "@ttoss/ui": "^6.0.4"
56
+ "@ttoss/react-i18n": "^2.0.24",
57
+ "@ttoss/ui": "^6.0.4",
58
+ "@ttoss/i18n-cli": "^0.7.38"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",