@ttoss/forms 0.23.7 → 0.24.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.
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
 
@@ -50,6 +50,7 @@ module.exports = __toCommonJS(Brazil_exports);
50
50
  var src_exports = {};
51
51
  __export(src_exports, {
52
52
  Controller: () => import_react_hook_form6.Controller,
53
+ ErrorMessage: () => ErrorMessage,
53
54
  Form: () => Form,
54
55
  FormField: () => FormField,
55
56
  FormFieldCheckbox: () => FormFieldCheckbox,
@@ -127,39 +128,12 @@ yup.addMethod(yup.string, "cnpj", function () {
127
128
  // src/yup/yup.ts
128
129
  var yup2 = __toESM(require("yup"));
129
130
 
130
- // src/Form.tsx
131
- var import_ui = require("@ttoss/ui");
132
- var import_react_hook_form = require("react-hook-form");
133
- var import_jsx_runtime = require("react/jsx-runtime");
134
- var Form = ({
135
- children,
136
- onSubmit,
137
- sx,
138
- ...formMethods
139
- }) => {
140
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_hook_form.FormProvider, {
141
- ...formMethods,
142
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.Box, {
143
- as: "form",
144
- variant: "forms.form",
145
- onSubmit: formMethods.handleSubmit(data => {
146
- return onSubmit?.(data);
147
- }),
148
- sx,
149
- children
150
- })
151
- });
152
- };
153
-
154
- // src/FormField.tsx
155
- var React = __toESM(require("react"));
156
-
157
131
  // src/ErrorMessage.tsx
158
- var import_react_hook_form2 = require("react-hook-form");
132
+ var import_react_hook_form = require("react-hook-form");
159
133
  var import_react_i18n2 = require("@ttoss/react-i18n");
160
- var import_ui2 = require("@ttoss/ui");
134
+ var import_ui = require("@ttoss/ui");
161
135
  var import_error_message = require("@hookform/error-message");
162
- var import_jsx_runtime2 = require("react/jsx-runtime");
136
+ var import_jsx_runtime = require("react/jsx-runtime");
163
137
  var isMessageDescriptor = possibleMessageDescriptor => {
164
138
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
165
139
  };
@@ -171,14 +145,14 @@ var ErrorMessage = ({
171
145
  formState: {
172
146
  errors
173
147
  }
174
- } = (0, import_react_hook_form2.useFormContext)();
175
- return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_error_message.ErrorMessage, {
148
+ } = (0, import_react_hook_form.useFormContext)();
149
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_error_message.ErrorMessage, {
176
150
  name,
177
151
  errors,
178
152
  render: ({
179
153
  message
180
154
  }) => {
181
- return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.HelpText, {
155
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.HelpText, {
182
156
  negative: true,
183
157
  disabled,
184
158
  children: (() => {
@@ -186,7 +160,7 @@ var ErrorMessage = ({
186
160
  return message;
187
161
  }
188
162
  if (isMessageDescriptor(message)) {
189
- return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_react_i18n2.FormattedMessage, {
163
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_i18n2.FormattedMessage, {
190
164
  ...message
191
165
  });
192
166
  }
@@ -197,7 +171,32 @@ var ErrorMessage = ({
197
171
  });
198
172
  };
199
173
 
174
+ // src/Form.tsx
175
+ var import_ui2 = require("@ttoss/ui");
176
+ var import_react_hook_form2 = require("react-hook-form");
177
+ var import_jsx_runtime2 = require("react/jsx-runtime");
178
+ var Form = ({
179
+ children,
180
+ onSubmit,
181
+ sx,
182
+ ...formMethods
183
+ }) => {
184
+ return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_react_hook_form2.FormProvider, {
185
+ ...formMethods,
186
+ children: /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.Box, {
187
+ as: "form",
188
+ variant: "forms.form",
189
+ onSubmit: formMethods.handleSubmit(data => {
190
+ return onSubmit?.(data);
191
+ }),
192
+ sx,
193
+ children
194
+ })
195
+ });
196
+ };
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");
@@ -637,6 +636,7 @@ var FormGroupWrapper = ({
637
636
  title,
638
637
  direction,
639
638
  children,
639
+ name,
640
640
  ...boxProps
641
641
  }) => {
642
642
  const {
@@ -677,6 +677,8 @@ var FormGroupWrapper = ({
677
677
  }), /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Flex, {
678
678
  sx: childrenContainerSx,
679
679
  children
680
+ }), name && /* @__PURE__ */(0, import_jsx_runtime14.jsx)(ErrorMessage, {
681
+ name
680
682
  })]
681
683
  });
682
684
  };
@@ -87,6 +87,7 @@ var import_ui17 = require("@ttoss/ui");
87
87
  var src_exports = {};
88
88
  __export(src_exports, {
89
89
  Controller: () => import_react_hook_form6.Controller,
90
+ ErrorMessage: () => ErrorMessage,
90
91
  Form: () => Form,
91
92
  FormField: () => FormField,
92
93
  FormFieldCheckbox: () => FormFieldCheckbox,
@@ -209,39 +210,12 @@ yup.addMethod(yup.string, "cnpj", function () {
209
210
  // src/yup/yup.ts
210
211
  var yup2 = __toESM(require("yup"));
211
212
 
212
- // src/Form.tsx
213
- var import_ui3 = require("@ttoss/ui");
214
- var import_react_hook_form = require("react-hook-form");
215
- var import_jsx_runtime3 = require("react/jsx-runtime");
216
- var Form = ({
217
- children,
218
- onSubmit,
219
- sx,
220
- ...formMethods
221
- }) => {
222
- return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_react_hook_form.FormProvider, {
223
- ...formMethods,
224
- children: /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.Box, {
225
- as: "form",
226
- variant: "forms.form",
227
- onSubmit: formMethods.handleSubmit(data => {
228
- return onSubmit?.(data);
229
- }),
230
- sx,
231
- children
232
- })
233
- });
234
- };
235
-
236
- // src/FormField.tsx
237
- var React = __toESM(require("react"));
238
-
239
213
  // src/ErrorMessage.tsx
240
- var import_react_hook_form2 = require("react-hook-form");
214
+ var import_react_hook_form = require("react-hook-form");
241
215
  var import_react_i18n2 = require("@ttoss/react-i18n");
242
- var import_ui4 = require("@ttoss/ui");
216
+ var import_ui3 = require("@ttoss/ui");
243
217
  var import_error_message = require("@hookform/error-message");
244
- var import_jsx_runtime4 = require("react/jsx-runtime");
218
+ var import_jsx_runtime3 = require("react/jsx-runtime");
245
219
  var isMessageDescriptor = possibleMessageDescriptor => {
246
220
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
247
221
  };
@@ -253,14 +227,14 @@ var ErrorMessage = ({
253
227
  formState: {
254
228
  errors
255
229
  }
256
- } = (0, import_react_hook_form2.useFormContext)();
257
- return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_error_message.ErrorMessage, {
230
+ } = (0, import_react_hook_form.useFormContext)();
231
+ return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_error_message.ErrorMessage, {
258
232
  name,
259
233
  errors,
260
234
  render: ({
261
235
  message
262
236
  }) => {
263
- return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_ui4.HelpText, {
237
+ return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.HelpText, {
264
238
  negative: true,
265
239
  disabled,
266
240
  children: (() => {
@@ -268,7 +242,7 @@ var ErrorMessage = ({
268
242
  return message;
269
243
  }
270
244
  if (isMessageDescriptor(message)) {
271
- return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_react_i18n2.FormattedMessage, {
245
+ return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_react_i18n2.FormattedMessage, {
272
246
  ...message
273
247
  });
274
248
  }
@@ -279,7 +253,32 @@ var ErrorMessage = ({
279
253
  });
280
254
  };
281
255
 
256
+ // src/Form.tsx
257
+ var import_ui4 = require("@ttoss/ui");
258
+ var import_react_hook_form2 = require("react-hook-form");
259
+ var import_jsx_runtime4 = require("react/jsx-runtime");
260
+ var Form = ({
261
+ children,
262
+ onSubmit,
263
+ sx,
264
+ ...formMethods
265
+ }) => {
266
+ return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_react_hook_form2.FormProvider, {
267
+ ...formMethods,
268
+ children: /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_ui4.Box, {
269
+ as: "form",
270
+ variant: "forms.form",
271
+ onSubmit: formMethods.handleSubmit(data => {
272
+ return onSubmit?.(data);
273
+ }),
274
+ sx,
275
+ children
276
+ })
277
+ });
278
+ };
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");
@@ -719,6 +718,7 @@ var FormGroupWrapper = ({
719
718
  title,
720
719
  direction,
721
720
  children,
721
+ name,
722
722
  ...boxProps
723
723
  }) => {
724
724
  const {
@@ -759,6 +759,8 @@ var FormGroupWrapper = ({
759
759
  }), /* @__PURE__ */(0, import_jsx_runtime16.jsx)(import_ui14.Flex, {
760
760
  sx: childrenContainerSx,
761
761
  children
762
+ }), name && /* @__PURE__ */(0, import_jsx_runtime16.jsx)(ErrorMessage, {
763
+ name
762
764
  })]
763
765
  });
764
766
  };
@@ -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-FGWZI374.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-FGWZI374.js";
3
3
 
4
4
  // src/MultistepForm/MultistepForm.tsx
5
5
  import * as React3 from "react";
@@ -154,39 +154,12 @@ yup.addMethod(yup.string, "cnpj", function () {
154
154
  // src/yup/yup.ts
155
155
  import * as yup2 from "yup";
156
156
 
157
- // src/Form.tsx
158
- import { Box } from "@ttoss/ui";
159
- import { FormProvider } from "react-hook-form";
160
- import { jsx as jsx2 } from "react/jsx-runtime";
161
- var Form = ({
162
- children,
163
- onSubmit,
164
- sx,
165
- ...formMethods
166
- }) => {
167
- return /* @__PURE__ */jsx2(FormProvider, {
168
- ...formMethods,
169
- children: /* @__PURE__ */jsx2(Box, {
170
- as: "form",
171
- variant: "forms.form",
172
- onSubmit: formMethods.handleSubmit(data => {
173
- return onSubmit?.(data);
174
- }),
175
- sx,
176
- children
177
- })
178
- });
179
- };
180
-
181
- // src/FormField.tsx
182
- import * as React from "react";
183
-
184
157
  // src/ErrorMessage.tsx
185
158
  import { useFormContext } from "react-hook-form";
186
159
  import { FormattedMessage } from "@ttoss/react-i18n";
187
160
  import { HelpText } from "@ttoss/ui";
188
161
  import { ErrorMessage as HookformErrorMessage } from "@hookform/error-message";
189
- import { jsx as jsx3 } from "react/jsx-runtime";
162
+ import { jsx as jsx2 } from "react/jsx-runtime";
190
163
  var isMessageDescriptor = possibleMessageDescriptor => {
191
164
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
192
165
  };
@@ -199,13 +172,13 @@ var ErrorMessage = ({
199
172
  errors
200
173
  }
201
174
  } = useFormContext();
202
- return /* @__PURE__ */jsx3(HookformErrorMessage, {
175
+ return /* @__PURE__ */jsx2(HookformErrorMessage, {
203
176
  name,
204
177
  errors,
205
178
  render: ({
206
179
  message
207
180
  }) => {
208
- return /* @__PURE__ */jsx3(HelpText, {
181
+ return /* @__PURE__ */jsx2(HelpText, {
209
182
  negative: true,
210
183
  disabled,
211
184
  children: (() => {
@@ -213,7 +186,7 @@ var ErrorMessage = ({
213
186
  return message;
214
187
  }
215
188
  if (isMessageDescriptor(message)) {
216
- return /* @__PURE__ */jsx3(FormattedMessage, {
189
+ return /* @__PURE__ */jsx2(FormattedMessage, {
217
190
  ...message
218
191
  });
219
192
  }
@@ -224,7 +197,32 @@ var ErrorMessage = ({
224
197
  });
225
198
  };
226
199
 
200
+ // src/Form.tsx
201
+ import { Box } from "@ttoss/ui";
202
+ import { FormProvider } from "react-hook-form";
203
+ import { jsx as jsx3 } from "react/jsx-runtime";
204
+ var Form = ({
205
+ children,
206
+ onSubmit,
207
+ sx,
208
+ ...formMethods
209
+ }) => {
210
+ return /* @__PURE__ */jsx3(FormProvider, {
211
+ ...formMethods,
212
+ children: /* @__PURE__ */jsx3(Box, {
213
+ as: "form",
214
+ variant: "forms.form",
215
+ onSubmit: formMethods.handleSubmit(data => {
216
+ return onSubmit?.(data);
217
+ }),
218
+ sx,
219
+ children
220
+ })
221
+ });
222
+ };
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";
@@ -664,6 +662,7 @@ var FormGroupWrapper = ({
664
662
  title,
665
663
  direction,
666
664
  children,
665
+ name,
667
666
  ...boxProps
668
667
  }) => {
669
668
  const {
@@ -704,6 +703,8 @@ var FormGroupWrapper = ({
704
703
  }), /* @__PURE__ */jsx15(Flex4, {
705
704
  sx: childrenContainerSx,
706
705
  children
706
+ }), name && /* @__PURE__ */jsx15(ErrorMessage, {
707
+ name
707
708
  })]
708
709
  });
709
710
  };
@@ -729,4 +730,4 @@ var FormGroup = props => {
729
730
  // src/index.ts
730
731
  import { useForm, useFormContext as useFormContext2, useWatch, useFieldArray, useController as useController4, useFormState, Controller, FormProvider as FormProvider2 } from "react-hook-form";
731
732
  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 };
733
+ export { __publicField, isCnpjValid, FormFieldCNPJ, yup2 as yup, ErrorMessage, 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 };
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, ErrorMessage, 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-FGWZI374.js";
3
+ export { Controller, ErrorMessage, Form, 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
@@ -3,15 +3,20 @@ import './typings.d-HZBqJJjn.mjs';
3
3
  import * as yup from 'yup';
4
4
  export { yup };
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import * as React from 'react';
7
- import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
8
- import { FieldValues, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
6
+ import { FieldValues, FieldName, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
9
7
  export * from 'react-hook-form';
10
8
  export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
9
+ import * as React from 'react';
10
+ import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
11
11
  import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-CkcL14ho.mjs';
12
12
  export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-CkcL14ho.mjs';
13
13
  import { NumericFormatProps } from 'react-number-format';
14
14
 
15
+ declare const ErrorMessage: <TFieldValues extends FieldValues = FieldValues>({ name, disabled, }: {
16
+ name: FieldName<TFieldValues>;
17
+ disabled?: boolean;
18
+ }) => react_jsx_runtime.JSX.Element;
19
+
15
20
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
16
21
  children?: React.ReactNode;
17
22
  onSubmit?: (data: TFieldValues) => Promise<void> | void;
@@ -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 { ErrorMessage, Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.d.ts CHANGED
@@ -3,15 +3,20 @@ import './typings.d-HZBqJJjn.js';
3
3
  import * as yup from 'yup';
4
4
  export { yup };
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import * as React from 'react';
7
- import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
8
- import { FieldValues, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
6
+ import { FieldValues, FieldName, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
9
7
  export * from 'react-hook-form';
10
8
  export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
9
+ import * as React from 'react';
10
+ import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
11
11
  import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-CkcL14ho.js';
12
12
  export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-CkcL14ho.js';
13
13
  import { NumericFormatProps } from 'react-number-format';
14
14
 
15
+ declare const ErrorMessage: <TFieldValues extends FieldValues = FieldValues>({ name, disabled, }: {
16
+ name: FieldName<TFieldValues>;
17
+ disabled?: boolean;
18
+ }) => react_jsx_runtime.JSX.Element;
19
+
15
20
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
16
21
  children?: React.ReactNode;
17
22
  onSubmit?: (data: TFieldValues) => Promise<void> | void;
@@ -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 { ErrorMessage, Form, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
40
40
  var src_exports = {};
41
41
  __export(src_exports, {
42
42
  Controller: () => import_react_hook_form6.Controller,
43
+ ErrorMessage: () => ErrorMessage,
43
44
  Form: () => Form,
44
45
  FormField: () => FormField,
45
46
  FormFieldCheckbox: () => FormFieldCheckbox,
@@ -163,39 +164,12 @@ yup.addMethod(yup.string, "cnpj", function () {
163
164
  // src/yup/yup.ts
164
165
  var yup2 = __toESM(require("yup"));
165
166
 
166
- // src/Form.tsx
167
- var import_ui2 = require("@ttoss/ui");
168
- var import_react_hook_form = require("react-hook-form");
169
- var import_jsx_runtime2 = require("react/jsx-runtime");
170
- var Form = ({
171
- children,
172
- onSubmit,
173
- sx,
174
- ...formMethods
175
- }) => {
176
- return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_react_hook_form.FormProvider, {
177
- ...formMethods,
178
- children: /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.Box, {
179
- as: "form",
180
- variant: "forms.form",
181
- onSubmit: formMethods.handleSubmit(data => {
182
- return onSubmit?.(data);
183
- }),
184
- sx,
185
- children
186
- })
187
- });
188
- };
189
-
190
- // src/FormField.tsx
191
- var React = __toESM(require("react"));
192
-
193
167
  // src/ErrorMessage.tsx
194
- var import_react_hook_form2 = require("react-hook-form");
168
+ var import_react_hook_form = require("react-hook-form");
195
169
  var import_react_i18n2 = require("@ttoss/react-i18n");
196
- var import_ui3 = require("@ttoss/ui");
170
+ var import_ui2 = require("@ttoss/ui");
197
171
  var import_error_message = require("@hookform/error-message");
198
- var import_jsx_runtime3 = require("react/jsx-runtime");
172
+ var import_jsx_runtime2 = require("react/jsx-runtime");
199
173
  var isMessageDescriptor = possibleMessageDescriptor => {
200
174
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
201
175
  };
@@ -207,14 +181,14 @@ var ErrorMessage = ({
207
181
  formState: {
208
182
  errors
209
183
  }
210
- } = (0, import_react_hook_form2.useFormContext)();
211
- return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_error_message.ErrorMessage, {
184
+ } = (0, import_react_hook_form.useFormContext)();
185
+ return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_error_message.ErrorMessage, {
212
186
  name,
213
187
  errors,
214
188
  render: ({
215
189
  message
216
190
  }) => {
217
- return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.HelpText, {
191
+ return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.HelpText, {
218
192
  negative: true,
219
193
  disabled,
220
194
  children: (() => {
@@ -222,7 +196,7 @@ var ErrorMessage = ({
222
196
  return message;
223
197
  }
224
198
  if (isMessageDescriptor(message)) {
225
- return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_react_i18n2.FormattedMessage, {
199
+ return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_react_i18n2.FormattedMessage, {
226
200
  ...message
227
201
  });
228
202
  }
@@ -233,7 +207,32 @@ var ErrorMessage = ({
233
207
  });
234
208
  };
235
209
 
210
+ // src/Form.tsx
211
+ var import_ui3 = require("@ttoss/ui");
212
+ var import_react_hook_form2 = require("react-hook-form");
213
+ var import_jsx_runtime3 = require("react/jsx-runtime");
214
+ var Form = ({
215
+ children,
216
+ onSubmit,
217
+ sx,
218
+ ...formMethods
219
+ }) => {
220
+ return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_react_hook_form2.FormProvider, {
221
+ ...formMethods,
222
+ children: /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.Box, {
223
+ as: "form",
224
+ variant: "forms.form",
225
+ onSubmit: formMethods.handleSubmit(data => {
226
+ return onSubmit?.(data);
227
+ }),
228
+ sx,
229
+ children
230
+ })
231
+ });
232
+ };
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");
@@ -673,6 +672,7 @@ var FormGroupWrapper = ({
673
672
  title,
674
673
  direction,
675
674
  children,
675
+ name,
676
676
  ...boxProps
677
677
  }) => {
678
678
  const {
@@ -713,6 +713,8 @@ var FormGroupWrapper = ({
713
713
  }), /* @__PURE__ */(0, import_jsx_runtime15.jsx)(import_ui13.Flex, {
714
714
  sx: childrenContainerSx,
715
715
  children
716
+ }), name && /* @__PURE__ */(0, import_jsx_runtime15.jsx)(ErrorMessage, {
717
+ name
716
718
  })]
717
719
  });
718
720
  };
@@ -741,6 +743,7 @@ __reExport(src_exports, require("react-hook-form"), module.exports);
741
743
  // Annotate the CommonJS export names for ESM import in node:
742
744
  0 && (module.exports = {
743
745
  Controller,
746
+ ErrorMessage,
744
747
  Form,
745
748
  FormField,
746
749
  FormFieldCheckbox,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.23.7",
3
+ "version": "0.24.0",
4
4
  "author": "ttoss",
5
5
  "contributors": [
6
6
  "Pedro Arantes <pedro@arantespp.com> (https://arantespp.com/contact)"
@@ -35,7 +35,7 @@
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
  },
@@ -54,11 +54,11 @@
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
58
  "@ttoss/react-icons": "^0.3.6",
60
59
  "@ttoss/test-utils": "^2.1.6",
61
- "@ttoss/ui": "^4.1.9"
60
+ "@ttoss/ui": "^4.1.9",
61
+ "@ttoss/react-i18n": "^1.26.7"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public",
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 { ErrorMessage } from './ErrorMessage';
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 && <ErrorMessage name={name} />}
112
116
  </Box>
113
117
  );
114
118
  };
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { yupResolver } from '@hookform/resolvers/yup';
2
2
  export { yup } from './yup/yup';
3
3
 
4
+ export { ErrorMessage } from './ErrorMessage';
4
5
  export { Form } from './Form';
5
6
  export { FormField } from './FormField';
6
7
  export { FormFieldCheckbox } from './FormFieldCheckbox';