@ttoss/forms 0.35.3 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Brazil/index.d.ts +25 -0
- package/dist/FormFieldPatternFormat-D5CI6eUA.d.ts +59 -0
- package/dist/MultistepForm/index.d.ts +65 -0
- package/dist/esm/Brazil/index.js +128 -0
- package/dist/esm/MultistepForm/index.js +2482 -0
- package/dist/esm/chunk-2ZLGQ7EE.js +973 -0
- package/dist/esm/chunk-QJQFXN4B.js +442 -0
- package/dist/esm/index.js +4 -0
- package/dist/index.d.ts +120 -0
- package/dist/typings.d-BZ6kUiQ4.d.ts +13 -0
- package/package.json +6 -6
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
+
value,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/FormErrorMessage.tsx
|
|
10
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
11
|
+
import { FormattedMessage } from "@ttoss/react-i18n";
|
|
12
|
+
import { HelpText } from "@ttoss/ui";
|
|
13
|
+
import { useFormContext } from "react-hook-form";
|
|
14
|
+
var isMessageDescriptor = /* @__PURE__ */__name(possibleMessageDescriptor => {
|
|
15
|
+
return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
|
|
16
|
+
}, "isMessageDescriptor");
|
|
17
|
+
var FormErrorMessage = /* @__PURE__ */__name(({
|
|
18
|
+
name,
|
|
19
|
+
disabled
|
|
20
|
+
}) => {
|
|
21
|
+
const {
|
|
22
|
+
formState: {
|
|
23
|
+
errors
|
|
24
|
+
}
|
|
25
|
+
} = useFormContext();
|
|
26
|
+
return /* @__PURE__ */React.createElement(ErrorMessage, {
|
|
27
|
+
name,
|
|
28
|
+
errors,
|
|
29
|
+
render: /* @__PURE__ */__name(({
|
|
30
|
+
message
|
|
31
|
+
}) => {
|
|
32
|
+
return /* @__PURE__ */React.createElement(HelpText, {
|
|
33
|
+
negative: true,
|
|
34
|
+
disabled
|
|
35
|
+
}, (() => {
|
|
36
|
+
if (typeof message === "string") {
|
|
37
|
+
return message;
|
|
38
|
+
}
|
|
39
|
+
if (isMessageDescriptor(message)) {
|
|
40
|
+
return /* @__PURE__ */React.createElement(FormattedMessage, message);
|
|
41
|
+
}
|
|
42
|
+
return JSON.stringify(message);
|
|
43
|
+
})());
|
|
44
|
+
}, "render")
|
|
45
|
+
});
|
|
46
|
+
}, "FormErrorMessage");
|
|
47
|
+
|
|
48
|
+
// src/FormField.tsx
|
|
49
|
+
import { Checkbox as Checkbox2, Flex as Flex2, Label as Label2, Switch } from "@ttoss/ui";
|
|
50
|
+
import * as React3 from "react";
|
|
51
|
+
import { useController as useController2, useFormContext as useFormContext2 } from "react-hook-form";
|
|
52
|
+
|
|
53
|
+
// src/AuxiliaryCheckbox.tsx
|
|
54
|
+
import { Checkbox, Flex, Label } from "@ttoss/ui";
|
|
55
|
+
import * as React2 from "react";
|
|
56
|
+
import { useController } from "react-hook-form";
|
|
57
|
+
var AuxiliaryCheckbox = /* @__PURE__ */__name(({
|
|
58
|
+
label,
|
|
59
|
+
name,
|
|
60
|
+
defaultValue = false,
|
|
61
|
+
rules,
|
|
62
|
+
disabled
|
|
63
|
+
}) => {
|
|
64
|
+
const uniqueId = React2.useId();
|
|
65
|
+
const id = `auxiliary-checkbox-${name}-${uniqueId}`;
|
|
66
|
+
const {
|
|
67
|
+
field
|
|
68
|
+
} = useController({
|
|
69
|
+
name,
|
|
70
|
+
defaultValue,
|
|
71
|
+
rules
|
|
72
|
+
});
|
|
73
|
+
const isDisabled = disabled ?? field.disabled;
|
|
74
|
+
const {
|
|
75
|
+
value,
|
|
76
|
+
...fieldWithoutValue
|
|
77
|
+
} = field;
|
|
78
|
+
return /* @__PURE__ */React2.createElement(Label, {
|
|
79
|
+
"aria-disabled": isDisabled,
|
|
80
|
+
htmlFor: id,
|
|
81
|
+
sx: {
|
|
82
|
+
flexDirection: "row",
|
|
83
|
+
alignItems: "center",
|
|
84
|
+
cursor: isDisabled ? "not-allowed" : "pointer"
|
|
85
|
+
}
|
|
86
|
+
}, /* @__PURE__ */React2.createElement(Flex, {
|
|
87
|
+
sx: {
|
|
88
|
+
position: "relative"
|
|
89
|
+
}
|
|
90
|
+
}, /* @__PURE__ */React2.createElement(Checkbox, {
|
|
91
|
+
id,
|
|
92
|
+
...fieldWithoutValue,
|
|
93
|
+
checked: value,
|
|
94
|
+
disabled: isDisabled
|
|
95
|
+
})), label);
|
|
96
|
+
}, "AuxiliaryCheckbox");
|
|
97
|
+
|
|
98
|
+
// src/FormField.tsx
|
|
99
|
+
var FormField = /* @__PURE__ */__name(({
|
|
100
|
+
label,
|
|
101
|
+
id: idProp,
|
|
102
|
+
name,
|
|
103
|
+
defaultValue,
|
|
104
|
+
disabled: propsDisabled,
|
|
105
|
+
labelTooltip,
|
|
106
|
+
sx,
|
|
107
|
+
css,
|
|
108
|
+
render,
|
|
109
|
+
warning,
|
|
110
|
+
rules,
|
|
111
|
+
auxiliaryCheckbox
|
|
112
|
+
}) => {
|
|
113
|
+
const controllerReturn = useController2({
|
|
114
|
+
name,
|
|
115
|
+
defaultValue,
|
|
116
|
+
rules
|
|
117
|
+
});
|
|
118
|
+
const {
|
|
119
|
+
formState: {
|
|
120
|
+
errors
|
|
121
|
+
}
|
|
122
|
+
} = useFormContext2();
|
|
123
|
+
const disabled = propsDisabled ?? controllerReturn.field.disabled;
|
|
124
|
+
const hasError = !!errors[name];
|
|
125
|
+
const hasAuxiliaryError = auxiliaryCheckbox ? !!errors[auxiliaryCheckbox.name] : false;
|
|
126
|
+
const uniqueId = React3.useId();
|
|
127
|
+
const id = idProp || `form-field-${name}-${uniqueId}`;
|
|
128
|
+
const isCheckboxOrSwitch = /* @__PURE__ */__name(element => {
|
|
129
|
+
return [Checkbox2, Switch].some(component => {
|
|
130
|
+
return element.type === component;
|
|
131
|
+
});
|
|
132
|
+
}, "isCheckboxOrSwitch");
|
|
133
|
+
const controllerReturnWithDisabled = React3.useMemo(() => {
|
|
134
|
+
return {
|
|
135
|
+
...controllerReturn,
|
|
136
|
+
field: {
|
|
137
|
+
...controllerReturn.field,
|
|
138
|
+
disabled
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}, [controllerReturn, disabled]);
|
|
142
|
+
const memoizedRender = React3.useMemo(() => {
|
|
143
|
+
return React3.Children.map(render(controllerReturnWithDisabled), child => {
|
|
144
|
+
if (! /* @__PURE__ */React3.isValidElement(child)) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const mergeProps = {
|
|
148
|
+
id,
|
|
149
|
+
...(warning && {
|
|
150
|
+
trailingIcon: "warning-alt"
|
|
151
|
+
})
|
|
152
|
+
};
|
|
153
|
+
if (label && isCheckboxOrSwitch(child)) {
|
|
154
|
+
return /* @__PURE__ */React3.createElement(Label2, {
|
|
155
|
+
"aria-disabled": disabled,
|
|
156
|
+
htmlFor: id,
|
|
157
|
+
tooltip: labelTooltip,
|
|
158
|
+
sx: {
|
|
159
|
+
flexDirection: "row",
|
|
160
|
+
alignItems: "center",
|
|
161
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
|
162
|
+
}
|
|
163
|
+
}, /* @__PURE__ */React3.createElement(Flex2, {
|
|
164
|
+
sx: {
|
|
165
|
+
position: "relative"
|
|
166
|
+
}
|
|
167
|
+
}, /* @__PURE__ */React3.cloneElement(child, mergeProps)), label);
|
|
168
|
+
}
|
|
169
|
+
return /* @__PURE__ */React3.createElement(Flex2, {
|
|
170
|
+
sx: {
|
|
171
|
+
width: "full",
|
|
172
|
+
flexDirection: "column",
|
|
173
|
+
gap: "2"
|
|
174
|
+
}
|
|
175
|
+
}, label && /* @__PURE__ */React3.createElement(Label2, {
|
|
176
|
+
"aria-disabled": disabled,
|
|
177
|
+
htmlFor: id,
|
|
178
|
+
tooltip: labelTooltip
|
|
179
|
+
}, label), /* @__PURE__ */React3.cloneElement(child, mergeProps));
|
|
180
|
+
});
|
|
181
|
+
}, [render, controllerReturnWithDisabled, label, disabled, id, labelTooltip, warning]);
|
|
182
|
+
const errorNameToDisplay = hasError ? name : hasAuxiliaryError && auxiliaryCheckbox ? auxiliaryCheckbox.name : name;
|
|
183
|
+
return /* @__PURE__ */React3.createElement(Flex2, {
|
|
184
|
+
sx: {
|
|
185
|
+
flexDirection: "column",
|
|
186
|
+
width: "100%",
|
|
187
|
+
gap: "1",
|
|
188
|
+
...sx
|
|
189
|
+
},
|
|
190
|
+
css
|
|
191
|
+
}, memoizedRender, auxiliaryCheckbox && /* @__PURE__ */React3.createElement(AuxiliaryCheckbox, {
|
|
192
|
+
...auxiliaryCheckbox,
|
|
193
|
+
disabled
|
|
194
|
+
}), /* @__PURE__ */React3.createElement(FormErrorMessage, {
|
|
195
|
+
name: errorNameToDisplay
|
|
196
|
+
}), warning && !hasError && /* @__PURE__ */React3.createElement(Flex2, {
|
|
197
|
+
className: "warning",
|
|
198
|
+
sx: {
|
|
199
|
+
color: "feedback.text.caution.default",
|
|
200
|
+
fontSize: "sm",
|
|
201
|
+
gap: "2",
|
|
202
|
+
paddingBottom: "1",
|
|
203
|
+
alignItems: "center"
|
|
204
|
+
}
|
|
205
|
+
}, warning));
|
|
206
|
+
}, "FormField");
|
|
207
|
+
|
|
208
|
+
// src/FormFieldPatternFormat.tsx
|
|
209
|
+
import { Input } from "@ttoss/ui";
|
|
210
|
+
import { PatternFormat } from "react-number-format";
|
|
211
|
+
var FormFieldPatternFormat = /* @__PURE__ */__name(({
|
|
212
|
+
disabled,
|
|
213
|
+
...props
|
|
214
|
+
}) => {
|
|
215
|
+
const {
|
|
216
|
+
label,
|
|
217
|
+
name,
|
|
218
|
+
labelTooltip,
|
|
219
|
+
warning,
|
|
220
|
+
sx,
|
|
221
|
+
css,
|
|
222
|
+
rules,
|
|
223
|
+
id,
|
|
224
|
+
defaultValue,
|
|
225
|
+
leadingIcon,
|
|
226
|
+
trailingIcon,
|
|
227
|
+
auxiliaryCheckbox,
|
|
228
|
+
onBlur,
|
|
229
|
+
onValueChange,
|
|
230
|
+
...patternFormatProps
|
|
231
|
+
} = props;
|
|
232
|
+
return /* @__PURE__ */React.createElement(FormField, {
|
|
233
|
+
id,
|
|
234
|
+
label,
|
|
235
|
+
name,
|
|
236
|
+
labelTooltip,
|
|
237
|
+
warning,
|
|
238
|
+
sx,
|
|
239
|
+
css,
|
|
240
|
+
defaultValue,
|
|
241
|
+
rules,
|
|
242
|
+
disabled,
|
|
243
|
+
auxiliaryCheckbox,
|
|
244
|
+
render: /* @__PURE__ */__name(({
|
|
245
|
+
field,
|
|
246
|
+
fieldState
|
|
247
|
+
}) => {
|
|
248
|
+
return /* @__PURE__ */React.createElement(PatternFormat, {
|
|
249
|
+
...patternFormatProps,
|
|
250
|
+
name: field.name,
|
|
251
|
+
value: field.value,
|
|
252
|
+
onBlur: /* @__PURE__ */__name(e => {
|
|
253
|
+
field.onBlur();
|
|
254
|
+
onBlur?.(e);
|
|
255
|
+
}, "onBlur"),
|
|
256
|
+
onValueChange: /* @__PURE__ */__name((values, sourceInfo) => {
|
|
257
|
+
field.onChange(values.value);
|
|
258
|
+
onValueChange?.(values, sourceInfo);
|
|
259
|
+
}, "onValueChange"),
|
|
260
|
+
customInput: Input,
|
|
261
|
+
leadingIcon,
|
|
262
|
+
trailingIcon,
|
|
263
|
+
disabled: disabled ?? field.disabled,
|
|
264
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
265
|
+
});
|
|
266
|
+
}, "render")
|
|
267
|
+
});
|
|
268
|
+
}, "FormFieldPatternFormat");
|
|
269
|
+
|
|
270
|
+
// src/Brazil/FormFieldCNPJ.tsx
|
|
271
|
+
import { Input as Input2 } from "@ttoss/ui";
|
|
272
|
+
import { PatternFormat as PatternFormat2 } from "react-number-format";
|
|
273
|
+
var isCnpjValid = /* @__PURE__ */__name(cnpj => {
|
|
274
|
+
if (cnpj?.length != 14) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
if (cnpj == "00000000000000" || cnpj == "11111111111111" || cnpj == "22222222222222" || cnpj == "33333333333333" || cnpj == "44444444444444" || cnpj == "55555555555555" || cnpj == "66666666666666" || cnpj == "77777777777777" || cnpj == "88888888888888" || cnpj == "99999999999999") {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
let size = cnpj.length - 2;
|
|
281
|
+
let numbers = cnpj.substring(0, size);
|
|
282
|
+
const digits = cnpj.substring(size);
|
|
283
|
+
let soma = 0;
|
|
284
|
+
let pos = size - 7;
|
|
285
|
+
for (let i = size; i >= 1; i--) {
|
|
286
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
287
|
+
if (pos < 2) {
|
|
288
|
+
pos = 9;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
let result = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
|
292
|
+
if (result != digits.charAt(0)) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
size = size + 1;
|
|
296
|
+
numbers = cnpj.substring(0, size);
|
|
297
|
+
soma = 0;
|
|
298
|
+
pos = size - 7;
|
|
299
|
+
for (let i = size; i >= 1; i--) {
|
|
300
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
301
|
+
if (pos < 2) {
|
|
302
|
+
pos = 9;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
result = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
|
306
|
+
if (result != digits.charAt(1)) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
return true;
|
|
310
|
+
}, "isCnpjValid");
|
|
311
|
+
var FormFieldCNPJ = /* @__PURE__ */__name(({
|
|
312
|
+
disabled,
|
|
313
|
+
...props
|
|
314
|
+
}) => {
|
|
315
|
+
const {
|
|
316
|
+
label,
|
|
317
|
+
name,
|
|
318
|
+
labelTooltip,
|
|
319
|
+
warning,
|
|
320
|
+
sx,
|
|
321
|
+
css,
|
|
322
|
+
rules,
|
|
323
|
+
id,
|
|
324
|
+
defaultValue,
|
|
325
|
+
placeholder = "12.345.678/0000-00",
|
|
326
|
+
auxiliaryCheckbox,
|
|
327
|
+
...patternFormatProps
|
|
328
|
+
} = props;
|
|
329
|
+
return /* @__PURE__ */React.createElement(FormField, {
|
|
330
|
+
id,
|
|
331
|
+
label,
|
|
332
|
+
name,
|
|
333
|
+
labelTooltip,
|
|
334
|
+
warning,
|
|
335
|
+
sx,
|
|
336
|
+
css,
|
|
337
|
+
defaultValue,
|
|
338
|
+
rules,
|
|
339
|
+
disabled,
|
|
340
|
+
auxiliaryCheckbox,
|
|
341
|
+
render: /* @__PURE__ */__name(({
|
|
342
|
+
field
|
|
343
|
+
}) => {
|
|
344
|
+
return /* @__PURE__ */React.createElement(PatternFormat2, {
|
|
345
|
+
...patternFormatProps,
|
|
346
|
+
name: field.name,
|
|
347
|
+
value: field.value,
|
|
348
|
+
onBlur: field.onBlur,
|
|
349
|
+
onValueChange: /* @__PURE__ */__name(values => {
|
|
350
|
+
field.onChange(values.value);
|
|
351
|
+
}, "onValueChange"),
|
|
352
|
+
format: "##.###.###/####-##",
|
|
353
|
+
customInput: Input2,
|
|
354
|
+
placeholder,
|
|
355
|
+
disabled: disabled ?? field.disabled
|
|
356
|
+
});
|
|
357
|
+
}, "render")
|
|
358
|
+
});
|
|
359
|
+
}, "FormFieldCNPJ");
|
|
360
|
+
|
|
361
|
+
// src/Brazil/FormFieldCPF.tsx
|
|
362
|
+
import { Input as Input3 } from "@ttoss/ui";
|
|
363
|
+
import { PatternFormat as PatternFormat3 } from "react-number-format";
|
|
364
|
+
var isCpfValid = /* @__PURE__ */__name(cpf => {
|
|
365
|
+
if (cpf?.length != 11) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
let soma = 0;
|
|
372
|
+
for (let i = 0; i < 9; i++) {
|
|
373
|
+
soma += parseInt(cpf.charAt(i)) * (10 - i);
|
|
374
|
+
}
|
|
375
|
+
let resto = soma * 10 % 11;
|
|
376
|
+
if (resto === 10 || resto === 11) {
|
|
377
|
+
resto = 0;
|
|
378
|
+
}
|
|
379
|
+
if (resto != parseInt(cpf.charAt(9))) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
soma = 0;
|
|
383
|
+
for (let i = 0; i < 10; i++) {
|
|
384
|
+
soma += parseInt(cpf.charAt(i)) * (11 - i);
|
|
385
|
+
}
|
|
386
|
+
resto = soma * 10 % 11;
|
|
387
|
+
if (resto === 10 || resto === 11) {
|
|
388
|
+
resto = 0;
|
|
389
|
+
}
|
|
390
|
+
if (resto != parseInt(cpf.charAt(10))) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
return true;
|
|
394
|
+
}, "isCpfValid");
|
|
395
|
+
var FormFieldCPF = /* @__PURE__ */__name(({
|
|
396
|
+
disabled,
|
|
397
|
+
...props
|
|
398
|
+
}) => {
|
|
399
|
+
const {
|
|
400
|
+
label,
|
|
401
|
+
name,
|
|
402
|
+
labelTooltip,
|
|
403
|
+
warning,
|
|
404
|
+
sx,
|
|
405
|
+
css,
|
|
406
|
+
rules,
|
|
407
|
+
id,
|
|
408
|
+
defaultValue,
|
|
409
|
+
placeholder = "123.456.789-00",
|
|
410
|
+
...patternFormatProps
|
|
411
|
+
} = props;
|
|
412
|
+
return /* @__PURE__ */React.createElement(FormField, {
|
|
413
|
+
id,
|
|
414
|
+
label,
|
|
415
|
+
name,
|
|
416
|
+
labelTooltip,
|
|
417
|
+
warning,
|
|
418
|
+
sx,
|
|
419
|
+
css,
|
|
420
|
+
defaultValue,
|
|
421
|
+
rules,
|
|
422
|
+
disabled,
|
|
423
|
+
render: /* @__PURE__ */__name(({
|
|
424
|
+
field
|
|
425
|
+
}) => {
|
|
426
|
+
return /* @__PURE__ */React.createElement(PatternFormat3, {
|
|
427
|
+
...patternFormatProps,
|
|
428
|
+
name: field.name,
|
|
429
|
+
value: field.value,
|
|
430
|
+
onBlur: field.onBlur,
|
|
431
|
+
onValueChange: /* @__PURE__ */__name(values => {
|
|
432
|
+
field.onChange(values.value);
|
|
433
|
+
}, "onValueChange"),
|
|
434
|
+
format: "###.###.###-##",
|
|
435
|
+
customInput: Input3,
|
|
436
|
+
placeholder,
|
|
437
|
+
disabled: disabled ?? field.disabled
|
|
438
|
+
});
|
|
439
|
+
}, "render")
|
|
440
|
+
});
|
|
441
|
+
}, "FormFieldCPF");
|
|
442
|
+
export { __name, FormErrorMessage, FormField, FormFieldPatternFormat, isCnpjValid, FormFieldCNPJ, isCpfValid, FormFieldCPF };
|
|
@@ -0,0 +1,4 @@
|
|
|
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, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-2ZLGQ7EE.js";
|
|
3
|
+
import { FormErrorMessage, FormField, FormFieldPatternFormat } from "./chunk-QJQFXN4B.js";
|
|
4
|
+
export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { BoxProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, ThemeUIStyleObject, SelectProps, SwitchProps, TextareaProps } from '@ttoss/ui';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { FieldValues, FormProviderProps, FieldName, FieldPath } from 'react-hook-form';
|
|
5
|
+
export * from 'react-hook-form';
|
|
6
|
+
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
7
|
+
import { F as FormFieldProps, a as FormFieldPatternFormatProps } from './FormFieldPatternFormat-D5CI6eUA.js';
|
|
8
|
+
export { b as FormField, c as FormFieldPatternFormat } from './FormFieldPatternFormat-D5CI6eUA.js';
|
|
9
|
+
import { NumericFormatProps } from 'react-number-format';
|
|
10
|
+
import { DateRange } from '@ttoss/components/DatePicker';
|
|
11
|
+
import './typings.d-BZ6kUiQ4.js';
|
|
12
|
+
import * as yup from 'yup';
|
|
13
|
+
export { yup };
|
|
14
|
+
export { yupResolver } from '@hookform/resolvers/yup';
|
|
15
|
+
|
|
16
|
+
declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues = TFieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
onSubmit?: (data: TTransformedValues) => Promise<void> | void;
|
|
19
|
+
sx?: BoxProps["sx"];
|
|
20
|
+
} & FormProviderProps<TFieldValues, TContext, TTransformedValues>) => react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
declare const FormErrorMessage: <TFieldValues extends FieldValues = FieldValues>({ name, disabled, }: {
|
|
23
|
+
name: FieldName<TFieldValues>;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
type FormFieldCheckboxProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<FormFieldProps<TFieldValues, TName>, 'defaultValue'> & Omit<CheckboxProps, 'name' | 'defaultValue'> & {
|
|
28
|
+
defaultValue?: boolean;
|
|
29
|
+
};
|
|
30
|
+
declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ defaultValue, disabled, ...props }: FormFieldCheckboxProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
type FormFieldCreditCardNumberProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldPatternFormatProps<TFieldValues, TName>;
|
|
33
|
+
declare const FormFieldCreditCardNumber: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ format, placeholder, ...formFieldPatternFormatProps }: FormFieldCreditCardNumberProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
34
|
+
|
|
35
|
+
type FormFieldNumericFormatProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<NumericFormatProps, 'name'> & Pick<InputProps, 'leadingIcon' | 'trailingIcon'>;
|
|
36
|
+
declare const FormFieldNumericFormat: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldNumericFormatProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
type FormFieldCurrencyInputProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldNumericFormatProps<TFieldValues, TName> & {
|
|
39
|
+
prefix: string;
|
|
40
|
+
};
|
|
41
|
+
declare const FormFieldCurrencyInput: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ prefix, decimalSeparator, thousandSeparator, ...formFieldNumericFormatProps }: FormFieldCurrencyInputProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
42
|
+
|
|
43
|
+
interface DateRangePreset {
|
|
44
|
+
label: string;
|
|
45
|
+
getValue: () => DateRange;
|
|
46
|
+
}
|
|
47
|
+
type FormFieldDatePickerProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & {
|
|
48
|
+
presets?: DateRangePreset[];
|
|
49
|
+
};
|
|
50
|
+
declare const FormFieldDatePicker: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldDatePickerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
51
|
+
|
|
52
|
+
type FormFieldInputProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<InputProps, 'name'>;
|
|
53
|
+
declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ defaultValue, disabled, ...props }: FormFieldInputProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
54
|
+
|
|
55
|
+
type FormFieldPasswordProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<InputPasswordProps, 'name'>;
|
|
56
|
+
declare const FormFieldPassword: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ defaultValue, disabled, ...props }: FormFieldPasswordProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
57
|
+
|
|
58
|
+
type FormRadioOption$2 = {
|
|
59
|
+
value: string | number;
|
|
60
|
+
label: string;
|
|
61
|
+
};
|
|
62
|
+
type FormFieldRadioProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<RadioProps, 'name'> & {
|
|
63
|
+
options: FormRadioOption$2[];
|
|
64
|
+
};
|
|
65
|
+
declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, options, ...props }: FormFieldRadioProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
66
|
+
|
|
67
|
+
type FormRadioOption$1 = {
|
|
68
|
+
value: string | number;
|
|
69
|
+
label: string;
|
|
70
|
+
description?: string;
|
|
71
|
+
};
|
|
72
|
+
type FormFieldRadioCardProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<RadioProps, 'name'> & {
|
|
73
|
+
options: FormRadioOption$1[];
|
|
74
|
+
direction?: 'column' | 'row';
|
|
75
|
+
width?: string;
|
|
76
|
+
};
|
|
77
|
+
declare const FormFieldRadioCard: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldRadioCardProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
78
|
+
|
|
79
|
+
type FormRadioOption = {
|
|
80
|
+
value: string | number;
|
|
81
|
+
label: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
icon?: React.ComponentType<{
|
|
84
|
+
size?: number;
|
|
85
|
+
className?: string;
|
|
86
|
+
}>;
|
|
87
|
+
tag?: {
|
|
88
|
+
label: string;
|
|
89
|
+
variant?: 'accent' | 'positive' | 'caution' | 'muted' | 'negative' | 'primary' | 'secondary' | 'default';
|
|
90
|
+
sx?: ThemeUIStyleObject;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
type FormFieldRadioCardIconyProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & {
|
|
94
|
+
options: FormRadioOption[];
|
|
95
|
+
direction?: 'column' | 'row';
|
|
96
|
+
width?: string;
|
|
97
|
+
};
|
|
98
|
+
declare const FormFieldRadioCardIcony: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldRadioCardIconyProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
99
|
+
|
|
100
|
+
type FormFieldSelectProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<SelectProps, 'name' | 'defaultValue'>;
|
|
101
|
+
declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldSelectProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
102
|
+
|
|
103
|
+
type FormFieldSwitchProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<SwitchProps, 'name'>;
|
|
104
|
+
declare const FormFieldSwitch: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldSwitchProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
105
|
+
|
|
106
|
+
type FormFieldTextareaProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<TextareaProps, 'name'>;
|
|
107
|
+
declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ defaultValue, disabled, ...props }: FormFieldTextareaProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
108
|
+
|
|
109
|
+
declare const useFormGroup: () => {
|
|
110
|
+
level: number | undefined;
|
|
111
|
+
levelsLength: number;
|
|
112
|
+
};
|
|
113
|
+
type FormGroupProps = {
|
|
114
|
+
name?: string;
|
|
115
|
+
title?: string;
|
|
116
|
+
direction?: 'column' | 'row';
|
|
117
|
+
} & BoxProps;
|
|
118
|
+
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
119
|
+
|
|
120
|
+
export { type DateRangePreset, Form, FormErrorMessage, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldProps, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, type FormRadioOption, useFormGroup };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Maybe, AnyObject, Flags, Schema } from 'yup';
|
|
2
|
+
|
|
3
|
+
declare module 'yup' {
|
|
4
|
+
interface StringSchema<
|
|
5
|
+
TType extends Maybe<string> = string | undefined,
|
|
6
|
+
TContext extends AnyObject = AnyObject,
|
|
7
|
+
TDefault = undefined,
|
|
8
|
+
TFlags extends Flags = '',
|
|
9
|
+
> extends Schema<TType, TContext, TDefault, TFlags> {
|
|
10
|
+
cnpj(): this;
|
|
11
|
+
cpf(): this;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16.8.0",
|
|
42
|
-
"@ttoss/
|
|
43
|
-
"@ttoss/
|
|
44
|
-
"@ttoss/
|
|
42
|
+
"@ttoss/ui": "^6.2.0",
|
|
43
|
+
"@ttoss/components": "^2.11.0",
|
|
44
|
+
"@ttoss/react-i18n": "^2.0.25"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/jest": "^30.0.0",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"react-error-boundary": "^6.0.0",
|
|
52
52
|
"tsup": "^8.5.1",
|
|
53
53
|
"yup": "^1.7.1",
|
|
54
|
-
"@ttoss/components": "^2.10.2",
|
|
55
54
|
"@ttoss/config": "^1.35.12",
|
|
55
|
+
"@ttoss/components": "^2.11.0",
|
|
56
56
|
"@ttoss/i18n-cli": "^0.7.38",
|
|
57
57
|
"@ttoss/react-i18n": "^2.0.25",
|
|
58
58
|
"@ttoss/react-icons": "^0.5.6",
|
|
59
59
|
"@ttoss/test-utils": "^4.0.2",
|
|
60
|
-
"@ttoss/ui": "^6.
|
|
60
|
+
"@ttoss/ui": "^6.2.0"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public",
|