@ttoss/forms 0.25.6 → 0.26.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/LICENSE +21 -674
- package/dist/Brazil/index.d.ts +24 -0
- package/dist/FormFieldPatternFormat-CkcL14ho.d.ts +10 -0
- package/dist/MultistepForm/index.d.ts +65 -0
- package/dist/esm/Brazil/index.js +51 -0
- package/dist/esm/MultistepForm/index.js +2502 -0
- package/dist/esm/chunk-6U527R3X.js +741 -0
- package/dist/esm/index.js +3 -0
- package/dist/index.d.ts +107 -0
- package/{src/yup/typings.d.ts → dist/typings.d-HZBqJJjn.d.ts} +1 -3
- package/package.json +11 -11
- package/src/Brazil/FormFieldCEP.tsx +0 -25
- package/src/Brazil/FormFieldCNPJ.tsx +0 -93
- package/src/Brazil/FormFieldPhone.tsx +0 -41
- package/src/Brazil/index.ts +0 -4
- package/src/Form.tsx +0 -29
- package/src/FormErrorMessage.tsx +0 -60
- package/src/FormField.tsx +0 -86
- package/src/FormFieldCheckbox.tsx +0 -49
- package/src/FormFieldCreditCardNumber.tsx +0 -25
- package/src/FormFieldCurrencyInput.tsx +0 -36
- package/src/FormFieldInput.tsx +0 -43
- package/src/FormFieldNumericFormat.tsx +0 -35
- package/src/FormFieldPassword.tsx +0 -43
- package/src/FormFieldPatternFormat.tsx +0 -36
- package/src/FormFieldRadio.tsx +0 -57
- package/src/FormFieldSelect.tsx +0 -47
- package/src/FormFieldTextarea.tsx +0 -36
- package/src/FormGroup.tsx +0 -136
- package/src/MultistepForm/MultistepFlowMessage.tsx +0 -14
- package/src/MultistepForm/MultistepFlowMessageImageText.tsx +0 -37
- package/src/MultistepForm/MultistepFooter.tsx +0 -18
- package/src/MultistepForm/MultistepForm.tsx +0 -117
- package/src/MultistepForm/MultistepFormStepper.tsx +0 -70
- package/src/MultistepForm/MultistepHeader.tsx +0 -78
- package/src/MultistepForm/MultistepNavigation.tsx +0 -38
- package/src/MultistepForm/MultistepQuestion.tsx +0 -28
- package/src/MultistepForm/index.ts +0 -1
- package/src/MultistepForm/types.ts +0 -7
- package/src/index.ts +0 -35
- package/src/yup/i18n.ts +0 -31
- package/src/yup/schema.ts +0 -26
- package/src/yup/yup.ts +0 -4
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value
|
|
8
|
+
}) : obj[key] = value;
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
|
|
11
|
+
// src/index.ts
|
|
12
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
13
|
+
|
|
14
|
+
// src/yup/i18n.ts
|
|
15
|
+
import { defineMessage } from "@ttoss/react-i18n";
|
|
16
|
+
import { setLocale } from "yup";
|
|
17
|
+
setLocale({
|
|
18
|
+
mixed: {
|
|
19
|
+
required: defineMessage({
|
|
20
|
+
id: "MfWGyg",
|
|
21
|
+
defaultMessage: [{
|
|
22
|
+
"type": 0,
|
|
23
|
+
"value": "Field is required"
|
|
24
|
+
}]
|
|
25
|
+
}),
|
|
26
|
+
notType: ({
|
|
27
|
+
type
|
|
28
|
+
}) => {
|
|
29
|
+
return {
|
|
30
|
+
...defineMessage({
|
|
31
|
+
id: "ZhaPt0",
|
|
32
|
+
defaultMessage: [{
|
|
33
|
+
"type": 0,
|
|
34
|
+
"value": "Invalid Value for Field of type "
|
|
35
|
+
}, {
|
|
36
|
+
"type": 1,
|
|
37
|
+
"value": "type"
|
|
38
|
+
}]
|
|
39
|
+
}),
|
|
40
|
+
values: {
|
|
41
|
+
type
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
string: {
|
|
47
|
+
min: ({
|
|
48
|
+
min
|
|
49
|
+
}) => {
|
|
50
|
+
return {
|
|
51
|
+
...defineMessage({
|
|
52
|
+
id: "D1C6fR",
|
|
53
|
+
defaultMessage: [{
|
|
54
|
+
"type": 0,
|
|
55
|
+
"value": "Field must be at least "
|
|
56
|
+
}, {
|
|
57
|
+
"type": 1,
|
|
58
|
+
"value": "min"
|
|
59
|
+
}, {
|
|
60
|
+
"type": 0,
|
|
61
|
+
"value": " characters"
|
|
62
|
+
}]
|
|
63
|
+
}),
|
|
64
|
+
values: {
|
|
65
|
+
min
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// src/yup/schema.ts
|
|
73
|
+
import * as yup from "yup";
|
|
74
|
+
|
|
75
|
+
// src/Brazil/FormFieldCNPJ.tsx
|
|
76
|
+
import { Input } from "@ttoss/ui";
|
|
77
|
+
import { PatternFormat } from "react-number-format";
|
|
78
|
+
import { jsx } from "react/jsx-runtime";
|
|
79
|
+
var isCnpjValid = cnpj => {
|
|
80
|
+
if (cnpj?.length != 14) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (cnpj == "00000000000000" || cnpj == "11111111111111" || cnpj == "22222222222222" || cnpj == "33333333333333" || cnpj == "44444444444444" || cnpj == "55555555555555" || cnpj == "66666666666666" || cnpj == "77777777777777" || cnpj == "88888888888888" || cnpj == "99999999999999") {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
let size = cnpj.length - 2;
|
|
87
|
+
let numbers = cnpj.substring(0, size);
|
|
88
|
+
const digits = cnpj.substring(size);
|
|
89
|
+
let soma = 0;
|
|
90
|
+
let pos = size - 7;
|
|
91
|
+
for (let i = size; i >= 1; i--) {
|
|
92
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
93
|
+
if (pos < 2) {
|
|
94
|
+
pos = 9;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let result = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
|
98
|
+
if (result != digits.charAt(0)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
size = size + 1;
|
|
102
|
+
numbers = cnpj.substring(0, size);
|
|
103
|
+
soma = 0;
|
|
104
|
+
pos = size - 7;
|
|
105
|
+
for (let i = size; i >= 1; i--) {
|
|
106
|
+
soma += numbers.charAt(size - i) * pos--;
|
|
107
|
+
if (pos < 2) {
|
|
108
|
+
pos = 9;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
result = soma % 11 < 2 ? 0 : 11 - soma % 11;
|
|
112
|
+
if (result != digits.charAt(1)) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
var FormFieldCNPJ = ({
|
|
118
|
+
label,
|
|
119
|
+
name,
|
|
120
|
+
...patternFormatProps
|
|
121
|
+
}) => {
|
|
122
|
+
return /* @__PURE__ */jsx(FormField, {
|
|
123
|
+
name,
|
|
124
|
+
label,
|
|
125
|
+
render: ({
|
|
126
|
+
field
|
|
127
|
+
}) => {
|
|
128
|
+
return /* @__PURE__ */jsx(PatternFormat, {
|
|
129
|
+
name: field.name,
|
|
130
|
+
value: field.value,
|
|
131
|
+
onBlur: field.onBlur,
|
|
132
|
+
onValueChange: values => {
|
|
133
|
+
field.onChange(values.value);
|
|
134
|
+
},
|
|
135
|
+
format: "##.###.###/####-##",
|
|
136
|
+
customInput: Input,
|
|
137
|
+
placeholder: "12.345.678/0000-00",
|
|
138
|
+
...patternFormatProps
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/yup/schema.ts
|
|
145
|
+
yup.addMethod(yup.string, "cnpj", function () {
|
|
146
|
+
return this.test("valid-cnpj", "Invalid CNPJ", value => {
|
|
147
|
+
return isCnpjValid(value);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
yup.addMethod(yup.string, "password", function ({
|
|
151
|
+
required
|
|
152
|
+
} = {}) {
|
|
153
|
+
const schema = this.trim();
|
|
154
|
+
if (required) {
|
|
155
|
+
schema.required("Password is required");
|
|
156
|
+
}
|
|
157
|
+
return schema.min(8, "Password must be at least 8 characters long");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// src/yup/yup.ts
|
|
161
|
+
import * as yup2 from "yup";
|
|
162
|
+
|
|
163
|
+
// src/Form.tsx
|
|
164
|
+
import { Box } from "@ttoss/ui";
|
|
165
|
+
import { FormProvider } from "react-hook-form";
|
|
166
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
167
|
+
var Form = ({
|
|
168
|
+
children,
|
|
169
|
+
onSubmit,
|
|
170
|
+
sx,
|
|
171
|
+
...formMethods
|
|
172
|
+
}) => {
|
|
173
|
+
return /* @__PURE__ */jsx2(FormProvider, {
|
|
174
|
+
...formMethods,
|
|
175
|
+
children: /* @__PURE__ */jsx2(Box, {
|
|
176
|
+
as: "form",
|
|
177
|
+
variant: "forms.form",
|
|
178
|
+
onSubmit: formMethods.handleSubmit(data => {
|
|
179
|
+
return onSubmit?.(data);
|
|
180
|
+
}),
|
|
181
|
+
sx,
|
|
182
|
+
children
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/FormErrorMessage.tsx
|
|
188
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
189
|
+
import { useFormContext } from "react-hook-form";
|
|
190
|
+
import { FormattedMessage } from "@ttoss/react-i18n";
|
|
191
|
+
import { HelpText } from "@ttoss/ui";
|
|
192
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
193
|
+
var isMessageDescriptor = possibleMessageDescriptor => {
|
|
194
|
+
return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
|
|
195
|
+
};
|
|
196
|
+
var FormErrorMessage = ({
|
|
197
|
+
name,
|
|
198
|
+
disabled
|
|
199
|
+
}) => {
|
|
200
|
+
const {
|
|
201
|
+
formState: {
|
|
202
|
+
errors
|
|
203
|
+
}
|
|
204
|
+
} = useFormContext();
|
|
205
|
+
return /* @__PURE__ */jsx3(ErrorMessage, {
|
|
206
|
+
name,
|
|
207
|
+
errors,
|
|
208
|
+
render: ({
|
|
209
|
+
message
|
|
210
|
+
}) => {
|
|
211
|
+
return /* @__PURE__ */jsx3(HelpText, {
|
|
212
|
+
negative: true,
|
|
213
|
+
disabled,
|
|
214
|
+
children: (() => {
|
|
215
|
+
if (typeof message === "string") {
|
|
216
|
+
return message;
|
|
217
|
+
}
|
|
218
|
+
if (isMessageDescriptor(message)) {
|
|
219
|
+
return /* @__PURE__ */jsx3(FormattedMessage, {
|
|
220
|
+
...message
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return JSON.stringify(message);
|
|
224
|
+
})()
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/FormField.tsx
|
|
231
|
+
import * as React from "react";
|
|
232
|
+
import { useController } from "react-hook-form";
|
|
233
|
+
import { Flex, Label } from "@ttoss/ui";
|
|
234
|
+
import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
235
|
+
var FormField = ({
|
|
236
|
+
label,
|
|
237
|
+
id: idProp,
|
|
238
|
+
name,
|
|
239
|
+
defaultValue,
|
|
240
|
+
disabled,
|
|
241
|
+
tooltip,
|
|
242
|
+
onTooltipClick,
|
|
243
|
+
sx,
|
|
244
|
+
css,
|
|
245
|
+
render
|
|
246
|
+
}) => {
|
|
247
|
+
const controllerReturn = useController({
|
|
248
|
+
name,
|
|
249
|
+
defaultValue
|
|
250
|
+
});
|
|
251
|
+
const id = idProp || `form-field-${name}`;
|
|
252
|
+
const memoizedRender = React.useMemo(() => {
|
|
253
|
+
return React.Children.map(render(controllerReturn), child => {
|
|
254
|
+
return /* @__PURE__ */jsxs(Fragment, {
|
|
255
|
+
children: [label && /* @__PURE__ */jsx4(Label, {
|
|
256
|
+
"aria-disabled": disabled,
|
|
257
|
+
htmlFor: id,
|
|
258
|
+
tooltip,
|
|
259
|
+
onTooltipClick,
|
|
260
|
+
children: label
|
|
261
|
+
}), React.createElement(child.type, {
|
|
262
|
+
id,
|
|
263
|
+
...child.props
|
|
264
|
+
})]
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
}, [controllerReturn, disabled, onTooltipClick, tooltip, id, label, render]);
|
|
268
|
+
return /* @__PURE__ */jsxs(Flex, {
|
|
269
|
+
sx: {
|
|
270
|
+
flexDirection: "column",
|
|
271
|
+
width: "100%",
|
|
272
|
+
gap: "md",
|
|
273
|
+
...sx
|
|
274
|
+
},
|
|
275
|
+
css,
|
|
276
|
+
children: [memoizedRender, /* @__PURE__ */jsx4(FormErrorMessage, {
|
|
277
|
+
name
|
|
278
|
+
})]
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// src/FormFieldCheckbox.tsx
|
|
283
|
+
import { Checkbox, Flex as Flex2, Label as Label2 } from "@ttoss/ui";
|
|
284
|
+
import { useController as useController2 } from "react-hook-form";
|
|
285
|
+
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
286
|
+
var FormFieldCheckbox = ({
|
|
287
|
+
label,
|
|
288
|
+
name,
|
|
289
|
+
sx,
|
|
290
|
+
...checkboxProps
|
|
291
|
+
}) => {
|
|
292
|
+
const {
|
|
293
|
+
field: {
|
|
294
|
+
onChange,
|
|
295
|
+
onBlur,
|
|
296
|
+
value,
|
|
297
|
+
ref
|
|
298
|
+
},
|
|
299
|
+
formState: {
|
|
300
|
+
errors
|
|
301
|
+
}
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
303
|
+
} = useController2({
|
|
304
|
+
name,
|
|
305
|
+
defaultValue: false
|
|
306
|
+
});
|
|
307
|
+
const id = `form-field-checkbox-${name}`;
|
|
308
|
+
const error = !!errors[name]?.message;
|
|
309
|
+
return /* @__PURE__ */jsxs2(Flex2, {
|
|
310
|
+
sx: {
|
|
311
|
+
flexDirection: "column",
|
|
312
|
+
width: "100%",
|
|
313
|
+
...sx
|
|
314
|
+
},
|
|
315
|
+
children: [/* @__PURE__ */jsx5(Flex2, {
|
|
316
|
+
sx: {
|
|
317
|
+
alignItems: "center"
|
|
318
|
+
},
|
|
319
|
+
children: /* @__PURE__ */jsxs2(Label2, {
|
|
320
|
+
"aria-disabled": checkboxProps.disabled,
|
|
321
|
+
htmlFor: id,
|
|
322
|
+
children: [/* @__PURE__ */jsx5(Checkbox, {
|
|
323
|
+
id,
|
|
324
|
+
ref,
|
|
325
|
+
checked: value,
|
|
326
|
+
onChange,
|
|
327
|
+
onBlur,
|
|
328
|
+
name,
|
|
329
|
+
"aria-invalid": error ? "true" : "false",
|
|
330
|
+
...checkboxProps
|
|
331
|
+
}), label]
|
|
332
|
+
})
|
|
333
|
+
}), /* @__PURE__ */jsx5(FormErrorMessage, {
|
|
334
|
+
name
|
|
335
|
+
})]
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// src/FormFieldPatternFormat.tsx
|
|
340
|
+
import { Input as Input2 } from "@ttoss/ui";
|
|
341
|
+
import { PatternFormat as PatternFormat2 } from "react-number-format";
|
|
342
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
343
|
+
var FormFieldPatternFormat = ({
|
|
344
|
+
label,
|
|
345
|
+
name,
|
|
346
|
+
...patternFormatProps
|
|
347
|
+
}) => {
|
|
348
|
+
return /* @__PURE__ */jsx6(FormField, {
|
|
349
|
+
name,
|
|
350
|
+
label,
|
|
351
|
+
render: ({
|
|
352
|
+
field,
|
|
353
|
+
fieldState
|
|
354
|
+
}) => {
|
|
355
|
+
return /* @__PURE__ */jsx6(PatternFormat2, {
|
|
356
|
+
name: field.name,
|
|
357
|
+
value: field.value,
|
|
358
|
+
onBlur: field.onBlur,
|
|
359
|
+
onValueChange: values => {
|
|
360
|
+
field.onChange(values.value);
|
|
361
|
+
},
|
|
362
|
+
customInput: Input2,
|
|
363
|
+
"aria-invalid": Boolean(fieldState.error).valueOf(),
|
|
364
|
+
...patternFormatProps
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/FormFieldCreditCardNumber.tsx
|
|
371
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
372
|
+
var FormFieldCreditCardNumber = ({
|
|
373
|
+
label,
|
|
374
|
+
name,
|
|
375
|
+
...formFieldPatternFormatProps
|
|
376
|
+
}) => {
|
|
377
|
+
return /* @__PURE__ */jsx7(FormFieldPatternFormat, {
|
|
378
|
+
name,
|
|
379
|
+
label,
|
|
380
|
+
format: "#### #### #### ####",
|
|
381
|
+
placeholder: "1234 1234 1234 1234",
|
|
382
|
+
...formFieldPatternFormatProps
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/FormFieldNumericFormat.tsx
|
|
387
|
+
import { Input as Input3 } from "@ttoss/ui";
|
|
388
|
+
import { NumericFormat } from "react-number-format";
|
|
389
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
390
|
+
var FormFieldNumericFormat = ({
|
|
391
|
+
label,
|
|
392
|
+
name,
|
|
393
|
+
...numericFormatProps
|
|
394
|
+
}) => {
|
|
395
|
+
return /* @__PURE__ */jsx8(FormField, {
|
|
396
|
+
label,
|
|
397
|
+
name,
|
|
398
|
+
render: ({
|
|
399
|
+
field
|
|
400
|
+
}) => {
|
|
401
|
+
return /* @__PURE__ */jsx8(NumericFormat, {
|
|
402
|
+
name: field.name,
|
|
403
|
+
value: field.value,
|
|
404
|
+
onBlur: field.onBlur,
|
|
405
|
+
onValueChange: values => {
|
|
406
|
+
field.onChange(values.floatValue);
|
|
407
|
+
},
|
|
408
|
+
customInput: Input3,
|
|
409
|
+
...numericFormatProps
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// src/FormFieldCurrencyInput.tsx
|
|
416
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
417
|
+
var FormFieldCurrencyInput = ({
|
|
418
|
+
label,
|
|
419
|
+
name,
|
|
420
|
+
prefix,
|
|
421
|
+
decimalSeparator,
|
|
422
|
+
thousandSeparator,
|
|
423
|
+
...formFieldNumericFormatProps
|
|
424
|
+
}) => {
|
|
425
|
+
return /* @__PURE__ */jsx9(FormFieldNumericFormat, {
|
|
426
|
+
name,
|
|
427
|
+
label,
|
|
428
|
+
fixedDecimalScale: true,
|
|
429
|
+
decimalScale: 2,
|
|
430
|
+
prefix,
|
|
431
|
+
decimalSeparator,
|
|
432
|
+
thousandSeparator,
|
|
433
|
+
placeholder: `${prefix} 0${decimalSeparator}00`,
|
|
434
|
+
allowNegative: false,
|
|
435
|
+
...formFieldNumericFormatProps
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/FormFieldInput.tsx
|
|
440
|
+
import { Input as Input4 } from "@ttoss/ui";
|
|
441
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
442
|
+
var FormFieldInput = ({
|
|
443
|
+
label,
|
|
444
|
+
name,
|
|
445
|
+
tooltip,
|
|
446
|
+
onTooltipClick,
|
|
447
|
+
sx,
|
|
448
|
+
defaultValue = "",
|
|
449
|
+
...inputProps
|
|
450
|
+
}) => {
|
|
451
|
+
return /* @__PURE__ */jsx10(FormField, {
|
|
452
|
+
name,
|
|
453
|
+
label,
|
|
454
|
+
disabled: inputProps.disabled,
|
|
455
|
+
tooltip,
|
|
456
|
+
onTooltipClick,
|
|
457
|
+
sx,
|
|
458
|
+
defaultValue,
|
|
459
|
+
render: ({
|
|
460
|
+
field,
|
|
461
|
+
fieldState
|
|
462
|
+
}) => {
|
|
463
|
+
return /* @__PURE__ */jsx10(Input4, {
|
|
464
|
+
...inputProps,
|
|
465
|
+
...field,
|
|
466
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
// src/FormFieldPassword.tsx
|
|
473
|
+
import { InputPassword } from "@ttoss/ui";
|
|
474
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
475
|
+
var FormFieldPassword = ({
|
|
476
|
+
label,
|
|
477
|
+
name,
|
|
478
|
+
tooltip,
|
|
479
|
+
onTooltipClick,
|
|
480
|
+
sx,
|
|
481
|
+
defaultValue = "",
|
|
482
|
+
...inputProps
|
|
483
|
+
}) => {
|
|
484
|
+
return /* @__PURE__ */jsx11(FormField, {
|
|
485
|
+
name,
|
|
486
|
+
label,
|
|
487
|
+
disabled: inputProps.disabled,
|
|
488
|
+
tooltip,
|
|
489
|
+
onTooltipClick,
|
|
490
|
+
sx,
|
|
491
|
+
defaultValue,
|
|
492
|
+
render: ({
|
|
493
|
+
field,
|
|
494
|
+
fieldState
|
|
495
|
+
}) => {
|
|
496
|
+
return /* @__PURE__ */jsx11(InputPassword, {
|
|
497
|
+
...inputProps,
|
|
498
|
+
...field,
|
|
499
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// src/FormFieldRadio.tsx
|
|
506
|
+
import { Box as Box2, Flex as Flex3, Label as Label3, Radio } from "@ttoss/ui";
|
|
507
|
+
import { useController as useController3 } from "react-hook-form";
|
|
508
|
+
import { jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
509
|
+
var FormFieldRadio = ({
|
|
510
|
+
label,
|
|
511
|
+
name,
|
|
512
|
+
options,
|
|
513
|
+
sx,
|
|
514
|
+
...radioProps
|
|
515
|
+
}) => {
|
|
516
|
+
const {
|
|
517
|
+
field: {
|
|
518
|
+
onChange,
|
|
519
|
+
onBlur,
|
|
520
|
+
value,
|
|
521
|
+
ref
|
|
522
|
+
}
|
|
523
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
524
|
+
} = useController3({
|
|
525
|
+
name,
|
|
526
|
+
defaultValue: ""
|
|
527
|
+
});
|
|
528
|
+
return /* @__PURE__ */jsxs3(Flex3, {
|
|
529
|
+
sx: {
|
|
530
|
+
flexDirection: "column",
|
|
531
|
+
width: "100%",
|
|
532
|
+
...sx
|
|
533
|
+
},
|
|
534
|
+
children: [label && /* @__PURE__ */jsx12(Label3, {
|
|
535
|
+
sx: {
|
|
536
|
+
marginBottom: "md"
|
|
537
|
+
},
|
|
538
|
+
children: label
|
|
539
|
+
}), /* @__PURE__ */jsx12(Box2, {
|
|
540
|
+
children: options.map(option => {
|
|
541
|
+
const id = `form-field-radio-${name}-${option.value}`;
|
|
542
|
+
return /* @__PURE__ */jsxs3(Label3, {
|
|
543
|
+
htmlFor: id,
|
|
544
|
+
children: [/* @__PURE__ */jsx12(Radio, {
|
|
545
|
+
ref,
|
|
546
|
+
onChange,
|
|
547
|
+
onBlur,
|
|
548
|
+
value: option.value,
|
|
549
|
+
checked: value === option.value,
|
|
550
|
+
name,
|
|
551
|
+
id,
|
|
552
|
+
...radioProps
|
|
553
|
+
}), option.label]
|
|
554
|
+
}, id);
|
|
555
|
+
})
|
|
556
|
+
}), /* @__PURE__ */jsx12(FormErrorMessage, {
|
|
557
|
+
name
|
|
558
|
+
})]
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// src/FormFieldSelect.tsx
|
|
563
|
+
import { Select } from "@ttoss/ui";
|
|
564
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
565
|
+
var FormFieldSelect = ({
|
|
566
|
+
label,
|
|
567
|
+
name,
|
|
568
|
+
id,
|
|
569
|
+
defaultValue,
|
|
570
|
+
sx,
|
|
571
|
+
css,
|
|
572
|
+
disabled,
|
|
573
|
+
tooltip,
|
|
574
|
+
onTooltipClick,
|
|
575
|
+
...selectProps
|
|
576
|
+
}) => {
|
|
577
|
+
return /* @__PURE__ */jsx13(FormField, {
|
|
578
|
+
name,
|
|
579
|
+
label,
|
|
580
|
+
id,
|
|
581
|
+
defaultValue,
|
|
582
|
+
disabled,
|
|
583
|
+
tooltip,
|
|
584
|
+
onTooltipClick,
|
|
585
|
+
sx,
|
|
586
|
+
css,
|
|
587
|
+
render: ({
|
|
588
|
+
field,
|
|
589
|
+
fieldState
|
|
590
|
+
}) => {
|
|
591
|
+
return /* @__PURE__ */jsx13(Select, {
|
|
592
|
+
...selectProps,
|
|
593
|
+
...field,
|
|
594
|
+
isDisabled: disabled,
|
|
595
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// src/FormFieldTextarea.tsx
|
|
602
|
+
import { Textarea } from "@ttoss/ui";
|
|
603
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
604
|
+
var FormFieldTextarea = ({
|
|
605
|
+
label,
|
|
606
|
+
name,
|
|
607
|
+
sx,
|
|
608
|
+
...textareaProps
|
|
609
|
+
}) => {
|
|
610
|
+
const id = `form-field-textarea-${name}`;
|
|
611
|
+
return /* @__PURE__ */jsx14(FormField, {
|
|
612
|
+
label,
|
|
613
|
+
name,
|
|
614
|
+
id,
|
|
615
|
+
sx,
|
|
616
|
+
render: ({
|
|
617
|
+
field,
|
|
618
|
+
fieldState
|
|
619
|
+
}) => {
|
|
620
|
+
return /* @__PURE__ */jsx14(Textarea, {
|
|
621
|
+
...field,
|
|
622
|
+
...textareaProps,
|
|
623
|
+
"aria-invalid": fieldState.error ? "true" : void 0
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// src/FormGroup.tsx
|
|
630
|
+
import * as React2 from "react";
|
|
631
|
+
import { Box as Box3, Flex as Flex4, Text } from "@ttoss/ui";
|
|
632
|
+
import { jsx as jsx15, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
633
|
+
var FormGroupLevelsManagerContext = React2.createContext({
|
|
634
|
+
levelsLength: 1,
|
|
635
|
+
registerChild: () => {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
var FormGroupLevelsManager = ({
|
|
640
|
+
children
|
|
641
|
+
}) => {
|
|
642
|
+
const [levelsLength, setLevelsLength] = React2.useState(0);
|
|
643
|
+
const registerChild = React2.useCallback(level => {
|
|
644
|
+
if (level + 1 > levelsLength) {
|
|
645
|
+
setLevelsLength(level + 1);
|
|
646
|
+
}
|
|
647
|
+
}, [levelsLength]);
|
|
648
|
+
return /* @__PURE__ */jsx15(FormGroupLevelsManagerContext.Provider, {
|
|
649
|
+
value: {
|
|
650
|
+
levelsLength,
|
|
651
|
+
registerChild
|
|
652
|
+
},
|
|
653
|
+
children
|
|
654
|
+
});
|
|
655
|
+
};
|
|
656
|
+
var FormGroupContext = React2.createContext({});
|
|
657
|
+
var useFormGroup = () => {
|
|
658
|
+
const {
|
|
659
|
+
parentLevel
|
|
660
|
+
} = React2.useContext(FormGroupContext);
|
|
661
|
+
const {
|
|
662
|
+
levelsLength
|
|
663
|
+
} = React2.useContext(FormGroupLevelsManagerContext);
|
|
664
|
+
return {
|
|
665
|
+
level: parentLevel,
|
|
666
|
+
levelsLength
|
|
667
|
+
};
|
|
668
|
+
};
|
|
669
|
+
var FormGroupWrapper = ({
|
|
670
|
+
title,
|
|
671
|
+
direction,
|
|
672
|
+
children,
|
|
673
|
+
name,
|
|
674
|
+
...boxProps
|
|
675
|
+
}) => {
|
|
676
|
+
const {
|
|
677
|
+
level
|
|
678
|
+
} = useFormGroup();
|
|
679
|
+
const {
|
|
680
|
+
registerChild
|
|
681
|
+
} = React2.useContext(FormGroupLevelsManagerContext);
|
|
682
|
+
React2.useEffect(() => {
|
|
683
|
+
if (typeof level === "number") {
|
|
684
|
+
registerChild(level);
|
|
685
|
+
}
|
|
686
|
+
}, [level, registerChild]);
|
|
687
|
+
const childrenContainerSx = {
|
|
688
|
+
flexDirection: direction || "column",
|
|
689
|
+
gap: "md",
|
|
690
|
+
width: "100%"
|
|
691
|
+
};
|
|
692
|
+
return /* @__PURE__ */jsxs4(Box3, {
|
|
693
|
+
"aria-level": level,
|
|
694
|
+
...boxProps,
|
|
695
|
+
sx: {
|
|
696
|
+
marginTop: level === 0 ? "none" : "lg",
|
|
697
|
+
marginBottom: "lg",
|
|
698
|
+
...boxProps.sx
|
|
699
|
+
},
|
|
700
|
+
children: [title && /* @__PURE__ */jsx15(Box3, {
|
|
701
|
+
sx: {
|
|
702
|
+
marginBottom: "md"
|
|
703
|
+
},
|
|
704
|
+
children: /* @__PURE__ */jsx15(Text, {
|
|
705
|
+
sx: {
|
|
706
|
+
fontSize: "2xl",
|
|
707
|
+
fontWeight: "bold"
|
|
708
|
+
},
|
|
709
|
+
children: title
|
|
710
|
+
})
|
|
711
|
+
}), /* @__PURE__ */jsx15(Flex4, {
|
|
712
|
+
sx: childrenContainerSx,
|
|
713
|
+
children
|
|
714
|
+
}), name && /* @__PURE__ */jsx15(FormErrorMessage, {
|
|
715
|
+
name
|
|
716
|
+
})]
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
var FormGroup = props => {
|
|
720
|
+
const {
|
|
721
|
+
level
|
|
722
|
+
} = useFormGroup();
|
|
723
|
+
const currentLevel = level === void 0 ? 0 : level + 1;
|
|
724
|
+
return /* @__PURE__ */jsx15(FormGroupContext.Provider, {
|
|
725
|
+
value: {
|
|
726
|
+
parentLevel: currentLevel
|
|
727
|
+
},
|
|
728
|
+
children: currentLevel === 0 ? /* @__PURE__ */jsx15(FormGroupLevelsManager, {
|
|
729
|
+
children: /* @__PURE__ */jsx15(FormGroupWrapper, {
|
|
730
|
+
...props
|
|
731
|
+
})
|
|
732
|
+
}) : /* @__PURE__ */jsx15(FormGroupWrapper, {
|
|
733
|
+
...props
|
|
734
|
+
})
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
// src/index.ts
|
|
739
|
+
import { useForm, useFormContext as useFormContext2, useWatch, useFieldArray, useController as useController4, useFormState, Controller, FormProvider as FormProvider2 } from "react-hook-form";
|
|
740
|
+
export * from "react-hook-form";
|
|
741
|
+
export { __publicField, isCnpjValid, FormFieldCNPJ, yup2 as yup, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldPatternFormat, FormFieldCreditCardNumber, FormFieldNumericFormat, FormFieldCurrencyInput, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, useFormGroup, FormGroup, yupResolver, useForm, useFormContext2 as useFormContext, useWatch, useFieldArray, useController4 as useController, useFormState, Controller, FormProvider2 as FormProvider };
|