@ttoss/forms 0.30.3 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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-WUCWRQAS.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-WUCWRQAS.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,169 @@ 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
+ as: "button",
611
+ onClick: () => {
612
+ return handleOptionClick(option.value);
613
+ },
614
+ sx: {
615
+ width,
616
+ padding: "6",
617
+ border: isSelected ? "lg" : "md",
618
+ borderColor: isSelected ? "input.background.accent.default" : "input.border.muted.default",
619
+ borderRadius: "md",
620
+ backgroundColor: "transparent",
621
+ display: "flex",
622
+ flexDirection: "column",
623
+ alignItems: "center",
624
+ justifyContent: "center",
625
+ textAlign: "center",
626
+ cursor: "pointer",
627
+ transition: "all 0.2s ease-in-out"
628
+ },
629
+ children: [IconComponent && /* @__PURE__ */jsx13(Box3, {
630
+ sx: {
631
+ marginBottom: "2",
632
+ color: "text.primary"
633
+ },
634
+ children: /* @__PURE__ */jsx13(IconComponent, {
635
+ size: 24
636
+ })
637
+ }), /* @__PURE__ */jsxs4(Flex4, {
638
+ sx: {
639
+ flexDirection: "column",
640
+ gap: "1"
641
+ },
642
+ children: [option.label && /* @__PURE__ */jsx13(Text2, {
643
+ sx: {
644
+ fontSize: "lg",
645
+ fontWeight: "semibold",
646
+ color: "text.primary"
647
+ },
648
+ children: option.label
649
+ }), option.description && /* @__PURE__ */jsx13(Text2, {
650
+ sx: {
651
+ fontSize: "md",
652
+ color: "text.secondary"
653
+ },
654
+ children: option.description
655
+ })]
656
+ })]
657
+ }, key);
658
+ })
659
+ });
660
+ }
661
+ });
662
+ };
663
+
503
664
  // src/FormFieldSelect.tsx
504
665
  import { Select } from "@ttoss/ui";
505
- import { jsx as jsx12 } from "react/jsx-runtime";
666
+ import { jsx as jsx14 } from "react/jsx-runtime";
506
667
  var FormFieldSelect = ({
507
668
  label,
508
669
  name,
@@ -514,7 +675,7 @@ var FormFieldSelect = ({
514
675
  tooltip,
515
676
  ...selectProps
516
677
  }) => {
517
- return /* @__PURE__ */jsx12(FormField, {
678
+ return /* @__PURE__ */jsx14(FormField, {
518
679
  name,
519
680
  label,
520
681
  id,
@@ -529,7 +690,7 @@ var FormFieldSelect = ({
529
690
  field,
530
691
  fieldState
531
692
  }) => {
532
- return /* @__PURE__ */jsx12(Select, {
693
+ return /* @__PURE__ */jsx14(Select, {
533
694
  ...selectProps,
534
695
  ...field,
535
696
  isDisabled: disabled,
@@ -541,7 +702,7 @@ var FormFieldSelect = ({
541
702
 
542
703
  // src/FormFieldSwitch.tsx
543
704
  import { Switch as Switch2 } from "@ttoss/ui";
544
- import { jsx as jsx13 } from "react/jsx-runtime";
705
+ import { jsx as jsx15 } from "react/jsx-runtime";
545
706
  var FormFieldSwitch = ({
546
707
  label,
547
708
  name,
@@ -549,7 +710,7 @@ var FormFieldSwitch = ({
549
710
  tooltip,
550
711
  ...switchProps
551
712
  }) => {
552
- return /* @__PURE__ */jsx13(FormField, {
713
+ return /* @__PURE__ */jsx15(FormField, {
553
714
  label,
554
715
  name,
555
716
  tooltip,
@@ -557,7 +718,7 @@ var FormFieldSwitch = ({
557
718
  field,
558
719
  fieldState
559
720
  }) => {
560
- return /* @__PURE__ */jsx13(Switch2, {
721
+ return /* @__PURE__ */jsx15(Switch2, {
561
722
  ...field,
562
723
  ...switchProps,
563
724
  "aria-invalid": !!fieldState.error,
@@ -569,7 +730,7 @@ var FormFieldSwitch = ({
569
730
 
570
731
  // src/FormFieldTextarea.tsx
571
732
  import { Textarea } from "@ttoss/ui";
572
- import { jsx as jsx14 } from "react/jsx-runtime";
733
+ import { jsx as jsx16 } from "react/jsx-runtime";
573
734
  var FormFieldTextarea = ({
574
735
  label,
575
736
  name,
@@ -579,7 +740,7 @@ var FormFieldTextarea = ({
579
740
  ...textareaProps
580
741
  }) => {
581
742
  const id = `form-field-textarea-${name}`;
582
- return /* @__PURE__ */jsx14(FormField, {
743
+ return /* @__PURE__ */jsx16(FormField, {
583
744
  label,
584
745
  name,
585
746
  id,
@@ -590,7 +751,7 @@ var FormFieldTextarea = ({
590
751
  field,
591
752
  fieldState
592
753
  }) => {
593
- return /* @__PURE__ */jsx14(Textarea, {
754
+ return /* @__PURE__ */jsx16(Textarea, {
594
755
  ...field,
595
756
  ...textareaProps,
596
757
  "aria-invalid": fieldState.error ? "true" : void 0
@@ -600,9 +761,9 @@ var FormFieldTextarea = ({
600
761
  };
601
762
 
602
763
  // src/FormGroup.tsx
603
- import { Box as Box2, Flex as Flex3, Text } from "@ttoss/ui";
764
+ import { Box as Box4, Flex as Flex5, Text as Text3 } from "@ttoss/ui";
604
765
  import * as React2 from "react";
605
- import { jsx as jsx15, jsxs as jsxs3 } from "react/jsx-runtime";
766
+ import { jsx as jsx17, jsxs as jsxs5 } from "react/jsx-runtime";
606
767
  var FormGroupLevelsManagerContext = React2.createContext({
607
768
  levelsLength: 1,
608
769
  registerChild: () => {
@@ -618,7 +779,7 @@ var FormGroupLevelsManager = ({
618
779
  setLevelsLength(level + 1);
619
780
  }
620
781
  }, [levelsLength]);
621
- return /* @__PURE__ */jsx15(FormGroupLevelsManagerContext.Provider, {
782
+ return /* @__PURE__ */jsx17(FormGroupLevelsManagerContext.Provider, {
622
783
  value: {
623
784
  levelsLength,
624
785
  registerChild
@@ -662,7 +823,7 @@ var FormGroupWrapper = ({
662
823
  gap: "1",
663
824
  width: "100%"
664
825
  };
665
- return /* @__PURE__ */jsxs3(Box2, {
826
+ return /* @__PURE__ */jsxs5(Box4, {
666
827
  "aria-level": level,
667
828
  ...boxProps,
668
829
  sx: {
@@ -670,21 +831,21 @@ var FormGroupWrapper = ({
670
831
  marginBottom: "4",
671
832
  ...boxProps.sx
672
833
  },
673
- children: [title && /* @__PURE__ */jsx15(Box2, {
834
+ children: [title && /* @__PURE__ */jsx17(Box4, {
674
835
  sx: {
675
836
  marginBottom: "2"
676
837
  },
677
- children: /* @__PURE__ */jsx15(Text, {
838
+ children: /* @__PURE__ */jsx17(Text3, {
678
839
  sx: {
679
840
  fontSize: "2xl",
680
841
  fontWeight: "bold"
681
842
  },
682
843
  children: title
683
844
  })
684
- }), /* @__PURE__ */jsx15(Flex3, {
845
+ }), /* @__PURE__ */jsx17(Flex5, {
685
846
  sx: childrenContainerSx,
686
847
  children
687
- }), name && /* @__PURE__ */jsx15(FormErrorMessage, {
848
+ }), name && /* @__PURE__ */jsx17(FormErrorMessage, {
688
849
  name
689
850
  })]
690
851
  });
@@ -694,15 +855,15 @@ var FormGroup = props => {
694
855
  level
695
856
  } = useFormGroup();
696
857
  const currentLevel = level === void 0 ? 0 : level + 1;
697
- return /* @__PURE__ */jsx15(FormGroupContext.Provider, {
858
+ return /* @__PURE__ */jsx17(FormGroupContext.Provider, {
698
859
  value: {
699
860
  parentLevel: currentLevel
700
861
  },
701
- children: currentLevel === 0 ? /* @__PURE__ */jsx15(FormGroupLevelsManager, {
702
- children: /* @__PURE__ */jsx15(FormGroupWrapper, {
862
+ children: currentLevel === 0 ? /* @__PURE__ */jsx17(FormGroupLevelsManager, {
863
+ children: /* @__PURE__ */jsx17(FormGroupWrapper, {
703
864
  ...props
704
865
  })
705
- }) : /* @__PURE__ */jsx15(FormGroupWrapper, {
866
+ }) : /* @__PURE__ */jsx17(FormGroupWrapper, {
706
867
  ...props
707
868
  })
708
869
  });
@@ -772,7 +933,7 @@ import * as yup from "yup";
772
933
  // src/Brazil/FormFieldCNPJ.tsx
773
934
  import { Input as Input4 } from "@ttoss/ui";
774
935
  import { PatternFormat as PatternFormat2 } from "react-number-format";
775
- import { jsx as jsx16 } from "react/jsx-runtime";
936
+ import { jsx as jsx18 } from "react/jsx-runtime";
776
937
  var isCnpjValid = cnpj => {
777
938
  if (cnpj?.length != 14) {
778
939
  return false;
@@ -816,7 +977,7 @@ var FormFieldCNPJ = ({
816
977
  name,
817
978
  ...patternFormatProps
818
979
  }) => {
819
- return /* @__PURE__ */jsx16(FormField, {
980
+ return /* @__PURE__ */jsx18(FormField, {
820
981
  name,
821
982
  label,
822
983
  warning: patternFormatProps.warning,
@@ -824,7 +985,7 @@ var FormFieldCNPJ = ({
824
985
  render: ({
825
986
  field
826
987
  }) => {
827
- return /* @__PURE__ */jsx16(PatternFormat2, {
988
+ return /* @__PURE__ */jsx18(PatternFormat2, {
828
989
  name: field.name,
829
990
  value: field.value,
830
991
  onBlur: field.onBlur,
@@ -863,4 +1024,4 @@ import * as yup2 from "yup";
863
1024
  import { yupResolver } from "@hookform/resolvers/yup";
864
1025
  import { Controller, FormProvider as FormProvider2, useController as useController2, useFieldArray, useForm, useFormContext as useFormContext3, useFormState, useWatch } from "react-hook-form";
865
1026
  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 };
1027
+ 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-WUCWRQAS.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.0",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -50,12 +50,12 @@
50
50
  "react-error-boundary": "^5.0.0",
51
51
  "tsup": "^8.5.0",
52
52
  "yup": "^1.6.1",
53
- "@ttoss/config": "^1.35.5",
54
53
  "@ttoss/i18n-cli": "^0.7.30",
55
54
  "@ttoss/react-i18n": "^2.0.13",
56
55
  "@ttoss/react-icons": "^0.4.13",
57
- "@ttoss/ui": "^5.9.0",
58
- "@ttoss/test-utils": "^2.1.25"
56
+ "@ttoss/test-utils": "^2.1.25",
57
+ "@ttoss/config": "^1.35.5",
58
+ "@ttoss/ui": "^5.9.0"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",