@ttoss/forms 0.41.1 → 0.42.0
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/README.md +31 -6
- package/dist/Brazil/index.d.ts +14 -3
- package/dist/FormFieldPhone-BKeOS0i6.d.ts +217 -0
- package/dist/esm/Brazil/index.js +15 -50
- package/dist/esm/MultistepForm/index.js +2 -2
- package/dist/esm/{chunk-6UQV3E5X.js → chunk-YCW3GPTZ.js} +16 -40
- package/dist/esm/{chunk-BL55OAIO.js → chunk-ZORKZWD7.js} +223 -9
- package/dist/esm/index.js +3 -3
- package/dist/index.d.ts +54 -3
- package/package.json +8 -8
- package/dist/FormFieldPatternFormat-kaO0pl1R.d.ts +0 -59
package/README.md
CHANGED
|
@@ -619,25 +619,50 @@ Brazilian phone number input with formatting.
|
|
|
619
619
|
|
|
620
620
|
## FormGroup
|
|
621
621
|
|
|
622
|
-
Groups related fields with optional
|
|
622
|
+
Groups related fields with an optional title, description, and layout direction.
|
|
623
623
|
|
|
624
624
|
```tsx
|
|
625
|
-
<FormGroup
|
|
625
|
+
<FormGroup title="Personal Information" direction="row">
|
|
626
626
|
<FormFieldInput name="firstName" label="First Name" />
|
|
627
627
|
<FormFieldInput name="lastName" label="Last Name" />
|
|
628
628
|
</FormGroup>
|
|
629
629
|
|
|
630
|
-
<FormGroup
|
|
630
|
+
<FormGroup title="Address" description="Where we'll send your order">
|
|
631
631
|
<FormFieldInput name="street" label="Street" />
|
|
632
632
|
<FormFieldInput name="city" label="City" />
|
|
633
633
|
</FormGroup>
|
|
634
634
|
```
|
|
635
635
|
|
|
636
|
+
Nest `FormGroup` components to create hierarchical sections:
|
|
637
|
+
|
|
638
|
+
```tsx
|
|
639
|
+
<FormGroup title="Personal details">
|
|
640
|
+
<FormFieldInput name="firstName" label="First name" />
|
|
641
|
+
<FormFieldInput name="lastName" label="Last name" />
|
|
642
|
+
|
|
643
|
+
<FormGroup title="Address" direction="row">
|
|
644
|
+
<FormFieldInput name="city" label="City" />
|
|
645
|
+
<FormFieldInput name="zip" label="ZIP" />
|
|
646
|
+
</FormGroup>
|
|
647
|
+
</FormGroup>
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
To display a group-level validation error (e.g. for an array field), pass the `name` prop:
|
|
651
|
+
|
|
652
|
+
```tsx
|
|
653
|
+
<FormGroup name="items" title="Items">
|
|
654
|
+
{fields.map((field, i) => (
|
|
655
|
+
<FormFieldInput key={field.id} name={`items[${i}].value`} label="Value" />
|
|
656
|
+
))}
|
|
657
|
+
</FormGroup>
|
|
658
|
+
```
|
|
659
|
+
|
|
636
660
|
**Props:**
|
|
637
661
|
|
|
638
|
-
- `
|
|
639
|
-
- `
|
|
640
|
-
- `
|
|
662
|
+
- `title`: Optional heading displayed above the group's children
|
|
663
|
+
- `description`: Optional description displayed below the title
|
|
664
|
+
- `direction`: Layout direction (`'row'` | `'column'`, default: `'column'`)
|
|
665
|
+
- `name`: Field name used to display a group-level validation error message
|
|
641
666
|
|
|
642
667
|
## Multistep Forms
|
|
643
668
|
|
package/dist/Brazil/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { FieldValues, FieldPath } from 'react-hook-form';
|
|
3
|
-
import { a as FormFieldPatternFormatProps, F as FormFieldProps } from '../
|
|
3
|
+
import { a as FormFieldPatternFormatProps, F as FormFieldProps, d as FormFieldPhoneProps$1 } from '../FormFieldPhone-BKeOS0i6.js';
|
|
4
4
|
import { PatternFormatProps, NumberFormatBaseProps } from 'react-number-format';
|
|
5
5
|
import '@ttoss/ui';
|
|
6
6
|
import 'react';
|
|
@@ -19,7 +19,18 @@ declare const FormFieldCPF: <TFieldValues extends FieldValues = FieldValues, TNa
|
|
|
19
19
|
type FormFieldCPFOrCNPJProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<NumberFormatBaseProps, 'name' | 'format'>;
|
|
20
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
21
|
|
|
22
|
-
type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> =
|
|
23
|
-
|
|
22
|
+
type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<FormFieldPhoneProps$1<TFieldValues, TName>, 'countryCode' | 'format'>;
|
|
23
|
+
/**
|
|
24
|
+
* Brazilian phone number form field.
|
|
25
|
+
*
|
|
26
|
+
* Wraps the generic `FormFieldPhone` with the Brazil country code (`+55`)
|
|
27
|
+
* and the appropriate local number format pre-configured.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* <FormFieldPhone name="phone" label="Phone" />
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const FormFieldPhone: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ placeholder, countryCodeOptions, ...props }: FormFieldPhoneProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
24
35
|
|
|
25
36
|
export { FormFieldCEP, FormFieldCNPJ, FormFieldCPF, FormFieldCPFOrCNPJ, FormFieldPhone, isCnpjValid, isCpfValid };
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { TooltipProps, SxProp, InputProps } from '@ttoss/ui';
|
|
3
|
+
import { FieldValues, FieldPath, RegisterOptions, FieldPathValue, UseControllerReturn } from 'react-hook-form';
|
|
4
|
+
import { PatternFormatProps } from 'react-number-format';
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
|
|
7
|
+
type AuxiliaryCheckboxRules<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
|
8
|
+
/**
|
|
9
|
+
* Props for the AuxiliaryCheckbox component.
|
|
10
|
+
*/
|
|
11
|
+
type AuxiliaryCheckboxProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
12
|
+
/**
|
|
13
|
+
* The label to display next to the checkbox.
|
|
14
|
+
*/
|
|
15
|
+
label: React.ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* The name of the checkbox field in the form.
|
|
18
|
+
*/
|
|
19
|
+
name: TName;
|
|
20
|
+
/**
|
|
21
|
+
* The default value of the checkbox.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
defaultValue?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Validation rules for the checkbox field.
|
|
27
|
+
*/
|
|
28
|
+
rules?: AuxiliaryCheckboxRules<TFieldValues, TName>;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the checkbox is disabled.
|
|
31
|
+
*/
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type Rules<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
|
36
|
+
type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
37
|
+
label?: React.ReactNode;
|
|
38
|
+
id?: string;
|
|
39
|
+
name: TName;
|
|
40
|
+
defaultValue?: FieldPathValue<TFieldValues, TName>;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
labelTooltip?: TooltipProps;
|
|
43
|
+
warning?: string | React.ReactNode;
|
|
44
|
+
rules?: Rules<TFieldValues, TName>;
|
|
45
|
+
/**
|
|
46
|
+
* Optional auxiliary checkbox to render between the field and error message.
|
|
47
|
+
* Useful for input confirmation or conditional display of other fields.
|
|
48
|
+
*/
|
|
49
|
+
auxiliaryCheckbox?: AuxiliaryCheckboxProps<TFieldValues, FieldPath<TFieldValues>>;
|
|
50
|
+
} & SxProp;
|
|
51
|
+
type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
52
|
+
render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
|
|
53
|
+
} & FormFieldProps<TFieldValues, TName>;
|
|
54
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled: propsDisabled, labelTooltip, sx, css, render, warning, rules, auxiliaryCheckbox, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
55
|
+
|
|
56
|
+
type FormFieldPatternFormatProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<PatternFormatProps, 'name'> & Pick<InputProps, 'leadingIcon' | 'trailingIcon'>;
|
|
57
|
+
declare const FormFieldPatternFormat: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldPatternFormatProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A curated list of the most common country calling codes paired with their
|
|
61
|
+
* typical local phone number format patterns (using `#` as digit placeholders).
|
|
62
|
+
*
|
|
63
|
+
* Import this constant and pass it to the `countryCodeOptions` prop of
|
|
64
|
+
* `FormFieldPhone` to give users a ready-made country-code picker that also
|
|
65
|
+
* automatically updates the number format when they switch countries.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* import { FormFieldPhone } from '@ttoss/forms';
|
|
70
|
+
*
|
|
71
|
+
* // COMMON_PHONE_COUNTRY_CODES is the default — no need to pass it explicitly.
|
|
72
|
+
* // Index 0 is the "Manual" entry; index 1 is US (+1).
|
|
73
|
+
* const [countryCode, setCountryCode] = React.useState(
|
|
74
|
+
* COMMON_PHONE_COUNTRY_CODES[1].value // '+1'
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* <FormFieldPhone
|
|
78
|
+
* name="phone"
|
|
79
|
+
* label="Phone"
|
|
80
|
+
* countryCode={countryCode}
|
|
81
|
+
* onCountryCodeChange={setCountryCode}
|
|
82
|
+
* />
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
type CountryCodeOption = {
|
|
86
|
+
/** Label displayed in the dropdown (e.g. 'US +1'). */
|
|
87
|
+
label: string;
|
|
88
|
+
/** The calling-code value (e.g. '+1'). */
|
|
89
|
+
value: string;
|
|
90
|
+
/**
|
|
91
|
+
* Optional phone number format for the local part specific to this country
|
|
92
|
+
* (e.g. '(###) ###-####'). When the user selects this option the format
|
|
93
|
+
* is used automatically, overriding the `format` prop of `FormFieldPhone`.
|
|
94
|
+
*/
|
|
95
|
+
format?: string | ((value: string) => string);
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Sentinel value used as `countryCode` to indicate that the user wants to
|
|
99
|
+
* type the entire phone number manually (no pattern mask is applied).
|
|
100
|
+
* A `+` prefix is displayed before the input.
|
|
101
|
+
*/
|
|
102
|
+
declare const MANUAL_PHONE_COUNTRY_CODE = "manual";
|
|
103
|
+
/**
|
|
104
|
+
* Common country calling codes sorted by numeric dial-code order.
|
|
105
|
+
* The "Manual" option is listed first, allowing users to type the full
|
|
106
|
+
* international number freely without any mask.
|
|
107
|
+
*/
|
|
108
|
+
declare const COMMON_PHONE_COUNTRY_CODES: CountryCodeOption[];
|
|
109
|
+
|
|
110
|
+
type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<PatternFormatProps, 'name' | 'format'> & {
|
|
111
|
+
/**
|
|
112
|
+
* The country calling code to display as a literal prefix in the input.
|
|
113
|
+
* For example, '+55' for Brazil or '+1' for the United States.
|
|
114
|
+
* Defaults to the first entry in `countryCodeOptions` when not provided.
|
|
115
|
+
*/
|
|
116
|
+
countryCode?: string;
|
|
117
|
+
/**
|
|
118
|
+
* The pattern format for the local part of the phone number.
|
|
119
|
+
* Accepts either a static string (e.g., '(##) #####-####') or a function
|
|
120
|
+
* that receives the current raw value and returns the format string,
|
|
121
|
+
* which is useful for dynamic formats (e.g., different lengths).
|
|
122
|
+
*
|
|
123
|
+
* When the selected entry in countryCodeOptions includes its own
|
|
124
|
+
* format, that value takes precedence over this prop.
|
|
125
|
+
*
|
|
126
|
+
* Defaults to '(###) ###-####' when neither this prop nor the selected
|
|
127
|
+
* country option supplies a format.
|
|
128
|
+
*
|
|
129
|
+
* Ignored when `countryCode` is `MANUAL_PHONE_COUNTRY_CODE`.
|
|
130
|
+
*/
|
|
131
|
+
format?: string | ((value: string) => string);
|
|
132
|
+
/**
|
|
133
|
+
* List of country calling code options to display in the dropdown.
|
|
134
|
+
* Defaults to `COMMON_PHONE_COUNTRY_CODES` (15 common countries + Manual).
|
|
135
|
+
* Pass an empty array to hide the dropdown and show a plain phone input.
|
|
136
|
+
*/
|
|
137
|
+
countryCodeOptions?: CountryCodeOption[];
|
|
138
|
+
/**
|
|
139
|
+
* Called with the newly selected country code value when the user changes
|
|
140
|
+
* the country code via the dropdown. Only relevant when
|
|
141
|
+
* countryCodeOptions is non-empty.
|
|
142
|
+
*/
|
|
143
|
+
onCountryCodeChange?: (countryCode: string) => void;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Generic phone number form field that supports an optional country code prefix.
|
|
147
|
+
*
|
|
148
|
+
* By default, a country-code dropdown is rendered using `COMMON_PHONE_COUNTRY_CODES`
|
|
149
|
+
* (15 common countries + a Manual entry; Manual is the first entry at index 0).
|
|
150
|
+
* Pass `countryCodeOptions={[]}` to disable the dropdown and show a plain phone input.
|
|
151
|
+
*
|
|
152
|
+
* The format prop defines the pattern for the local phone number (using #
|
|
153
|
+
* as digit placeholders). When a countryCode is provided it is prepended to
|
|
154
|
+
* the format and rendered as a read-only literal inside the input.
|
|
155
|
+
*
|
|
156
|
+
* When the user selects the "Manual" option (`MANUAL_PHONE_COUNTRY_CODE`),
|
|
157
|
+
* the pattern mask is disabled and a plain text input is shown so the user
|
|
158
|
+
* can type the full international number freely.
|
|
159
|
+
*
|
|
160
|
+
* When a country code is provided, the stored value is the country code
|
|
161
|
+
* concatenated directly with the raw local digits (e.g., `"+15555555555"`
|
|
162
|
+
* for country code `"+1"` and local digits `"5555555555"`). When no country
|
|
163
|
+
* code is set, only the raw local digits are stored.
|
|
164
|
+
*
|
|
165
|
+
* Changing the country code via the dropdown automatically resets the phone
|
|
166
|
+
* number field to an empty string, so a new number can be entered in the
|
|
167
|
+
* correct format for the selected country.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```tsx
|
|
171
|
+
* // Default: dropdown with COMMON_PHONE_COUNTRY_CODES, US (+1) pre-selected
|
|
172
|
+
* <FormFieldPhone name="phone" label="Phone" countryCode="+1" />
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* // Controlled country code — submitted value includes the prefix
|
|
178
|
+
* // e.g. { phone: '+15555555555' }
|
|
179
|
+
* const [countryCode, setCountryCode] = React.useState('+1');
|
|
180
|
+
* <FormFieldPhone
|
|
181
|
+
* name="phone"
|
|
182
|
+
* label="Phone"
|
|
183
|
+
* countryCode={countryCode}
|
|
184
|
+
* onCountryCodeChange={setCountryCode}
|
|
185
|
+
* />
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* // No dropdown — plain phone input; value includes the prefix
|
|
191
|
+
* // e.g. { phone: '+15555555555' }
|
|
192
|
+
* <FormFieldPhone
|
|
193
|
+
* name="phone"
|
|
194
|
+
* label="Phone"
|
|
195
|
+
* countryCode="+1"
|
|
196
|
+
* format="(###) ###-####"
|
|
197
|
+
* countryCodeOptions={[]}
|
|
198
|
+
* />
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```tsx
|
|
203
|
+
* // Dynamic format (e.g. Brazilian numbers with 8 or 9 local digits)
|
|
204
|
+
* <FormFieldPhone
|
|
205
|
+
* name="phone"
|
|
206
|
+
* label="Phone"
|
|
207
|
+
* countryCode="+55"
|
|
208
|
+
* format={(value) =>
|
|
209
|
+
* value.length > 10 ? '(##) #####-####' : '(##) ####-#####'
|
|
210
|
+
* }
|
|
211
|
+
* countryCodeOptions={[]}
|
|
212
|
+
* />
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare const FormFieldPhone: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, countryCode: countryCodeProp, format, countryCodeOptions, onCountryCodeChange, ...props }: FormFieldPhoneProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
216
|
+
|
|
217
|
+
export { type CountryCodeOption as C, type FormFieldProps as F, MANUAL_PHONE_COUNTRY_CODE as M, type FormFieldPatternFormatProps as a, FormField as b, FormFieldPatternFormat as c, type FormFieldPhoneProps as d, FormFieldPhone as e, COMMON_PHONE_COUNTRY_CODES as f };
|
package/dist/esm/Brazil/index.js
CHANGED
|
@@ -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 { FormField, FormFieldCNPJ, FormFieldCPF, FormFieldPatternFormat, __name, isCnpjValid, isCpfValid } from "../chunk-
|
|
3
|
+
import { FormField, FormFieldCNPJ, FormFieldCPF, FormFieldPatternFormat, FormFieldPhone, __name, isCnpjValid, isCpfValid } from "../chunk-ZORKZWD7.js";
|
|
4
4
|
|
|
5
5
|
// src/Brazil/FormFieldCEP.tsx
|
|
6
6
|
var FormFieldCEP = /* @__PURE__ */__name(({
|
|
@@ -73,56 +73,21 @@ var FormFieldCPFOrCNPJ = /* @__PURE__ */__name(({
|
|
|
73
73
|
}, "FormFieldCPFOrCNPJ");
|
|
74
74
|
|
|
75
75
|
// src/Brazil/FormFieldPhone.tsx
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
var BRAZIL_COUNTRY_CODE = "+55";
|
|
77
|
+
var getBrazilPhoneFormat = /* @__PURE__ */__name(value => {
|
|
78
|
+
return value.length > 10 ? "(##) #####-####" : "(##) ####-#####";
|
|
79
|
+
}, "getBrazilPhoneFormat");
|
|
80
|
+
var FormFieldPhone2 = /* @__PURE__ */__name(({
|
|
81
|
+
placeholder = "(11) 91234-1234",
|
|
82
|
+
countryCodeOptions = [],
|
|
80
83
|
...props
|
|
81
84
|
}) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
css,
|
|
89
|
-
rules,
|
|
90
|
-
id,
|
|
91
|
-
defaultValue,
|
|
92
|
-
placeholder = "(11) 91234-1234",
|
|
93
|
-
auxiliaryCheckbox,
|
|
94
|
-
...patternFormatProps
|
|
95
|
-
} = props;
|
|
96
|
-
return /* @__PURE__ */React.createElement(FormField, {
|
|
97
|
-
id,
|
|
98
|
-
label,
|
|
99
|
-
name,
|
|
100
|
-
labelTooltip,
|
|
101
|
-
warning,
|
|
102
|
-
sx,
|
|
103
|
-
css,
|
|
104
|
-
defaultValue,
|
|
105
|
-
rules,
|
|
106
|
-
disabled,
|
|
107
|
-
auxiliaryCheckbox,
|
|
108
|
-
render: /* @__PURE__ */__name(({
|
|
109
|
-
field
|
|
110
|
-
}) => {
|
|
111
|
-
const format = field.value?.length > 10 ? "(##) #####-####" : "(##) ####-#####";
|
|
112
|
-
return /* @__PURE__ */React.createElement(PatternFormat, {
|
|
113
|
-
...patternFormatProps,
|
|
114
|
-
name: field.name,
|
|
115
|
-
value: field.value,
|
|
116
|
-
onBlur: field.onBlur,
|
|
117
|
-
onValueChange: /* @__PURE__ */__name(values => {
|
|
118
|
-
field.onChange(values.value);
|
|
119
|
-
}, "onValueChange"),
|
|
120
|
-
format,
|
|
121
|
-
customInput: Input2,
|
|
122
|
-
placeholder,
|
|
123
|
-
disabled: disabled ?? field.disabled
|
|
124
|
-
});
|
|
125
|
-
}, "render")
|
|
85
|
+
return /* @__PURE__ */React.createElement(FormFieldPhone, {
|
|
86
|
+
...props,
|
|
87
|
+
countryCode: BRAZIL_COUNTRY_CODE,
|
|
88
|
+
format: getBrazilPhoneFormat,
|
|
89
|
+
placeholder,
|
|
90
|
+
countryCodeOptions
|
|
126
91
|
});
|
|
127
92
|
}, "FormFieldPhone");
|
|
128
|
-
export { FormFieldCEP, FormFieldCNPJ, FormFieldCPF, FormFieldCPFOrCNPJ, FormFieldPhone, isCnpjValid, isCpfValid };
|
|
93
|
+
export { FormFieldCEP, FormFieldCNPJ, FormFieldCPF, FormFieldCPFOrCNPJ, FormFieldPhone2 as 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-
|
|
4
|
-
import { __name } from "../chunk-
|
|
3
|
+
import { Form, useForm, yupResolver } from "../chunk-YCW3GPTZ.js";
|
|
4
|
+
import { __name } from "../chunk-ZORKZWD7.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, isCpfValid } from "./chunk-
|
|
3
|
+
import { FormErrorMessage, FormField, FormFieldPatternFormat, __name, isCnpjValid, isCpfValid } from "./chunk-ZORKZWD7.js";
|
|
4
4
|
|
|
5
5
|
// src/Form.tsx
|
|
6
6
|
import { Box } from "@ttoss/ui";
|
|
@@ -848,43 +848,23 @@ var FormFieldTextarea = /* @__PURE__ */__name(({
|
|
|
848
848
|
// src/FormGroup.tsx
|
|
849
849
|
import { Box as Box4, Flex as Flex4, Text as Text3 } from "@ttoss/ui";
|
|
850
850
|
import * as React4 from "react";
|
|
851
|
-
var FormGroupLevelsManagerContext = /* @__PURE__ */React4.createContext({
|
|
852
|
-
levelsLength: 1,
|
|
853
|
-
registerChild: /* @__PURE__ */__name(() => {
|
|
854
|
-
return null;
|
|
855
|
-
}, "registerChild")
|
|
856
|
-
});
|
|
857
|
-
var FormGroupLevelsManager = /* @__PURE__ */__name(({
|
|
858
|
-
children
|
|
859
|
-
}) => {
|
|
860
|
-
const [levelsLength, setLevelsLength] = React4.useState(0);
|
|
861
|
-
const registerChild = React4.useCallback(level => {
|
|
862
|
-
if (level + 1 > levelsLength) {
|
|
863
|
-
setLevelsLength(level + 1);
|
|
864
|
-
}
|
|
865
|
-
}, [levelsLength]);
|
|
866
|
-
return /* @__PURE__ */React4.createElement(FormGroupLevelsManagerContext.Provider, {
|
|
867
|
-
value: {
|
|
868
|
-
levelsLength,
|
|
869
|
-
registerChild
|
|
870
|
-
}
|
|
871
|
-
}, children);
|
|
872
|
-
}, "FormGroupLevelsManager");
|
|
873
851
|
var FormGroupContext = /* @__PURE__ */React4.createContext({});
|
|
874
852
|
var useFormGroup = /* @__PURE__ */__name(() => {
|
|
875
853
|
const {
|
|
876
854
|
parentLevel
|
|
877
855
|
} = React4.useContext(FormGroupContext);
|
|
878
|
-
const {
|
|
879
|
-
levelsLength
|
|
880
|
-
} = React4.useContext(FormGroupLevelsManagerContext);
|
|
881
856
|
return {
|
|
882
857
|
level: parentLevel,
|
|
883
|
-
|
|
858
|
+
/**
|
|
859
|
+
* @deprecated `levelsLength` has been removed from `FormGroup` internals.
|
|
860
|
+
* This field always returns `undefined`. Use `level` to determine nesting depth.
|
|
861
|
+
*/
|
|
862
|
+
levelsLength: void 0
|
|
884
863
|
};
|
|
885
864
|
}, "useFormGroup");
|
|
886
865
|
var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
887
866
|
title,
|
|
867
|
+
description,
|
|
888
868
|
direction,
|
|
889
869
|
children,
|
|
890
870
|
name,
|
|
@@ -893,37 +873,33 @@ var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
|
893
873
|
const {
|
|
894
874
|
level
|
|
895
875
|
} = useFormGroup();
|
|
896
|
-
const {
|
|
897
|
-
registerChild
|
|
898
|
-
} = React4.useContext(FormGroupLevelsManagerContext);
|
|
899
|
-
React4.useEffect(() => {
|
|
900
|
-
if (typeof level === "number") {
|
|
901
|
-
registerChild(level);
|
|
902
|
-
}
|
|
903
|
-
}, [level, registerChild]);
|
|
904
876
|
const childrenContainerSx = {
|
|
905
877
|
flexDirection: direction || "column",
|
|
906
878
|
gap: "1",
|
|
907
879
|
width: "100%"
|
|
908
880
|
};
|
|
909
881
|
return /* @__PURE__ */React4.createElement(Box4, {
|
|
910
|
-
"
|
|
882
|
+
"data-level": level,
|
|
911
883
|
...boxProps,
|
|
912
884
|
sx: {
|
|
913
885
|
marginTop: level === 0 ? "none" : "4",
|
|
914
886
|
marginBottom: "4",
|
|
915
887
|
...boxProps.sx
|
|
916
888
|
}
|
|
917
|
-
}, title && /* @__PURE__ */React4.createElement(Box4, {
|
|
889
|
+
}, (title || description) && /* @__PURE__ */React4.createElement(Box4, {
|
|
918
890
|
sx: {
|
|
919
891
|
marginBottom: "2"
|
|
920
892
|
}
|
|
921
|
-
}, /* @__PURE__ */React4.createElement(Text3, {
|
|
893
|
+
}, title && /* @__PURE__ */React4.createElement(Text3, {
|
|
922
894
|
sx: {
|
|
923
895
|
fontSize: "2xl",
|
|
924
896
|
fontWeight: "bold"
|
|
925
897
|
}
|
|
926
|
-
}, title)
|
|
898
|
+
}, title), description && /* @__PURE__ */React4.createElement(Text3, {
|
|
899
|
+
sx: {
|
|
900
|
+
color: "text.secondary"
|
|
901
|
+
}
|
|
902
|
+
}, description)), /* @__PURE__ */React4.createElement(Flex4, {
|
|
927
903
|
sx: childrenContainerSx
|
|
928
904
|
}, children), name && /* @__PURE__ */React4.createElement(FormErrorMessage, {
|
|
929
905
|
name
|
|
@@ -938,7 +914,7 @@ var FormGroup = /* @__PURE__ */__name(props => {
|
|
|
938
914
|
value: {
|
|
939
915
|
parentLevel: currentLevel
|
|
940
916
|
}
|
|
941
|
-
},
|
|
917
|
+
}, /* @__PURE__ */React4.createElement(FormGroupWrapper, props));
|
|
942
918
|
}, "FormGroup");
|
|
943
919
|
|
|
944
920
|
// src/yup/i18n.ts
|
|
@@ -268,9 +268,223 @@ var FormFieldPatternFormat = /* @__PURE__ */__name(({
|
|
|
268
268
|
});
|
|
269
269
|
}, "FormFieldPatternFormat");
|
|
270
270
|
|
|
271
|
+
// src/phoneCountryCodes.ts
|
|
272
|
+
var MANUAL_PHONE_COUNTRY_CODE = "manual";
|
|
273
|
+
var COMMON_PHONE_COUNTRY_CODES = [{
|
|
274
|
+
label: "Manual",
|
|
275
|
+
value: MANUAL_PHONE_COUNTRY_CODE
|
|
276
|
+
}, {
|
|
277
|
+
label: "\u{1F1FA}\u{1F1F8} +1 (US/Canada)",
|
|
278
|
+
value: "+1",
|
|
279
|
+
format: "(###) ###-####"
|
|
280
|
+
}, {
|
|
281
|
+
label: "\u{1F1FF}\u{1F1E6} +27 (South Africa)",
|
|
282
|
+
value: "+27",
|
|
283
|
+
format: "## ### ####"
|
|
284
|
+
}, {
|
|
285
|
+
label: "\u{1F1EB}\u{1F1F7} +33 (France)",
|
|
286
|
+
value: "+33",
|
|
287
|
+
format: "# ## ## ## ##"
|
|
288
|
+
}, {
|
|
289
|
+
label: "\u{1F1EA}\u{1F1F8} +34 (Spain)",
|
|
290
|
+
value: "+34",
|
|
291
|
+
format: "### ### ###"
|
|
292
|
+
}, {
|
|
293
|
+
label: "\u{1F1EE}\u{1F1F9} +39 (Italy)",
|
|
294
|
+
value: "+39",
|
|
295
|
+
format: "### ### ####"
|
|
296
|
+
}, {
|
|
297
|
+
label: "\u{1F1EC}\u{1F1E7} +44 (UK)",
|
|
298
|
+
value: "+44",
|
|
299
|
+
format: "#### ### ####"
|
|
300
|
+
}, {
|
|
301
|
+
label: "\u{1F1E9}\u{1F1EA} +49 (Germany)",
|
|
302
|
+
value: "+49",
|
|
303
|
+
format: "### ########"
|
|
304
|
+
}, {
|
|
305
|
+
label: "\u{1F1F2}\u{1F1FD} +52 (Mexico)",
|
|
306
|
+
value: "+52",
|
|
307
|
+
format: "## ########"
|
|
308
|
+
}, {
|
|
309
|
+
label: "\u{1F1E6}\u{1F1F7} +54 (Argentina)",
|
|
310
|
+
value: "+54",
|
|
311
|
+
format: "## ########"
|
|
312
|
+
}, {
|
|
313
|
+
label: "\u{1F1E7}\u{1F1F7} +55 (Brazil)",
|
|
314
|
+
value: "+55",
|
|
315
|
+
format: "(##) #####-####"
|
|
316
|
+
}, {
|
|
317
|
+
label: "\u{1F1E6}\u{1F1FA} +61 (Australia)",
|
|
318
|
+
value: "+61",
|
|
319
|
+
format: "#### ### ###"
|
|
320
|
+
}, {
|
|
321
|
+
label: "\u{1F1EF}\u{1F1F5} +81 (Japan)",
|
|
322
|
+
value: "+81",
|
|
323
|
+
format: "##-####-####"
|
|
324
|
+
}, {
|
|
325
|
+
label: "\u{1F1E8}\u{1F1F3} +86 (China)",
|
|
326
|
+
value: "+86",
|
|
327
|
+
format: "###-####-####"
|
|
328
|
+
}, {
|
|
329
|
+
label: "\u{1F1EE}\u{1F1F3} +91 (India)",
|
|
330
|
+
value: "+91",
|
|
331
|
+
format: "#####-#####"
|
|
332
|
+
}, {
|
|
333
|
+
label: "\u{1F1F5}\u{1F1F9} +351 (Portugal)",
|
|
334
|
+
value: "+351",
|
|
335
|
+
format: "### ### ###"
|
|
336
|
+
}];
|
|
337
|
+
|
|
338
|
+
// src/FormFieldPhone.tsx
|
|
339
|
+
import { Box, Flex as Flex3, Input as Input2, Select } from "@ttoss/ui";
|
|
340
|
+
import * as React4 from "react";
|
|
341
|
+
import { NumericFormat, PatternFormat as PatternFormat2 } from "react-number-format";
|
|
342
|
+
var PhoneDropdownWrapper = /* @__PURE__ */__name(({
|
|
343
|
+
id,
|
|
344
|
+
countryCode,
|
|
345
|
+
countryCodeOptions,
|
|
346
|
+
disabled,
|
|
347
|
+
onCountryCodeChange,
|
|
348
|
+
onPhoneReset,
|
|
349
|
+
inputNode
|
|
350
|
+
}) => {
|
|
351
|
+
return /* @__PURE__ */React4.createElement(Flex3, {
|
|
352
|
+
sx: {
|
|
353
|
+
gap: "2",
|
|
354
|
+
alignItems: "stretch"
|
|
355
|
+
}
|
|
356
|
+
}, /* @__PURE__ */React4.createElement(Box, {
|
|
357
|
+
sx: {
|
|
358
|
+
minWidth: "180px"
|
|
359
|
+
}
|
|
360
|
+
}, /* @__PURE__ */React4.createElement(Select, {
|
|
361
|
+
options: countryCodeOptions,
|
|
362
|
+
value: countryCode,
|
|
363
|
+
disabled,
|
|
364
|
+
onChange: /* @__PURE__ */__name(value => {
|
|
365
|
+
if (value !== void 0) {
|
|
366
|
+
onPhoneReset?.();
|
|
367
|
+
onCountryCodeChange?.(String(value));
|
|
368
|
+
}
|
|
369
|
+
}, "onChange")
|
|
370
|
+
})), /* @__PURE__ */React4.createElement(Box, {
|
|
371
|
+
sx: {
|
|
372
|
+
flex: 1
|
|
373
|
+
}
|
|
374
|
+
}, /* @__PURE__ */React4.cloneElement(inputNode, {
|
|
375
|
+
id
|
|
376
|
+
})));
|
|
377
|
+
}, "PhoneDropdownWrapper");
|
|
378
|
+
var FormFieldPhone = /* @__PURE__ */__name(({
|
|
379
|
+
disabled,
|
|
380
|
+
countryCode: countryCodeProp,
|
|
381
|
+
format,
|
|
382
|
+
countryCodeOptions = COMMON_PHONE_COUNTRY_CODES,
|
|
383
|
+
onCountryCodeChange,
|
|
384
|
+
...props
|
|
385
|
+
}) => {
|
|
386
|
+
const {
|
|
387
|
+
label,
|
|
388
|
+
name,
|
|
389
|
+
labelTooltip,
|
|
390
|
+
warning,
|
|
391
|
+
sx,
|
|
392
|
+
css,
|
|
393
|
+
rules,
|
|
394
|
+
id,
|
|
395
|
+
defaultValue,
|
|
396
|
+
auxiliaryCheckbox,
|
|
397
|
+
onBlur,
|
|
398
|
+
onValueChange,
|
|
399
|
+
placeholder,
|
|
400
|
+
...patternFormatProps
|
|
401
|
+
} = props;
|
|
402
|
+
const countryCode = countryCodeProp ?? countryCodeOptions[0]?.value ?? void 0;
|
|
403
|
+
const isManual = countryCode === MANUAL_PHONE_COUNTRY_CODE;
|
|
404
|
+
const getFormat = /* @__PURE__ */__name(value => {
|
|
405
|
+
const selectedOption = countryCodeOptions.find(opt => {
|
|
406
|
+
return opt.value === countryCode;
|
|
407
|
+
});
|
|
408
|
+
const resolvedFormat = selectedOption?.format ?? format ?? "(###) ###-####";
|
|
409
|
+
const baseFormat = typeof resolvedFormat === "function" ? resolvedFormat(value) : resolvedFormat;
|
|
410
|
+
return countryCode && !isManual ? `${countryCode} ${baseFormat}` : baseFormat;
|
|
411
|
+
}, "getFormat");
|
|
412
|
+
const showDropdown = countryCodeOptions.length > 0;
|
|
413
|
+
return /* @__PURE__ */React4.createElement(FormField, {
|
|
414
|
+
id,
|
|
415
|
+
label,
|
|
416
|
+
name,
|
|
417
|
+
labelTooltip,
|
|
418
|
+
warning,
|
|
419
|
+
sx,
|
|
420
|
+
css,
|
|
421
|
+
defaultValue,
|
|
422
|
+
rules,
|
|
423
|
+
disabled,
|
|
424
|
+
auxiliaryCheckbox,
|
|
425
|
+
render: /* @__PURE__ */__name(({
|
|
426
|
+
field,
|
|
427
|
+
fieldState
|
|
428
|
+
}) => {
|
|
429
|
+
const localPhoneValue = !isManual && countryCode && field.value?.startsWith(countryCode) ? field.value.slice(countryCode.length) : field.value;
|
|
430
|
+
const inputNode = isManual ? /* @__PURE__ */React4.createElement(NumericFormat, {
|
|
431
|
+
name: field.name,
|
|
432
|
+
value: field.value ?? "",
|
|
433
|
+
placeholder,
|
|
434
|
+
prefix: "+",
|
|
435
|
+
allowLeadingZeros: true,
|
|
436
|
+
decimalScale: 0,
|
|
437
|
+
thousandSeparator: false,
|
|
438
|
+
onBlur: /* @__PURE__ */__name(e => {
|
|
439
|
+
field.onBlur();
|
|
440
|
+
onBlur?.(e);
|
|
441
|
+
}, "onBlur"),
|
|
442
|
+
onValueChange: /* @__PURE__ */__name((values, sourceInfo) => {
|
|
443
|
+
field.onChange(values.formattedValue);
|
|
444
|
+
onValueChange?.(values, sourceInfo);
|
|
445
|
+
}, "onValueChange"),
|
|
446
|
+
customInput: Input2,
|
|
447
|
+
disabled: disabled ?? field.disabled,
|
|
448
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
449
|
+
}) : /* @__PURE__ */React4.createElement(PatternFormat2, {
|
|
450
|
+
...patternFormatProps,
|
|
451
|
+
name: field.name,
|
|
452
|
+
value: localPhoneValue,
|
|
453
|
+
placeholder,
|
|
454
|
+
onBlur: /* @__PURE__ */__name(e => {
|
|
455
|
+
field.onBlur();
|
|
456
|
+
onBlur?.(e);
|
|
457
|
+
}, "onBlur"),
|
|
458
|
+
onValueChange: /* @__PURE__ */__name((values, sourceInfo) => {
|
|
459
|
+
const fullValue = countryCode && values.value ? countryCode + values.value : values.value;
|
|
460
|
+
field.onChange(fullValue);
|
|
461
|
+
onValueChange?.(values, sourceInfo);
|
|
462
|
+
}, "onValueChange"),
|
|
463
|
+
format: getFormat(localPhoneValue ?? ""),
|
|
464
|
+
customInput: Input2,
|
|
465
|
+
disabled: disabled ?? field.disabled,
|
|
466
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
467
|
+
});
|
|
468
|
+
if (!showDropdown) {
|
|
469
|
+
return inputNode;
|
|
470
|
+
}
|
|
471
|
+
return /* @__PURE__ */React4.createElement(PhoneDropdownWrapper, {
|
|
472
|
+
countryCode,
|
|
473
|
+
countryCodeOptions,
|
|
474
|
+
disabled: disabled ?? field.disabled,
|
|
475
|
+
onCountryCodeChange,
|
|
476
|
+
onPhoneReset: /* @__PURE__ */__name(() => {
|
|
477
|
+
return field.onChange("");
|
|
478
|
+
}, "onPhoneReset"),
|
|
479
|
+
inputNode
|
|
480
|
+
});
|
|
481
|
+
}, "render")
|
|
482
|
+
});
|
|
483
|
+
}, "FormFieldPhone");
|
|
484
|
+
|
|
271
485
|
// src/Brazil/FormFieldCNPJ.tsx
|
|
272
|
-
import { Input as
|
|
273
|
-
import { PatternFormat as
|
|
486
|
+
import { Input as Input3 } from "@ttoss/ui";
|
|
487
|
+
import { PatternFormat as PatternFormat3 } from "react-number-format";
|
|
274
488
|
var isCnpjValid = /* @__PURE__ */__name(cnpj => {
|
|
275
489
|
if (cnpj?.length != 14) {
|
|
276
490
|
return false;
|
|
@@ -342,7 +556,7 @@ var FormFieldCNPJ = /* @__PURE__ */__name(({
|
|
|
342
556
|
render: /* @__PURE__ */__name(({
|
|
343
557
|
field
|
|
344
558
|
}) => {
|
|
345
|
-
return /* @__PURE__ */React.createElement(
|
|
559
|
+
return /* @__PURE__ */React.createElement(PatternFormat3, {
|
|
346
560
|
...patternFormatProps,
|
|
347
561
|
name: field.name,
|
|
348
562
|
value: field.value,
|
|
@@ -351,7 +565,7 @@ var FormFieldCNPJ = /* @__PURE__ */__name(({
|
|
|
351
565
|
field.onChange(values.value);
|
|
352
566
|
}, "onValueChange"),
|
|
353
567
|
format: "##.###.###/####-##",
|
|
354
|
-
customInput:
|
|
568
|
+
customInput: Input3,
|
|
355
569
|
placeholder,
|
|
356
570
|
disabled: disabled ?? field.disabled
|
|
357
571
|
});
|
|
@@ -360,8 +574,8 @@ var FormFieldCNPJ = /* @__PURE__ */__name(({
|
|
|
360
574
|
}, "FormFieldCNPJ");
|
|
361
575
|
|
|
362
576
|
// src/Brazil/FormFieldCPF.tsx
|
|
363
|
-
import { Input as
|
|
364
|
-
import { PatternFormat as
|
|
577
|
+
import { Input as Input4 } from "@ttoss/ui";
|
|
578
|
+
import { PatternFormat as PatternFormat4 } from "react-number-format";
|
|
365
579
|
var isCpfValid = /* @__PURE__ */__name(cpf => {
|
|
366
580
|
if (cpf?.length != 11) {
|
|
367
581
|
return false;
|
|
@@ -424,7 +638,7 @@ var FormFieldCPF = /* @__PURE__ */__name(({
|
|
|
424
638
|
render: /* @__PURE__ */__name(({
|
|
425
639
|
field
|
|
426
640
|
}) => {
|
|
427
|
-
return /* @__PURE__ */React.createElement(
|
|
641
|
+
return /* @__PURE__ */React.createElement(PatternFormat4, {
|
|
428
642
|
...patternFormatProps,
|
|
429
643
|
name: field.name,
|
|
430
644
|
value: field.value,
|
|
@@ -433,11 +647,11 @@ var FormFieldCPF = /* @__PURE__ */__name(({
|
|
|
433
647
|
field.onChange(values.value);
|
|
434
648
|
}, "onValueChange"),
|
|
435
649
|
format: "###.###.###-##",
|
|
436
|
-
customInput:
|
|
650
|
+
customInput: Input4,
|
|
437
651
|
placeholder,
|
|
438
652
|
disabled: disabled ?? field.disabled
|
|
439
653
|
});
|
|
440
654
|
}, "render")
|
|
441
655
|
});
|
|
442
656
|
}, "FormFieldCPF");
|
|
443
|
-
export { __name, FormErrorMessage, FormField, FormFieldPatternFormat, isCnpjValid, FormFieldCNPJ, isCpfValid, FormFieldCPF };
|
|
657
|
+
export { __name, FormErrorMessage, FormField, FormFieldPatternFormat, MANUAL_PHONE_COUNTRY_CODE, COMMON_PHONE_COUNTRY_CODES, FormFieldPhone, 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, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver } from "./chunk-
|
|
3
|
-
import { FormErrorMessage, FormField, FormFieldPatternFormat } from "./chunk-
|
|
4
|
-
export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver };
|
|
2
|
+
import { Controller, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver } from "./chunk-YCW3GPTZ.js";
|
|
3
|
+
import { COMMON_PHONE_COUNTRY_CODES, FormErrorMessage, FormField, FormFieldPatternFormat, FormFieldPhone, MANUAL_PHONE_COUNTRY_CODE } from "./chunk-ZORKZWD7.js";
|
|
4
|
+
export { COMMON_PHONE_COUNTRY_CODES, Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldPhone, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, MANUAL_PHONE_COUNTRY_CODE, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import * as React from 'react';
|
|
|
4
4
|
import { FieldValues, FormProviderProps, FieldName, FieldPath } from 'react-hook-form';
|
|
5
5
|
export * from 'react-hook-form';
|
|
6
6
|
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
7
|
-
import { F as FormFieldProps, a as FormFieldPatternFormatProps } from './
|
|
8
|
-
export { b as FormField, c as FormFieldPatternFormat } from './
|
|
7
|
+
import { F as FormFieldProps, a as FormFieldPatternFormatProps } from './FormFieldPhone-BKeOS0i6.js';
|
|
8
|
+
export { f as COMMON_PHONE_COUNTRY_CODES, C as CountryCodeOption, b as FormField, c as FormFieldPatternFormat, e as FormFieldPhone, d as FormFieldPhoneProps, M as MANUAL_PHONE_COUNTRY_CODE } from './FormFieldPhone-BKeOS0i6.js';
|
|
9
9
|
import { NumericFormatProps } from 'react-number-format';
|
|
10
10
|
import { DateRange } from '@ttoss/components/DatePicker';
|
|
11
11
|
import './typings.d-BzNUo1mD.js';
|
|
@@ -114,13 +114,64 @@ declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues
|
|
|
114
114
|
|
|
115
115
|
declare const useFormGroup: () => {
|
|
116
116
|
level: number | undefined;
|
|
117
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated `levelsLength` has been removed from `FormGroup` internals.
|
|
119
|
+
* This field always returns `undefined`. Use `level` to determine nesting depth.
|
|
120
|
+
*/
|
|
121
|
+
levelsLength: number | undefined;
|
|
118
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Props for the FormGroup component.
|
|
125
|
+
*/
|
|
119
126
|
type FormGroupProps = {
|
|
127
|
+
/**
|
|
128
|
+
* The field name used to display a validation error message below the group.
|
|
129
|
+
* Useful when the group maps to an array or object field in the form schema.
|
|
130
|
+
*/
|
|
120
131
|
name?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Optional heading displayed above the group's children.
|
|
134
|
+
*/
|
|
121
135
|
title?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Optional description displayed below the title.
|
|
138
|
+
*/
|
|
139
|
+
description?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Layout direction for the group's children.
|
|
142
|
+
* @default 'column'
|
|
143
|
+
*/
|
|
122
144
|
direction?: 'column' | 'row';
|
|
123
145
|
} & BoxProps;
|
|
146
|
+
/**
|
|
147
|
+
* FormGroup is a layout container that organises form fields into labelled,
|
|
148
|
+
* optionally nested sections. Each nested `FormGroup` increments an internal
|
|
149
|
+
* `level` counter exposed via `useFormGroup`, which drives a `data-level`
|
|
150
|
+
* attribute and top-margin spacing so deeper groups are visually indented.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* <FormGroup title="Personal details">
|
|
155
|
+
* <FormFieldInput name="firstName" label="First name" />
|
|
156
|
+
* <FormFieldInput name="lastName" label="Last name" />
|
|
157
|
+
*
|
|
158
|
+
* <FormGroup title="Address" direction="row">
|
|
159
|
+
* <FormFieldInput name="city" label="City" />
|
|
160
|
+
* <FormFieldInput name="zip" label="ZIP" />
|
|
161
|
+
* </FormGroup>
|
|
162
|
+
* </FormGroup>
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // Show a group-level validation error (e.g. for an array field)
|
|
167
|
+
* ```tsx
|
|
168
|
+
* <FormGroup name="items" title="Items">
|
|
169
|
+
* {fields.map((field, i) => (
|
|
170
|
+
* <FormFieldInput key={field.id} name={`items[${i}].value`} label="Value" />
|
|
171
|
+
* ))}
|
|
172
|
+
* </FormGroup>
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
124
175
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
125
176
|
|
|
126
177
|
export { type DateRangePreset, Form, FormErrorMessage, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldProps, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, type FormRadioOption, useFormGroup };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": ">=16.8.0",
|
|
43
|
-
"@ttoss/components": "^2.13.
|
|
44
|
-
"@ttoss/
|
|
45
|
-
"@ttoss/
|
|
43
|
+
"@ttoss/components": "^2.13.2",
|
|
44
|
+
"@ttoss/react-i18n": "^2.1.0",
|
|
45
|
+
"@ttoss/ui": "^6.8.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/jest": "^30.0.0",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"react-error-boundary": "^6.1.0",
|
|
53
53
|
"tsup": "^8.5.1",
|
|
54
54
|
"yup": "^1.7.1",
|
|
55
|
-
"@ttoss/
|
|
55
|
+
"@ttoss/components": "^2.13.2",
|
|
56
56
|
"@ttoss/i18n-cli": "^0.7.39",
|
|
57
|
-
"@ttoss/components": "^2.13.1",
|
|
58
|
-
"@ttoss/react-icons": "^0.6.0",
|
|
59
57
|
"@ttoss/react-i18n": "^2.1.0",
|
|
58
|
+
"@ttoss/react-icons": "^0.6.0",
|
|
60
59
|
"@ttoss/test-utils": "^4.1.0",
|
|
61
|
-
"@ttoss/ui": "^6.
|
|
60
|
+
"@ttoss/ui": "^6.8.0",
|
|
61
|
+
"@ttoss/config": "^1.36.0"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public",
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { TooltipProps, SxProp, InputProps } from '@ttoss/ui';
|
|
3
|
-
import { FieldValues, FieldPath, RegisterOptions, FieldPathValue, UseControllerReturn } from 'react-hook-form';
|
|
4
|
-
import { PatternFormatProps } from 'react-number-format';
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
|
|
7
|
-
type AuxiliaryCheckboxRules<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
|
8
|
-
/**
|
|
9
|
-
* Props for the AuxiliaryCheckbox component.
|
|
10
|
-
*/
|
|
11
|
-
type AuxiliaryCheckboxProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
12
|
-
/**
|
|
13
|
-
* The label to display next to the checkbox.
|
|
14
|
-
*/
|
|
15
|
-
label: React.ReactNode;
|
|
16
|
-
/**
|
|
17
|
-
* The name of the checkbox field in the form.
|
|
18
|
-
*/
|
|
19
|
-
name: TName;
|
|
20
|
-
/**
|
|
21
|
-
* The default value of the checkbox.
|
|
22
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
defaultValue?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Validation rules for the checkbox field.
|
|
27
|
-
*/
|
|
28
|
-
rules?: AuxiliaryCheckboxRules<TFieldValues, TName>;
|
|
29
|
-
/**
|
|
30
|
-
* Whether the checkbox is disabled.
|
|
31
|
-
*/
|
|
32
|
-
disabled?: boolean;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type Rules<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
|
36
|
-
type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
37
|
-
label?: React.ReactNode;
|
|
38
|
-
id?: string;
|
|
39
|
-
name: TName;
|
|
40
|
-
defaultValue?: FieldPathValue<TFieldValues, TName>;
|
|
41
|
-
disabled?: boolean;
|
|
42
|
-
labelTooltip?: TooltipProps;
|
|
43
|
-
warning?: string | React.ReactNode;
|
|
44
|
-
rules?: Rules<TFieldValues, TName>;
|
|
45
|
-
/**
|
|
46
|
-
* Optional auxiliary checkbox to render between the field and error message.
|
|
47
|
-
* Useful for input confirmation or conditional display of other fields.
|
|
48
|
-
*/
|
|
49
|
-
auxiliaryCheckbox?: AuxiliaryCheckboxProps<TFieldValues, FieldPath<TFieldValues>>;
|
|
50
|
-
} & SxProp;
|
|
51
|
-
type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
52
|
-
render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
|
|
53
|
-
} & FormFieldProps<TFieldValues, TName>;
|
|
54
|
-
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled: propsDisabled, labelTooltip, sx, css, render, warning, rules, auxiliaryCheckbox, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
55
|
-
|
|
56
|
-
type FormFieldPatternFormatProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<PatternFormatProps, 'name'> & Pick<InputProps, 'leadingIcon' | 'trailingIcon'>;
|
|
57
|
-
declare const FormFieldPatternFormat: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldPatternFormatProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
58
|
-
|
|
59
|
-
export { type FormFieldProps as F, type FormFieldPatternFormatProps as a, FormField as b, FormFieldPatternFormat as c };
|