@ttoss/forms 0.32.0 → 0.32.2

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.
@@ -1,983 +0,0 @@
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/Form.tsx
10
- import { Box } from "@ttoss/ui";
11
- import * as React2 from "react";
12
- import { FormProvider } from "react-hook-form";
13
- var Form = /* @__PURE__ */__name(({
14
- children,
15
- onSubmit,
16
- sx,
17
- ...formMethods
18
- }) => {
19
- return /* @__PURE__ */React2.createElement(FormProvider, formMethods, /* @__PURE__ */React2.createElement(Box, {
20
- as: "form",
21
- variant: "forms.form",
22
- onSubmit: formMethods.handleSubmit(data => {
23
- return onSubmit?.(data);
24
- }),
25
- sx
26
- }, children));
27
- }, "Form");
28
-
29
- // src/FormErrorMessage.tsx
30
- import { ErrorMessage } from "@hookform/error-message";
31
- import { FormattedMessage } from "@ttoss/react-i18n";
32
- import { HelpText } from "@ttoss/ui";
33
- import { useFormContext } from "react-hook-form";
34
- var isMessageDescriptor = /* @__PURE__ */__name(possibleMessageDescriptor => {
35
- return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
36
- }, "isMessageDescriptor");
37
- var FormErrorMessage = /* @__PURE__ */__name(({
38
- name,
39
- disabled
40
- }) => {
41
- const {
42
- formState: {
43
- errors
44
- }
45
- } = useFormContext();
46
- return /* @__PURE__ */React.createElement(ErrorMessage, {
47
- name,
48
- errors,
49
- render: /* @__PURE__ */__name(({
50
- message
51
- }) => {
52
- return /* @__PURE__ */React.createElement(HelpText, {
53
- negative: true,
54
- disabled
55
- }, (() => {
56
- if (typeof message === "string") {
57
- return message;
58
- }
59
- if (isMessageDescriptor(message)) {
60
- return /* @__PURE__ */React.createElement(FormattedMessage, message);
61
- }
62
- return JSON.stringify(message);
63
- })());
64
- }, "render")
65
- });
66
- }, "FormErrorMessage");
67
-
68
- // src/FormField.tsx
69
- import { Checkbox, Flex, Label, Switch, Tooltip } from "@ttoss/ui";
70
- import * as React3 from "react";
71
- import { useController, useFormContext as useFormContext2 } from "react-hook-form";
72
- var FormField = /* @__PURE__ */__name(({
73
- label,
74
- id: idProp,
75
- name,
76
- defaultValue,
77
- disabled,
78
- tooltip,
79
- inputTooltip,
80
- sx,
81
- css,
82
- render,
83
- warning
84
- }) => {
85
- const controllerReturn = useController({
86
- name,
87
- defaultValue
88
- });
89
- const {
90
- formState: {
91
- errors
92
- }
93
- } = useFormContext2();
94
- const hasError = !!errors[name];
95
- const uniqueId = React3.useId();
96
- const id = idProp || `form-field-${name}-${uniqueId}`;
97
- const tooltipId = `${id}-tooltip`;
98
- const [showInputTooltip, setShowInputTooltip] = React3.useState(false);
99
- const inputRef = React3.useRef(null);
100
- React3.useEffect(() => {
101
- if (!inputTooltip) return;
102
- const handleClickOutside = /* @__PURE__ */__name(event => {
103
- if (inputRef.current && !inputRef.current.contains(event.target)) {
104
- setShowInputTooltip(false);
105
- }
106
- }, "handleClickOutside");
107
- const handleEscapeKey = /* @__PURE__ */__name(event => {
108
- if (event.key === "Escape") {
109
- setShowInputTooltip(false);
110
- }
111
- }, "handleEscapeKey");
112
- if (showInputTooltip) {
113
- document.addEventListener("mousedown", handleClickOutside);
114
- document.addEventListener("keydown", handleEscapeKey);
115
- }
116
- return () => {
117
- document.removeEventListener("mousedown", handleClickOutside);
118
- document.removeEventListener("keydown", handleEscapeKey);
119
- };
120
- }, [showInputTooltip, inputTooltip]);
121
- const memoizedRender = React3.useMemo(() => {
122
- return React3.Children.map(render(controllerReturn), child => {
123
- if (! /* @__PURE__ */React3.isValidElement(child)) {
124
- return null;
125
- }
126
- const childProps = child.props;
127
- const inputProps = {
128
- ...childProps,
129
- ref: inputRef,
130
- onClick: /* @__PURE__ */__name(e => {
131
- childProps.onClick?.(e);
132
- if (inputTooltip) {
133
- setShowInputTooltip(true);
134
- }
135
- }, "onClick"),
136
- onFocus: /* @__PURE__ */__name(e => {
137
- childProps.onFocus?.(e);
138
- if (inputTooltip && !inputTooltip.openOnClick) {
139
- setShowInputTooltip(true);
140
- }
141
- }, "onFocus"),
142
- onBlur: /* @__PURE__ */__name(e => {
143
- childProps.onBlur?.(e);
144
- if (inputTooltip && !inputTooltip.openOnClick) {
145
- setShowInputTooltip(false);
146
- }
147
- }, "onBlur"),
148
- ...(inputTooltip && showInputTooltip ? {
149
- "data-tooltip-id": tooltipId
150
- } : {})
151
- };
152
- if (label && [Checkbox, Switch].some(component => {
153
- return child.type === component;
154
- })) {
155
- return /* @__PURE__ */React3.createElement(React3.Fragment, null, /* @__PURE__ */React3.createElement(Label, {
156
- "aria-disabled": disabled,
157
- tooltip
158
- }, /* @__PURE__ */React3.createElement(Flex, null, warning ? /* @__PURE__ */React3.createElement(child.type, {
159
- id,
160
- ...inputProps,
161
- ...(warning ? {
162
- trailingIcon: "warning-alt"
163
- } : {})
164
- }) : /* @__PURE__ */React3.createElement(child.type, {
165
- id,
166
- ...inputProps
167
- })), label), inputTooltip && showInputTooltip && /* @__PURE__ */React3.createElement(Flex, {
168
- sx: {
169
- width: "full",
170
- fontSize: "sm"
171
- }
172
- }, /* @__PURE__ */React3.createElement(Tooltip, {
173
- id: tooltipId,
174
- place: inputTooltip.place,
175
- clickable: inputTooltip.clickable,
176
- isOpen: showInputTooltip,
177
- variant: inputTooltip.variant
178
- }, inputTooltip.render)));
179
- }
180
- return /* @__PURE__ */React3.createElement(Flex, {
181
- sx: {
182
- width: "full",
183
- flexDirection: "column",
184
- gap: "2"
185
- }
186
- }, label && /* @__PURE__ */React3.createElement(Label, {
187
- "aria-disabled": disabled,
188
- htmlFor: id,
189
- tooltip
190
- }, label), warning ? /* @__PURE__ */React3.createElement(child.type, {
191
- id,
192
- ...inputProps,
193
- ...(warning ? {
194
- trailingIcon: "warning-alt"
195
- } : {})
196
- }) : /* @__PURE__ */React3.createElement(child.type, {
197
- id,
198
- ...inputProps
199
- }), inputTooltip && showInputTooltip && /* @__PURE__ */React3.createElement(Flex, {
200
- sx: {
201
- width: "full",
202
- fontSize: "sm"
203
- }
204
- }, /* @__PURE__ */React3.createElement(Tooltip, {
205
- id: tooltipId,
206
- place: inputTooltip.place,
207
- clickable: inputTooltip.clickable,
208
- isOpen: showInputTooltip,
209
- variant: inputTooltip.variant,
210
- sx: inputTooltip.sx
211
- }, inputTooltip.render)));
212
- });
213
- }, [render, controllerReturn, label, disabled, id, tooltip, warning, inputTooltip, showInputTooltip, tooltipId]);
214
- return /* @__PURE__ */React3.createElement(Flex, {
215
- sx: {
216
- flexDirection: "column",
217
- width: "100%",
218
- gap: "1",
219
- ...sx
220
- },
221
- css
222
- }, memoizedRender, /* @__PURE__ */React3.createElement(FormErrorMessage, {
223
- name
224
- }), warning && !hasError && /* @__PURE__ */React3.createElement(Flex, {
225
- className: "warning",
226
- sx: {
227
- color: "feedback.text.caution.default",
228
- fontSize: "sm",
229
- gap: "2",
230
- paddingBottom: "1",
231
- alignItems: "center"
232
- }
233
- }, warning));
234
- }, "FormField");
235
-
236
- // src/FormFieldCheckbox.tsx
237
- import { Checkbox as Checkbox2 } from "@ttoss/ui";
238
- var FormFieldCheckbox = /* @__PURE__ */__name(({
239
- label,
240
- name,
241
- sx,
242
- tooltip,
243
- ...checkboxProps
244
- }) => {
245
- return /* @__PURE__ */React.createElement(FormField, {
246
- label,
247
- name,
248
- tooltip,
249
- render: /* @__PURE__ */__name(({
250
- field,
251
- fieldState
252
- }) => {
253
- return /* @__PURE__ */React.createElement(Checkbox2, {
254
- ...field,
255
- ...checkboxProps,
256
- "aria-invalid": !!fieldState.error,
257
- sx
258
- });
259
- }, "render")
260
- });
261
- }, "FormFieldCheckbox");
262
-
263
- // src/FormFieldPatternFormat.tsx
264
- import { Input } from "@ttoss/ui";
265
- import { PatternFormat } from "react-number-format";
266
- var FormFieldPatternFormat = /* @__PURE__ */__name(({
267
- label,
268
- name,
269
- warning,
270
- inputTooltip,
271
- ...patternFormatProps
272
- }) => {
273
- return /* @__PURE__ */React.createElement(FormField, {
274
- name,
275
- label,
276
- warning,
277
- inputTooltip,
278
- render: /* @__PURE__ */__name(({
279
- field,
280
- fieldState
281
- }) => {
282
- return /* @__PURE__ */React.createElement(PatternFormat, {
283
- name: field.name,
284
- value: field.value,
285
- onBlur: field.onBlur,
286
- onValueChange: /* @__PURE__ */__name(values => {
287
- field.onChange(values.value);
288
- }, "onValueChange"),
289
- customInput: Input,
290
- "aria-invalid": Boolean(fieldState.error).valueOf(),
291
- ...patternFormatProps
292
- });
293
- }, "render")
294
- });
295
- }, "FormFieldPatternFormat");
296
-
297
- // src/FormFieldCreditCardNumber.tsx
298
- var FormFieldCreditCardNumber = /* @__PURE__ */__name(({
299
- label,
300
- name,
301
- ...formFieldPatternFormatProps
302
- }) => {
303
- return /* @__PURE__ */React.createElement(FormFieldPatternFormat, {
304
- name,
305
- label,
306
- warning: formFieldPatternFormatProps.warning,
307
- format: "#### #### #### ####",
308
- placeholder: "1234 1234 1234 1234",
309
- ...formFieldPatternFormatProps
310
- });
311
- }, "FormFieldCreditCardNumber");
312
-
313
- // src/FormFieldNumericFormat.tsx
314
- import { Input as Input2 } from "@ttoss/ui";
315
- import * as React4 from "react";
316
- import { NumericFormat } from "react-number-format";
317
- var FormFieldNumericFormat = /* @__PURE__ */__name(({
318
- label,
319
- name,
320
- warning,
321
- tooltip,
322
- inputTooltip,
323
- ...numericFormatProps
324
- }) => {
325
- return /* @__PURE__ */React4.createElement(FormField, {
326
- label,
327
- name,
328
- warning,
329
- tooltip,
330
- inputTooltip,
331
- render: /* @__PURE__ */__name(({
332
- field
333
- }) => {
334
- return /* @__PURE__ */React4.createElement(NumericFormat, {
335
- name: field.name,
336
- value: field.value,
337
- onBlur: field.onBlur,
338
- onValueChange: /* @__PURE__ */__name(values => {
339
- field.onChange(values.floatValue);
340
- }, "onValueChange"),
341
- customInput: Input2,
342
- ...numericFormatProps
343
- });
344
- }, "render")
345
- });
346
- }, "FormFieldNumericFormat");
347
-
348
- // src/FormFieldCurrencyInput.tsx
349
- var FormFieldCurrencyInput = /* @__PURE__ */__name(({
350
- label,
351
- name,
352
- prefix,
353
- decimalSeparator,
354
- thousandSeparator,
355
- ...formFieldNumericFormatProps
356
- }) => {
357
- return /* @__PURE__ */React.createElement(FormFieldNumericFormat, {
358
- name,
359
- label,
360
- warning: formFieldNumericFormatProps.warning,
361
- fixedDecimalScale: true,
362
- decimalScale: 2,
363
- prefix,
364
- decimalSeparator,
365
- thousandSeparator,
366
- placeholder: `${prefix} 0${decimalSeparator}00`,
367
- allowNegative: false,
368
- ...formFieldNumericFormatProps
369
- });
370
- }, "FormFieldCurrencyInput");
371
-
372
- // src/FormFieldInput.tsx
373
- import { Input as Input3 } from "@ttoss/ui";
374
- var FormFieldInput = /* @__PURE__ */__name(({
375
- label,
376
- name,
377
- tooltip,
378
- sx,
379
- defaultValue = "",
380
- ...inputProps
381
- }) => {
382
- return /* @__PURE__ */React.createElement(FormField, {
383
- name,
384
- label,
385
- disabled: inputProps.disabled,
386
- tooltip,
387
- warning: inputProps.warning,
388
- inputTooltip: inputProps.inputTooltip,
389
- sx,
390
- defaultValue,
391
- render: /* @__PURE__ */__name(({
392
- field,
393
- fieldState
394
- }) => {
395
- return /* @__PURE__ */React.createElement(Input3, {
396
- ...inputProps,
397
- ...field,
398
- "aria-invalid": fieldState.error ? "true" : void 0
399
- });
400
- }, "render")
401
- });
402
- }, "FormFieldInput");
403
-
404
- // src/FormFieldPassword.tsx
405
- import { InputPassword } from "@ttoss/ui";
406
- var FormFieldPassword = /* @__PURE__ */__name(({
407
- label,
408
- name,
409
- tooltip,
410
- sx,
411
- defaultValue = "",
412
- ...inputProps
413
- }) => {
414
- return /* @__PURE__ */React.createElement(FormField, {
415
- name,
416
- label,
417
- disabled: inputProps.disabled,
418
- tooltip,
419
- warning: inputProps.warning,
420
- inputTooltip: inputProps.inputTooltip,
421
- sx,
422
- defaultValue,
423
- render: /* @__PURE__ */__name(({
424
- field,
425
- fieldState
426
- }) => {
427
- return /* @__PURE__ */React.createElement(InputPassword, {
428
- ...inputProps,
429
- ...field,
430
- "aria-invalid": fieldState.error ? "true" : void 0
431
- });
432
- }, "render")
433
- });
434
- }, "FormFieldPassword");
435
-
436
- // src/FormFieldRadio.tsx
437
- import { Flex as Flex2, Label as Label2, Radio } from "@ttoss/ui";
438
- var FormFieldRadio = /* @__PURE__ */__name(({
439
- label,
440
- name,
441
- sx,
442
- options,
443
- tooltip,
444
- ...radioProps
445
- }) => {
446
- return /* @__PURE__ */React.createElement(FormField, {
447
- label,
448
- name,
449
- sx,
450
- tooltip,
451
- render: /* @__PURE__ */__name(({
452
- field
453
- }) => {
454
- return /* @__PURE__ */React.createElement(Flex2, {
455
- sx: {
456
- flexDirection: "column",
457
- gap: "1"
458
- }
459
- }, options.map(option => {
460
- const key = `form-field-radio-${name}-${option.value}`;
461
- return /* @__PURE__ */React.createElement(Label2, {
462
- key,
463
- sx: {
464
- fontSize: "md"
465
- }
466
- }, /* @__PURE__ */React.createElement(Radio, {
467
- ref: field.ref,
468
- onChange: field.onChange,
469
- onBlur: field.onBlur,
470
- value: option.value,
471
- checked: field.value === option.value,
472
- name,
473
- ...radioProps
474
- }), option.label);
475
- }));
476
- }, "render")
477
- });
478
- }, "FormFieldRadio");
479
-
480
- // src/FormFieldRadioCard.tsx
481
- import { Box as Box2, Flex as Flex3, Label as Label3, Radio as Radio2, Text } from "@ttoss/ui";
482
- var FormFieldRadioCard = /* @__PURE__ */__name(({
483
- label,
484
- name,
485
- direction = "column",
486
- width = "full",
487
- sx,
488
- options,
489
- tooltip,
490
- ...radioProps
491
- }) => {
492
- return /* @__PURE__ */React.createElement(FormField, {
493
- label,
494
- name,
495
- sx,
496
- tooltip,
497
- render: /* @__PURE__ */__name(({
498
- field
499
- }) => {
500
- return /* @__PURE__ */React.createElement(Flex3, {
501
- sx: {
502
- flexDirection: direction,
503
- gap: "4"
504
- }
505
- }, options.map(option => {
506
- const key = `form-field-radio-${name}-${option.value}`;
507
- return /* @__PURE__ */React.createElement(Box2, {
508
- key,
509
- sx: {
510
- gap: "2",
511
- width,
512
- border: "md",
513
- borderColor: "display.border.muted.default",
514
- borderRadius: "md"
515
- }
516
- }, /* @__PURE__ */React.createElement(Label3, {
517
- sx: {
518
- fontSize: "md",
519
- width: "100%",
520
- padding: "4"
521
- }
522
- }, /* @__PURE__ */React.createElement(Radio2, {
523
- ref: field.ref,
524
- onChange: field.onChange,
525
- onBlur: field.onBlur,
526
- value: option.value,
527
- checked: field.value === option.value,
528
- name,
529
- ...radioProps
530
- }), /* @__PURE__ */React.createElement(Flex3, {
531
- sx: {
532
- flexDirection: "column",
533
- gap: "1"
534
- }
535
- }, option.label && /* @__PURE__ */React.createElement(Text, null, option.label), option.description && /* @__PURE__ */React.createElement(Text, {
536
- sx: {
537
- fontSize: "sm"
538
- }
539
- }, option.description))));
540
- }));
541
- }, "render")
542
- });
543
- }, "FormFieldRadioCard");
544
-
545
- // src/FormFieldRadioCardIcony.tsx
546
- import { Box as Box3, Flex as Flex4, Text as Text2 } from "@ttoss/ui";
547
- import { Tag } from "@ttoss/ui";
548
- import * as React5 from "react";
549
- var FormFieldRadioCardIcony = /* @__PURE__ */__name(({
550
- label,
551
- name,
552
- direction = "row",
553
- width = "full",
554
- sx,
555
- options,
556
- tooltip
557
- }) => {
558
- return /* @__PURE__ */React5.createElement(FormField, {
559
- label,
560
- name,
561
- sx,
562
- tooltip,
563
- render: /* @__PURE__ */__name(({
564
- field
565
- }) => {
566
- const handleOptionClick = /* @__PURE__ */__name(optionValue => {
567
- field.onChange(optionValue);
568
- field.onBlur();
569
- }, "handleOptionClick");
570
- return /* @__PURE__ */React5.createElement(Flex4, {
571
- sx: {
572
- flexDirection: direction,
573
- gap: "4"
574
- }
575
- }, options.map(option => {
576
- const key = `form-field-radio-card-${name}-${option.value}`;
577
- const isSelected = field.value === option.value;
578
- const IconComponent = option.icon;
579
- const tag = option.tag;
580
- return /* @__PURE__ */React5.createElement(Box3, {
581
- key,
582
- onClick: /* @__PURE__ */__name(() => {
583
- return handleOptionClick(option.value);
584
- }, "onClick"),
585
- sx: {
586
- width,
587
- padding: "6",
588
- border: isSelected ? "lg" : "md",
589
- borderColor: isSelected ? "input.background.accent.default" : "input.border.muted.default",
590
- borderRadius: "md",
591
- backgroundColor: isSelected ? "feedback.background.positive.default" : "transparent",
592
- display: "flex",
593
- flexDirection: "column",
594
- alignItems: "center",
595
- justifyContent: "center",
596
- textAlign: "center",
597
- cursor: "pointer",
598
- transition: "all 0.2s ease-in-out"
599
- }
600
- }, IconComponent && /* @__PURE__ */React5.createElement(Box3, {
601
- sx: {
602
- marginBottom: "2",
603
- color: "text.primary"
604
- }
605
- }, /* @__PURE__ */React5.createElement(IconComponent, {
606
- size: 24
607
- })), /* @__PURE__ */React5.createElement(Flex4, {
608
- sx: {
609
- flexDirection: "column",
610
- gap: "1"
611
- }
612
- }, option.label && /* @__PURE__ */React5.createElement(Text2, {
613
- sx: {
614
- fontSize: "lg",
615
- fontWeight: "semibold",
616
- color: "text.primary"
617
- }
618
- }, option.label), option.description && /* @__PURE__ */React5.createElement(Text2, {
619
- sx: {
620
- fontSize: "md",
621
- color: "text.secondary"
622
- }
623
- }, option.description)), tag?.label && /* @__PURE__ */React5.createElement(Tag, {
624
- variant: tag?.variant,
625
- sx: {
626
- px: "3",
627
- mt: "2",
628
- fontSize: "sm",
629
- ...tag?.sx
630
- }
631
- }, tag.label));
632
- }));
633
- }, "render")
634
- });
635
- }, "FormFieldRadioCardIcony");
636
-
637
- // src/FormFieldSelect.tsx
638
- import { Select } from "@ttoss/ui";
639
- var FormFieldSelect = /* @__PURE__ */__name(({
640
- label,
641
- name,
642
- id,
643
- defaultValue,
644
- sx,
645
- css,
646
- disabled,
647
- tooltip,
648
- ...selectProps
649
- }) => {
650
- return /* @__PURE__ */React.createElement(FormField, {
651
- name,
652
- label,
653
- id,
654
- defaultValue,
655
- disabled,
656
- tooltip,
657
- inputTooltip: selectProps.inputTooltip,
658
- warning: selectProps.warning,
659
- sx,
660
- css,
661
- render: /* @__PURE__ */__name(({
662
- field,
663
- fieldState
664
- }) => {
665
- return /* @__PURE__ */React.createElement(Select, {
666
- ...selectProps,
667
- ...field,
668
- isDisabled: disabled,
669
- "aria-invalid": fieldState.error ? "true" : void 0
670
- });
671
- }, "render")
672
- });
673
- }, "FormFieldSelect");
674
-
675
- // src/FormFieldSwitch.tsx
676
- import { Switch as Switch2 } from "@ttoss/ui";
677
- var FormFieldSwitch = /* @__PURE__ */__name(({
678
- label,
679
- name,
680
- sx,
681
- tooltip,
682
- ...switchProps
683
- }) => {
684
- return /* @__PURE__ */React.createElement(FormField, {
685
- label,
686
- name,
687
- tooltip,
688
- render: /* @__PURE__ */__name(({
689
- field,
690
- fieldState
691
- }) => {
692
- return /* @__PURE__ */React.createElement(Switch2, {
693
- ...field,
694
- ...switchProps,
695
- "aria-invalid": !!fieldState.error,
696
- sx
697
- });
698
- }, "render")
699
- });
700
- }, "FormFieldSwitch");
701
-
702
- // src/FormFieldTextarea.tsx
703
- import { Textarea } from "@ttoss/ui";
704
- var FormFieldTextarea = /* @__PURE__ */__name(({
705
- label,
706
- name,
707
- warning,
708
- inputTooltip,
709
- sx,
710
- ...textareaProps
711
- }) => {
712
- const id = `form-field-textarea-${name}`;
713
- return /* @__PURE__ */React.createElement(FormField, {
714
- label,
715
- name,
716
- id,
717
- sx,
718
- warning,
719
- inputTooltip,
720
- render: /* @__PURE__ */__name(({
721
- field,
722
- fieldState
723
- }) => {
724
- return /* @__PURE__ */React.createElement(Textarea, {
725
- ...field,
726
- ...textareaProps,
727
- "aria-invalid": fieldState.error ? "true" : void 0
728
- });
729
- }, "render")
730
- });
731
- }, "FormFieldTextarea");
732
-
733
- // src/FormGroup.tsx
734
- import { Box as Box4, Flex as Flex5, Text as Text3 } from "@ttoss/ui";
735
- import * as React6 from "react";
736
- var FormGroupLevelsManagerContext = /* @__PURE__ */React6.createContext({
737
- levelsLength: 1,
738
- registerChild: /* @__PURE__ */__name(() => {
739
- return null;
740
- }, "registerChild")
741
- });
742
- var FormGroupLevelsManager = /* @__PURE__ */__name(({
743
- children
744
- }) => {
745
- const [levelsLength, setLevelsLength] = React6.useState(0);
746
- const registerChild = React6.useCallback(level => {
747
- if (level + 1 > levelsLength) {
748
- setLevelsLength(level + 1);
749
- }
750
- }, [levelsLength]);
751
- return /* @__PURE__ */React6.createElement(FormGroupLevelsManagerContext.Provider, {
752
- value: {
753
- levelsLength,
754
- registerChild
755
- }
756
- }, children);
757
- }, "FormGroupLevelsManager");
758
- var FormGroupContext = /* @__PURE__ */React6.createContext({});
759
- var useFormGroup = /* @__PURE__ */__name(() => {
760
- const {
761
- parentLevel
762
- } = React6.useContext(FormGroupContext);
763
- const {
764
- levelsLength
765
- } = React6.useContext(FormGroupLevelsManagerContext);
766
- return {
767
- level: parentLevel,
768
- levelsLength
769
- };
770
- }, "useFormGroup");
771
- var FormGroupWrapper = /* @__PURE__ */__name(({
772
- title,
773
- direction,
774
- children,
775
- name,
776
- ...boxProps
777
- }) => {
778
- const {
779
- level
780
- } = useFormGroup();
781
- const {
782
- registerChild
783
- } = React6.useContext(FormGroupLevelsManagerContext);
784
- React6.useEffect(() => {
785
- if (typeof level === "number") {
786
- registerChild(level);
787
- }
788
- }, [level, registerChild]);
789
- const childrenContainerSx = {
790
- flexDirection: direction || "column",
791
- gap: "1",
792
- width: "100%"
793
- };
794
- return /* @__PURE__ */React6.createElement(Box4, {
795
- "aria-level": level,
796
- ...boxProps,
797
- sx: {
798
- marginTop: level === 0 ? "none" : "4",
799
- marginBottom: "4",
800
- ...boxProps.sx
801
- }
802
- }, title && /* @__PURE__ */React6.createElement(Box4, {
803
- sx: {
804
- marginBottom: "2"
805
- }
806
- }, /* @__PURE__ */React6.createElement(Text3, {
807
- sx: {
808
- fontSize: "2xl",
809
- fontWeight: "bold"
810
- }
811
- }, title)), /* @__PURE__ */React6.createElement(Flex5, {
812
- sx: childrenContainerSx
813
- }, children), name && /* @__PURE__ */React6.createElement(FormErrorMessage, {
814
- name
815
- }));
816
- }, "FormGroupWrapper");
817
- var FormGroup = /* @__PURE__ */__name(props => {
818
- const {
819
- level
820
- } = useFormGroup();
821
- const currentLevel = level === void 0 ? 0 : level + 1;
822
- return /* @__PURE__ */React6.createElement(FormGroupContext.Provider, {
823
- value: {
824
- parentLevel: currentLevel
825
- }
826
- }, currentLevel === 0 ? /* @__PURE__ */React6.createElement(FormGroupLevelsManager, null, /* @__PURE__ */React6.createElement(FormGroupWrapper, props)) : /* @__PURE__ */React6.createElement(FormGroupWrapper, props));
827
- }, "FormGroup");
828
-
829
- // src/yup/i18n.ts
830
- import { defineMessage } from "@ttoss/react-i18n";
831
- import { setLocale } from "yup";
832
- setLocale({
833
- mixed: {
834
- required: defineMessage({
835
- id: "MfWGyg",
836
- defaultMessage: [{
837
- "type": 0,
838
- "value": "Field is required"
839
- }]
840
- }),
841
- notType: /* @__PURE__ */__name(({
842
- type
843
- }) => {
844
- return {
845
- ...defineMessage({
846
- id: "ZhaPt0",
847
- defaultMessage: [{
848
- "type": 0,
849
- "value": "Invalid Value for Field of type "
850
- }, {
851
- "type": 1,
852
- "value": "type"
853
- }]
854
- }),
855
- values: {
856
- type
857
- }
858
- };
859
- }, "notType")
860
- },
861
- string: {
862
- min: /* @__PURE__ */__name(({
863
- min
864
- }) => {
865
- return {
866
- ...defineMessage({
867
- id: "D1C6fR",
868
- defaultMessage: [{
869
- "type": 0,
870
- "value": "Field must be at least "
871
- }, {
872
- "type": 1,
873
- "value": "min"
874
- }, {
875
- "type": 0,
876
- "value": " characters"
877
- }]
878
- }),
879
- values: {
880
- min
881
- }
882
- };
883
- }, "min")
884
- }
885
- });
886
-
887
- // src/yup/schema.ts
888
- import * as yup from "yup";
889
-
890
- // src/Brazil/FormFieldCNPJ.tsx
891
- import { Input as Input4 } from "@ttoss/ui";
892
- import { PatternFormat as PatternFormat2 } from "react-number-format";
893
- var isCnpjValid = /* @__PURE__ */__name(cnpj => {
894
- if (cnpj?.length != 14) {
895
- return false;
896
- }
897
- if (cnpj == "00000000000000" || cnpj == "11111111111111" || cnpj == "22222222222222" || cnpj == "33333333333333" || cnpj == "44444444444444" || cnpj == "55555555555555" || cnpj == "66666666666666" || cnpj == "77777777777777" || cnpj == "88888888888888" || cnpj == "99999999999999") {
898
- return false;
899
- }
900
- let size = cnpj.length - 2;
901
- let numbers = cnpj.substring(0, size);
902
- const digits = cnpj.substring(size);
903
- let soma = 0;
904
- let pos = size - 7;
905
- for (let i = size; i >= 1; i--) {
906
- soma += numbers.charAt(size - i) * pos--;
907
- if (pos < 2) {
908
- pos = 9;
909
- }
910
- }
911
- let result = soma % 11 < 2 ? 0 : 11 - soma % 11;
912
- if (result != digits.charAt(0)) {
913
- return false;
914
- }
915
- size = size + 1;
916
- numbers = cnpj.substring(0, size);
917
- soma = 0;
918
- pos = size - 7;
919
- for (let i = size; i >= 1; i--) {
920
- soma += numbers.charAt(size - i) * pos--;
921
- if (pos < 2) {
922
- pos = 9;
923
- }
924
- }
925
- result = soma % 11 < 2 ? 0 : 11 - soma % 11;
926
- if (result != digits.charAt(1)) {
927
- return false;
928
- }
929
- return true;
930
- }, "isCnpjValid");
931
- var FormFieldCNPJ = /* @__PURE__ */__name(({
932
- label,
933
- name,
934
- ...patternFormatProps
935
- }) => {
936
- return /* @__PURE__ */React.createElement(FormField, {
937
- name,
938
- label,
939
- warning: patternFormatProps.warning,
940
- inputTooltip: patternFormatProps.inputTooltip,
941
- render: /* @__PURE__ */__name(({
942
- field
943
- }) => {
944
- return /* @__PURE__ */React.createElement(PatternFormat2, {
945
- name: field.name,
946
- value: field.value,
947
- onBlur: field.onBlur,
948
- onValueChange: /* @__PURE__ */__name(values => {
949
- field.onChange(values.value);
950
- }, "onValueChange"),
951
- format: "##.###.###/####-##",
952
- customInput: Input4,
953
- placeholder: "12.345.678/0000-00",
954
- ...patternFormatProps
955
- });
956
- }, "render")
957
- });
958
- }, "FormFieldCNPJ");
959
-
960
- // src/yup/schema.ts
961
- yup.addMethod(yup.string, "cnpj", function () {
962
- return this.test("valid-cnpj", "Invalid CNPJ", value => {
963
- return isCnpjValid(value);
964
- });
965
- });
966
- yup.addMethod(yup.string, "password", function ({
967
- required
968
- } = {}) {
969
- const schema = this.trim();
970
- if (required) {
971
- schema.required("Password is required");
972
- }
973
- return schema.min(8, "Password must be at least 8 characters long");
974
- });
975
-
976
- // src/yup/yup.ts
977
- import * as yup2 from "yup";
978
-
979
- // src/index.ts
980
- import { yupResolver } from "@hookform/resolvers/yup";
981
- import { Controller, FormProvider as FormProvider2, useController as useController2, useFieldArray, useForm, useFormContext as useFormContext3, useFormState, useWatch } from "react-hook-form";
982
- export * from "react-hook-form";
983
- export { __name, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldPatternFormat, FormFieldCreditCardNumber, FormFieldNumericFormat, FormFieldCurrencyInput, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, useFormGroup, FormGroup, isCnpjValid, FormFieldCNPJ, yup2 as yup, yupResolver, Controller, FormProvider2 as FormProvider, useController2 as useController, useFieldArray, useForm, useFormContext3 as useFormContext, useFormState, useWatch };