@ttoss/forms 0.23.7 → 0.24.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/README.md CHANGED
@@ -49,9 +49,82 @@ export const FormComponent = () => {
49
49
 
50
50
  It exposes all the API from react-hook-form, so you can use all the methods and properties from it. Check the [React Hook Form](https://react-hook-form.com/docs) documentation for more details.
51
51
 
52
- ## FormFieldSelect support for Default Value
52
+ ## Yup Validation
53
53
 
54
- FormFieldSelect has support for default values, by assigning the first option defined or the value passed to it in the parameter `defaultValue`.
54
+ You can also use yup and all of API from react-hook-form importing `import { yup, useForm } from @ttoss/forms`
55
+
56
+ ```tsx
57
+ const FirstNameForm = () => {
58
+ const schema = yup.object({
59
+ firstName: yup.string().required(),
60
+ });
61
+
62
+ const formMethods = useForm({
63
+ resolver: yupResolver(schema),
64
+ });
65
+
66
+ return (
67
+ <Form {...formMethods} onSubmit={onSubmit}>
68
+ <FormField
69
+ name="firstName"
70
+ label="First Name"
71
+ defaultValue={''}
72
+ render={({ field }) => {
73
+ return <Input {...field} />;
74
+ }}
75
+ />
76
+ <Button type="submit">Submit</Button>
77
+ </Form>
78
+ );
79
+ };
80
+ ```
81
+
82
+ When field is invalid according with schema requirements, it gonna return the default. In this example, for required fields, it gonna be `Field is required`.
83
+
84
+ You can translate the message or change the generic message by configuring the messages in the json i18n definition. To use this, please, refer to the docs on [React-i18n](https://ttoss.dev/docs/modules/packages/react-i18n/) and [i18n-CLI](https://ttoss.dev/docs/modules/packages/i18n-cli/).
85
+
86
+ ### Custom Error messages
87
+
88
+ You can, also, pass custom error messages to the validation constraints in schema. It's really recommended that you use i18n pattern to create your custom message.
89
+
90
+ ```tsx
91
+ const ComponentForm = () => {
92
+ const {
93
+ intl: { formatMessage },
94
+ } = useI18n();
95
+
96
+ const schema = useMemo(() => {
97
+ return yup.object({
98
+ name: yup.string().required(
99
+ formatMessage({
100
+ defaultMessage: 'Name must be not null',
101
+ description: 'Name required constraint',
102
+ })
103
+ ),
104
+ age: yup.number().min(
105
+ 18,
106
+ formatMessage(
107
+ {
108
+ defaultMessage: 'You should be {age} years old or more',
109
+ description: 'Min Age Constriant message',
110
+ },
111
+ { age: 18 }
112
+ )
113
+ ),
114
+ });
115
+ }, [formatMessage]);
116
+
117
+ // ...
118
+ };
119
+ ```
120
+
121
+ ## Components
122
+
123
+ ### FormFieldSelect
124
+
125
+ #### FormFieldSelect support for Default Value
126
+
127
+ `FormFieldSelect` has support for default values, by assigning the first option defined or the value passed to it in the parameter `defaultValue`.
55
128
 
56
129
  ```tsx
57
130
  const RADIO_OPTIONS = [
@@ -160,74 +233,35 @@ const RenderForm = () => {
160
233
  };
161
234
  ```
162
235
 
163
- ### Yup Validation
236
+ ### FormGroup
164
237
 
165
- You can also use yup and all of API from react-hook-form importing `import { yup, useForm } from @ttoss/forms`
238
+ `FormGroup` is a component that groups fields together. It's useful when you need to group fields that are related to each other.
166
239
 
167
240
  ```tsx
168
- const FirstNameForm = () => {
169
- const schema = yup.object({
170
- firstName: yup.string().required(),
171
- });
172
-
173
- const formMethods = useForm({
174
- resolver: yupResolver(schema),
175
- });
241
+ const RenderForm = () => {
242
+ const formMethods = useForm();
176
243
 
177
244
  return (
178
245
  <Form {...formMethods} onSubmit={onSubmit}>
179
- <FormField
180
- name="firstName"
181
- label="First Name"
182
- defaultValue={''}
183
- render={({ field }) => {
184
- return <Input {...field} />;
185
- }}
186
- />
246
+ <FormGroup label="Personal Information" direction="row">
247
+ <FormField.Input name="firstName" label="First Name" />
248
+ <FormField.Input name="lastName" label="Last Name" />
249
+ </FormGroup>
250
+ <FormGroup label="Address">
251
+ <FormField.Input name="street" label="Street" />
252
+ <FormField.Input name="city" label="City" />
253
+ </FormGroup>
187
254
  <Button type="submit">Submit</Button>
188
255
  </Form>
189
256
  );
190
257
  };
191
258
  ```
192
259
 
193
- When field is invalid according with schema requirements, it gonna return the default. In this example, for required fields, it gonna be `Field is required`.
194
-
195
- You can translate the message or change the generic message by configuring the messages in the json i18n definition. To use this, please, refer to the docs on [React-i18n](https://ttoss.dev/docs/modules/packages/react-i18n/) and [i18n-CLI](https://ttoss.dev/docs/modules/packages/i18n-cli/).
196
-
197
- ### Custom Error messages
198
-
199
- You can, also, pass custom error messages to the validation constraints in schema. It's really recommended that you use i18n pattern to create your custom message.
200
-
201
- ```tsx
202
- const ComponentForm = () => {
203
- const {
204
- intl: { formatMessage },
205
- } = useI18n();
206
-
207
- const schema = useMemo(() => {
208
- return yup.object({
209
- name: yup.string().required(
210
- formatMessage({
211
- defaultMessage: 'Name must be not null',
212
- description: 'Name required constraint',
213
- })
214
- ),
215
- age: yup.number().min(
216
- 18,
217
- formatMessage(
218
- {
219
- defaultMessage: 'You should be {age} years old or more',
220
- description: 'Min Age Constriant message',
221
- },
222
- { age: 18 }
223
- )
224
- ),
225
- });
226
- }, [formatMessage]);
260
+ #### Props
227
261
 
228
- // ...
229
- };
230
- ```
262
+ - `title`: The label of the group.
263
+ - `direction`: The direction of the group. It can be `row` or `column`.
264
+ - `name`: The name of the group. It is used to render the group error message.
231
265
 
232
266
  ## @ttoss/forms/multistep-form
233
267
 
@@ -51,6 +51,7 @@ var src_exports = {};
51
51
  __export(src_exports, {
52
52
  Controller: () => import_react_hook_form6.Controller,
53
53
  Form: () => Form,
54
+ FormErrorMessage: () => FormErrorMessage,
54
55
  FormField: () => FormField,
55
56
  FormFieldCheckbox: () => FormFieldCheckbox,
56
57
  FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
@@ -151,19 +152,16 @@ var Form = ({
151
152
  });
152
153
  };
153
154
 
154
- // src/FormField.tsx
155
- var React = __toESM(require("react"));
156
-
157
- // src/ErrorMessage.tsx
155
+ // src/FormErrorMessage.tsx
156
+ var import_error_message = require("@hookform/error-message");
158
157
  var import_react_hook_form2 = require("react-hook-form");
159
158
  var import_react_i18n2 = require("@ttoss/react-i18n");
160
159
  var import_ui2 = require("@ttoss/ui");
161
- var import_error_message = require("@hookform/error-message");
162
160
  var import_jsx_runtime2 = require("react/jsx-runtime");
163
161
  var isMessageDescriptor = possibleMessageDescriptor => {
164
162
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
165
163
  };
166
- var ErrorMessage = ({
164
+ var FormErrorMessage = ({
167
165
  name,
168
166
  disabled
169
167
  }) => {
@@ -198,6 +196,7 @@ var ErrorMessage = ({
198
196
  };
199
197
 
200
198
  // src/FormField.tsx
199
+ var React = __toESM(require("react"));
201
200
  var import_react_hook_form3 = require("react-hook-form");
202
201
  var import_ui3 = require("@ttoss/ui");
203
202
  var import_jsx_runtime3 = require("react/jsx-runtime");
@@ -242,7 +241,7 @@ var FormField = ({
242
241
  ...sx
243
242
  },
244
243
  css,
245
- children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime3.jsx)(ErrorMessage, {
244
+ children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime3.jsx)(FormErrorMessage, {
246
245
  name
247
246
  })]
248
247
  });
@@ -268,6 +267,7 @@ var FormFieldCheckbox = ({
268
267
  formState: {
269
268
  errors
270
269
  }
270
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
271
271
  } = (0, import_react_hook_form4.useController)({
272
272
  name,
273
273
  defaultValue: false
@@ -298,7 +298,7 @@ var FormFieldCheckbox = ({
298
298
  ...checkboxProps
299
299
  }), label]
300
300
  })
301
- }), /* @__PURE__ */(0, import_jsx_runtime4.jsx)(ErrorMessage, {
301
+ }), /* @__PURE__ */(0, import_jsx_runtime4.jsx)(FormErrorMessage, {
302
302
  name
303
303
  })]
304
304
  });
@@ -488,6 +488,7 @@ var FormFieldRadio = ({
488
488
  value,
489
489
  ref
490
490
  }
491
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
491
492
  } = (0, import_react_hook_form5.useController)({
492
493
  name,
493
494
  defaultValue: ""
@@ -520,7 +521,7 @@ var FormFieldRadio = ({
520
521
  }), option.label]
521
522
  }, id);
522
523
  })
523
- }), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(ErrorMessage, {
524
+ }), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormErrorMessage, {
524
525
  name
525
526
  })]
526
527
  });
@@ -637,6 +638,7 @@ var FormGroupWrapper = ({
637
638
  title,
638
639
  direction,
639
640
  children,
641
+ name,
640
642
  ...boxProps
641
643
  }) => {
642
644
  const {
@@ -677,6 +679,8 @@ var FormGroupWrapper = ({
677
679
  }), /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Flex, {
678
680
  sx: childrenContainerSx,
679
681
  children
682
+ }), name && /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormErrorMessage, {
683
+ name
680
684
  })]
681
685
  });
682
686
  };
@@ -88,6 +88,7 @@ var src_exports = {};
88
88
  __export(src_exports, {
89
89
  Controller: () => import_react_hook_form6.Controller,
90
90
  Form: () => Form,
91
+ FormErrorMessage: () => FormErrorMessage,
91
92
  FormField: () => FormField,
92
93
  FormFieldCheckbox: () => FormFieldCheckbox,
93
94
  FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
@@ -233,19 +234,16 @@ var Form = ({
233
234
  });
234
235
  };
235
236
 
236
- // src/FormField.tsx
237
- var React = __toESM(require("react"));
238
-
239
- // src/ErrorMessage.tsx
237
+ // src/FormErrorMessage.tsx
238
+ var import_error_message = require("@hookform/error-message");
240
239
  var import_react_hook_form2 = require("react-hook-form");
241
240
  var import_react_i18n2 = require("@ttoss/react-i18n");
242
241
  var import_ui4 = require("@ttoss/ui");
243
- var import_error_message = require("@hookform/error-message");
244
242
  var import_jsx_runtime4 = require("react/jsx-runtime");
245
243
  var isMessageDescriptor = possibleMessageDescriptor => {
246
244
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
247
245
  };
248
- var ErrorMessage = ({
246
+ var FormErrorMessage = ({
249
247
  name,
250
248
  disabled
251
249
  }) => {
@@ -280,6 +278,7 @@ var ErrorMessage = ({
280
278
  };
281
279
 
282
280
  // src/FormField.tsx
281
+ var React = __toESM(require("react"));
283
282
  var import_react_hook_form3 = require("react-hook-form");
284
283
  var import_ui5 = require("@ttoss/ui");
285
284
  var import_jsx_runtime5 = require("react/jsx-runtime");
@@ -324,7 +323,7 @@ var FormField = ({
324
323
  ...sx
325
324
  },
326
325
  css,
327
- children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime5.jsx)(ErrorMessage, {
326
+ children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormErrorMessage, {
328
327
  name
329
328
  })]
330
329
  });
@@ -350,6 +349,7 @@ var FormFieldCheckbox = ({
350
349
  formState: {
351
350
  errors
352
351
  }
352
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
353
353
  } = (0, import_react_hook_form4.useController)({
354
354
  name,
355
355
  defaultValue: false
@@ -380,7 +380,7 @@ var FormFieldCheckbox = ({
380
380
  ...checkboxProps
381
381
  }), label]
382
382
  })
383
- }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(ErrorMessage, {
383
+ }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(FormErrorMessage, {
384
384
  name
385
385
  })]
386
386
  });
@@ -570,6 +570,7 @@ var FormFieldRadio = ({
570
570
  value,
571
571
  ref
572
572
  }
573
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
573
574
  } = (0, import_react_hook_form5.useController)({
574
575
  name,
575
576
  defaultValue: ""
@@ -602,7 +603,7 @@ var FormFieldRadio = ({
602
603
  }), option.label]
603
604
  }, id);
604
605
  })
605
- }), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(ErrorMessage, {
606
+ }), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(FormErrorMessage, {
606
607
  name
607
608
  })]
608
609
  });
@@ -719,6 +720,7 @@ var FormGroupWrapper = ({
719
720
  title,
720
721
  direction,
721
722
  children,
723
+ name,
722
724
  ...boxProps
723
725
  }) => {
724
726
  const {
@@ -759,6 +761,8 @@ var FormGroupWrapper = ({
759
761
  }), /* @__PURE__ */(0, import_jsx_runtime16.jsx)(import_ui14.Flex, {
760
762
  sx: childrenContainerSx,
761
763
  children
764
+ }), name && /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormErrorMessage, {
765
+ name
762
766
  })]
763
767
  });
764
768
  };
@@ -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-KCGLFWPY.js";
2
+ import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-CDQJBSC2.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, __publicField, useForm, yupResolver } from "../chunk-KCGLFWPY.js";
2
+ import { Form, __publicField, useForm, yupResolver } from "../chunk-CDQJBSC2.js";
3
3
 
4
4
  // src/MultistepForm/MultistepForm.tsx
5
5
  import * as React3 from "react";
@@ -178,19 +178,16 @@ var Form = ({
178
178
  });
179
179
  };
180
180
 
181
- // src/FormField.tsx
182
- import * as React from "react";
183
-
184
- // src/ErrorMessage.tsx
181
+ // src/FormErrorMessage.tsx
182
+ import { ErrorMessage } from "@hookform/error-message";
185
183
  import { useFormContext } from "react-hook-form";
186
184
  import { FormattedMessage } from "@ttoss/react-i18n";
187
185
  import { HelpText } from "@ttoss/ui";
188
- import { ErrorMessage as HookformErrorMessage } from "@hookform/error-message";
189
186
  import { jsx as jsx3 } from "react/jsx-runtime";
190
187
  var isMessageDescriptor = possibleMessageDescriptor => {
191
188
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
192
189
  };
193
- var ErrorMessage = ({
190
+ var FormErrorMessage = ({
194
191
  name,
195
192
  disabled
196
193
  }) => {
@@ -199,7 +196,7 @@ var ErrorMessage = ({
199
196
  errors
200
197
  }
201
198
  } = useFormContext();
202
- return /* @__PURE__ */jsx3(HookformErrorMessage, {
199
+ return /* @__PURE__ */jsx3(ErrorMessage, {
203
200
  name,
204
201
  errors,
205
202
  render: ({
@@ -225,6 +222,7 @@ var ErrorMessage = ({
225
222
  };
226
223
 
227
224
  // src/FormField.tsx
225
+ import * as React from "react";
228
226
  import { useController } from "react-hook-form";
229
227
  import { Flex, Label } from "@ttoss/ui";
230
228
  import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
@@ -269,7 +267,7 @@ var FormField = ({
269
267
  ...sx
270
268
  },
271
269
  css,
272
- children: [memoizedRender, /* @__PURE__ */jsx4(ErrorMessage, {
270
+ children: [memoizedRender, /* @__PURE__ */jsx4(FormErrorMessage, {
273
271
  name
274
272
  })]
275
273
  });
@@ -295,6 +293,7 @@ var FormFieldCheckbox = ({
295
293
  formState: {
296
294
  errors
297
295
  }
296
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
297
  } = useController2({
299
298
  name,
300
299
  defaultValue: false
@@ -325,7 +324,7 @@ var FormFieldCheckbox = ({
325
324
  ...checkboxProps
326
325
  }), label]
327
326
  })
328
- }), /* @__PURE__ */jsx5(ErrorMessage, {
327
+ }), /* @__PURE__ */jsx5(FormErrorMessage, {
329
328
  name
330
329
  })]
331
330
  });
@@ -515,6 +514,7 @@ var FormFieldRadio = ({
515
514
  value,
516
515
  ref
517
516
  }
517
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
518
518
  } = useController3({
519
519
  name,
520
520
  defaultValue: ""
@@ -547,7 +547,7 @@ var FormFieldRadio = ({
547
547
  }), option.label]
548
548
  }, id);
549
549
  })
550
- }), /* @__PURE__ */jsx12(ErrorMessage, {
550
+ }), /* @__PURE__ */jsx12(FormErrorMessage, {
551
551
  name
552
552
  })]
553
553
  });
@@ -664,6 +664,7 @@ var FormGroupWrapper = ({
664
664
  title,
665
665
  direction,
666
666
  children,
667
+ name,
667
668
  ...boxProps
668
669
  }) => {
669
670
  const {
@@ -704,6 +705,8 @@ var FormGroupWrapper = ({
704
705
  }), /* @__PURE__ */jsx15(Flex4, {
705
706
  sx: childrenContainerSx,
706
707
  children
708
+ }), name && /* @__PURE__ */jsx15(FormErrorMessage, {
709
+ name
707
710
  })]
708
711
  });
709
712
  };
@@ -729,4 +732,4 @@ var FormGroup = props => {
729
732
  // src/index.ts
730
733
  import { useForm, useFormContext as useFormContext2, useWatch, useFieldArray, useController as useController4, useFormState, Controller, FormProvider as FormProvider2 } from "react-hook-form";
731
734
  export * from "react-hook-form";
732
- export { __publicField, isCnpjValid, FormFieldCNPJ, yup2 as yup, Form, 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 };
735
+ 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 };
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, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-KCGLFWPY.js";
3
- export { Controller, Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, 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, FormFieldSelect, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-CDQJBSC2.js";
3
+ export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver };
package/dist/index.d.mts CHANGED
@@ -5,7 +5,7 @@ export { yup };
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import * as React from 'react';
7
7
  import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
8
- import { FieldValues, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
8
+ import { FieldValues, FormProviderProps, FieldName, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
9
9
  export * from 'react-hook-form';
10
10
  export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
11
11
  import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-CkcL14ho.mjs';
@@ -18,6 +18,11 @@ declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children,
18
18
  sx?: BoxProps['sx'];
19
19
  } & FormProviderProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
20
20
 
21
+ declare const FormErrorMessage: <TFieldValues extends FieldValues = FieldValues>({ name, disabled, }: {
22
+ name: FieldName<TFieldValues>;
23
+ disabled?: boolean;
24
+ }) => react_jsx_runtime.JSX.Element;
25
+
21
26
  type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
22
27
  label?: string;
23
28
  id?: string;
@@ -93,9 +98,10 @@ declare const useFormGroup: () => {
93
98
  levelsLength: number;
94
99
  };
95
100
  type FormGroupProps = {
101
+ name?: string;
96
102
  title?: string;
97
103
  direction?: 'column' | 'row';
98
104
  } & BoxProps;
99
105
  declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
100
106
 
101
- export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
107
+ export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { yup };
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import * as React from 'react';
7
7
  import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
8
- import { FieldValues, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
8
+ import { FieldValues, FormProviderProps, FieldName, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
9
9
  export * from 'react-hook-form';
10
10
  export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
11
11
  import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-CkcL14ho.js';
@@ -18,6 +18,11 @@ declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children,
18
18
  sx?: BoxProps['sx'];
19
19
  } & FormProviderProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
20
20
 
21
+ declare const FormErrorMessage: <TFieldValues extends FieldValues = FieldValues>({ name, disabled, }: {
22
+ name: FieldName<TFieldValues>;
23
+ disabled?: boolean;
24
+ }) => react_jsx_runtime.JSX.Element;
25
+
21
26
  type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
22
27
  label?: string;
23
28
  id?: string;
@@ -93,9 +98,10 @@ declare const useFormGroup: () => {
93
98
  levelsLength: number;
94
99
  };
95
100
  type FormGroupProps = {
101
+ name?: string;
96
102
  title?: string;
97
103
  direction?: 'column' | 'row';
98
104
  } & BoxProps;
99
105
  declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
100
106
 
101
- export { Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
107
+ export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.js CHANGED
@@ -41,6 +41,7 @@ var src_exports = {};
41
41
  __export(src_exports, {
42
42
  Controller: () => import_react_hook_form6.Controller,
43
43
  Form: () => Form,
44
+ FormErrorMessage: () => FormErrorMessage,
44
45
  FormField: () => FormField,
45
46
  FormFieldCheckbox: () => FormFieldCheckbox,
46
47
  FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
@@ -187,19 +188,16 @@ var Form = ({
187
188
  });
188
189
  };
189
190
 
190
- // src/FormField.tsx
191
- var React = __toESM(require("react"));
192
-
193
- // src/ErrorMessage.tsx
191
+ // src/FormErrorMessage.tsx
192
+ var import_error_message = require("@hookform/error-message");
194
193
  var import_react_hook_form2 = require("react-hook-form");
195
194
  var import_react_i18n2 = require("@ttoss/react-i18n");
196
195
  var import_ui3 = require("@ttoss/ui");
197
- var import_error_message = require("@hookform/error-message");
198
196
  var import_jsx_runtime3 = require("react/jsx-runtime");
199
197
  var isMessageDescriptor = possibleMessageDescriptor => {
200
198
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
201
199
  };
202
- var ErrorMessage = ({
200
+ var FormErrorMessage = ({
203
201
  name,
204
202
  disabled
205
203
  }) => {
@@ -234,6 +232,7 @@ var ErrorMessage = ({
234
232
  };
235
233
 
236
234
  // src/FormField.tsx
235
+ var React = __toESM(require("react"));
237
236
  var import_react_hook_form3 = require("react-hook-form");
238
237
  var import_ui4 = require("@ttoss/ui");
239
238
  var import_jsx_runtime4 = require("react/jsx-runtime");
@@ -278,7 +277,7 @@ var FormField = ({
278
277
  ...sx
279
278
  },
280
279
  css,
281
- children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime4.jsx)(ErrorMessage, {
280
+ children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime4.jsx)(FormErrorMessage, {
282
281
  name
283
282
  })]
284
283
  });
@@ -304,6 +303,7 @@ var FormFieldCheckbox = ({
304
303
  formState: {
305
304
  errors
306
305
  }
306
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
307
307
  } = (0, import_react_hook_form4.useController)({
308
308
  name,
309
309
  defaultValue: false
@@ -334,7 +334,7 @@ var FormFieldCheckbox = ({
334
334
  ...checkboxProps
335
335
  }), label]
336
336
  })
337
- }), /* @__PURE__ */(0, import_jsx_runtime5.jsx)(ErrorMessage, {
337
+ }), /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormErrorMessage, {
338
338
  name
339
339
  })]
340
340
  });
@@ -524,6 +524,7 @@ var FormFieldRadio = ({
524
524
  value,
525
525
  ref
526
526
  }
527
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
527
528
  } = (0, import_react_hook_form5.useController)({
528
529
  name,
529
530
  defaultValue: ""
@@ -556,7 +557,7 @@ var FormFieldRadio = ({
556
557
  }), option.label]
557
558
  }, id);
558
559
  })
559
- }), /* @__PURE__ */(0, import_jsx_runtime12.jsx)(ErrorMessage, {
560
+ }), /* @__PURE__ */(0, import_jsx_runtime12.jsx)(FormErrorMessage, {
560
561
  name
561
562
  })]
562
563
  });
@@ -673,6 +674,7 @@ var FormGroupWrapper = ({
673
674
  title,
674
675
  direction,
675
676
  children,
677
+ name,
676
678
  ...boxProps
677
679
  }) => {
678
680
  const {
@@ -713,6 +715,8 @@ var FormGroupWrapper = ({
713
715
  }), /* @__PURE__ */(0, import_jsx_runtime15.jsx)(import_ui13.Flex, {
714
716
  sx: childrenContainerSx,
715
717
  children
718
+ }), name && /* @__PURE__ */(0, import_jsx_runtime15.jsx)(FormErrorMessage, {
719
+ name
716
720
  })]
717
721
  });
718
722
  };
@@ -742,6 +746,7 @@ __reExport(src_exports, require("react-hook-form"), module.exports);
742
746
  0 && (module.exports = {
743
747
  Controller,
744
748
  Form,
749
+ FormErrorMessage,
745
750
  FormField,
746
751
  FormFieldCheckbox,
747
752
  FormFieldCreditCardNumber,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.23.7",
3
+ "version": "0.24.1",
4
4
  "author": "ttoss",
5
5
  "contributors": [
6
6
  "Pedro Arantes <pedro@arantespp.com> (https://arantespp.com/contact)"
@@ -35,14 +35,14 @@
35
35
  "dependencies": {
36
36
  "@hookform/error-message": "^2.0.1",
37
37
  "@hookform/resolvers": "^3.3.4",
38
- "react-hook-form": "^7.51.2",
38
+ "react-hook-form": "^7.51.4",
39
39
  "react-number-format": "^5.3.4",
40
40
  "yup": "^1.4.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=16.8.0",
44
- "@ttoss/react-i18n": "^1.26.7",
45
- "@ttoss/ui": "^4.1.9"
44
+ "@ttoss/ui": "^4.1.9",
45
+ "@ttoss/react-i18n": "^1.26.7"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jest": "^29.5.12",
@@ -54,10 +54,10 @@
54
54
  "tsup": "^8.0.2",
55
55
  "yup": "^1.4.0",
56
56
  "@ttoss/config": "^1.32.3",
57
- "@ttoss/react-i18n": "^1.26.7",
58
57
  "@ttoss/i18n-cli": "^0.7.11",
59
- "@ttoss/react-icons": "^0.3.6",
60
58
  "@ttoss/test-utils": "^2.1.6",
59
+ "@ttoss/react-icons": "^0.3.6",
60
+ "@ttoss/react-i18n": "^1.26.7",
61
61
  "@ttoss/ui": "^4.1.9"
62
62
  },
63
63
  "publishConfig": {
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { ErrorMessage } from '@hookform/error-message';
2
3
  import {
3
4
  FieldError,
4
5
  FieldName,
@@ -7,7 +8,6 @@ import {
7
8
  } from 'react-hook-form';
8
9
  import { FormattedMessage, MessageDescriptor } from '@ttoss/react-i18n';
9
10
  import { HelpText } from '@ttoss/ui';
10
- import { ErrorMessage as HookformErrorMessage } from '@hookform/error-message';
11
11
 
12
12
  type ModifiedDescriptor = MessageDescriptor & { values?: any };
13
13
 
@@ -21,7 +21,9 @@ const isMessageDescriptor = (
21
21
  );
22
22
  };
23
23
 
24
- export const ErrorMessage = <TFieldValues extends FieldValues = FieldValues>({
24
+ export const FormErrorMessage = <
25
+ TFieldValues extends FieldValues = FieldValues,
26
+ >({
25
27
  name,
26
28
  disabled,
27
29
  }: {
@@ -33,7 +35,7 @@ export const ErrorMessage = <TFieldValues extends FieldValues = FieldValues>({
33
35
  } = useFormContext<TFieldValues>();
34
36
 
35
37
  return (
36
- <HookformErrorMessage
38
+ <ErrorMessage
37
39
  name={name as any}
38
40
  errors={errors}
39
41
  render={({ message }: { message: FieldError | string }) => {
package/src/FormField.tsx CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { ErrorMessage } from './ErrorMessage';
3
2
  import {
4
3
  FieldPath,
5
4
  FieldPathValue,
@@ -8,6 +7,7 @@ import {
8
7
  useController,
9
8
  } from 'react-hook-form';
10
9
  import { Flex, Label, type SxProp } from '@ttoss/ui';
10
+ import { FormErrorMessage } from './FormErrorMessage';
11
11
 
12
12
  export type FormFieldProps<
13
13
  TFieldValues extends FieldValues = FieldValues,
@@ -80,7 +80,7 @@ export const FormField = <
80
80
  css={css}
81
81
  >
82
82
  {memoizedRender}
83
- <ErrorMessage name={name} />
83
+ <FormErrorMessage name={name} />
84
84
  </Flex>
85
85
  );
86
86
  };
@@ -1,9 +1,9 @@
1
1
  import { Checkbox, type CheckboxProps, Flex, Label } from '@ttoss/ui';
2
- import { ErrorMessage } from './ErrorMessage';
3
2
  import { FieldPath, FieldValues, useController } from 'react-hook-form';
3
+ import { FormErrorMessage } from './FormErrorMessage';
4
4
 
5
5
  export const FormFieldCheckbox = <
6
- TFieldValues extends FieldValues = FieldValues
6
+ TFieldValues extends FieldValues = FieldValues,
7
7
  >({
8
8
  label,
9
9
  name,
@@ -16,6 +16,7 @@ export const FormFieldCheckbox = <
16
16
  const {
17
17
  field: { onChange, onBlur, value, ref },
18
18
  formState: { errors },
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
20
  } = useController<any>({
20
21
  name,
21
22
  defaultValue: false,
@@ -42,7 +43,7 @@ export const FormFieldCheckbox = <
42
43
  {label}
43
44
  </Label>
44
45
  </Flex>
45
- <ErrorMessage name={name} />
46
+ <FormErrorMessage name={name} />
46
47
  </Flex>
47
48
  );
48
49
  };
@@ -1,6 +1,6 @@
1
1
  import { Box, Flex, Label, Radio, type RadioProps } from '@ttoss/ui';
2
- import { ErrorMessage } from './ErrorMessage';
3
2
  import { FieldPath, FieldValues, useController } from 'react-hook-form';
3
+ import { FormErrorMessage } from './FormErrorMessage';
4
4
 
5
5
  type FormRadioOption = {
6
6
  value: string | number;
@@ -20,6 +20,7 @@ export const FormFieldRadio = <TFieldValues extends FieldValues = FieldValues>({
20
20
  } & RadioProps) => {
21
21
  const {
22
22
  field: { onChange, onBlur, value, ref },
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
24
  } = useController<any>({
24
25
  name,
25
26
  defaultValue: '',
@@ -50,7 +51,7 @@ export const FormFieldRadio = <TFieldValues extends FieldValues = FieldValues>({
50
51
  })}
51
52
  </Box>
52
53
 
53
- <ErrorMessage name={name} />
54
+ <FormErrorMessage name={name} />
54
55
  </Flex>
55
56
  );
56
57
  };
package/src/FormGroup.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Box, BoxProps, Flex, FlexProps, Text } from '@ttoss/ui';
3
+ import { FormErrorMessage } from './FormErrorMessage';
3
4
 
4
5
  type FormGroupLevelsManagerContextType = {
5
6
  levelsLength: number;
@@ -56,6 +57,7 @@ export const useFormGroup = () => {
56
57
  };
57
58
 
58
59
  type FormGroupProps = {
60
+ name?: string;
59
61
  title?: string;
60
62
  direction?: 'column' | 'row';
61
63
  } & BoxProps;
@@ -64,6 +66,7 @@ const FormGroupWrapper = ({
64
66
  title,
65
67
  direction,
66
68
  children,
69
+ name,
67
70
  ...boxProps
68
71
  }: FormGroupProps) => {
69
72
  const { level } = useFormGroup();
@@ -109,6 +112,7 @@ const FormGroupWrapper = ({
109
112
  </Box>
110
113
  )}
111
114
  <Flex sx={childrenContainerSx}>{children}</Flex>
115
+ {name && <FormErrorMessage name={name} />}
112
116
  </Box>
113
117
  );
114
118
  };
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export { yupResolver } from '@hookform/resolvers/yup';
2
2
  export { yup } from './yup/yup';
3
3
 
4
4
  export { Form } from './Form';
5
+ export { FormErrorMessage } from './FormErrorMessage';
5
6
  export { FormField } from './FormField';
6
7
  export { FormFieldCheckbox } from './FormFieldCheckbox';
7
8
  export { FormFieldCreditCardNumber } from './FormFieldCreditCardNumber';