@ttoss/forms 0.24.0 → 0.24.2
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/dist/Brazil/index.js +40 -38
- package/dist/MultistepForm/index.js +40 -38
- package/dist/esm/Brazil/index.js +1 -1
- package/dist/esm/MultistepForm/index.js +1 -1
- package/dist/esm/{chunk-FGWZI374.js → chunk-CDQJBSC2.js} +38 -36
- package/dist/esm/index.js +2 -2
- package/dist/index.d.mts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +41 -39
- package/package.json +9 -9
- package/src/{ErrorMessage.tsx → FormErrorMessage.tsx} +5 -3
- package/src/FormField.tsx +2 -2
- package/src/FormFieldCheckbox.tsx +4 -3
- package/src/FormFieldRadio.tsx +3 -2
- package/src/FormGroup.tsx +2 -2
- package/src/index.ts +1 -1
package/dist/Brazil/index.js
CHANGED
|
@@ -50,8 +50,8 @@ 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,
|
|
54
53
|
Form: () => Form,
|
|
54
|
+
FormErrorMessage: () => FormErrorMessage,
|
|
55
55
|
FormField: () => FormField,
|
|
56
56
|
FormFieldCheckbox: () => FormFieldCheckbox,
|
|
57
57
|
FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
|
|
@@ -128,16 +128,40 @@ yup.addMethod(yup.string, "cnpj", function () {
|
|
|
128
128
|
// src/yup/yup.ts
|
|
129
129
|
var yup2 = __toESM(require("yup"));
|
|
130
130
|
|
|
131
|
-
// src/
|
|
132
|
-
var import_react_hook_form = require("react-hook-form");
|
|
133
|
-
var import_react_i18n2 = require("@ttoss/react-i18n");
|
|
131
|
+
// src/Form.tsx
|
|
134
132
|
var import_ui = require("@ttoss/ui");
|
|
135
|
-
var
|
|
133
|
+
var import_react_hook_form = require("react-hook-form");
|
|
136
134
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
135
|
+
var Form = ({
|
|
136
|
+
children,
|
|
137
|
+
onSubmit,
|
|
138
|
+
sx,
|
|
139
|
+
...formMethods
|
|
140
|
+
}) => {
|
|
141
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react_hook_form.FormProvider, {
|
|
142
|
+
...formMethods,
|
|
143
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.Box, {
|
|
144
|
+
as: "form",
|
|
145
|
+
variant: "forms.form",
|
|
146
|
+
onSubmit: formMethods.handleSubmit(data => {
|
|
147
|
+
return onSubmit?.(data);
|
|
148
|
+
}),
|
|
149
|
+
sx,
|
|
150
|
+
children
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/FormErrorMessage.tsx
|
|
156
|
+
var import_error_message = require("@hookform/error-message");
|
|
157
|
+
var import_react_hook_form2 = require("react-hook-form");
|
|
158
|
+
var import_react_i18n2 = require("@ttoss/react-i18n");
|
|
159
|
+
var import_ui2 = require("@ttoss/ui");
|
|
160
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
137
161
|
var isMessageDescriptor = possibleMessageDescriptor => {
|
|
138
162
|
return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
|
|
139
163
|
};
|
|
140
|
-
var
|
|
164
|
+
var FormErrorMessage = ({
|
|
141
165
|
name,
|
|
142
166
|
disabled
|
|
143
167
|
}) => {
|
|
@@ -145,14 +169,14 @@ var ErrorMessage = ({
|
|
|
145
169
|
formState: {
|
|
146
170
|
errors
|
|
147
171
|
}
|
|
148
|
-
} = (0,
|
|
149
|
-
return /* @__PURE__ */(0,
|
|
172
|
+
} = (0, import_react_hook_form2.useFormContext)();
|
|
173
|
+
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_error_message.ErrorMessage, {
|
|
150
174
|
name,
|
|
151
175
|
errors,
|
|
152
176
|
render: ({
|
|
153
177
|
message
|
|
154
178
|
}) => {
|
|
155
|
-
return /* @__PURE__ */(0,
|
|
179
|
+
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.HelpText, {
|
|
156
180
|
negative: true,
|
|
157
181
|
disabled,
|
|
158
182
|
children: (() => {
|
|
@@ -160,7 +184,7 @@ var ErrorMessage = ({
|
|
|
160
184
|
return message;
|
|
161
185
|
}
|
|
162
186
|
if (isMessageDescriptor(message)) {
|
|
163
|
-
return /* @__PURE__ */(0,
|
|
187
|
+
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_react_i18n2.FormattedMessage, {
|
|
164
188
|
...message
|
|
165
189
|
});
|
|
166
190
|
}
|
|
@@ -171,30 +195,6 @@ var ErrorMessage = ({
|
|
|
171
195
|
});
|
|
172
196
|
};
|
|
173
197
|
|
|
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
|
-
|
|
198
198
|
// src/FormField.tsx
|
|
199
199
|
var React = __toESM(require("react"));
|
|
200
200
|
var import_react_hook_form3 = require("react-hook-form");
|
|
@@ -241,7 +241,7 @@ var FormField = ({
|
|
|
241
241
|
...sx
|
|
242
242
|
},
|
|
243
243
|
css,
|
|
244
|
-
children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime3.jsx)(
|
|
244
|
+
children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime3.jsx)(FormErrorMessage, {
|
|
245
245
|
name
|
|
246
246
|
})]
|
|
247
247
|
});
|
|
@@ -267,6 +267,7 @@ var FormFieldCheckbox = ({
|
|
|
267
267
|
formState: {
|
|
268
268
|
errors
|
|
269
269
|
}
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
270
271
|
} = (0, import_react_hook_form4.useController)({
|
|
271
272
|
name,
|
|
272
273
|
defaultValue: false
|
|
@@ -297,7 +298,7 @@ var FormFieldCheckbox = ({
|
|
|
297
298
|
...checkboxProps
|
|
298
299
|
}), label]
|
|
299
300
|
})
|
|
300
|
-
}), /* @__PURE__ */(0, import_jsx_runtime4.jsx)(
|
|
301
|
+
}), /* @__PURE__ */(0, import_jsx_runtime4.jsx)(FormErrorMessage, {
|
|
301
302
|
name
|
|
302
303
|
})]
|
|
303
304
|
});
|
|
@@ -487,6 +488,7 @@ var FormFieldRadio = ({
|
|
|
487
488
|
value,
|
|
488
489
|
ref
|
|
489
490
|
}
|
|
491
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
490
492
|
} = (0, import_react_hook_form5.useController)({
|
|
491
493
|
name,
|
|
492
494
|
defaultValue: ""
|
|
@@ -519,7 +521,7 @@ var FormFieldRadio = ({
|
|
|
519
521
|
}), option.label]
|
|
520
522
|
}, id);
|
|
521
523
|
})
|
|
522
|
-
}), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(
|
|
524
|
+
}), /* @__PURE__ */(0, import_jsx_runtime11.jsx)(FormErrorMessage, {
|
|
523
525
|
name
|
|
524
526
|
})]
|
|
525
527
|
});
|
|
@@ -677,7 +679,7 @@ var FormGroupWrapper = ({
|
|
|
677
679
|
}), /* @__PURE__ */(0, import_jsx_runtime14.jsx)(import_ui12.Flex, {
|
|
678
680
|
sx: childrenContainerSx,
|
|
679
681
|
children
|
|
680
|
-
}), name && /* @__PURE__ */(0, import_jsx_runtime14.jsx)(
|
|
682
|
+
}), name && /* @__PURE__ */(0, import_jsx_runtime14.jsx)(FormErrorMessage, {
|
|
681
683
|
name
|
|
682
684
|
})]
|
|
683
685
|
});
|
|
@@ -87,8 +87,8 @@ 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,
|
|
91
90
|
Form: () => Form,
|
|
91
|
+
FormErrorMessage: () => FormErrorMessage,
|
|
92
92
|
FormField: () => FormField,
|
|
93
93
|
FormFieldCheckbox: () => FormFieldCheckbox,
|
|
94
94
|
FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
|
|
@@ -210,16 +210,40 @@ yup.addMethod(yup.string, "cnpj", function () {
|
|
|
210
210
|
// src/yup/yup.ts
|
|
211
211
|
var yup2 = __toESM(require("yup"));
|
|
212
212
|
|
|
213
|
-
// src/
|
|
214
|
-
var import_react_hook_form = require("react-hook-form");
|
|
215
|
-
var import_react_i18n2 = require("@ttoss/react-i18n");
|
|
213
|
+
// src/Form.tsx
|
|
216
214
|
var import_ui3 = require("@ttoss/ui");
|
|
217
|
-
var
|
|
215
|
+
var import_react_hook_form = require("react-hook-form");
|
|
218
216
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
217
|
+
var Form = ({
|
|
218
|
+
children,
|
|
219
|
+
onSubmit,
|
|
220
|
+
sx,
|
|
221
|
+
...formMethods
|
|
222
|
+
}) => {
|
|
223
|
+
return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_react_hook_form.FormProvider, {
|
|
224
|
+
...formMethods,
|
|
225
|
+
children: /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.Box, {
|
|
226
|
+
as: "form",
|
|
227
|
+
variant: "forms.form",
|
|
228
|
+
onSubmit: formMethods.handleSubmit(data => {
|
|
229
|
+
return onSubmit?.(data);
|
|
230
|
+
}),
|
|
231
|
+
sx,
|
|
232
|
+
children
|
|
233
|
+
})
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/FormErrorMessage.tsx
|
|
238
|
+
var import_error_message = require("@hookform/error-message");
|
|
239
|
+
var import_react_hook_form2 = require("react-hook-form");
|
|
240
|
+
var import_react_i18n2 = require("@ttoss/react-i18n");
|
|
241
|
+
var import_ui4 = require("@ttoss/ui");
|
|
242
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
219
243
|
var isMessageDescriptor = possibleMessageDescriptor => {
|
|
220
244
|
return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
|
|
221
245
|
};
|
|
222
|
-
var
|
|
246
|
+
var FormErrorMessage = ({
|
|
223
247
|
name,
|
|
224
248
|
disabled
|
|
225
249
|
}) => {
|
|
@@ -227,14 +251,14 @@ var ErrorMessage = ({
|
|
|
227
251
|
formState: {
|
|
228
252
|
errors
|
|
229
253
|
}
|
|
230
|
-
} = (0,
|
|
231
|
-
return /* @__PURE__ */(0,
|
|
254
|
+
} = (0, import_react_hook_form2.useFormContext)();
|
|
255
|
+
return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_error_message.ErrorMessage, {
|
|
232
256
|
name,
|
|
233
257
|
errors,
|
|
234
258
|
render: ({
|
|
235
259
|
message
|
|
236
260
|
}) => {
|
|
237
|
-
return /* @__PURE__ */(0,
|
|
261
|
+
return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_ui4.HelpText, {
|
|
238
262
|
negative: true,
|
|
239
263
|
disabled,
|
|
240
264
|
children: (() => {
|
|
@@ -242,7 +266,7 @@ var ErrorMessage = ({
|
|
|
242
266
|
return message;
|
|
243
267
|
}
|
|
244
268
|
if (isMessageDescriptor(message)) {
|
|
245
|
-
return /* @__PURE__ */(0,
|
|
269
|
+
return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_react_i18n2.FormattedMessage, {
|
|
246
270
|
...message
|
|
247
271
|
});
|
|
248
272
|
}
|
|
@@ -253,30 +277,6 @@ var ErrorMessage = ({
|
|
|
253
277
|
});
|
|
254
278
|
};
|
|
255
279
|
|
|
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
|
-
|
|
280
280
|
// src/FormField.tsx
|
|
281
281
|
var React = __toESM(require("react"));
|
|
282
282
|
var import_react_hook_form3 = require("react-hook-form");
|
|
@@ -323,7 +323,7 @@ var FormField = ({
|
|
|
323
323
|
...sx
|
|
324
324
|
},
|
|
325
325
|
css,
|
|
326
|
-
children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime5.jsx)(
|
|
326
|
+
children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormErrorMessage, {
|
|
327
327
|
name
|
|
328
328
|
})]
|
|
329
329
|
});
|
|
@@ -349,6 +349,7 @@ var FormFieldCheckbox = ({
|
|
|
349
349
|
formState: {
|
|
350
350
|
errors
|
|
351
351
|
}
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
352
353
|
} = (0, import_react_hook_form4.useController)({
|
|
353
354
|
name,
|
|
354
355
|
defaultValue: false
|
|
@@ -379,7 +380,7 @@ var FormFieldCheckbox = ({
|
|
|
379
380
|
...checkboxProps
|
|
380
381
|
}), label]
|
|
381
382
|
})
|
|
382
|
-
}), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(
|
|
383
|
+
}), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(FormErrorMessage, {
|
|
383
384
|
name
|
|
384
385
|
})]
|
|
385
386
|
});
|
|
@@ -569,6 +570,7 @@ var FormFieldRadio = ({
|
|
|
569
570
|
value,
|
|
570
571
|
ref
|
|
571
572
|
}
|
|
573
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
572
574
|
} = (0, import_react_hook_form5.useController)({
|
|
573
575
|
name,
|
|
574
576
|
defaultValue: ""
|
|
@@ -601,7 +603,7 @@ var FormFieldRadio = ({
|
|
|
601
603
|
}), option.label]
|
|
602
604
|
}, id);
|
|
603
605
|
})
|
|
604
|
-
}), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(
|
|
606
|
+
}), /* @__PURE__ */(0, import_jsx_runtime13.jsx)(FormErrorMessage, {
|
|
605
607
|
name
|
|
606
608
|
})]
|
|
607
609
|
});
|
|
@@ -759,7 +761,7 @@ var FormGroupWrapper = ({
|
|
|
759
761
|
}), /* @__PURE__ */(0, import_jsx_runtime16.jsx)(import_ui14.Flex, {
|
|
760
762
|
sx: childrenContainerSx,
|
|
761
763
|
children
|
|
762
|
-
}), name && /* @__PURE__ */(0, import_jsx_runtime16.jsx)(
|
|
764
|
+
}), name && /* @__PURE__ */(0, import_jsx_runtime16.jsx)(FormErrorMessage, {
|
|
763
765
|
name
|
|
764
766
|
})]
|
|
765
767
|
});
|
package/dist/esm/Brazil/index.js
CHANGED
|
@@ -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-
|
|
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-
|
|
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";
|
|
@@ -154,16 +154,40 @@ yup.addMethod(yup.string, "cnpj", function () {
|
|
|
154
154
|
// src/yup/yup.ts
|
|
155
155
|
import * as yup2 from "yup";
|
|
156
156
|
|
|
157
|
-
// src/
|
|
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/FormErrorMessage.tsx
|
|
182
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
158
183
|
import { useFormContext } from "react-hook-form";
|
|
159
184
|
import { FormattedMessage } from "@ttoss/react-i18n";
|
|
160
185
|
import { HelpText } from "@ttoss/ui";
|
|
161
|
-
import {
|
|
162
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
186
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
163
187
|
var isMessageDescriptor = possibleMessageDescriptor => {
|
|
164
188
|
return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
|
|
165
189
|
};
|
|
166
|
-
var
|
|
190
|
+
var FormErrorMessage = ({
|
|
167
191
|
name,
|
|
168
192
|
disabled
|
|
169
193
|
}) => {
|
|
@@ -172,13 +196,13 @@ var ErrorMessage = ({
|
|
|
172
196
|
errors
|
|
173
197
|
}
|
|
174
198
|
} = useFormContext();
|
|
175
|
-
return /* @__PURE__ */
|
|
199
|
+
return /* @__PURE__ */jsx3(ErrorMessage, {
|
|
176
200
|
name,
|
|
177
201
|
errors,
|
|
178
202
|
render: ({
|
|
179
203
|
message
|
|
180
204
|
}) => {
|
|
181
|
-
return /* @__PURE__ */
|
|
205
|
+
return /* @__PURE__ */jsx3(HelpText, {
|
|
182
206
|
negative: true,
|
|
183
207
|
disabled,
|
|
184
208
|
children: (() => {
|
|
@@ -186,7 +210,7 @@ var ErrorMessage = ({
|
|
|
186
210
|
return message;
|
|
187
211
|
}
|
|
188
212
|
if (isMessageDescriptor(message)) {
|
|
189
|
-
return /* @__PURE__ */
|
|
213
|
+
return /* @__PURE__ */jsx3(FormattedMessage, {
|
|
190
214
|
...message
|
|
191
215
|
});
|
|
192
216
|
}
|
|
@@ -197,30 +221,6 @@ var ErrorMessage = ({
|
|
|
197
221
|
});
|
|
198
222
|
};
|
|
199
223
|
|
|
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
|
-
|
|
224
224
|
// src/FormField.tsx
|
|
225
225
|
import * as React from "react";
|
|
226
226
|
import { useController } from "react-hook-form";
|
|
@@ -267,7 +267,7 @@ var FormField = ({
|
|
|
267
267
|
...sx
|
|
268
268
|
},
|
|
269
269
|
css,
|
|
270
|
-
children: [memoizedRender, /* @__PURE__ */jsx4(
|
|
270
|
+
children: [memoizedRender, /* @__PURE__ */jsx4(FormErrorMessage, {
|
|
271
271
|
name
|
|
272
272
|
})]
|
|
273
273
|
});
|
|
@@ -293,6 +293,7 @@ var FormFieldCheckbox = ({
|
|
|
293
293
|
formState: {
|
|
294
294
|
errors
|
|
295
295
|
}
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
296
297
|
} = useController2({
|
|
297
298
|
name,
|
|
298
299
|
defaultValue: false
|
|
@@ -323,7 +324,7 @@ var FormFieldCheckbox = ({
|
|
|
323
324
|
...checkboxProps
|
|
324
325
|
}), label]
|
|
325
326
|
})
|
|
326
|
-
}), /* @__PURE__ */jsx5(
|
|
327
|
+
}), /* @__PURE__ */jsx5(FormErrorMessage, {
|
|
327
328
|
name
|
|
328
329
|
})]
|
|
329
330
|
});
|
|
@@ -513,6 +514,7 @@ var FormFieldRadio = ({
|
|
|
513
514
|
value,
|
|
514
515
|
ref
|
|
515
516
|
}
|
|
517
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
516
518
|
} = useController3({
|
|
517
519
|
name,
|
|
518
520
|
defaultValue: ""
|
|
@@ -545,7 +547,7 @@ var FormFieldRadio = ({
|
|
|
545
547
|
}), option.label]
|
|
546
548
|
}, id);
|
|
547
549
|
})
|
|
548
|
-
}), /* @__PURE__ */jsx12(
|
|
550
|
+
}), /* @__PURE__ */jsx12(FormErrorMessage, {
|
|
549
551
|
name
|
|
550
552
|
})]
|
|
551
553
|
});
|
|
@@ -703,7 +705,7 @@ var FormGroupWrapper = ({
|
|
|
703
705
|
}), /* @__PURE__ */jsx15(Flex4, {
|
|
704
706
|
sx: childrenContainerSx,
|
|
705
707
|
children
|
|
706
|
-
}), name && /* @__PURE__ */jsx15(
|
|
708
|
+
}), name && /* @__PURE__ */jsx15(FormErrorMessage, {
|
|
707
709
|
name
|
|
708
710
|
})]
|
|
709
711
|
});
|
|
@@ -730,4 +732,4 @@ var FormGroup = props => {
|
|
|
730
732
|
// src/index.ts
|
|
731
733
|
import { useForm, useFormContext as useFormContext2, useWatch, useFieldArray, useController as useController4, useFormState, Controller, FormProvider as FormProvider2 } from "react-hook-form";
|
|
732
734
|
export * from "react-hook-form";
|
|
733
|
-
export { __publicField, isCnpjValid, FormFieldCNPJ, yup2 as yup,
|
|
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,
|
|
3
|
-
export { Controller,
|
|
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
|
@@ -3,26 +3,26 @@ 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 { FieldValues, FieldName, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
|
|
7
|
-
export * from 'react-hook-form';
|
|
8
|
-
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
9
6
|
import * as React from 'react';
|
|
10
7
|
import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
|
|
8
|
+
import { FieldValues, FormProviderProps, FieldName, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
|
|
9
|
+
export * from 'react-hook-form';
|
|
10
|
+
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
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
|
-
|
|
20
15
|
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
21
16
|
children?: React.ReactNode;
|
|
22
17
|
onSubmit?: (data: TFieldValues) => Promise<void> | void;
|
|
23
18
|
sx?: BoxProps['sx'];
|
|
24
19
|
} & FormProviderProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
|
|
25
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
|
+
|
|
26
26
|
type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
27
27
|
label?: string;
|
|
28
28
|
id?: string;
|
|
@@ -104,4 +104,4 @@ type FormGroupProps = {
|
|
|
104
104
|
} & BoxProps;
|
|
105
105
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
106
106
|
|
|
107
|
-
export {
|
|
107
|
+
export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,26 +3,26 @@ 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 { FieldValues, FieldName, FormProviderProps, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
|
|
7
|
-
export * from 'react-hook-form';
|
|
8
|
-
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
9
6
|
import * as React from 'react';
|
|
10
7
|
import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
|
|
8
|
+
import { FieldValues, FormProviderProps, FieldName, FieldPath, UseControllerReturn, FieldPathValue } from 'react-hook-form';
|
|
9
|
+
export * from 'react-hook-form';
|
|
10
|
+
export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
|
|
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
|
-
|
|
20
15
|
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
21
16
|
children?: React.ReactNode;
|
|
22
17
|
onSubmit?: (data: TFieldValues) => Promise<void> | void;
|
|
23
18
|
sx?: BoxProps['sx'];
|
|
24
19
|
} & FormProviderProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
|
|
25
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
|
+
|
|
26
26
|
type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
|
|
27
27
|
label?: string;
|
|
28
28
|
id?: string;
|
|
@@ -104,4 +104,4 @@ type FormGroupProps = {
|
|
|
104
104
|
} & BoxProps;
|
|
105
105
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
106
106
|
|
|
107
|
-
export {
|
|
107
|
+
export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
package/dist/index.js
CHANGED
|
@@ -40,8 +40,8 @@ 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,
|
|
44
43
|
Form: () => Form,
|
|
44
|
+
FormErrorMessage: () => FormErrorMessage,
|
|
45
45
|
FormField: () => FormField,
|
|
46
46
|
FormFieldCheckbox: () => FormFieldCheckbox,
|
|
47
47
|
FormFieldCreditCardNumber: () => FormFieldCreditCardNumber,
|
|
@@ -164,16 +164,40 @@ yup.addMethod(yup.string, "cnpj", function () {
|
|
|
164
164
|
// src/yup/yup.ts
|
|
165
165
|
var yup2 = __toESM(require("yup"));
|
|
166
166
|
|
|
167
|
-
// src/
|
|
168
|
-
var import_react_hook_form = require("react-hook-form");
|
|
169
|
-
var import_react_i18n2 = require("@ttoss/react-i18n");
|
|
167
|
+
// src/Form.tsx
|
|
170
168
|
var import_ui2 = require("@ttoss/ui");
|
|
171
|
-
var
|
|
169
|
+
var import_react_hook_form = require("react-hook-form");
|
|
172
170
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
171
|
+
var Form = ({
|
|
172
|
+
children,
|
|
173
|
+
onSubmit,
|
|
174
|
+
sx,
|
|
175
|
+
...formMethods
|
|
176
|
+
}) => {
|
|
177
|
+
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_react_hook_form.FormProvider, {
|
|
178
|
+
...formMethods,
|
|
179
|
+
children: /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.Box, {
|
|
180
|
+
as: "form",
|
|
181
|
+
variant: "forms.form",
|
|
182
|
+
onSubmit: formMethods.handleSubmit(data => {
|
|
183
|
+
return onSubmit?.(data);
|
|
184
|
+
}),
|
|
185
|
+
sx,
|
|
186
|
+
children
|
|
187
|
+
})
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/FormErrorMessage.tsx
|
|
192
|
+
var import_error_message = require("@hookform/error-message");
|
|
193
|
+
var import_react_hook_form2 = require("react-hook-form");
|
|
194
|
+
var import_react_i18n2 = require("@ttoss/react-i18n");
|
|
195
|
+
var import_ui3 = require("@ttoss/ui");
|
|
196
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
173
197
|
var isMessageDescriptor = possibleMessageDescriptor => {
|
|
174
198
|
return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
|
|
175
199
|
};
|
|
176
|
-
var
|
|
200
|
+
var FormErrorMessage = ({
|
|
177
201
|
name,
|
|
178
202
|
disabled
|
|
179
203
|
}) => {
|
|
@@ -181,14 +205,14 @@ var ErrorMessage = ({
|
|
|
181
205
|
formState: {
|
|
182
206
|
errors
|
|
183
207
|
}
|
|
184
|
-
} = (0,
|
|
185
|
-
return /* @__PURE__ */(0,
|
|
208
|
+
} = (0, import_react_hook_form2.useFormContext)();
|
|
209
|
+
return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_error_message.ErrorMessage, {
|
|
186
210
|
name,
|
|
187
211
|
errors,
|
|
188
212
|
render: ({
|
|
189
213
|
message
|
|
190
214
|
}) => {
|
|
191
|
-
return /* @__PURE__ */(0,
|
|
215
|
+
return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.HelpText, {
|
|
192
216
|
negative: true,
|
|
193
217
|
disabled,
|
|
194
218
|
children: (() => {
|
|
@@ -196,7 +220,7 @@ var ErrorMessage = ({
|
|
|
196
220
|
return message;
|
|
197
221
|
}
|
|
198
222
|
if (isMessageDescriptor(message)) {
|
|
199
|
-
return /* @__PURE__ */(0,
|
|
223
|
+
return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_react_i18n2.FormattedMessage, {
|
|
200
224
|
...message
|
|
201
225
|
});
|
|
202
226
|
}
|
|
@@ -207,30 +231,6 @@ var ErrorMessage = ({
|
|
|
207
231
|
});
|
|
208
232
|
};
|
|
209
233
|
|
|
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
|
-
|
|
234
234
|
// src/FormField.tsx
|
|
235
235
|
var React = __toESM(require("react"));
|
|
236
236
|
var import_react_hook_form3 = require("react-hook-form");
|
|
@@ -277,7 +277,7 @@ var FormField = ({
|
|
|
277
277
|
...sx
|
|
278
278
|
},
|
|
279
279
|
css,
|
|
280
|
-
children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime4.jsx)(
|
|
280
|
+
children: [memoizedRender, /* @__PURE__ */(0, import_jsx_runtime4.jsx)(FormErrorMessage, {
|
|
281
281
|
name
|
|
282
282
|
})]
|
|
283
283
|
});
|
|
@@ -303,6 +303,7 @@ var FormFieldCheckbox = ({
|
|
|
303
303
|
formState: {
|
|
304
304
|
errors
|
|
305
305
|
}
|
|
306
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
306
307
|
} = (0, import_react_hook_form4.useController)({
|
|
307
308
|
name,
|
|
308
309
|
defaultValue: false
|
|
@@ -333,7 +334,7 @@ var FormFieldCheckbox = ({
|
|
|
333
334
|
...checkboxProps
|
|
334
335
|
}), label]
|
|
335
336
|
})
|
|
336
|
-
}), /* @__PURE__ */(0, import_jsx_runtime5.jsx)(
|
|
337
|
+
}), /* @__PURE__ */(0, import_jsx_runtime5.jsx)(FormErrorMessage, {
|
|
337
338
|
name
|
|
338
339
|
})]
|
|
339
340
|
});
|
|
@@ -523,6 +524,7 @@ var FormFieldRadio = ({
|
|
|
523
524
|
value,
|
|
524
525
|
ref
|
|
525
526
|
}
|
|
527
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
526
528
|
} = (0, import_react_hook_form5.useController)({
|
|
527
529
|
name,
|
|
528
530
|
defaultValue: ""
|
|
@@ -555,7 +557,7 @@ var FormFieldRadio = ({
|
|
|
555
557
|
}), option.label]
|
|
556
558
|
}, id);
|
|
557
559
|
})
|
|
558
|
-
}), /* @__PURE__ */(0, import_jsx_runtime12.jsx)(
|
|
560
|
+
}), /* @__PURE__ */(0, import_jsx_runtime12.jsx)(FormErrorMessage, {
|
|
559
561
|
name
|
|
560
562
|
})]
|
|
561
563
|
});
|
|
@@ -713,7 +715,7 @@ var FormGroupWrapper = ({
|
|
|
713
715
|
}), /* @__PURE__ */(0, import_jsx_runtime15.jsx)(import_ui13.Flex, {
|
|
714
716
|
sx: childrenContainerSx,
|
|
715
717
|
children
|
|
716
|
-
}), name && /* @__PURE__ */(0, import_jsx_runtime15.jsx)(
|
|
718
|
+
}), name && /* @__PURE__ */(0, import_jsx_runtime15.jsx)(FormErrorMessage, {
|
|
717
719
|
name
|
|
718
720
|
})]
|
|
719
721
|
});
|
|
@@ -743,8 +745,8 @@ __reExport(src_exports, require("react-hook-form"), module.exports);
|
|
|
743
745
|
// Annotate the CommonJS export names for ESM import in node:
|
|
744
746
|
0 && (module.exports = {
|
|
745
747
|
Controller,
|
|
746
|
-
ErrorMessage,
|
|
747
748
|
Form,
|
|
749
|
+
FormErrorMessage,
|
|
748
750
|
FormField,
|
|
749
751
|
FormFieldCheckbox,
|
|
750
752
|
FormFieldCreditCardNumber,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.2",
|
|
4
4
|
"author": "ttoss",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Pedro Arantes <pedro@arantespp.com> (https://arantespp.com/contact)"
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=16.8.0",
|
|
44
|
-
"@ttoss/react-i18n": "^1.26.
|
|
45
|
-
"@ttoss/ui": "^4.1.
|
|
44
|
+
"@ttoss/react-i18n": "^1.26.8",
|
|
45
|
+
"@ttoss/ui": "^4.1.10"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/jest": "^29.5.12",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"theme-ui": "^0.16.2",
|
|
54
54
|
"tsup": "^8.0.2",
|
|
55
55
|
"yup": "^1.4.0",
|
|
56
|
-
"@ttoss/config": "^1.32.
|
|
57
|
-
"@ttoss/i18n
|
|
58
|
-
"@ttoss/
|
|
59
|
-
"@ttoss/
|
|
60
|
-
"@ttoss/
|
|
61
|
-
"@ttoss/
|
|
56
|
+
"@ttoss/config": "^1.32.4",
|
|
57
|
+
"@ttoss/react-i18n": "^1.26.8",
|
|
58
|
+
"@ttoss/i18n-cli": "^0.7.12",
|
|
59
|
+
"@ttoss/react-icons": "^0.3.7",
|
|
60
|
+
"@ttoss/test-utils": "^2.1.7",
|
|
61
|
+
"@ttoss/ui": "^4.1.10"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public",
|
|
@@ -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
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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
|
-
<
|
|
46
|
+
<FormErrorMessage name={name} />
|
|
46
47
|
</Flex>
|
|
47
48
|
);
|
|
48
49
|
};
|
package/src/FormFieldRadio.tsx
CHANGED
|
@@ -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
|
-
<
|
|
54
|
+
<FormErrorMessage name={name} />
|
|
54
55
|
</Flex>
|
|
55
56
|
);
|
|
56
57
|
};
|
package/src/FormGroup.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Box, BoxProps, Flex, FlexProps, Text } from '@ttoss/ui';
|
|
3
|
-
import {
|
|
3
|
+
import { FormErrorMessage } from './FormErrorMessage';
|
|
4
4
|
|
|
5
5
|
type FormGroupLevelsManagerContextType = {
|
|
6
6
|
levelsLength: number;
|
|
@@ -112,7 +112,7 @@ const FormGroupWrapper = ({
|
|
|
112
112
|
</Box>
|
|
113
113
|
)}
|
|
114
114
|
<Flex sx={childrenContainerSx}>{children}</Flex>
|
|
115
|
-
{name && <
|
|
115
|
+
{name && <FormErrorMessage name={name} />}
|
|
116
116
|
</Box>
|
|
117
117
|
);
|
|
118
118
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { yupResolver } from '@hookform/resolvers/yup';
|
|
2
2
|
export { yup } from './yup/yup';
|
|
3
3
|
|
|
4
|
-
export { ErrorMessage } from './ErrorMessage';
|
|
5
4
|
export { Form } from './Form';
|
|
5
|
+
export { FormErrorMessage } from './FormErrorMessage';
|
|
6
6
|
export { FormField } from './FormField';
|
|
7
7
|
export { FormFieldCheckbox } from './FormFieldCheckbox';
|
|
8
8
|
export { FormFieldCreditCardNumber } from './FormFieldCreditCardNumber';
|