@ttoss/forms 0.28.1 → 0.28.3

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-C7MZJ6SO.js";
2
+ import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-MXENUSCP.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-C7MZJ6SO.js";
2
+ import { Form, useForm, yupResolver } from "../chunk-MXENUSCP.js";
3
3
 
4
4
  // src/MultistepForm/MultistepForm.tsx
5
5
  import { Flex as Flex6 } from "@ttoss/ui";
@@ -68,13 +68,12 @@ var FormErrorMessage = ({
68
68
  };
69
69
 
70
70
  // src/FormField.tsx
71
- import { Box as Box2, Flex, Label } from "@ttoss/ui";
71
+ import { Checkbox, Flex, Label, Switch } from "@ttoss/ui";
72
72
  import * as React from "react";
73
73
  import { useController } from "react-hook-form";
74
74
  import { jsx as jsx3, jsxs } from "react/jsx-runtime";
75
75
  var FormField = ({
76
76
  label,
77
- labelPosition = "top",
78
77
  id: idProp,
79
78
  name,
80
79
  defaultValue,
@@ -97,38 +96,40 @@ var FormField = ({
97
96
  return null;
98
97
  }
99
98
  const childProps = child.props;
100
- const isLabelHorizontal = ["left", "right"].includes(labelPosition);
101
- const labelFontSize = isLabelHorizontal ? "md" : "sm";
102
- const flexDirectionMap = {
103
- top: "column",
104
- bottom: "column-reverse",
105
- left: "row",
106
- right: "row-reverse"
107
- };
99
+ if (label && [Checkbox, Switch].some(component => {
100
+ return child.type === component;
101
+ })) {
102
+ return /* @__PURE__ */jsxs(Label, {
103
+ "aria-disabled": disabled,
104
+ tooltip,
105
+ onTooltipClick,
106
+ children: [/* @__PURE__ */jsx3(Flex, {
107
+ children: React.createElement(child.type, {
108
+ id,
109
+ ...childProps
110
+ })
111
+ }), label]
112
+ });
113
+ }
108
114
  return /* @__PURE__ */jsxs(Flex, {
109
115
  sx: {
110
116
  width: "100%",
111
- flexDirection: flexDirectionMap[labelPosition],
112
- gap: "sm"
117
+ flexDirection: "column",
118
+ gap: "1"
113
119
  },
114
120
  children: [label && /* @__PURE__ */jsx3(Label, {
115
121
  "aria-disabled": disabled,
116
122
  htmlFor: id,
117
123
  tooltip,
118
124
  onTooltipClick,
119
- sx: {
120
- fontSize: labelFontSize
121
- },
122
125
  children: label
123
- }), /* @__PURE__ */jsx3(Box2, {
124
- children: React.createElement(child.type, {
125
- id,
126
- ...childProps
127
- })
126
+ }), React.createElement(child.type, {
127
+ id,
128
+ ...childProps
128
129
  })]
129
130
  });
130
131
  });
131
- }, [render, controllerReturn, labelPosition, label, disabled, id, tooltip, onTooltipClick]);
132
+ }, [render, controllerReturn, label, disabled, id, tooltip, onTooltipClick]);
132
133
  return /* @__PURE__ */jsxs(Flex, {
133
134
  sx: {
134
135
  flexDirection: "column",
@@ -144,7 +145,7 @@ var FormField = ({
144
145
  };
145
146
 
146
147
  // src/FormFieldCheckbox.tsx
147
- import { Checkbox } from "@ttoss/ui";
148
+ import { Checkbox as Checkbox2 } from "@ttoss/ui";
148
149
  import { jsx as jsx4 } from "react/jsx-runtime";
149
150
  var FormFieldCheckbox = ({
150
151
  label,
@@ -154,13 +155,12 @@ var FormFieldCheckbox = ({
154
155
  }) => {
155
156
  return /* @__PURE__ */jsx4(FormField, {
156
157
  label,
157
- labelPosition: "right",
158
158
  name,
159
159
  render: ({
160
160
  field,
161
161
  fieldState
162
162
  }) => {
163
- return /* @__PURE__ */jsx4(Checkbox, {
163
+ return /* @__PURE__ */jsx4(Checkbox2, {
164
164
  ...field,
165
165
  ...checkboxProps,
166
166
  "aria-invalid": !!fieldState.error,
@@ -337,59 +337,46 @@ var FormFieldPassword = ({
337
337
  };
338
338
 
339
339
  // src/FormFieldRadio.tsx
340
- import { Box as Box3, Flex as Flex2, Label as Label2, Radio } from "@ttoss/ui";
341
- import { useController as useController2 } from "react-hook-form";
340
+ import { Flex as Flex2, Label as Label2, Radio } from "@ttoss/ui";
342
341
  import { jsx as jsx11, jsxs as jsxs2 } from "react/jsx-runtime";
343
342
  var FormFieldRadio = ({
344
343
  label,
345
344
  name,
346
- options,
347
345
  sx,
346
+ options,
348
347
  ...radioProps
349
348
  }) => {
350
- const {
351
- field: {
352
- onChange,
353
- onBlur,
354
- value,
355
- ref
356
- }
357
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
358
- } = useController2({
349
+ return /* @__PURE__ */jsx11(FormField, {
350
+ label,
359
351
  name,
360
- defaultValue: ""
361
- });
362
- return /* @__PURE__ */jsxs2(Flex2, {
363
- sx: {
364
- flexDirection: "column",
365
- width: "100%",
366
- ...sx
367
- },
368
- children: [label && /* @__PURE__ */jsx11(Label2, {
369
- sx: {
370
- marginBottom: "1"
371
- },
372
- children: label
373
- }), /* @__PURE__ */jsx11(Box3, {
374
- children: options.map(option => {
375
- const id = `form-field-radio-${name}-${option.value}`;
376
- return /* @__PURE__ */jsxs2(Label2, {
377
- htmlFor: id,
378
- children: [/* @__PURE__ */jsx11(Radio, {
379
- ref,
380
- onChange,
381
- onBlur,
382
- value: option.value,
383
- checked: value === option.value,
384
- name,
385
- id,
386
- ...radioProps
387
- }), option.label]
388
- }, id);
389
- })
390
- }), /* @__PURE__ */jsx11(FormErrorMessage, {
391
- name
392
- })]
352
+ sx,
353
+ render: ({
354
+ field
355
+ }) => {
356
+ return /* @__PURE__ */jsx11(Flex2, {
357
+ sx: {
358
+ flexDirection: "column",
359
+ gap: "1"
360
+ },
361
+ children: options.map(option => {
362
+ const id = `form-field-radio-${name}-${option.value}`;
363
+ return /* @__PURE__ */jsxs2(Label2, {
364
+ sx: {
365
+ fontSize: "md"
366
+ },
367
+ children: [/* @__PURE__ */jsx11(Radio, {
368
+ ref: field.ref,
369
+ onChange: field.onChange,
370
+ onBlur: field.onBlur,
371
+ value: option.value,
372
+ checked: field.value === option.value,
373
+ name,
374
+ ...radioProps
375
+ }), option.label]
376
+ }, id);
377
+ })
378
+ });
379
+ }
393
380
  });
394
381
  };
395
382
 
@@ -433,7 +420,7 @@ var FormFieldSelect = ({
433
420
  };
434
421
 
435
422
  // src/FormFieldSwitch.tsx
436
- import { Switch } from "@ttoss/ui";
423
+ import { Switch as Switch2 } from "@ttoss/ui";
437
424
  import { jsx as jsx13 } from "react/jsx-runtime";
438
425
  var FormFieldSwitch = ({
439
426
  label,
@@ -443,13 +430,12 @@ var FormFieldSwitch = ({
443
430
  }) => {
444
431
  return /* @__PURE__ */jsx13(FormField, {
445
432
  label,
446
- labelPosition: "right",
447
433
  name,
448
434
  render: ({
449
435
  field,
450
436
  fieldState
451
437
  }) => {
452
- return /* @__PURE__ */jsx13(Switch, {
438
+ return /* @__PURE__ */jsx13(Switch2, {
453
439
  ...field,
454
440
  ...switchProps,
455
441
  "aria-invalid": !!fieldState.error,
@@ -488,7 +474,7 @@ var FormFieldTextarea = ({
488
474
  };
489
475
 
490
476
  // src/FormGroup.tsx
491
- import { Box as Box4, Flex as Flex3, Text } from "@ttoss/ui";
477
+ import { Box as Box2, Flex as Flex3, Text } from "@ttoss/ui";
492
478
  import * as React2 from "react";
493
479
  import { jsx as jsx15, jsxs as jsxs3 } from "react/jsx-runtime";
494
480
  var FormGroupLevelsManagerContext = React2.createContext({
@@ -550,7 +536,7 @@ var FormGroupWrapper = ({
550
536
  gap: "1",
551
537
  width: "100%"
552
538
  };
553
- return /* @__PURE__ */jsxs3(Box4, {
539
+ return /* @__PURE__ */jsxs3(Box2, {
554
540
  "aria-level": level,
555
541
  ...boxProps,
556
542
  sx: {
@@ -558,7 +544,7 @@ var FormGroupWrapper = ({
558
544
  marginBottom: "4",
559
545
  ...boxProps.sx
560
546
  },
561
- children: [title && /* @__PURE__ */jsx15(Box4, {
547
+ children: [title && /* @__PURE__ */jsx15(Box2, {
562
548
  sx: {
563
549
  marginBottom: "2"
564
550
  },
@@ -747,6 +733,6 @@ import * as yup2 from "yup";
747
733
 
748
734
  // src/index.ts
749
735
  import { yupResolver } from "@hookform/resolvers/yup";
750
- import { Controller, FormProvider as FormProvider2, useController as useController3, useFieldArray, useForm, useFormContext as useFormContext2, useFormState, useWatch } from "react-hook-form";
736
+ import { Controller, FormProvider as FormProvider2, useController as useController2, useFieldArray, useForm, useFormContext as useFormContext2, useFormState, useWatch } from "react-hook-form";
751
737
  export * from "react-hook-form";
752
- 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, useController3 as useController, useFieldArray, useForm, useFormContext2 as useFormContext, useFormState, useWatch };
738
+ 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, useFormContext2 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-C7MZJ6SO.js";
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-MXENUSCP.js";
3
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 };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as React from 'react';
3
2
  import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@ttoss/ui';
3
+ import * as React$1 from 'react';
4
4
  import { FieldValues, FormProviderProps, FieldName, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
5
5
  export * from 'react-hook-form';
6
6
  export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
@@ -13,7 +13,7 @@ export { yup };
13
13
  export { yupResolver } from '@hookform/resolvers/yup';
14
14
 
15
15
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
16
- children?: React.ReactNode;
16
+ children?: React$1.ReactNode;
17
17
  onSubmit?: (data: TFieldValues) => Promise<void> | void;
18
18
  sx?: BoxProps["sx"];
19
19
  } & FormProviderProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
@@ -24,8 +24,7 @@ declare const FormErrorMessage: <TFieldValues extends FieldValues = FieldValues>
24
24
  }) => react_jsx_runtime.JSX.Element;
25
25
 
26
26
  type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
27
- label?: React.ReactNode;
28
- labelPosition?: 'top' | 'bottom' | 'left' | 'right';
27
+ label?: React$1.ReactNode;
29
28
  id?: string;
30
29
  name: TName;
31
30
  defaultValue?: FieldPathValue<TFieldValues, TName>;
@@ -34,12 +33,12 @@ type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extend
34
33
  onTooltipClick?: () => void;
35
34
  } & SxProp;
36
35
  type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
37
- render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
36
+ render: (props: UseControllerReturn<TFieldValues, TName>) => React$1.ReactElement;
38
37
  } & FormFieldProps<TFieldValues, TName>;
39
- declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, labelPosition, id: idProp, name, defaultValue, disabled, tooltip, onTooltipClick, sx, css, render, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
38
+ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled, tooltip, onTooltipClick, sx, css, render, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
40
39
 
41
40
  declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues>({ label, name, sx, ...checkboxProps }: {
42
- label?: React.ReactNode;
41
+ label?: React$1.ReactNode;
43
42
  name: FieldPath<TFieldValues>;
44
43
  } & CheckboxProps) => react_jsx_runtime.JSX.Element;
45
44
 
@@ -80,9 +79,9 @@ type FormRadioOption = {
80
79
  value: string | number;
81
80
  label: string;
82
81
  };
83
- declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues>({ label, name, options, sx, ...radioProps }: {
84
- label?: string;
85
- name: FieldPath<TFieldValues>;
82
+ declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, options, ...radioProps }: {
83
+ label?: React.ReactNode;
84
+ name: TName;
86
85
  options: FormRadioOption[];
87
86
  } & RadioProps) => react_jsx_runtime.JSX.Element;
88
87
 
@@ -90,7 +89,7 @@ type FormFieldSelectProps<TFieldValues extends FieldValues = FieldValues, TName
90
89
  declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>({ label, name, id, defaultValue, sx, css, disabled, tooltip, onTooltipClick, ...selectProps }: FormFieldSelectProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
91
90
 
92
91
  declare const FormFieldSwitch: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, ...switchProps }: {
93
- label?: React.ReactNode;
92
+ label?: React$1.ReactNode;
94
93
  name: TName;
95
94
  } & SwitchProps) => react_jsx_runtime.JSX.Element;
96
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.28.1",
3
+ "version": "0.28.3",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
42
- "@ttoss/react-i18n": "^2.0.9",
43
- "@ttoss/ui": "^5.1.1"
42
+ "@ttoss/ui": "^5.1.2",
43
+ "@ttoss/react-i18n": "^2.0.9"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/jest": "^29.5.14",
@@ -52,10 +52,10 @@
52
52
  "yup": "^1.6.1",
53
53
  "@ttoss/config": "^1.35.2",
54
54
  "@ttoss/react-i18n": "^2.0.9",
55
+ "@ttoss/i18n-cli": "^0.7.26",
55
56
  "@ttoss/react-icons": "^0.4.9",
56
57
  "@ttoss/test-utils": "^2.1.22",
57
- "@ttoss/i18n-cli": "^0.7.26",
58
- "@ttoss/ui": "^5.1.1"
58
+ "@ttoss/ui": "^5.1.2"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",