@ttoss/forms 0.22.6 → 0.23.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.mts +23 -0
- package/dist/Brazil/index.d.ts +23 -0
- package/dist/Brazil/index.js +780 -0
- package/dist/FormFieldPatternFormat-DF8nU9tn.d.mts +10 -0
- package/dist/FormFieldPatternFormat-DF8nU9tn.d.ts +10 -0
- package/dist/esm/Brazil/index.js +82 -0
- package/dist/index.d.mts +4 -8
- package/dist/index.d.ts +4 -8
- package/package.json +10 -5
- package/src/Brazil/FormFieldCEP.tsx +25 -0
- package/src/Brazil/FormFieldCNPJ.tsx +37 -0
- package/src/Brazil/FormFieldPhone.tsx +41 -0
- package/src/Brazil/index.ts +3 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PatternFormatProps } from 'react-number-format';
|
|
3
|
+
import { F as FormFieldPatternFormatProps } from '../FormFieldPatternFormat-DF8nU9tn.mjs';
|
|
4
|
+
|
|
5
|
+
type FormFieldCNPJProps = {
|
|
6
|
+
label: string;
|
|
7
|
+
name: string;
|
|
8
|
+
} & Partial<PatternFormatProps>;
|
|
9
|
+
declare const FormFieldCNPJ: ({ label, name, ...patternFormatProps }: FormFieldCNPJProps) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
type FormFieldPhoneProps = {
|
|
12
|
+
label: string;
|
|
13
|
+
name: string;
|
|
14
|
+
} & Partial<PatternFormatProps>;
|
|
15
|
+
declare const FormFieldPhone: ({ label, name, ...patternFormatProps }: FormFieldPhoneProps) => react_jsx_runtime.JSX.Element;
|
|
16
|
+
|
|
17
|
+
type FormFieldCEPProps = {
|
|
18
|
+
label: string;
|
|
19
|
+
name: string;
|
|
20
|
+
} & Partial<FormFieldPatternFormatProps>;
|
|
21
|
+
declare const FormFieldCEP: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCEPProps) => react_jsx_runtime.JSX.Element;
|
|
22
|
+
|
|
23
|
+
export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PatternFormatProps } from 'react-number-format';
|
|
3
|
+
import { F as FormFieldPatternFormatProps } from '../FormFieldPatternFormat-DF8nU9tn.js';
|
|
4
|
+
|
|
5
|
+
type FormFieldCNPJProps = {
|
|
6
|
+
label: string;
|
|
7
|
+
name: string;
|
|
8
|
+
} & Partial<PatternFormatProps>;
|
|
9
|
+
declare const FormFieldCNPJ: ({ label, name, ...patternFormatProps }: FormFieldCNPJProps) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
type FormFieldPhoneProps = {
|
|
12
|
+
label: string;
|
|
13
|
+
name: string;
|
|
14
|
+
} & Partial<PatternFormatProps>;
|
|
15
|
+
declare const FormFieldPhone: ({ label, name, ...patternFormatProps }: FormFieldPhoneProps) => react_jsx_runtime.JSX.Element;
|
|
16
|
+
|
|
17
|
+
type FormFieldCEPProps = {
|
|
18
|
+
label: string;
|
|
19
|
+
name: string;
|
|
20
|
+
} & Partial<FormFieldPatternFormatProps>;
|
|
21
|
+
declare const FormFieldCEP: ({ label, name, ...formFieldPatternFormatProps }: FormFieldCEPProps) => react_jsx_runtime.JSX.Element;
|
|
22
|
+
|
|
23
|
+
export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone };
|
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
32
|
+
value: mod,
|
|
33
|
+
enumerable: true
|
|
34
|
+
}) : target, mod));
|
|
35
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
36
|
+
value: true
|
|
37
|
+
}), mod);
|
|
38
|
+
|
|
39
|
+
// src/Brazil/index.ts
|
|
40
|
+
var Brazil_exports = {};
|
|
41
|
+
__export(Brazil_exports, {
|
|
42
|
+
FormFieldCEP: () => FormFieldCEP,
|
|
43
|
+
FormFieldCNPJ: () => FormFieldCNPJ,
|
|
44
|
+
FormFieldPhone: () => FormFieldPhone
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(Brazil_exports);
|
|
47
|
+
|
|
48
|
+
// src/index.ts
|
|
49
|
+
var src_exports = {};
|
|
50
|
+
__export(src_exports, {
|
|
51
|
+
Controller: () => import_react_hook_form6.Controller,
|
|
52
|
+
Form: () => Form,
|
|
53
|
+
FormField: () => FormField,
|
|
54
|
+
FormFieldCheckbox: () => FormFieldCheckbox,
|
|
55
|
+
FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
|
|
56
|
+
FormFieldCurrencyInput: () => FormFieldCurrencyInput,
|
|
57
|
+
FormFieldInput: () => FormFieldInput,
|
|
58
|
+
FormFieldNumericFormat: () => FormFieldNumericFormat,
|
|
59
|
+
FormFieldPassword: () => FormFieldPassword,
|
|
60
|
+
FormFieldPatternFormat: () => FormFieldPatternFormat,
|
|
61
|
+
FormFieldRadio: () => FormFieldRadio,
|
|
62
|
+
FormFieldSelect: () => FormFieldSelect,
|
|
63
|
+
FormFieldTextarea: () => FormFieldTextarea,
|
|
64
|
+
FormGroup: () => FormGroup,
|
|
65
|
+
FormProvider: () => import_react_hook_form6.FormProvider,
|
|
66
|
+
useController: () => import_react_hook_form6.useController,
|
|
67
|
+
useFieldArray: () => import_react_hook_form6.useFieldArray,
|
|
68
|
+
useForm: () => import_react_hook_form6.useForm,
|
|
69
|
+
useFormContext: () => import_react_hook_form6.useFormContext,
|
|
70
|
+
useFormGroup: () => useFormGroup,
|
|
71
|
+
useFormState: () => import_react_hook_form6.useFormState,
|
|
72
|
+
useWatch: () => import_react_hook_form6.useWatch,
|
|
73
|
+
yup: () => yup,
|
|
74
|
+
yupResolver: () => import_yup2.yupResolver
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// src/i18n.ts
|
|
78
|
+
var import_react_i18n = require("@ttoss/react-i18n");
|
|
79
|
+
var import_yup = require("yup");
|
|
80
|
+
(0, import_yup.setLocale)({
|
|
81
|
+
mixed: {
|
|
82
|
+
required: (0, import_react_i18n.defineMessage)({
|
|
83
|
+
defaultMessage: "Field is required",
|
|
84
|
+
description: "Field is required"
|
|
85
|
+
}),
|
|
86
|
+
notType: ({
|
|
87
|
+
type
|
|
88
|
+
}) => {
|
|
89
|
+
return {
|
|
90
|
+
...(0, import_react_i18n.defineMessage)({
|
|
91
|
+
defaultMessage: "Invalid Value for Field of type {type}",
|
|
92
|
+
description: "Invalid Value"
|
|
93
|
+
}),
|
|
94
|
+
values: {
|
|
95
|
+
type
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
string: {
|
|
101
|
+
min: ({
|
|
102
|
+
min
|
|
103
|
+
}) => {
|
|
104
|
+
return {
|
|
105
|
+
...(0, import_react_i18n.defineMessage)({
|
|
106
|
+
defaultMessage: "Field must be at least {min} characters",
|
|
107
|
+
description: "Min length field"
|
|
108
|
+
}),
|
|
109
|
+
values: {
|
|
110
|
+
min
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// src/index.ts
|
|
118
|
+
var import_yup2 = require("@hookform/resolvers/yup");
|
|
119
|
+
var yup = __toESM(require("yup"));
|
|
120
|
+
|
|
121
|
+
// src/Form.tsx
|
|
122
|
+
var import_ui = require("@ttoss/ui");
|
|
123
|
+
var import_react_hook_form = require("react-hook-form");
|
|
124
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
125
|
+
var Form = ({
|
|
126
|
+
children,
|
|
127
|
+
onSubmit,
|
|
128
|
+
sx,
|
|
129
|
+
...formMethods
|
|
130
|
+
}) => {
|
|
131
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_hook_form.FormProvider, {
|
|
132
|
+
...formMethods,
|
|
133
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.Box, {
|
|
134
|
+
as: "form",
|
|
135
|
+
variant: "forms.form",
|
|
136
|
+
onSubmit: formMethods.handleSubmit(data => {
|
|
137
|
+
return onSubmit?.(data);
|
|
138
|
+
}),
|
|
139
|
+
sx,
|
|
140
|
+
children
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/FormField.tsx
|
|
146
|
+
var React = __toESM(require("react"));
|
|
147
|
+
|
|
148
|
+
// src/ErrorMessage.tsx
|
|
149
|
+
var import_react_hook_form2 = require("react-hook-form");
|
|
150
|
+
var import_react_i18n2 = require("@ttoss/react-i18n");
|
|
151
|
+
var import_ui2 = require("@ttoss/ui");
|
|
152
|
+
var import_error_message = require("@hookform/error-message");
|
|
153
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
154
|
+
var isMessageDescriptor = possibleMessageDescriptor => {
|
|
155
|
+
return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
|
|
156
|
+
};
|
|
157
|
+
var ErrorMessage = ({
|
|
158
|
+
name,
|
|
159
|
+
disabled
|
|
160
|
+
}) => {
|
|
161
|
+
const {
|
|
162
|
+
formState: {
|
|
163
|
+
errors
|
|
164
|
+
}
|
|
165
|
+
} = (0, import_react_hook_form2.useFormContext)();
|
|
166
|
+
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_error_message.ErrorMessage, {
|
|
167
|
+
name,
|
|
168
|
+
errors,
|
|
169
|
+
render: ({
|
|
170
|
+
message
|
|
171
|
+
}) => {
|
|
172
|
+
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.HelpText, {
|
|
173
|
+
negative: true,
|
|
174
|
+
disabled,
|
|
175
|
+
children: (() => {
|
|
176
|
+
if (typeof message === "string") {
|
|
177
|
+
return message;
|
|
178
|
+
}
|
|
179
|
+
if (isMessageDescriptor(message)) {
|
|
180
|
+
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_react_i18n2.FormattedMessage, {
|
|
181
|
+
...message
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return JSON.stringify(message);
|
|
185
|
+
})()
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/FormField.tsx
|
|
192
|
+
var import_react_hook_form3 = require("react-hook-form");
|
|
193
|
+
var import_ui3 = require("@ttoss/ui");
|
|
194
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
195
|
+
var FormField = ({
|
|
196
|
+
label,
|
|
197
|
+
id: idProp,
|
|
198
|
+
name,
|
|
199
|
+
defaultValue,
|
|
200
|
+
disabled,
|
|
201
|
+
tooltip,
|
|
202
|
+
onTooltipClick,
|
|
203
|
+
sx,
|
|
204
|
+
css,
|
|
205
|
+
render
|
|
206
|
+
}) => {
|
|
207
|
+
const controllerReturn = (0, import_react_hook_form3.useController)({
|
|
208
|
+
name,
|
|
209
|
+
defaultValue
|
|
210
|
+
});
|
|
211
|
+
const id = idProp || `form-field-${name}`;
|
|
212
|
+
const memoizedRender = React.useMemo(() => {
|
|
213
|
+
return React.Children.map(render(controllerReturn), child => {
|
|
214
|
+
return /* @__PURE__ */(0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, {
|
|
215
|
+
children: [label && /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.Label, {
|
|
216
|
+
"aria-disabled": disabled,
|
|
217
|
+
htmlFor: id,
|
|
218
|
+
tooltip,
|
|
219
|
+
onTooltipClick,
|
|
220
|
+
children: label
|
|
221
|
+
}), React.createElement(child.type, {
|
|
222
|
+
id,
|
|
223
|
+
...child.props
|
|
224
|
+
})]
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
}, [controllerReturn, disabled, onTooltipClick, tooltip, id, label, render]);
|
|
228
|
+
return /* @__PURE__ */(0, import_jsx_runtime3.jsxs)(import_ui3.Flex, {
|
|
229
|
+
sx: {
|
|
230
|
+
flexDirection: "column",
|
|
231
|
+
width: "100%",
|
|
232
|
+
gap: "md",
|
|
233
|
+
...sx
|
|
234
|
+
},
|
|
235
|
+
css,
|
|
236
|
+
children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime3.jsx)(ErrorMessage, {
|
|
237
|
+
name
|
|
238
|
+
})]
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// src/FormFieldCheckbox.tsx
|
|
243
|
+
var import_ui4 = require("@ttoss/ui");
|
|
244
|
+
var import_react_hook_form4 = require("react-hook-form");
|
|
245
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
246
|
+
var FormFieldCheckbox = ({
|
|
247
|
+
label,
|
|
248
|
+
name,
|
|
249
|
+
sx,
|
|
250
|
+
...checkboxProps
|
|
251
|
+
}) => {
|
|
252
|
+
const {
|
|
253
|
+
field: {
|
|
254
|
+
onChange,
|
|
255
|
+
onBlur,
|
|
256
|
+
value,
|
|
257
|
+
ref
|
|
258
|
+
},
|
|
259
|
+
formState: {
|
|
260
|
+
errors
|
|
261
|
+
}
|
|
262
|
+
} = (0, import_react_hook_form4.useController)({
|
|
263
|
+
name,
|
|
264
|
+
defaultValue: false
|
|
265
|
+
});
|
|
266
|
+
const id = `form-field-checkbox-${name}`;
|
|
267
|
+
const error = !!errors[name]?.message;
|
|
268
|
+
return /* @__PURE__ */(0, import_jsx_runtime4.jsxs)(import_ui4.Flex, {
|
|
269
|
+
sx: {
|
|
270
|
+
flexDirection: "column",
|
|
271
|
+
width: "100%",
|
|
272
|
+
...sx
|
|
273
|
+
},
|
|
274
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_ui4.Flex, {
|
|
275
|
+
sx: {
|
|
276
|
+
alignItems: "center"
|
|
277
|
+
},
|
|
278
|
+
children: /* @__PURE__ */(0, import_jsx_runtime4.jsxs)(import_ui4.Label, {
|
|
279
|
+
"aria-disabled": checkboxProps.disabled,
|
|
280
|
+
htmlFor: id,
|
|
281
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_ui4.Checkbox, {
|
|
282
|
+
id,
|
|
283
|
+
ref,
|
|
284
|
+
checked: value,
|
|
285
|
+
onChange,
|
|
286
|
+
onBlur,
|
|
287
|
+
name,
|
|
288
|
+
"aria-invalid": error ? "true" : "false",
|
|
289
|
+
...checkboxProps
|
|
290
|
+
}), label]
|
|
291
|
+
})
|
|
292
|
+
}), /* @__PURE__ */(0, import_jsx_runtime4.jsx)(ErrorMessage, {
|
|
293
|
+
name
|
|
294
|
+
})]
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// src/FormFieldPatternFormat.tsx
|
|
299
|
+
var import_ui5 = require("@ttoss/ui");
|
|
300
|
+
var import_react_number_format = require("react-number-format");
|
|
301
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
302
|
+
var FormFieldPatternFormat = ({
|
|
303
|
+
label,
|
|
304
|
+
name,
|
|
305
|
+
...patternFormatProps
|
|
306
|
+
}) => {
|
|
307
|
+
return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormField, {
|
|
308
|
+
name,
|
|
309
|
+
label,
|
|
310
|
+
render: ({
|
|
311
|
+
field,
|
|
312
|
+
fieldState
|
|
313
|
+
}) => {
|
|
314
|
+
return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_react_number_format.PatternFormat, {
|
|
315
|
+
name: field.name,
|
|
316
|
+
value: field.value,
|
|
317
|
+
onBlur: field.onBlur,
|
|
318
|
+
onValueChange: values => {
|
|
319
|
+
field.onChange(values.value);
|
|
320
|
+
},
|
|
321
|
+
customInput: import_ui5.Input,
|
|
322
|
+
"aria-invalid": Boolean(fieldState.error).valueOf(),
|
|
323
|
+
...patternFormatProps
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// src/FormFieldCreditCardNumber.tsx
|
|
330
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
331
|
+
var FormFieldCreditCardNumber = ({
|
|
332
|
+
label,
|
|
333
|
+
name,
|
|
334
|
+
...formFieldPatternFormatProps
|
|
335
|
+
}) => {
|
|
336
|
+
return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(FormFieldPatternFormat, {
|
|
337
|
+
name,
|
|
338
|
+
label,
|
|
339
|
+
format: "#### #### #### ####",
|
|
340
|
+
placeholder: "1234 1234 1234 1234",
|
|
341
|
+
...formFieldPatternFormatProps
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/FormFieldNumericFormat.tsx
|
|
346
|
+
var import_ui6 = require("@ttoss/ui");
|
|
347
|
+
var import_react_number_format2 = require("react-number-format");
|
|
348
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
349
|
+
var FormFieldNumericFormat = ({
|
|
350
|
+
label,
|
|
351
|
+
name,
|
|
352
|
+
...numericFormatProps
|
|
353
|
+
}) => {
|
|
354
|
+
return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(FormField, {
|
|
355
|
+
label,
|
|
356
|
+
name,
|
|
357
|
+
render: ({
|
|
358
|
+
field
|
|
359
|
+
}) => {
|
|
360
|
+
return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_react_number_format2.NumericFormat, {
|
|
361
|
+
name: field.name,
|
|
362
|
+
value: field.value,
|
|
363
|
+
onBlur: field.onBlur,
|
|
364
|
+
onValueChange: values => {
|
|
365
|
+
field.onChange(values.floatValue);
|
|
366
|
+
},
|
|
367
|
+
customInput: import_ui6.Input,
|
|
368
|
+
...numericFormatProps
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
// src/FormFieldCurrencyInput.tsx
|
|
375
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
376
|
+
var FormFieldCurrencyInput = ({
|
|
377
|
+
label,
|
|
378
|
+
name,
|
|
379
|
+
prefix,
|
|
380
|
+
decimalSeparator,
|
|
381
|
+
thousandSeparator,
|
|
382
|
+
...formFieldNumericFormatProps
|
|
383
|
+
}) => {
|
|
384
|
+
return /* @__PURE__ */(0, import_jsx_runtime8.jsx)(FormFieldNumericFormat, {
|
|
385
|
+
name,
|
|
386
|
+
label,
|
|
387
|
+
fixedDecimalScale: true,
|
|
388
|
+
decimalScale: 2,
|
|
389
|
+
prefix,
|
|
390
|
+
decimalSeparator,
|
|
391
|
+
thousandSeparator,
|
|
392
|
+
placeholder: `${prefix} 0${decimalSeparator}00`,
|
|
393
|
+
allowNegative: false,
|
|
394
|
+
...formFieldNumericFormatProps
|
|
395
|
+
});
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// src/FormFieldInput.tsx
|
|
399
|
+
var import_ui7 = require("@ttoss/ui");
|
|
400
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
401
|
+
var FormFieldInput = ({
|
|
402
|
+
label,
|
|
403
|
+
name,
|
|
404
|
+
tooltip,
|
|
405
|
+
onTooltipClick,
|
|
406
|
+
sx,
|
|
407
|
+
defaultValue = "",
|
|
408
|
+
...inputProps
|
|
409
|
+
}) => {
|
|
410
|
+
return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormField, {
|
|
411
|
+
name,
|
|
412
|
+
label,
|
|
413
|
+
disabled: inputProps.disabled,
|
|
414
|
+
tooltip,
|
|
415
|
+
onTooltipClick,
|
|
416
|
+
sx,
|
|
417
|
+
defaultValue,
|
|
418
|
+
render: ({
|
|
419
|
+
field,
|
|
420
|
+
fieldState
|
|
421
|
+
}) => {
|
|
422
|
+
return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui7.Input, {
|
|
423
|
+
...inputProps,
|
|
424
|
+
...field,
|
|
425
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// src/FormFieldPassword.tsx
|
|
432
|
+
var import_ui8 = require("@ttoss/ui");
|
|
433
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
434
|
+
var FormFieldPassword = ({
|
|
435
|
+
label,
|
|
436
|
+
name,
|
|
437
|
+
tooltip,
|
|
438
|
+
onTooltipClick,
|
|
439
|
+
sx,
|
|
440
|
+
defaultValue = "",
|
|
441
|
+
...inputProps
|
|
442
|
+
}) => {
|
|
443
|
+
return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(FormField, {
|
|
444
|
+
name,
|
|
445
|
+
label,
|
|
446
|
+
disabled: inputProps.disabled,
|
|
447
|
+
tooltip,
|
|
448
|
+
onTooltipClick,
|
|
449
|
+
sx,
|
|
450
|
+
defaultValue,
|
|
451
|
+
render: ({
|
|
452
|
+
field,
|
|
453
|
+
fieldState
|
|
454
|
+
}) => {
|
|
455
|
+
return /* @__PURE__ */(0, import_jsx_runtime10.jsx)(import_ui8.InputPassword, {
|
|
456
|
+
...inputProps,
|
|
457
|
+
...field,
|
|
458
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
// src/FormFieldRadio.tsx
|
|
465
|
+
var import_ui9 = require("@ttoss/ui");
|
|
466
|
+
var import_react_hook_form5 = require("react-hook-form");
|
|
467
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
468
|
+
var FormFieldRadio = ({
|
|
469
|
+
label,
|
|
470
|
+
name,
|
|
471
|
+
options,
|
|
472
|
+
sx,
|
|
473
|
+
...radioProps
|
|
474
|
+
}) => {
|
|
475
|
+
const {
|
|
476
|
+
field: {
|
|
477
|
+
onChange,
|
|
478
|
+
onBlur,
|
|
479
|
+
value,
|
|
480
|
+
ref
|
|
481
|
+
}
|
|
482
|
+
} = (0, import_react_hook_form5.useController)({
|
|
483
|
+
name,
|
|
484
|
+
defaultValue: ""
|
|
485
|
+
});
|
|
486
|
+
return /* @__PURE__ */(0, import_jsx_runtime11.jsxs)(import_ui9.Flex, {
|
|
487
|
+
sx: {
|
|
488
|
+
flexDirection: "column",
|
|
489
|
+
width: "100%",
|
|
490
|
+
...sx
|
|
491
|
+
},
|
|
492
|
+
children: [label && /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui9.Label, {
|
|
493
|
+
sx: {
|
|
494
|
+
marginBottom: "md"
|
|
495
|
+
},
|
|
496
|
+
children: label
|
|
497
|
+
}), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui9.Box, {
|
|
498
|
+
children: options.map(option => {
|
|
499
|
+
const id = `form-field-radio-${name}-${option.value}`;
|
|
500
|
+
return /* @__PURE__ */(0, import_jsx_runtime11.jsxs)(import_ui9.Label, {
|
|
501
|
+
htmlFor: id,
|
|
502
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime11.jsx)(import_ui9.Radio, {
|
|
503
|
+
ref,
|
|
504
|
+
onChange,
|
|
505
|
+
onBlur,
|
|
506
|
+
value: option.value,
|
|
507
|
+
checked: value === option.value,
|
|
508
|
+
name,
|
|
509
|
+
id,
|
|
510
|
+
...radioProps
|
|
511
|
+
}), option.label]
|
|
512
|
+
}, id);
|
|
513
|
+
})
|
|
514
|
+
}), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(ErrorMessage, {
|
|
515
|
+
name
|
|
516
|
+
})]
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// src/FormFieldSelect.tsx
|
|
521
|
+
var import_ui10 = require("@ttoss/ui");
|
|
522
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
523
|
+
var FormFieldSelect = ({
|
|
524
|
+
label,
|
|
525
|
+
name,
|
|
526
|
+
id,
|
|
527
|
+
defaultValue,
|
|
528
|
+
sx,
|
|
529
|
+
css,
|
|
530
|
+
disabled,
|
|
531
|
+
tooltip,
|
|
532
|
+
onTooltipClick,
|
|
533
|
+
...selectProps
|
|
534
|
+
}) => {
|
|
535
|
+
return /* @__PURE__ */(0, import_jsx_runtime12.jsx)(FormField, {
|
|
536
|
+
name,
|
|
537
|
+
label,
|
|
538
|
+
id,
|
|
539
|
+
defaultValue,
|
|
540
|
+
disabled,
|
|
541
|
+
tooltip,
|
|
542
|
+
onTooltipClick,
|
|
543
|
+
sx,
|
|
544
|
+
css,
|
|
545
|
+
render: ({
|
|
546
|
+
field,
|
|
547
|
+
fieldState
|
|
548
|
+
}) => {
|
|
549
|
+
return /* @__PURE__ */(0, import_jsx_runtime12.jsx)(import_ui10.Select, {
|
|
550
|
+
...selectProps,
|
|
551
|
+
...field,
|
|
552
|
+
isDisabled: disabled,
|
|
553
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/FormFieldTextarea.tsx
|
|
560
|
+
var import_ui11 = require("@ttoss/ui");
|
|
561
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
562
|
+
var FormFieldTextarea = ({
|
|
563
|
+
label,
|
|
564
|
+
name,
|
|
565
|
+
sx,
|
|
566
|
+
...textareaProps
|
|
567
|
+
}) => {
|
|
568
|
+
const id = `form-field-textarea-${name}`;
|
|
569
|
+
return /* @__PURE__ */(0, import_jsx_runtime13.jsx)(FormField, {
|
|
570
|
+
label,
|
|
571
|
+
name,
|
|
572
|
+
id,
|
|
573
|
+
sx,
|
|
574
|
+
render: ({
|
|
575
|
+
field,
|
|
576
|
+
fieldState
|
|
577
|
+
}) => {
|
|
578
|
+
return /* @__PURE__ */(0, import_jsx_runtime13.jsx)(import_ui11.Textarea, {
|
|
579
|
+
...field,
|
|
580
|
+
...textareaProps,
|
|
581
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
// src/FormGroup.tsx
|
|
588
|
+
var React2 = __toESM(require("react"));
|
|
589
|
+
var import_ui12 = require("@ttoss/ui");
|
|
590
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
591
|
+
var FormGroupLevelsManagerContext = React2.createContext({
|
|
592
|
+
levelsLength: 1,
|
|
593
|
+
registerChild: () => {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
var FormGroupLevelsManager = ({
|
|
598
|
+
children
|
|
599
|
+
}) => {
|
|
600
|
+
const [levelsLength, setLevelsLength] = React2.useState(0);
|
|
601
|
+
const registerChild = React2.useCallback(level => {
|
|
602
|
+
if (level + 1 > levelsLength) {
|
|
603
|
+
setLevelsLength(level + 1);
|
|
604
|
+
}
|
|
605
|
+
}, [levelsLength]);
|
|
606
|
+
return /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupLevelsManagerContext.Provider, {
|
|
607
|
+
value: {
|
|
608
|
+
levelsLength,
|
|
609
|
+
registerChild
|
|
610
|
+
},
|
|
611
|
+
children
|
|
612
|
+
});
|
|
613
|
+
};
|
|
614
|
+
var FormGroupContext = React2.createContext({});
|
|
615
|
+
var useFormGroup = () => {
|
|
616
|
+
const {
|
|
617
|
+
parentLevel
|
|
618
|
+
} = React2.useContext(FormGroupContext);
|
|
619
|
+
const {
|
|
620
|
+
levelsLength
|
|
621
|
+
} = React2.useContext(FormGroupLevelsManagerContext);
|
|
622
|
+
return {
|
|
623
|
+
level: parentLevel,
|
|
624
|
+
levelsLength
|
|
625
|
+
};
|
|
626
|
+
};
|
|
627
|
+
var FormGroupWrapper = ({
|
|
628
|
+
title,
|
|
629
|
+
direction,
|
|
630
|
+
children,
|
|
631
|
+
...boxProps
|
|
632
|
+
}) => {
|
|
633
|
+
const {
|
|
634
|
+
level
|
|
635
|
+
} = useFormGroup();
|
|
636
|
+
const {
|
|
637
|
+
registerChild
|
|
638
|
+
} = React2.useContext(FormGroupLevelsManagerContext);
|
|
639
|
+
React2.useEffect(() => {
|
|
640
|
+
if (typeof level === "number") {
|
|
641
|
+
registerChild(level);
|
|
642
|
+
}
|
|
643
|
+
}, [level, registerChild]);
|
|
644
|
+
const childrenContainerSx = {
|
|
645
|
+
flexDirection: direction || "column",
|
|
646
|
+
gap: "md",
|
|
647
|
+
width: "100%"
|
|
648
|
+
};
|
|
649
|
+
return /* @__PURE__ */(0, import_jsx_runtime14.jsxs)(import_ui12.Box, {
|
|
650
|
+
"aria-level": level,
|
|
651
|
+
...boxProps,
|
|
652
|
+
sx: {
|
|
653
|
+
marginTop: level === 0 ? "none" : "lg",
|
|
654
|
+
marginBottom: "lg",
|
|
655
|
+
...boxProps.sx
|
|
656
|
+
},
|
|
657
|
+
children: [title && /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Box, {
|
|
658
|
+
sx: {
|
|
659
|
+
marginBottom: "md"
|
|
660
|
+
},
|
|
661
|
+
children: /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Text, {
|
|
662
|
+
sx: {
|
|
663
|
+
fontSize: "2xl",
|
|
664
|
+
fontWeight: "bold"
|
|
665
|
+
},
|
|
666
|
+
children: title
|
|
667
|
+
})
|
|
668
|
+
}), /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Flex, {
|
|
669
|
+
sx: childrenContainerSx,
|
|
670
|
+
children
|
|
671
|
+
})]
|
|
672
|
+
});
|
|
673
|
+
};
|
|
674
|
+
var FormGroup = props => {
|
|
675
|
+
const {
|
|
676
|
+
level
|
|
677
|
+
} = useFormGroup();
|
|
678
|
+
const currentLevel = level === void 0 ? 0 : level + 1;
|
|
679
|
+
return /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupContext.Provider, {
|
|
680
|
+
value: {
|
|
681
|
+
parentLevel: currentLevel
|
|
682
|
+
},
|
|
683
|
+
children: currentLevel === 0 ? /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupLevelsManager, {
|
|
684
|
+
children: /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupWrapper, {
|
|
685
|
+
...props
|
|
686
|
+
})
|
|
687
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormGroupWrapper, {
|
|
688
|
+
...props
|
|
689
|
+
})
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// src/index.ts
|
|
694
|
+
var import_react_hook_form6 = require("react-hook-form");
|
|
695
|
+
__reExport(src_exports, require("react-hook-form"));
|
|
696
|
+
|
|
697
|
+
// src/Brazil/FormFieldCNPJ.tsx
|
|
698
|
+
var import_ui13 = require("@ttoss/ui");
|
|
699
|
+
var import_react_number_format3 = require("react-number-format");
|
|
700
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
701
|
+
var FormFieldCNPJ = ({
|
|
702
|
+
label,
|
|
703
|
+
name,
|
|
704
|
+
...patternFormatProps
|
|
705
|
+
}) => {
|
|
706
|
+
return /* @__PURE__ */(0, import_jsx_runtime15.jsx)(FormField, {
|
|
707
|
+
name,
|
|
708
|
+
label,
|
|
709
|
+
render: ({
|
|
710
|
+
field
|
|
711
|
+
}) => {
|
|
712
|
+
return /* @__PURE__ */(0, import_jsx_runtime15.jsx)(import_react_number_format3.PatternFormat, {
|
|
713
|
+
name: field.name,
|
|
714
|
+
value: field.value,
|
|
715
|
+
onBlur: field.onBlur,
|
|
716
|
+
onValueChange: values => {
|
|
717
|
+
field.onChange(values.value);
|
|
718
|
+
},
|
|
719
|
+
format: "##.###.###/####-##",
|
|
720
|
+
customInput: import_ui13.Input,
|
|
721
|
+
placeholder: "12.345.678/0000-00",
|
|
722
|
+
...patternFormatProps
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
// src/Brazil/FormFieldPhone.tsx
|
|
729
|
+
var import_ui14 = require("@ttoss/ui");
|
|
730
|
+
var import_react_number_format4 = require("react-number-format");
|
|
731
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
732
|
+
var FormFieldPhone = ({
|
|
733
|
+
label,
|
|
734
|
+
name,
|
|
735
|
+
...patternFormatProps
|
|
736
|
+
}) => {
|
|
737
|
+
return /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormField, {
|
|
738
|
+
name,
|
|
739
|
+
label,
|
|
740
|
+
render: ({
|
|
741
|
+
field
|
|
742
|
+
}) => {
|
|
743
|
+
const format = field.value?.length > 10 ? "(##) #####-####" : "(##) ####-#####";
|
|
744
|
+
return /* @__PURE__ */(0, import_jsx_runtime16.jsx)(import_react_number_format4.PatternFormat, {
|
|
745
|
+
name: field.name,
|
|
746
|
+
value: field.value,
|
|
747
|
+
onBlur: field.onBlur,
|
|
748
|
+
onValueChange: values => {
|
|
749
|
+
field.onChange(values.value);
|
|
750
|
+
},
|
|
751
|
+
format,
|
|
752
|
+
customInput: import_ui14.Input,
|
|
753
|
+
placeholder: "(11) 91234-1234",
|
|
754
|
+
...patternFormatProps
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// src/Brazil/FormFieldCEP.tsx
|
|
761
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
762
|
+
var FormFieldCEP = ({
|
|
763
|
+
label,
|
|
764
|
+
name,
|
|
765
|
+
...formFieldPatternFormatProps
|
|
766
|
+
}) => {
|
|
767
|
+
return /* @__PURE__ */(0, import_jsx_runtime17.jsx)(FormFieldPatternFormat, {
|
|
768
|
+
name,
|
|
769
|
+
label,
|
|
770
|
+
format: "#####-###",
|
|
771
|
+
placeholder: "12345-678",
|
|
772
|
+
...formFieldPatternFormatProps
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
776
|
+
0 && (module.exports = {
|
|
777
|
+
FormFieldCEP,
|
|
778
|
+
FormFieldCNPJ,
|
|
779
|
+
FormFieldPhone
|
|
780
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PatternFormatProps } from 'react-number-format';
|
|
3
|
+
|
|
4
|
+
type FormFieldPatternFormatProps = {
|
|
5
|
+
label?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
} & PatternFormatProps;
|
|
8
|
+
declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
|
|
9
|
+
|
|
10
|
+
export { type FormFieldPatternFormatProps as F, FormFieldPatternFormat as a };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PatternFormatProps } from 'react-number-format';
|
|
3
|
+
|
|
4
|
+
type FormFieldPatternFormatProps = {
|
|
5
|
+
label?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
} & PatternFormatProps;
|
|
8
|
+
declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
|
|
9
|
+
|
|
10
|
+
export { type FormFieldPatternFormatProps as F, FormFieldPatternFormat as a };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import { FormField, FormFieldPatternFormat } from "../chunk-5SH4STWG.js";
|
|
3
|
+
|
|
4
|
+
// src/Brazil/FormFieldCNPJ.tsx
|
|
5
|
+
import { Input } from "@ttoss/ui";
|
|
6
|
+
import { PatternFormat } from "react-number-format";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
var FormFieldCNPJ = ({
|
|
9
|
+
label,
|
|
10
|
+
name,
|
|
11
|
+
...patternFormatProps
|
|
12
|
+
}) => {
|
|
13
|
+
return /* @__PURE__ */jsx(FormField, {
|
|
14
|
+
name,
|
|
15
|
+
label,
|
|
16
|
+
render: ({
|
|
17
|
+
field
|
|
18
|
+
}) => {
|
|
19
|
+
return /* @__PURE__ */jsx(PatternFormat, {
|
|
20
|
+
name: field.name,
|
|
21
|
+
value: field.value,
|
|
22
|
+
onBlur: field.onBlur,
|
|
23
|
+
onValueChange: values => {
|
|
24
|
+
field.onChange(values.value);
|
|
25
|
+
},
|
|
26
|
+
format: "##.###.###/####-##",
|
|
27
|
+
customInput: Input,
|
|
28
|
+
placeholder: "12.345.678/0000-00",
|
|
29
|
+
...patternFormatProps
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/Brazil/FormFieldPhone.tsx
|
|
36
|
+
import { Input as Input2 } from "@ttoss/ui";
|
|
37
|
+
import { PatternFormat as PatternFormat2 } from "react-number-format";
|
|
38
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
39
|
+
var FormFieldPhone = ({
|
|
40
|
+
label,
|
|
41
|
+
name,
|
|
42
|
+
...patternFormatProps
|
|
43
|
+
}) => {
|
|
44
|
+
return /* @__PURE__ */jsx2(FormField, {
|
|
45
|
+
name,
|
|
46
|
+
label,
|
|
47
|
+
render: ({
|
|
48
|
+
field
|
|
49
|
+
}) => {
|
|
50
|
+
const format = field.value?.length > 10 ? "(##) #####-####" : "(##) ####-#####";
|
|
51
|
+
return /* @__PURE__ */jsx2(PatternFormat2, {
|
|
52
|
+
name: field.name,
|
|
53
|
+
value: field.value,
|
|
54
|
+
onBlur: field.onBlur,
|
|
55
|
+
onValueChange: values => {
|
|
56
|
+
field.onChange(values.value);
|
|
57
|
+
},
|
|
58
|
+
format,
|
|
59
|
+
customInput: Input2,
|
|
60
|
+
placeholder: "(11) 91234-1234",
|
|
61
|
+
...patternFormatProps
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/Brazil/FormFieldCEP.tsx
|
|
68
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
69
|
+
var FormFieldCEP = ({
|
|
70
|
+
label,
|
|
71
|
+
name,
|
|
72
|
+
...formFieldPatternFormatProps
|
|
73
|
+
}) => {
|
|
74
|
+
return /* @__PURE__ */jsx3(FormFieldPatternFormat, {
|
|
75
|
+
name,
|
|
76
|
+
label,
|
|
77
|
+
format: "#####-###",
|
|
78
|
+
placeholder: "12345-678",
|
|
79
|
+
...formFieldPatternFormatProps
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
export { FormFieldCEP, FormFieldCNPJ, FormFieldPhone };
|
package/dist/index.d.mts
CHANGED
|
@@ -8,7 +8,9 @@ export * from 'react-hook-form';
|
|
|
8
8
|
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
9
9
|
import * as React from 'react';
|
|
10
10
|
import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
|
|
11
|
-
import {
|
|
11
|
+
import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-DF8nU9tn.mjs';
|
|
12
|
+
export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-DF8nU9tn.mjs';
|
|
13
|
+
import { NumericFormatProps } from 'react-number-format';
|
|
12
14
|
|
|
13
15
|
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
14
16
|
children?: React.ReactNode;
|
|
@@ -37,12 +39,6 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
|
|
|
37
39
|
name: FieldPath<TFieldValues>;
|
|
38
40
|
} & CheckboxProps) => react_jsx_runtime.JSX.Element;
|
|
39
41
|
|
|
40
|
-
type FormFieldPatternFormatProps = {
|
|
41
|
-
label?: string;
|
|
42
|
-
name: string;
|
|
43
|
-
} & PatternFormatProps;
|
|
44
|
-
declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
|
|
45
|
-
|
|
46
42
|
type FormFieldCreditCardNumberProps = {
|
|
47
43
|
label: string;
|
|
48
44
|
name: string;
|
|
@@ -104,4 +100,4 @@ type FormGroupProps = {
|
|
|
104
100
|
} & BoxProps;
|
|
105
101
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
106
102
|
|
|
107
|
-
export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword,
|
|
103
|
+
export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ export * from 'react-hook-form';
|
|
|
8
8
|
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
9
9
|
import * as React from 'react';
|
|
10
10
|
import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
|
|
11
|
-
import {
|
|
11
|
+
import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-DF8nU9tn.js';
|
|
12
|
+
export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-DF8nU9tn.js';
|
|
13
|
+
import { NumericFormatProps } from 'react-number-format';
|
|
12
14
|
|
|
13
15
|
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
14
16
|
children?: React.ReactNode;
|
|
@@ -37,12 +39,6 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
|
|
|
37
39
|
name: FieldPath<TFieldValues>;
|
|
38
40
|
} & CheckboxProps) => react_jsx_runtime.JSX.Element;
|
|
39
41
|
|
|
40
|
-
type FormFieldPatternFormatProps = {
|
|
41
|
-
label?: string;
|
|
42
|
-
name: string;
|
|
43
|
-
} & PatternFormatProps;
|
|
44
|
-
declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
|
|
45
|
-
|
|
46
42
|
type FormFieldCreditCardNumberProps = {
|
|
47
43
|
label: string;
|
|
48
44
|
name: string;
|
|
@@ -104,4 +100,4 @@ type FormGroupProps = {
|
|
|
104
100
|
} & BoxProps;
|
|
105
101
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
106
102
|
|
|
107
|
-
export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword,
|
|
103
|
+
export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"author": "ttoss",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Pedro Arantes <pedro@arantespp.com> (https://arantespp.com/contact)"
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
"import": "./dist/esm/MultistepForm/index.js",
|
|
21
21
|
"require": "./dist/MultistepForm/index.js",
|
|
22
22
|
"types": "./dist/MultistepForm/index.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./brazil": {
|
|
25
|
+
"import": "./dist/esm/Brazil/index.js",
|
|
26
|
+
"require": "./dist/Brazil/index.js",
|
|
27
|
+
"types": "./dist/Brazil/index.d.ts"
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
"files": [
|
|
@@ -37,7 +42,7 @@
|
|
|
37
42
|
"peerDependencies": {
|
|
38
43
|
"react": ">=16.8.0",
|
|
39
44
|
"@ttoss/react-i18n": "^1.26.1",
|
|
40
|
-
"@ttoss/ui": "^4.1.
|
|
45
|
+
"@ttoss/ui": "^4.1.4"
|
|
41
46
|
},
|
|
42
47
|
"devDependencies": {
|
|
43
48
|
"@types/jest": "^29.5.12",
|
|
@@ -49,11 +54,11 @@
|
|
|
49
54
|
"tsup": "^8.0.2",
|
|
50
55
|
"yup": "^1.3.3",
|
|
51
56
|
"@ttoss/config": "^1.31.5",
|
|
57
|
+
"@ttoss/react-i18n": "^1.26.1",
|
|
52
58
|
"@ttoss/i18n-cli": "^0.7.6",
|
|
53
59
|
"@ttoss/react-icons": "^0.3.1",
|
|
54
|
-
"@ttoss/
|
|
55
|
-
"@ttoss/
|
|
56
|
-
"@ttoss/react-i18n": "^1.26.1"
|
|
60
|
+
"@ttoss/ui": "^4.1.4",
|
|
61
|
+
"@ttoss/test-utils": "^2.1.1"
|
|
57
62
|
},
|
|
58
63
|
"publishConfig": {
|
|
59
64
|
"access": "public",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FormFieldPatternFormat,
|
|
3
|
+
FormFieldPatternFormatProps,
|
|
4
|
+
} from '../FormFieldPatternFormat';
|
|
5
|
+
|
|
6
|
+
export type FormFieldCEPProps = {
|
|
7
|
+
label: string;
|
|
8
|
+
name: string;
|
|
9
|
+
} & Partial<FormFieldPatternFormatProps>;
|
|
10
|
+
|
|
11
|
+
export const FormFieldCEP = ({
|
|
12
|
+
label,
|
|
13
|
+
name,
|
|
14
|
+
...formFieldPatternFormatProps
|
|
15
|
+
}: FormFieldCEPProps) => {
|
|
16
|
+
return (
|
|
17
|
+
<FormFieldPatternFormat
|
|
18
|
+
name={name}
|
|
19
|
+
label={label}
|
|
20
|
+
format="#####-###"
|
|
21
|
+
placeholder="12345-678"
|
|
22
|
+
{...formFieldPatternFormatProps}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { FormField } from '..';
|
|
2
|
+
import { Input } from '@ttoss/ui';
|
|
3
|
+
import { PatternFormat, PatternFormatProps } from 'react-number-format';
|
|
4
|
+
|
|
5
|
+
export type FormFieldCNPJProps = {
|
|
6
|
+
label: string;
|
|
7
|
+
name: string;
|
|
8
|
+
} & Partial<PatternFormatProps>;
|
|
9
|
+
|
|
10
|
+
export const FormFieldCNPJ = ({
|
|
11
|
+
label,
|
|
12
|
+
name,
|
|
13
|
+
...patternFormatProps
|
|
14
|
+
}: FormFieldCNPJProps) => {
|
|
15
|
+
return (
|
|
16
|
+
<FormField
|
|
17
|
+
name={name}
|
|
18
|
+
label={label}
|
|
19
|
+
render={({ field }) => {
|
|
20
|
+
return (
|
|
21
|
+
<PatternFormat
|
|
22
|
+
name={field.name}
|
|
23
|
+
value={field.value}
|
|
24
|
+
onBlur={field.onBlur}
|
|
25
|
+
onValueChange={(values) => {
|
|
26
|
+
field.onChange(values.value);
|
|
27
|
+
}}
|
|
28
|
+
format={'##.###.###/####-##'}
|
|
29
|
+
customInput={Input}
|
|
30
|
+
placeholder="12.345.678/0000-00"
|
|
31
|
+
{...patternFormatProps}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FormField } from '../FormField';
|
|
2
|
+
import { Input } from '@ttoss/ui';
|
|
3
|
+
|
|
4
|
+
import { PatternFormat, PatternFormatProps } from 'react-number-format';
|
|
5
|
+
|
|
6
|
+
export type FormFieldPhoneProps = {
|
|
7
|
+
label: string;
|
|
8
|
+
name: string;
|
|
9
|
+
} & Partial<PatternFormatProps>;
|
|
10
|
+
|
|
11
|
+
export const FormFieldPhone = ({
|
|
12
|
+
label,
|
|
13
|
+
name,
|
|
14
|
+
...patternFormatProps
|
|
15
|
+
}: FormFieldPhoneProps) => {
|
|
16
|
+
return (
|
|
17
|
+
<FormField
|
|
18
|
+
name={name}
|
|
19
|
+
label={label}
|
|
20
|
+
render={({ field }) => {
|
|
21
|
+
const format =
|
|
22
|
+
field.value?.length > 10 ? '(##) #####-####' : '(##) ####-#####';
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<PatternFormat
|
|
26
|
+
name={field.name}
|
|
27
|
+
value={field.value}
|
|
28
|
+
onBlur={field.onBlur}
|
|
29
|
+
onValueChange={(values) => {
|
|
30
|
+
field.onChange(values.value);
|
|
31
|
+
}}
|
|
32
|
+
format={format}
|
|
33
|
+
customInput={Input}
|
|
34
|
+
placeholder="(11) 91234-1234"
|
|
35
|
+
{...patternFormatProps}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
};
|