@ttoss/forms 0.30.3 → 0.31.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.
@@ -1,5 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-AZFECRBC.js";
2
+ import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-7COMWRW2.js";
3
3
 
4
4
  // src/Brazil/FormFieldPhone.tsx
5
5
  import { Input } from "@ttoss/ui";
@@ -1,5 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Form, useForm, yupResolver } from "../chunk-AZFECRBC.js";
2
+ import { Form, useForm, yupResolver } from "../chunk-7COMWRW2.js";
3
3
 
4
4
  // src/MultistepForm/MultistepForm.tsx
5
5
  import { Flex as Flex6 } from "@ttoss/ui";
@@ -190,7 +190,8 @@ var FormField = ({
190
190
  return /* @__PURE__ */jsxs(Flex, {
191
191
  sx: {
192
192
  width: "full",
193
- flexDirection: "column"
193
+ flexDirection: "column",
194
+ gap: "2"
194
195
  },
195
196
  children: [label && /* @__PURE__ */jsx3(Label, {
196
197
  "aria-disabled": disabled,
@@ -500,9 +501,168 @@ var FormFieldRadio = ({
500
501
  });
501
502
  };
502
503
 
504
+ // src/FormFieldRadioCard.tsx
505
+ import { Box as Box2, Flex as Flex3, Label as Label3, Radio as Radio2, Text } from "@ttoss/ui";
506
+ import { jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
507
+ var FormFieldRadioCard = ({
508
+ label,
509
+ name,
510
+ direction = "column",
511
+ width = "full",
512
+ sx,
513
+ options,
514
+ tooltip,
515
+ ...radioProps
516
+ }) => {
517
+ return /* @__PURE__ */jsx12(FormField, {
518
+ label,
519
+ name,
520
+ sx,
521
+ tooltip,
522
+ render: ({
523
+ field
524
+ }) => {
525
+ return /* @__PURE__ */jsx12(Flex3, {
526
+ sx: {
527
+ flexDirection: direction,
528
+ gap: "4"
529
+ },
530
+ children: options.map(option => {
531
+ const key = `form-field-radio-${name}-${option.value}`;
532
+ return /* @__PURE__ */jsx12(Box2, {
533
+ sx: {
534
+ gap: "2",
535
+ width,
536
+ border: "md",
537
+ borderColor: "display.border.muted.default",
538
+ borderRadius: "md"
539
+ },
540
+ children: /* @__PURE__ */jsxs3(Label3, {
541
+ sx: {
542
+ fontSize: "md",
543
+ width: "100%",
544
+ padding: "4"
545
+ },
546
+ children: [/* @__PURE__ */jsx12(Radio2, {
547
+ ref: field.ref,
548
+ onChange: field.onChange,
549
+ onBlur: field.onBlur,
550
+ value: option.value,
551
+ checked: field.value === option.value,
552
+ name,
553
+ ...radioProps
554
+ }), /* @__PURE__ */jsxs3(Flex3, {
555
+ sx: {
556
+ flexDirection: "column",
557
+ gap: "1"
558
+ },
559
+ children: [option.label && /* @__PURE__ */jsx12(Text, {
560
+ children: option.label
561
+ }), option.description && /* @__PURE__ */jsx12(Text, {
562
+ sx: {
563
+ fontSize: "sm"
564
+ },
565
+ children: option.description
566
+ })]
567
+ })]
568
+ })
569
+ }, key);
570
+ })
571
+ });
572
+ }
573
+ });
574
+ };
575
+
576
+ // src/FormFieldRadioCardIcony.tsx
577
+ import { Box as Box3, Flex as Flex4, Text as Text2 } from "@ttoss/ui";
578
+ import { jsx as jsx13, jsxs as jsxs4 } from "react/jsx-runtime";
579
+ var FormFieldRadioCardIcony = ({
580
+ label,
581
+ name,
582
+ direction = "row",
583
+ width = "full",
584
+ sx,
585
+ options,
586
+ tooltip
587
+ }) => {
588
+ return /* @__PURE__ */jsx13(FormField, {
589
+ label,
590
+ name,
591
+ sx,
592
+ tooltip,
593
+ render: ({
594
+ field
595
+ }) => {
596
+ const handleOptionClick = optionValue => {
597
+ field.onChange(optionValue);
598
+ field.onBlur();
599
+ };
600
+ return /* @__PURE__ */jsx13(Flex4, {
601
+ sx: {
602
+ flexDirection: direction,
603
+ gap: "4"
604
+ },
605
+ children: options.map(option => {
606
+ const key = `form-field-radio-card-${name}-${option.value}`;
607
+ const isSelected = field.value === option.value;
608
+ const IconComponent = option.icon;
609
+ return /* @__PURE__ */jsxs4(Box3, {
610
+ onClick: () => {
611
+ return handleOptionClick(option.value);
612
+ },
613
+ sx: {
614
+ width,
615
+ padding: "6",
616
+ border: isSelected ? "lg" : "md",
617
+ borderColor: isSelected ? "input.background.accent.default" : "input.border.muted.default",
618
+ borderRadius: "md",
619
+ backgroundColor: "transparent",
620
+ display: "flex",
621
+ flexDirection: "column",
622
+ alignItems: "center",
623
+ justifyContent: "center",
624
+ textAlign: "center",
625
+ cursor: "pointer",
626
+ transition: "all 0.2s ease-in-out"
627
+ },
628
+ children: [IconComponent && /* @__PURE__ */jsx13(Box3, {
629
+ sx: {
630
+ marginBottom: "2",
631
+ color: "text.primary"
632
+ },
633
+ children: /* @__PURE__ */jsx13(IconComponent, {
634
+ size: 24
635
+ })
636
+ }), /* @__PURE__ */jsxs4(Flex4, {
637
+ sx: {
638
+ flexDirection: "column",
639
+ gap: "1"
640
+ },
641
+ children: [option.label && /* @__PURE__ */jsx13(Text2, {
642
+ sx: {
643
+ fontSize: "lg",
644
+ fontWeight: "semibold",
645
+ color: "text.primary"
646
+ },
647
+ children: option.label
648
+ }), option.description && /* @__PURE__ */jsx13(Text2, {
649
+ sx: {
650
+ fontSize: "md",
651
+ color: "text.secondary"
652
+ },
653
+ children: option.description
654
+ })]
655
+ })]
656
+ }, key);
657
+ })
658
+ });
659
+ }
660
+ });
661
+ };
662
+
503
663
  // src/FormFieldSelect.tsx
504
664
  import { Select } from "@ttoss/ui";
505
- import { jsx as jsx12 } from "react/jsx-runtime";
665
+ import { jsx as jsx14 } from "react/jsx-runtime";
506
666
  var FormFieldSelect = ({
507
667
  label,
508
668
  name,
@@ -514,7 +674,7 @@ var FormFieldSelect = ({
514
674
  tooltip,
515
675
  ...selectProps
516
676
  }) => {
517
- return /* @__PURE__ */jsx12(FormField, {
677
+ return /* @__PURE__ */jsx14(FormField, {
518
678
  name,
519
679
  label,
520
680
  id,
@@ -529,7 +689,7 @@ var FormFieldSelect = ({
529
689
  field,
530
690
  fieldState
531
691
  }) => {
532
- return /* @__PURE__ */jsx12(Select, {
692
+ return /* @__PURE__ */jsx14(Select, {
533
693
  ...selectProps,
534
694
  ...field,
535
695
  isDisabled: disabled,
@@ -541,7 +701,7 @@ var FormFieldSelect = ({
541
701
 
542
702
  // src/FormFieldSwitch.tsx
543
703
  import { Switch as Switch2 } from "@ttoss/ui";
544
- import { jsx as jsx13 } from "react/jsx-runtime";
704
+ import { jsx as jsx15 } from "react/jsx-runtime";
545
705
  var FormFieldSwitch = ({
546
706
  label,
547
707
  name,
@@ -549,7 +709,7 @@ var FormFieldSwitch = ({
549
709
  tooltip,
550
710
  ...switchProps
551
711
  }) => {
552
- return /* @__PURE__ */jsx13(FormField, {
712
+ return /* @__PURE__ */jsx15(FormField, {
553
713
  label,
554
714
  name,
555
715
  tooltip,
@@ -557,7 +717,7 @@ var FormFieldSwitch = ({
557
717
  field,
558
718
  fieldState
559
719
  }) => {
560
- return /* @__PURE__ */jsx13(Switch2, {
720
+ return /* @__PURE__ */jsx15(Switch2, {
561
721
  ...field,
562
722
  ...switchProps,
563
723
  "aria-invalid": !!fieldState.error,
@@ -569,7 +729,7 @@ var FormFieldSwitch = ({
569
729
 
570
730
  // src/FormFieldTextarea.tsx
571
731
  import { Textarea } from "@ttoss/ui";
572
- import { jsx as jsx14 } from "react/jsx-runtime";
732
+ import { jsx as jsx16 } from "react/jsx-runtime";
573
733
  var FormFieldTextarea = ({
574
734
  label,
575
735
  name,
@@ -579,7 +739,7 @@ var FormFieldTextarea = ({
579
739
  ...textareaProps
580
740
  }) => {
581
741
  const id = `form-field-textarea-${name}`;
582
- return /* @__PURE__ */jsx14(FormField, {
742
+ return /* @__PURE__ */jsx16(FormField, {
583
743
  label,
584
744
  name,
585
745
  id,
@@ -590,7 +750,7 @@ var FormFieldTextarea = ({
590
750
  field,
591
751
  fieldState
592
752
  }) => {
593
- return /* @__PURE__ */jsx14(Textarea, {
753
+ return /* @__PURE__ */jsx16(Textarea, {
594
754
  ...field,
595
755
  ...textareaProps,
596
756
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -600,9 +760,9 @@ var FormFieldTextarea = ({
600
760
  };
601
761
 
602
762
  // src/FormGroup.tsx
603
- import { Box as Box2, Flex as Flex3, Text } from "@ttoss/ui";
763
+ import { Box as Box4, Flex as Flex5, Text as Text3 } from "@ttoss/ui";
604
764
  import * as React2 from "react";
605
- import { jsx as jsx15, jsxs as jsxs3 } from "react/jsx-runtime";
765
+ import { jsx as jsx17, jsxs as jsxs5 } from "react/jsx-runtime";
606
766
  var FormGroupLevelsManagerContext = React2.createContext({
607
767
  levelsLength: 1,
608
768
  registerChild: () => {
@@ -618,7 +778,7 @@ var FormGroupLevelsManager = ({
618
778
  setLevelsLength(level + 1);
619
779
  }
620
780
  }, [levelsLength]);
621
- return /* @__PURE__ */jsx15(FormGroupLevelsManagerContext.Provider, {
781
+ return /* @__PURE__ */jsx17(FormGroupLevelsManagerContext.Provider, {
622
782
  value: {
623
783
  levelsLength,
624
784
  registerChild
@@ -662,7 +822,7 @@ var FormGroupWrapper = ({
662
822
  gap: "1",
663
823
  width: "100%"
664
824
  };
665
- return /* @__PURE__ */jsxs3(Box2, {
825
+ return /* @__PURE__ */jsxs5(Box4, {
666
826
  "aria-level": level,
667
827
  ...boxProps,
668
828
  sx: {
@@ -670,21 +830,21 @@ var FormGroupWrapper = ({
670
830
  marginBottom: "4",
671
831
  ...boxProps.sx
672
832
  },
673
- children: [title && /* @__PURE__ */jsx15(Box2, {
833
+ children: [title && /* @__PURE__ */jsx17(Box4, {
674
834
  sx: {
675
835
  marginBottom: "2"
676
836
  },
677
- children: /* @__PURE__ */jsx15(Text, {
837
+ children: /* @__PURE__ */jsx17(Text3, {
678
838
  sx: {
679
839
  fontSize: "2xl",
680
840
  fontWeight: "bold"
681
841
  },
682
842
  children: title
683
843
  })
684
- }), /* @__PURE__ */jsx15(Flex3, {
844
+ }), /* @__PURE__ */jsx17(Flex5, {
685
845
  sx: childrenContainerSx,
686
846
  children
687
- }), name && /* @__PURE__ */jsx15(FormErrorMessage, {
847
+ }), name && /* @__PURE__ */jsx17(FormErrorMessage, {
688
848
  name
689
849
  })]
690
850
  });
@@ -694,15 +854,15 @@ var FormGroup = props => {
694
854
  level
695
855
  } = useFormGroup();
696
856
  const currentLevel = level === void 0 ? 0 : level + 1;
697
- return /* @__PURE__ */jsx15(FormGroupContext.Provider, {
857
+ return /* @__PURE__ */jsx17(FormGroupContext.Provider, {
698
858
  value: {
699
859
  parentLevel: currentLevel
700
860
  },
701
- children: currentLevel === 0 ? /* @__PURE__ */jsx15(FormGroupLevelsManager, {
702
- children: /* @__PURE__ */jsx15(FormGroupWrapper, {
861
+ children: currentLevel === 0 ? /* @__PURE__ */jsx17(FormGroupLevelsManager, {
862
+ children: /* @__PURE__ */jsx17(FormGroupWrapper, {
703
863
  ...props
704
864
  })
705
- }) : /* @__PURE__ */jsx15(FormGroupWrapper, {
865
+ }) : /* @__PURE__ */jsx17(FormGroupWrapper, {
706
866
  ...props
707
867
  })
708
868
  });
@@ -772,7 +932,7 @@ import * as yup from "yup";
772
932
  // src/Brazil/FormFieldCNPJ.tsx
773
933
  import { Input as Input4 } from "@ttoss/ui";
774
934
  import { PatternFormat as PatternFormat2 } from "react-number-format";
775
- import { jsx as jsx16 } from "react/jsx-runtime";
935
+ import { jsx as jsx18 } from "react/jsx-runtime";
776
936
  var isCnpjValid = cnpj => {
777
937
  if (cnpj?.length != 14) {
778
938
  return false;
@@ -816,7 +976,7 @@ var FormFieldCNPJ = ({
816
976
  name,
817
977
  ...patternFormatProps
818
978
  }) => {
819
- return /* @__PURE__ */jsx16(FormField, {
979
+ return /* @__PURE__ */jsx18(FormField, {
820
980
  name,
821
981
  label,
822
982
  warning: patternFormatProps.warning,
@@ -824,7 +984,7 @@ var FormFieldCNPJ = ({
824
984
  render: ({
825
985
  field
826
986
  }) => {
827
- return /* @__PURE__ */jsx16(PatternFormat2, {
987
+ return /* @__PURE__ */jsx18(PatternFormat2, {
828
988
  name: field.name,
829
989
  value: field.value,
830
990
  onBlur: field.onBlur,
@@ -863,4 +1023,4 @@ import * as yup2 from "yup";
863
1023
  import { yupResolver } from "@hookform/resolvers/yup";
864
1024
  import { Controller, FormProvider as FormProvider2, useController as useController2, useFieldArray, useForm, useFormContext as useFormContext3, useFormState, useWatch } from "react-hook-form";
865
1025
  export * from "react-hook-form";
866
- export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldPatternFormat, FormFieldCreditCardNumber, FormFieldNumericFormat, FormFieldCurrencyInput, FormFieldInput, FormFieldPassword, FormFieldRadio, 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 };
1026
+ export { 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 };
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-AZFECRBC.js";
3
- export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver };
2
+ import { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-7COMWRW2.js";
3
+ export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, 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 CHANGED
@@ -98,14 +98,40 @@ type FormFieldPasswordProps<TName> = {
98
98
  } & InputPasswordProps & FormFieldProps;
99
99
  declare const FormFieldPassword: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, tooltip, sx, defaultValue, ...inputProps }: FormFieldPasswordProps<TName>) => react_jsx_runtime.JSX.Element;
100
100
 
101
- type FormRadioOption = {
101
+ type FormRadioOption$2 = {
102
102
  value: string | number;
103
103
  label: string;
104
104
  };
105
105
  declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, options, tooltip, ...radioProps }: {
106
- options: FormRadioOption[];
106
+ options: FormRadioOption$2[];
107
+ } & FormFieldProps<TFieldValues, TName> & RadioProps) => react_jsx_runtime.JSX.Element;
108
+
109
+ type FormRadioOption$1 = {
110
+ value: string | number;
111
+ label: string;
112
+ description?: string;
113
+ };
114
+ declare const FormFieldRadioCard: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, direction, width, sx, options, tooltip, ...radioProps }: {
115
+ options: FormRadioOption$1[];
116
+ direction?: "column" | "row";
117
+ width?: string;
107
118
  } & FormFieldProps<TFieldValues, TName> & RadioProps) => react_jsx_runtime.JSX.Element;
108
119
 
120
+ type FormRadioOption = {
121
+ value: string | number;
122
+ label: string;
123
+ description?: string;
124
+ icon?: React$1.ComponentType<{
125
+ size?: number;
126
+ className?: string;
127
+ }>;
128
+ };
129
+ declare const FormFieldRadioCardIcony: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, direction, width, sx, options, tooltip, }: {
130
+ options: FormRadioOption[];
131
+ direction?: "column" | "row";
132
+ width?: string;
133
+ } & FormFieldProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
134
+
109
135
  type FormFieldSelectProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<SelectProps, 'defaultValue'> & FormFieldProps<TFieldValues, TName>;
110
136
  declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>({ label, name, id, defaultValue, sx, css, disabled, tooltip, ...selectProps }: FormFieldSelectProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
111
137
 
@@ -136,4 +162,4 @@ type FormGroupProps = {
136
162
  } & BoxProps;
137
163
  declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
138
164
 
139
- export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, useFormGroup };
165
+ export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, useFormGroup };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.30.3",
3
+ "version": "0.31.1",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -52,10 +52,10 @@
52
52
  "yup": "^1.6.1",
53
53
  "@ttoss/config": "^1.35.5",
54
54
  "@ttoss/i18n-cli": "^0.7.30",
55
- "@ttoss/react-i18n": "^2.0.13",
56
55
  "@ttoss/react-icons": "^0.4.13",
57
56
  "@ttoss/ui": "^5.9.0",
58
- "@ttoss/test-utils": "^2.1.25"
57
+ "@ttoss/test-utils": "^2.1.25",
58
+ "@ttoss/react-i18n": "^2.0.13"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",