@ttoss/forms 0.41.2 → 0.43.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/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-HN7QPZLJ.js → chunk-4YLT3VPV.js} +135 -94
- package/dist/esm/{chunk-BL55OAIO.js → chunk-ZORKZWD7.js} +223 -9
- package/dist/esm/index.js +3 -3
- package/dist/index.d.ts +136 -68
- package/package.json +8 -8
- package/dist/FormFieldPatternFormat-kaO0pl1R.d.ts +0 -59
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-4YLT3VPV.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,26 +1,139 @@
|
|
|
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
|
-
import { Box } from "@ttoss/ui";
|
|
7
|
-
import * as React2 from "react";
|
|
6
|
+
import { Box as Box2 } from "@ttoss/ui";
|
|
8
7
|
import { FormProvider } from "react-hook-form";
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
// src/FormActions.tsx
|
|
10
|
+
import { Flex } from "@ttoss/ui";
|
|
11
|
+
var alignMap = {
|
|
12
|
+
left: "flex-start",
|
|
13
|
+
center: "center",
|
|
14
|
+
right: "flex-end"
|
|
15
|
+
};
|
|
16
|
+
var FormActions = /* @__PURE__ */__name(({
|
|
17
|
+
align = "right",
|
|
18
|
+
children,
|
|
19
|
+
sticky = false,
|
|
20
|
+
sx,
|
|
21
|
+
...flexProps
|
|
22
|
+
}) => {
|
|
23
|
+
return /* @__PURE__ */React.createElement(Flex, {
|
|
24
|
+
...flexProps,
|
|
25
|
+
sx: {
|
|
26
|
+
flexDirection: "row",
|
|
27
|
+
gap: "2",
|
|
28
|
+
justifyContent: alignMap[align],
|
|
29
|
+
...(sticky && {
|
|
30
|
+
position: "sticky",
|
|
31
|
+
bottom: 0,
|
|
32
|
+
backgroundColor: "background",
|
|
33
|
+
paddingY: "3",
|
|
34
|
+
zIndex: "sticky"
|
|
35
|
+
}),
|
|
36
|
+
...sx
|
|
37
|
+
}
|
|
38
|
+
}, children);
|
|
39
|
+
}, "FormActions");
|
|
40
|
+
|
|
41
|
+
// src/FormGroup.tsx
|
|
42
|
+
import { Box, Flex as Flex2, Text } from "@ttoss/ui";
|
|
43
|
+
import * as React2 from "react";
|
|
44
|
+
var FormGroupContext = /* @__PURE__ */React2.createContext({});
|
|
45
|
+
var useFormGroup = /* @__PURE__ */__name(() => {
|
|
46
|
+
const {
|
|
47
|
+
parentLevel
|
|
48
|
+
} = React2.useContext(FormGroupContext);
|
|
49
|
+
return {
|
|
50
|
+
level: parentLevel,
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated `levelsLength` has been removed from `FormGroup` internals.
|
|
53
|
+
* This field always returns `undefined`. Use `level` to determine nesting depth.
|
|
54
|
+
*/
|
|
55
|
+
levelsLength: void 0
|
|
56
|
+
};
|
|
57
|
+
}, "useFormGroup");
|
|
58
|
+
var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
59
|
+
title,
|
|
60
|
+
description,
|
|
61
|
+
direction,
|
|
62
|
+
children,
|
|
63
|
+
name,
|
|
64
|
+
...boxProps
|
|
65
|
+
}) => {
|
|
66
|
+
const {
|
|
67
|
+
level
|
|
68
|
+
} = useFormGroup();
|
|
69
|
+
const childrenContainerSx = {
|
|
70
|
+
flexDirection: direction || "column",
|
|
71
|
+
gap: "4",
|
|
72
|
+
width: "100%"
|
|
73
|
+
};
|
|
74
|
+
return /* @__PURE__ */React2.createElement(Box, {
|
|
75
|
+
"data-level": level,
|
|
76
|
+
...boxProps,
|
|
77
|
+
sx: {
|
|
78
|
+
marginTop: level === 0 ? "none" : "4",
|
|
79
|
+
...boxProps.sx
|
|
80
|
+
}
|
|
81
|
+
}, (title || description) && /* @__PURE__ */React2.createElement(Box, {
|
|
82
|
+
sx: {
|
|
83
|
+
marginBottom: "2"
|
|
84
|
+
}
|
|
85
|
+
}, title && /* @__PURE__ */React2.createElement(Text, {
|
|
86
|
+
sx: {
|
|
87
|
+
fontSize: "2xl",
|
|
88
|
+
fontWeight: "bold"
|
|
89
|
+
}
|
|
90
|
+
}, title), description && /* @__PURE__ */React2.createElement(Text, {
|
|
91
|
+
sx: {
|
|
92
|
+
color: "text.secondary"
|
|
93
|
+
}
|
|
94
|
+
}, description)), /* @__PURE__ */React2.createElement(Flex2, {
|
|
95
|
+
sx: childrenContainerSx
|
|
96
|
+
}, children), name && /* @__PURE__ */React2.createElement(FormErrorMessage, {
|
|
97
|
+
name
|
|
98
|
+
}));
|
|
99
|
+
}, "FormGroupWrapper");
|
|
100
|
+
var FormGroup = /* @__PURE__ */__name(props => {
|
|
101
|
+
const {
|
|
102
|
+
level
|
|
103
|
+
} = useFormGroup();
|
|
104
|
+
const currentLevel = level === void 0 ? 0 : level + 1;
|
|
105
|
+
return /* @__PURE__ */React2.createElement(FormGroupContext.Provider, {
|
|
106
|
+
value: {
|
|
107
|
+
parentLevel: currentLevel
|
|
108
|
+
}
|
|
109
|
+
}, /* @__PURE__ */React2.createElement(FormGroupWrapper, props));
|
|
110
|
+
}, "FormGroup");
|
|
111
|
+
|
|
112
|
+
// src/Form.tsx
|
|
113
|
+
var FormBase = /* @__PURE__ */__name(({
|
|
10
114
|
children,
|
|
11
115
|
onSubmit,
|
|
12
116
|
sx,
|
|
13
117
|
...formMethods
|
|
14
118
|
}) => {
|
|
15
|
-
return /* @__PURE__ */
|
|
119
|
+
return /* @__PURE__ */React.createElement(FormProvider, formMethods, /* @__PURE__ */React.createElement(Box2, {
|
|
16
120
|
as: "form",
|
|
17
121
|
variant: "forms.form",
|
|
18
122
|
onSubmit: formMethods.handleSubmit(data => {
|
|
19
123
|
return onSubmit?.(data);
|
|
20
124
|
}),
|
|
21
|
-
sx
|
|
125
|
+
sx: {
|
|
126
|
+
display: "flex",
|
|
127
|
+
flexDirection: "column",
|
|
128
|
+
gap: "4",
|
|
129
|
+
...sx
|
|
130
|
+
}
|
|
22
131
|
}, children));
|
|
23
|
-
}, "
|
|
132
|
+
}, "FormBase");
|
|
133
|
+
var Form = Object.assign(FormBase, {
|
|
134
|
+
Group: FormGroup,
|
|
135
|
+
Actions: FormActions
|
|
136
|
+
});
|
|
24
137
|
|
|
25
138
|
// src/FormFieldCheckbox.tsx
|
|
26
139
|
import { Checkbox } from "@ttoss/ui";
|
|
@@ -363,7 +476,7 @@ var FormFieldPassword = /* @__PURE__ */__name(({
|
|
|
363
476
|
}, "FormFieldPassword");
|
|
364
477
|
|
|
365
478
|
// src/FormFieldRadio.tsx
|
|
366
|
-
import { Flex, Label, Radio } from "@ttoss/ui";
|
|
479
|
+
import { Flex as Flex3, Label, Radio } from "@ttoss/ui";
|
|
367
480
|
var FormFieldRadio = /* @__PURE__ */__name(({
|
|
368
481
|
disabled,
|
|
369
482
|
options,
|
|
@@ -397,7 +510,7 @@ var FormFieldRadio = /* @__PURE__ */__name(({
|
|
|
397
510
|
render: /* @__PURE__ */__name(({
|
|
398
511
|
field
|
|
399
512
|
}) => {
|
|
400
|
-
return /* @__PURE__ */React.createElement(
|
|
513
|
+
return /* @__PURE__ */React.createElement(Flex3, {
|
|
401
514
|
sx: {
|
|
402
515
|
flexDirection: "column",
|
|
403
516
|
gap: "1"
|
|
@@ -431,7 +544,7 @@ var FormFieldRadio = /* @__PURE__ */__name(({
|
|
|
431
544
|
}, "FormFieldRadio");
|
|
432
545
|
|
|
433
546
|
// src/FormFieldRadioCard.tsx
|
|
434
|
-
import { Box as
|
|
547
|
+
import { Box as Box3, Flex as Flex4, Label as Label2, Radio as Radio2, Text as Text2 } from "@ttoss/ui";
|
|
435
548
|
var FormFieldRadioCard = /* @__PURE__ */__name(({
|
|
436
549
|
disabled,
|
|
437
550
|
...props
|
|
@@ -467,7 +580,7 @@ var FormFieldRadioCard = /* @__PURE__ */__name(({
|
|
|
467
580
|
render: /* @__PURE__ */__name(({
|
|
468
581
|
field
|
|
469
582
|
}) => {
|
|
470
|
-
return /* @__PURE__ */React.createElement(
|
|
583
|
+
return /* @__PURE__ */React.createElement(Flex4, {
|
|
471
584
|
sx: {
|
|
472
585
|
flexDirection: direction,
|
|
473
586
|
gap: "4"
|
|
@@ -475,7 +588,7 @@ var FormFieldRadioCard = /* @__PURE__ */__name(({
|
|
|
475
588
|
}, options.map(option => {
|
|
476
589
|
const key = `form-field-radio-${name}-${option.value}`;
|
|
477
590
|
const isSelected = field.value === option.value;
|
|
478
|
-
return /* @__PURE__ */React.createElement(
|
|
591
|
+
return /* @__PURE__ */React.createElement(Box3, {
|
|
479
592
|
key,
|
|
480
593
|
sx: {
|
|
481
594
|
gap: "2",
|
|
@@ -506,12 +619,12 @@ var FormFieldRadioCard = /* @__PURE__ */__name(({
|
|
|
506
619
|
checked: field.value === option.value,
|
|
507
620
|
name,
|
|
508
621
|
disabled: disabled ?? field.disabled
|
|
509
|
-
}), /* @__PURE__ */React.createElement(
|
|
622
|
+
}), /* @__PURE__ */React.createElement(Flex4, {
|
|
510
623
|
sx: {
|
|
511
624
|
flexDirection: "column",
|
|
512
625
|
gap: "1"
|
|
513
626
|
}
|
|
514
|
-
}, option.label && /* @__PURE__ */React.createElement(
|
|
627
|
+
}, option.label && /* @__PURE__ */React.createElement(Text2, null, option.label), option.description && /* @__PURE__ */React.createElement(Text2, {
|
|
515
628
|
sx: {
|
|
516
629
|
fontSize: "sm"
|
|
517
630
|
}
|
|
@@ -522,7 +635,7 @@ var FormFieldRadioCard = /* @__PURE__ */__name(({
|
|
|
522
635
|
}, "FormFieldRadioCard");
|
|
523
636
|
|
|
524
637
|
// src/FormFieldRadioCardIcony.tsx
|
|
525
|
-
import { Box as
|
|
638
|
+
import { Box as Box4, Flex as Flex5, Tag, Text as Text3 } from "@ttoss/ui";
|
|
526
639
|
import * as React3 from "react";
|
|
527
640
|
var FormFieldRadioCardIcony = /* @__PURE__ */__name(({
|
|
528
641
|
disabled,
|
|
@@ -563,7 +676,7 @@ var FormFieldRadioCardIcony = /* @__PURE__ */__name(({
|
|
|
563
676
|
field.onBlur();
|
|
564
677
|
}
|
|
565
678
|
}, "handleOptionClick");
|
|
566
|
-
return /* @__PURE__ */React3.createElement(
|
|
679
|
+
return /* @__PURE__ */React3.createElement(Flex5, {
|
|
567
680
|
sx: {
|
|
568
681
|
flexDirection: direction,
|
|
569
682
|
gap: "4"
|
|
@@ -573,7 +686,7 @@ var FormFieldRadioCardIcony = /* @__PURE__ */__name(({
|
|
|
573
686
|
const isSelected = field.value === option.value;
|
|
574
687
|
const IconComponent = option.icon;
|
|
575
688
|
const tag = option.tag;
|
|
576
|
-
return /* @__PURE__ */React3.createElement(
|
|
689
|
+
return /* @__PURE__ */React3.createElement(Box4, {
|
|
577
690
|
key,
|
|
578
691
|
onClick: /* @__PURE__ */__name(() => {
|
|
579
692
|
return handleOptionClick(option.value);
|
|
@@ -594,25 +707,25 @@ var FormFieldRadioCardIcony = /* @__PURE__ */__name(({
|
|
|
594
707
|
opacity: isDisabled ? 0.5 : 1,
|
|
595
708
|
transition: "all 0.2s ease-in-out"
|
|
596
709
|
}
|
|
597
|
-
}, IconComponent && /* @__PURE__ */React3.createElement(
|
|
710
|
+
}, IconComponent && /* @__PURE__ */React3.createElement(Box4, {
|
|
598
711
|
sx: {
|
|
599
712
|
marginBottom: "2",
|
|
600
713
|
color: "text.primary"
|
|
601
714
|
}
|
|
602
715
|
}, /* @__PURE__ */React3.createElement(IconComponent, {
|
|
603
716
|
size: 24
|
|
604
|
-
})), /* @__PURE__ */React3.createElement(
|
|
717
|
+
})), /* @__PURE__ */React3.createElement(Flex5, {
|
|
605
718
|
sx: {
|
|
606
719
|
flexDirection: "column",
|
|
607
720
|
gap: "1"
|
|
608
721
|
}
|
|
609
|
-
}, option.label && /* @__PURE__ */React3.createElement(
|
|
722
|
+
}, option.label && /* @__PURE__ */React3.createElement(Text3, {
|
|
610
723
|
sx: {
|
|
611
724
|
fontSize: "lg",
|
|
612
725
|
fontWeight: "semibold",
|
|
613
726
|
color: "text.primary"
|
|
614
727
|
}
|
|
615
|
-
}, option.label), option.description && /* @__PURE__ */React3.createElement(
|
|
728
|
+
}, option.label), option.description && /* @__PURE__ */React3.createElement(Text3, {
|
|
616
729
|
sx: {
|
|
617
730
|
fontSize: "md",
|
|
618
731
|
color: "text.secondary"
|
|
@@ -845,78 +958,6 @@ var FormFieldTextarea = /* @__PURE__ */__name(({
|
|
|
845
958
|
});
|
|
846
959
|
}, "FormFieldTextarea");
|
|
847
960
|
|
|
848
|
-
// src/FormGroup.tsx
|
|
849
|
-
import { Box as Box4, Flex as Flex4, Text as Text3 } from "@ttoss/ui";
|
|
850
|
-
import * as React4 from "react";
|
|
851
|
-
var FormGroupContext = /* @__PURE__ */React4.createContext({});
|
|
852
|
-
var useFormGroup = /* @__PURE__ */__name(() => {
|
|
853
|
-
const {
|
|
854
|
-
parentLevel
|
|
855
|
-
} = React4.useContext(FormGroupContext);
|
|
856
|
-
return {
|
|
857
|
-
level: parentLevel,
|
|
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
|
|
863
|
-
};
|
|
864
|
-
}, "useFormGroup");
|
|
865
|
-
var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
866
|
-
title,
|
|
867
|
-
description,
|
|
868
|
-
direction,
|
|
869
|
-
children,
|
|
870
|
-
name,
|
|
871
|
-
...boxProps
|
|
872
|
-
}) => {
|
|
873
|
-
const {
|
|
874
|
-
level
|
|
875
|
-
} = useFormGroup();
|
|
876
|
-
const childrenContainerSx = {
|
|
877
|
-
flexDirection: direction || "column",
|
|
878
|
-
gap: "1",
|
|
879
|
-
width: "100%"
|
|
880
|
-
};
|
|
881
|
-
return /* @__PURE__ */React4.createElement(Box4, {
|
|
882
|
-
"data-level": level,
|
|
883
|
-
...boxProps,
|
|
884
|
-
sx: {
|
|
885
|
-
marginTop: level === 0 ? "none" : "4",
|
|
886
|
-
marginBottom: "4",
|
|
887
|
-
...boxProps.sx
|
|
888
|
-
}
|
|
889
|
-
}, (title || description) && /* @__PURE__ */React4.createElement(Box4, {
|
|
890
|
-
sx: {
|
|
891
|
-
marginBottom: "2"
|
|
892
|
-
}
|
|
893
|
-
}, title && /* @__PURE__ */React4.createElement(Text3, {
|
|
894
|
-
sx: {
|
|
895
|
-
fontSize: "2xl",
|
|
896
|
-
fontWeight: "bold"
|
|
897
|
-
}
|
|
898
|
-
}, title), description && /* @__PURE__ */React4.createElement(Text3, {
|
|
899
|
-
sx: {
|
|
900
|
-
color: "text.secondary"
|
|
901
|
-
}
|
|
902
|
-
}, description)), /* @__PURE__ */React4.createElement(Flex4, {
|
|
903
|
-
sx: childrenContainerSx
|
|
904
|
-
}, children), name && /* @__PURE__ */React4.createElement(FormErrorMessage, {
|
|
905
|
-
name
|
|
906
|
-
}));
|
|
907
|
-
}, "FormGroupWrapper");
|
|
908
|
-
var FormGroup = /* @__PURE__ */__name(props => {
|
|
909
|
-
const {
|
|
910
|
-
level
|
|
911
|
-
} = useFormGroup();
|
|
912
|
-
const currentLevel = level === void 0 ? 0 : level + 1;
|
|
913
|
-
return /* @__PURE__ */React4.createElement(FormGroupContext.Provider, {
|
|
914
|
-
value: {
|
|
915
|
-
parentLevel: currentLevel
|
|
916
|
-
}
|
|
917
|
-
}, /* @__PURE__ */React4.createElement(FormGroupWrapper, props));
|
|
918
|
-
}, "FormGroup");
|
|
919
|
-
|
|
920
961
|
// src/yup/i18n.ts
|
|
921
962
|
import { defineMessage } from "@ttoss/react-i18n";
|
|
922
963
|
import { setLocale } from "yup";
|
|
@@ -1083,4 +1124,4 @@ import { yupResolver } from "@hookform/resolvers/yup";
|
|
|
1083
1124
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
1084
1125
|
import { Controller, FormProvider as FormProvider2, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from "react-hook-form";
|
|
1085
1126
|
export * from "react-hook-form";
|
|
1086
|
-
export { Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldNumericFormat, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea,
|
|
1127
|
+
export { FormActions, useFormGroup, FormGroup, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldNumericFormat, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, yup2 as yup, z3 as z, yupResolver, zodResolver, Controller, FormProvider2 as FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
|
|
@@ -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, FormActions, 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-4YLT3VPV.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, FormActions, 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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { BoxProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, ThemeUIStyleObject, SegmentedControlProps, SelectProps, SwitchProps, TextareaProps } from '@ttoss/ui';
|
|
2
|
+
import { FlexProps, BoxProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, ThemeUIStyleObject, SegmentedControlProps, SelectProps, SwitchProps, TextareaProps } from '@ttoss/ui';
|
|
3
3
|
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';
|
|
@@ -16,11 +16,141 @@ export { z };
|
|
|
16
16
|
export { yupResolver } from '@hookform/resolvers/yup';
|
|
17
17
|
export { zodResolver } from '@hookform/resolvers/zod';
|
|
18
18
|
|
|
19
|
-
declare const
|
|
19
|
+
declare const alignMap: {
|
|
20
|
+
readonly left: "flex-start";
|
|
21
|
+
readonly center: "center";
|
|
22
|
+
readonly right: "flex-end";
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Props for the FormActions component.
|
|
26
|
+
*/
|
|
27
|
+
type FormActionsProps = {
|
|
28
|
+
/** Action buttons (Submit, Cancel, Reset, etc.). */
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* Horizontal alignment of the action buttons.
|
|
32
|
+
* @default 'right'
|
|
33
|
+
*/
|
|
34
|
+
align?: keyof typeof alignMap;
|
|
35
|
+
/**
|
|
36
|
+
* When `true`, the action bar sticks to the bottom of the viewport so it
|
|
37
|
+
* remains visible while the user scrolls through a long form.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
sticky?: boolean;
|
|
41
|
+
} & Omit<FlexProps, 'children'>;
|
|
42
|
+
/**
|
|
43
|
+
* FormActions is a layout container for form action buttons such as Submit,
|
|
44
|
+
* Cancel, and Reset. It renders a flex row with consistent spacing.
|
|
45
|
+
*
|
|
46
|
+
* Use `align` to control horizontal button placement (`'left'`, `'center'`,
|
|
47
|
+
* or `'right'`). Use `sticky` to keep the action bar visible while the user
|
|
48
|
+
* scrolls through a long form.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <Form.Actions align="right" sticky>
|
|
53
|
+
* <Button variant="secondary" onClick={onCancel}>Cancel</Button>
|
|
54
|
+
* <Button type="submit">Save</Button>
|
|
55
|
+
* </Form.Actions>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare const FormActions: ({ align, children, sticky, sx, ...flexProps }: FormActionsProps) => react_jsx_runtime.JSX.Element;
|
|
59
|
+
|
|
60
|
+
declare const useFormGroup: () => {
|
|
61
|
+
level: number | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated `levelsLength` has been removed from `FormGroup` internals.
|
|
64
|
+
* This field always returns `undefined`. Use `level` to determine nesting depth.
|
|
65
|
+
*/
|
|
66
|
+
levelsLength: number | undefined;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Props for the FormGroup component.
|
|
70
|
+
*/
|
|
71
|
+
type FormGroupProps = {
|
|
72
|
+
/**
|
|
73
|
+
* The field name used to display a validation error message below the group.
|
|
74
|
+
* Useful when the group maps to an array or object field in the form schema.
|
|
75
|
+
*/
|
|
76
|
+
name?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Optional heading displayed above the group's children.
|
|
79
|
+
*/
|
|
80
|
+
title?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Optional description displayed below the title.
|
|
83
|
+
*/
|
|
84
|
+
description?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Layout direction for the group's children.
|
|
87
|
+
* @default 'column'
|
|
88
|
+
*/
|
|
89
|
+
direction?: 'column' | 'row';
|
|
90
|
+
} & BoxProps;
|
|
91
|
+
/**
|
|
92
|
+
* FormGroup is a layout container that organises form fields into labelled,
|
|
93
|
+
* optionally nested sections. Each nested `FormGroup` increments an internal
|
|
94
|
+
* `level` counter exposed via `useFormGroup`, which drives a `data-level`
|
|
95
|
+
* attribute and top-margin spacing so deeper groups are visually indented.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <FormGroup title="Personal details">
|
|
100
|
+
* <FormFieldInput name="firstName" label="First name" />
|
|
101
|
+
* <FormFieldInput name="lastName" label="Last name" />
|
|
102
|
+
*
|
|
103
|
+
* <FormGroup title="Address" direction="row">
|
|
104
|
+
* <FormFieldInput name="city" label="City" />
|
|
105
|
+
* <FormFieldInput name="zip" label="ZIP" />
|
|
106
|
+
* </FormGroup>
|
|
107
|
+
* </FormGroup>
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Show a group-level validation error (e.g. for an array field)
|
|
112
|
+
* ```tsx
|
|
113
|
+
* <FormGroup name="items" title="Items">
|
|
114
|
+
* {fields.map((field, i) => (
|
|
115
|
+
* <FormFieldInput key={field.id} name={`items[${i}].value`} label="Value" />
|
|
116
|
+
* ))}
|
|
117
|
+
* </FormGroup>
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Form is the root component for all form compositions. It wraps
|
|
124
|
+
* `react-hook-form`'s `FormProvider` and an HTML `<form>` element,
|
|
125
|
+
* forwarding submission handling.
|
|
126
|
+
*
|
|
127
|
+
* Use the compound sub-components for structure:
|
|
128
|
+
* - `Form.Group` – groups related fields with optional title/description
|
|
129
|
+
* - `Form.Actions` – footer bar for Submit / Cancel / Reset buttons
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* const methods = useForm<FormValues>();
|
|
134
|
+
*
|
|
135
|
+
* <Form {...methods} onSubmit={handleSubmit}>
|
|
136
|
+
* <Form.Group title="Personal details">
|
|
137
|
+
* <FormFieldInput name="firstName" label="First name" />
|
|
138
|
+
* </Form.Group>
|
|
139
|
+
* <Form.Actions>
|
|
140
|
+
* <Button variant="secondary" onClick={onCancel}>Cancel</Button>
|
|
141
|
+
* <Button type="submit">Save</Button>
|
|
142
|
+
* </Form.Actions>
|
|
143
|
+
* </Form>
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare const Form: (<TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
20
147
|
children?: React.ReactNode;
|
|
21
148
|
onSubmit?: (data: TTransformedValues) => Promise<void> | void;
|
|
22
149
|
sx?: BoxProps["sx"];
|
|
23
|
-
} & FormProviderProps<TFieldValues, TContext, TTransformedValues>) => react_jsx_runtime.JSX.Element
|
|
150
|
+
} & FormProviderProps<TFieldValues, TContext, TTransformedValues>) => react_jsx_runtime.JSX.Element) & {
|
|
151
|
+
Group: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
152
|
+
Actions: ({ align, children, sticky, sx, ...flexProps }: FormActionsProps) => react_jsx_runtime.JSX.Element;
|
|
153
|
+
};
|
|
24
154
|
|
|
25
155
|
declare const FormErrorMessage: <TFieldValues extends FieldValues = FieldValues>({ name, disabled, }: {
|
|
26
156
|
name: FieldName<TFieldValues>;
|
|
@@ -112,66 +242,4 @@ declare const FormFieldSwitch: <TFieldValues extends FieldValues = FieldValues,
|
|
|
112
242
|
type FormFieldTextareaProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<TextareaProps, 'name'>;
|
|
113
243
|
declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ defaultValue, disabled, ...props }: FormFieldTextareaProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
114
244
|
|
|
115
|
-
|
|
116
|
-
level: number | undefined;
|
|
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;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Props for the FormGroup component.
|
|
125
|
-
*/
|
|
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
|
-
*/
|
|
131
|
-
name?: string;
|
|
132
|
-
/**
|
|
133
|
-
* Optional heading displayed above the group's children.
|
|
134
|
-
*/
|
|
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
|
-
*/
|
|
144
|
-
direction?: 'column' | 'row';
|
|
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
|
-
*/
|
|
175
|
-
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
176
|
-
|
|
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 };
|
|
245
|
+
export { type DateRangePreset, Form, FormActions, type FormActionsProps, 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.43.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/
|
|
44
|
-
"@ttoss/
|
|
45
|
-
"@ttoss/
|
|
43
|
+
"@ttoss/react-i18n": "^2.1.0",
|
|
44
|
+
"@ttoss/ui": "^6.8.0",
|
|
45
|
+
"@ttoss/components": "^2.13.2"
|
|
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/components": "^2.13.
|
|
55
|
+
"@ttoss/components": "^2.13.2",
|
|
56
56
|
"@ttoss/i18n-cli": "^0.7.39",
|
|
57
|
+
"@ttoss/react-i18n": "^2.1.0",
|
|
57
58
|
"@ttoss/react-icons": "^0.6.0",
|
|
58
|
-
"@ttoss/config": "^1.36.0",
|
|
59
|
-
"@ttoss/ui": "^6.7.0",
|
|
60
59
|
"@ttoss/test-utils": "^4.1.0",
|
|
61
|
-
"@ttoss/
|
|
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 };
|