@ttoss/forms 0.11.7 → 0.12.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/dist/esm/index.js +102 -56
- package/dist/index.d.ts +27 -55
- package/dist/index.js +103 -58
- package/package.json +7 -7
- package/src/FormField.tsx +47 -16
- package/src/FormFieldCheckbox.tsx +8 -8
- package/src/FormFieldInput.tsx +11 -12
- package/src/FormFieldRadio.tsx +6 -4
- package/src/FormFieldSelect.tsx +5 -6
- package/src/FormFieldTextarea.tsx +28 -0
- package/src/index.ts +1 -0
- package/src/FormFieldController.tsx +0 -0
package/dist/esm/index.js
CHANGED
|
@@ -29,8 +29,9 @@ var Form = ({
|
|
|
29
29
|
) });
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
// src/
|
|
33
|
-
import
|
|
32
|
+
// src/FormField.tsx
|
|
33
|
+
import * as React2 from "react";
|
|
34
|
+
import { Box as Box2, Label } from "@ttoss/ui";
|
|
34
35
|
|
|
35
36
|
// src/ErrorMessage.tsx
|
|
36
37
|
import { useFormContext } from "react-hook-form";
|
|
@@ -53,60 +54,90 @@ var ErrorMessage = ({
|
|
|
53
54
|
);
|
|
54
55
|
};
|
|
55
56
|
|
|
56
|
-
// src/
|
|
57
|
-
import {
|
|
57
|
+
// src/FormField.tsx
|
|
58
|
+
import {
|
|
59
|
+
useController
|
|
60
|
+
} from "react-hook-form";
|
|
58
61
|
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
62
|
+
var FormField = ({
|
|
63
|
+
label,
|
|
64
|
+
id: idProp,
|
|
65
|
+
name,
|
|
66
|
+
defaultValue,
|
|
67
|
+
render
|
|
68
|
+
}) => {
|
|
69
|
+
const controllerReturn = useController({
|
|
70
|
+
name,
|
|
71
|
+
defaultValue
|
|
72
|
+
});
|
|
73
|
+
const id = idProp || `form-field-${name}`;
|
|
74
|
+
const memoizedRender = React2.useMemo(() => {
|
|
75
|
+
return React2.Children.map(render(controllerReturn), (child) => {
|
|
76
|
+
return React2.createElement(child.type, { id, ...child.props });
|
|
77
|
+
});
|
|
78
|
+
}, [controllerReturn, id, render]);
|
|
79
|
+
return /* @__PURE__ */ jsxs(Box2, { children: [
|
|
80
|
+
label && /* @__PURE__ */ jsx3(Label, { htmlFor: id, children: label }),
|
|
81
|
+
memoizedRender,
|
|
82
|
+
/* @__PURE__ */ jsx3(ErrorMessage, { name })
|
|
83
|
+
] });
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/FormFieldCheckbox.tsx
|
|
87
|
+
import { Box as Box3, Checkbox, Flex, Label as Label2 } from "@ttoss/ui";
|
|
88
|
+
import { useController as useController2 } from "react-hook-form";
|
|
89
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
59
90
|
var FormFieldCheckbox = ({
|
|
60
91
|
label,
|
|
61
92
|
name,
|
|
62
|
-
|
|
93
|
+
...checkboxProps
|
|
63
94
|
}) => {
|
|
64
95
|
const {
|
|
65
96
|
field: { onChange, onBlur, value, ref }
|
|
66
|
-
} =
|
|
97
|
+
} = useController2({
|
|
67
98
|
name,
|
|
68
99
|
defaultValue: false
|
|
69
100
|
});
|
|
70
101
|
const id = `form-field-checkbox-${name}`;
|
|
71
|
-
return /* @__PURE__ */
|
|
72
|
-
/* @__PURE__ */
|
|
73
|
-
/* @__PURE__ */
|
|
102
|
+
return /* @__PURE__ */ jsxs2(Box3, { children: [
|
|
103
|
+
/* @__PURE__ */ jsxs2(Flex, { sx: { alignItems: "center" }, children: [
|
|
104
|
+
/* @__PURE__ */ jsx4(
|
|
74
105
|
Checkbox,
|
|
75
106
|
{
|
|
76
107
|
id,
|
|
77
108
|
ref,
|
|
78
|
-
disabled,
|
|
79
109
|
checked: value,
|
|
80
110
|
onChange,
|
|
81
|
-
onBlur
|
|
111
|
+
onBlur,
|
|
112
|
+
name,
|
|
113
|
+
...checkboxProps
|
|
82
114
|
}
|
|
83
115
|
),
|
|
84
|
-
label && /* @__PURE__ */
|
|
116
|
+
label && /* @__PURE__ */ jsx4(Label2, { "aria-disabled": checkboxProps.disabled, htmlFor: id, children: label })
|
|
85
117
|
] }),
|
|
86
|
-
/* @__PURE__ */
|
|
118
|
+
/* @__PURE__ */ jsx4(ErrorMessage, { name })
|
|
87
119
|
] });
|
|
88
120
|
};
|
|
89
121
|
|
|
90
122
|
// src/FormFieldInput.tsx
|
|
91
|
-
import { Box as
|
|
92
|
-
import { useController as
|
|
93
|
-
import { jsx as
|
|
123
|
+
import { Box as Box4, Input, Label as Label3 } from "@ttoss/ui";
|
|
124
|
+
import { useController as useController3 } from "react-hook-form";
|
|
125
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
94
126
|
var FormFieldInput = ({
|
|
95
127
|
label,
|
|
96
128
|
name,
|
|
97
|
-
|
|
98
|
-
placeholder
|
|
129
|
+
...inputProps
|
|
99
130
|
}) => {
|
|
100
131
|
const {
|
|
101
132
|
field: { onChange, onBlur, value, ref }
|
|
102
|
-
} =
|
|
133
|
+
} = useController3({
|
|
103
134
|
name,
|
|
104
135
|
defaultValue: ""
|
|
105
136
|
});
|
|
106
137
|
const id = `form-field-input-${name}`;
|
|
107
|
-
return /* @__PURE__ */
|
|
108
|
-
label && /* @__PURE__ */
|
|
109
|
-
/* @__PURE__ */
|
|
138
|
+
return /* @__PURE__ */ jsxs3(Box4, { children: [
|
|
139
|
+
label && /* @__PURE__ */ jsx5(Label3, { "aria-disabled": inputProps.disabled, htmlFor: id, children: label }),
|
|
140
|
+
/* @__PURE__ */ jsx5(
|
|
110
141
|
Input,
|
|
111
142
|
{
|
|
112
143
|
ref,
|
|
@@ -114,36 +145,36 @@ var FormFieldInput = ({
|
|
|
114
145
|
onBlur,
|
|
115
146
|
value,
|
|
116
147
|
name,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
id
|
|
148
|
+
id,
|
|
149
|
+
...inputProps
|
|
120
150
|
}
|
|
121
151
|
),
|
|
122
|
-
/* @__PURE__ */
|
|
152
|
+
/* @__PURE__ */ jsx5(ErrorMessage, { name })
|
|
123
153
|
] });
|
|
124
154
|
};
|
|
125
155
|
|
|
126
156
|
// src/FormFieldRadio.tsx
|
|
127
|
-
import { Box as
|
|
128
|
-
import { useController as
|
|
129
|
-
import { jsx as
|
|
157
|
+
import { Box as Box5, Label as Label4, Radio } from "@ttoss/ui";
|
|
158
|
+
import { useController as useController4 } from "react-hook-form";
|
|
159
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
130
160
|
var FormFieldRadio = ({
|
|
131
161
|
label,
|
|
132
162
|
name,
|
|
133
|
-
options
|
|
163
|
+
options,
|
|
164
|
+
...radioProps
|
|
134
165
|
}) => {
|
|
135
166
|
const {
|
|
136
167
|
field: { onChange, onBlur, value, ref }
|
|
137
|
-
} =
|
|
168
|
+
} = useController4({
|
|
138
169
|
name,
|
|
139
170
|
defaultValue: ""
|
|
140
171
|
});
|
|
141
|
-
return /* @__PURE__ */
|
|
142
|
-
label && /* @__PURE__ */
|
|
143
|
-
/* @__PURE__ */
|
|
172
|
+
return /* @__PURE__ */ jsxs4(Box5, { children: [
|
|
173
|
+
label && /* @__PURE__ */ jsx6(Label4, { children: label }),
|
|
174
|
+
/* @__PURE__ */ jsx6(Box5, { children: options.map((option) => {
|
|
144
175
|
const id = `form-field-radio-${name}-${option.value}`;
|
|
145
|
-
return /* @__PURE__ */
|
|
146
|
-
/* @__PURE__ */
|
|
176
|
+
return /* @__PURE__ */ jsxs4(Label4, { htmlFor: id, children: [
|
|
177
|
+
/* @__PURE__ */ jsx6(
|
|
147
178
|
Radio,
|
|
148
179
|
{
|
|
149
180
|
ref,
|
|
@@ -152,36 +183,37 @@ var FormFieldRadio = ({
|
|
|
152
183
|
value: option.value,
|
|
153
184
|
defaultChecked: value === option.value,
|
|
154
185
|
name,
|
|
155
|
-
id
|
|
186
|
+
id,
|
|
187
|
+
...radioProps
|
|
156
188
|
}
|
|
157
189
|
),
|
|
158
190
|
option.label
|
|
159
191
|
] }, id);
|
|
160
192
|
}) }),
|
|
161
|
-
/* @__PURE__ */
|
|
193
|
+
/* @__PURE__ */ jsx6(ErrorMessage, { name })
|
|
162
194
|
] });
|
|
163
195
|
};
|
|
164
196
|
|
|
165
197
|
// src/FormFieldSelect.tsx
|
|
166
|
-
import { Box as
|
|
167
|
-
import { useController as
|
|
168
|
-
import { jsx as
|
|
198
|
+
import { Box as Box6, Label as Label5, Select } from "@ttoss/ui";
|
|
199
|
+
import { useController as useController5 } from "react-hook-form";
|
|
200
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
169
201
|
var FormFieldSelect = ({
|
|
170
202
|
label,
|
|
171
203
|
name,
|
|
172
204
|
options,
|
|
173
|
-
|
|
205
|
+
...selectProps
|
|
174
206
|
}) => {
|
|
175
207
|
const {
|
|
176
208
|
field: { onChange, onBlur, value, ref }
|
|
177
|
-
} =
|
|
209
|
+
} = useController5({
|
|
178
210
|
name,
|
|
179
211
|
defaultValue: ""
|
|
180
212
|
});
|
|
181
213
|
const id = `form-field-select-${name}`;
|
|
182
|
-
return /* @__PURE__ */
|
|
183
|
-
label && /* @__PURE__ */
|
|
184
|
-
/* @__PURE__ */
|
|
214
|
+
return /* @__PURE__ */ jsxs5(Box6, { children: [
|
|
215
|
+
label && /* @__PURE__ */ jsx7(Label5, { htmlFor: id, children: label }),
|
|
216
|
+
/* @__PURE__ */ jsx7(
|
|
185
217
|
Select,
|
|
186
218
|
{
|
|
187
219
|
ref,
|
|
@@ -189,25 +221,38 @@ var FormFieldSelect = ({
|
|
|
189
221
|
onChange,
|
|
190
222
|
onBlur,
|
|
191
223
|
value,
|
|
192
|
-
arrow,
|
|
193
224
|
id,
|
|
225
|
+
...selectProps,
|
|
194
226
|
children: options.map((option) => {
|
|
195
|
-
return /* @__PURE__ */
|
|
227
|
+
return /* @__PURE__ */ jsx7("option", { value: option.value, children: option.label }, option.label);
|
|
196
228
|
})
|
|
197
229
|
}
|
|
198
230
|
),
|
|
199
|
-
/* @__PURE__ */
|
|
231
|
+
/* @__PURE__ */ jsx7(ErrorMessage, { name })
|
|
200
232
|
] });
|
|
201
233
|
};
|
|
202
234
|
|
|
203
|
-
// src/
|
|
204
|
-
|
|
205
|
-
|
|
235
|
+
// src/FormFieldTextarea.tsx
|
|
236
|
+
import { Textarea } from "@ttoss/ui";
|
|
237
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
238
|
+
var FormFieldTextarea = ({
|
|
239
|
+
label,
|
|
240
|
+
name,
|
|
241
|
+
...textareaProps
|
|
242
|
+
}) => {
|
|
243
|
+
const id = `form-field-textarea-${name}`;
|
|
244
|
+
return /* @__PURE__ */ jsx8(
|
|
245
|
+
FormField,
|
|
246
|
+
{
|
|
247
|
+
label,
|
|
248
|
+
name,
|
|
249
|
+
id,
|
|
250
|
+
render: ({ field }) => {
|
|
251
|
+
return /* @__PURE__ */ jsx8(Textarea, { ...field, ...textareaProps });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
);
|
|
206
255
|
};
|
|
207
|
-
FormField.Input = FormFieldInput;
|
|
208
|
-
FormField.Radio = FormFieldRadio;
|
|
209
|
-
FormField.Select = FormFieldSelect;
|
|
210
|
-
FormField.Checkbox = FormFieldCheckbox;
|
|
211
256
|
export {
|
|
212
257
|
Form,
|
|
213
258
|
FormField,
|
|
@@ -215,6 +260,7 @@ export {
|
|
|
215
260
|
FormFieldInput,
|
|
216
261
|
FormFieldRadio,
|
|
217
262
|
FormFieldSelect,
|
|
263
|
+
FormFieldTextarea,
|
|
218
264
|
yup,
|
|
219
265
|
yupResolver
|
|
220
266
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { yupResolver } from '@hookform/resolvers/yup';
|
|
2
2
|
import * as react_hook_form from 'react-hook-form';
|
|
3
|
-
import { FieldValues,
|
|
3
|
+
import { FieldValues, UseControllerReturn } from 'react-hook-form';
|
|
4
4
|
export * from 'react-hook-form';
|
|
5
5
|
import * as yup from 'yup';
|
|
6
6
|
export { yup };
|
|
7
7
|
import * as React from 'react';
|
|
8
|
-
import { BoxProps, SelectProps } from '@ttoss/ui';
|
|
8
|
+
import { BoxProps, CheckboxProps, InputProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
|
|
9
9
|
|
|
10
10
|
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
11
11
|
children?: React.ReactNode;
|
|
@@ -15,75 +15,47 @@ declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children,
|
|
|
15
15
|
children: React.ReactNode | React.ReactNode[];
|
|
16
16
|
} & react_hook_form.UseFormReturn<TFieldValues, any>) => JSX.Element;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
* DEPRECATED: Use `FormFieldInput` instead.
|
|
20
|
-
*/
|
|
21
|
-
declare const FormField: {
|
|
22
|
-
(): null;
|
|
23
|
-
Input: <TFieldValues extends react_hook_form.FieldValues = react_hook_form.FieldValues>({ label, name, disabled, placeholder, }: {
|
|
24
|
-
label?: string | undefined;
|
|
25
|
-
name: react_hook_form.Path<TFieldValues>;
|
|
26
|
-
disabled?: boolean | undefined;
|
|
27
|
-
placeholder?: string | undefined;
|
|
28
|
-
}) => JSX.Element;
|
|
29
|
-
Radio: <TFieldValues_1 extends react_hook_form.FieldValues = react_hook_form.FieldValues>({ label, name, options, }: {
|
|
30
|
-
label?: string | undefined;
|
|
31
|
-
name: react_hook_form.Path<TFieldValues_1>;
|
|
32
|
-
options: {
|
|
33
|
-
value: string | number; /**
|
|
34
|
-
* DEPRECATED: Use `FormFieldInput` instead.
|
|
35
|
-
*/
|
|
36
|
-
label: string;
|
|
37
|
-
}[];
|
|
38
|
-
}) => JSX.Element;
|
|
39
|
-
Select: <TFieldValues_2 extends react_hook_form.FieldValues = react_hook_form.FieldValues>({ label, name, options, arrow, }: {
|
|
40
|
-
label?: string | undefined;
|
|
41
|
-
name: react_hook_form.Path<TFieldValues_2>;
|
|
42
|
-
options: {
|
|
43
|
-
value: string | number;
|
|
44
|
-
label: string;
|
|
45
|
-
}[];
|
|
46
|
-
arrow?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
47
|
-
}) => JSX.Element;
|
|
48
|
-
Checkbox: <TFieldValues_3 extends react_hook_form.FieldValues = react_hook_form.FieldValues>({ label, name, disabled, }: {
|
|
49
|
-
label?: string | undefined;
|
|
50
|
-
name: react_hook_form.Path<TFieldValues_3>;
|
|
51
|
-
disabled?: boolean | undefined;
|
|
52
|
-
}) => JSX.Element;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues>({ label, name, disabled, }: {
|
|
18
|
+
declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>> = react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>>>({ label, id: idProp, name, defaultValue, render, }: {
|
|
56
19
|
label?: string | undefined;
|
|
57
|
-
|
|
58
|
-
|
|
20
|
+
id?: string | undefined;
|
|
21
|
+
name: TName;
|
|
22
|
+
defaultValue?: react_hook_form.PathValue<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>, TName> | undefined;
|
|
23
|
+
render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
|
|
59
24
|
}) => JSX.Element;
|
|
60
25
|
|
|
61
|
-
declare const
|
|
26
|
+
declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues>({ label, name, ...checkboxProps }: {
|
|
62
27
|
label?: string | undefined;
|
|
63
|
-
name: Path<TFieldValues
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
28
|
+
name: react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>>;
|
|
29
|
+
} & CheckboxProps) => JSX.Element;
|
|
30
|
+
|
|
31
|
+
declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>> = react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>>>({ label, name, ...inputProps }: {
|
|
32
|
+
label?: string | undefined;
|
|
33
|
+
name: TName;
|
|
34
|
+
} & InputProps) => JSX.Element;
|
|
67
35
|
|
|
68
36
|
type FormRadioOption$1 = {
|
|
69
37
|
value: string | number;
|
|
70
38
|
label: string;
|
|
71
39
|
};
|
|
72
|
-
declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues>({ label, name, options, }: {
|
|
40
|
+
declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues>({ label, name, options, ...radioProps }: {
|
|
73
41
|
label?: string | undefined;
|
|
74
|
-
name: Path<TFieldValues
|
|
42
|
+
name: react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>>;
|
|
75
43
|
options: FormRadioOption$1[];
|
|
76
|
-
}) => JSX.Element;
|
|
44
|
+
} & RadioProps) => JSX.Element;
|
|
77
45
|
|
|
78
46
|
type FormRadioOption = {
|
|
79
47
|
value: string | number;
|
|
80
48
|
label: string;
|
|
81
49
|
};
|
|
82
|
-
declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>({ label, name, options,
|
|
50
|
+
declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>({ label, name, options, ...selectProps }: {
|
|
83
51
|
label?: string | undefined;
|
|
84
|
-
name: Path<TFieldValues
|
|
52
|
+
name: react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>>;
|
|
85
53
|
options: FormRadioOption[];
|
|
86
|
-
|
|
87
|
-
|
|
54
|
+
} & SelectProps) => JSX.Element;
|
|
55
|
+
|
|
56
|
+
declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>> = react_hook_form.Path<react_hook_form.UnPackAsyncDefaultValues<TFieldValues>>>({ label, name, ...textareaProps }: {
|
|
57
|
+
label?: string | undefined;
|
|
58
|
+
name: TName;
|
|
59
|
+
} & TextareaProps) => JSX.Element;
|
|
88
60
|
|
|
89
|
-
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldRadio, FormFieldSelect };
|
|
61
|
+
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldRadio, FormFieldSelect, FormFieldTextarea };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
FormFieldInput: () => FormFieldInput,
|
|
35
35
|
FormFieldRadio: () => FormFieldRadio,
|
|
36
36
|
FormFieldSelect: () => FormFieldSelect,
|
|
37
|
+
FormFieldTextarea: () => FormFieldTextarea,
|
|
37
38
|
yup: () => yup,
|
|
38
39
|
yupResolver: () => import_yup.yupResolver
|
|
39
40
|
});
|
|
@@ -66,7 +67,8 @@ var Form = ({
|
|
|
66
67
|
) });
|
|
67
68
|
};
|
|
68
69
|
|
|
69
|
-
// src/
|
|
70
|
+
// src/FormField.tsx
|
|
71
|
+
var React2 = __toESM(require("react"));
|
|
70
72
|
var import_ui3 = require("@ttoss/ui");
|
|
71
73
|
|
|
72
74
|
// src/ErrorMessage.tsx
|
|
@@ -90,98 +92,126 @@ var ErrorMessage = ({
|
|
|
90
92
|
);
|
|
91
93
|
};
|
|
92
94
|
|
|
93
|
-
// src/
|
|
95
|
+
// src/FormField.tsx
|
|
94
96
|
var import_react_hook_form3 = require("react-hook-form");
|
|
95
97
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
98
|
+
var FormField = ({
|
|
99
|
+
label,
|
|
100
|
+
id: idProp,
|
|
101
|
+
name,
|
|
102
|
+
defaultValue,
|
|
103
|
+
render
|
|
104
|
+
}) => {
|
|
105
|
+
const controllerReturn = (0, import_react_hook_form3.useController)({
|
|
106
|
+
name,
|
|
107
|
+
defaultValue
|
|
108
|
+
});
|
|
109
|
+
const id = idProp || `form-field-${name}`;
|
|
110
|
+
const memoizedRender = React2.useMemo(() => {
|
|
111
|
+
return React2.Children.map(render(controllerReturn), (child) => {
|
|
112
|
+
return React2.createElement(child.type, { id, ...child.props });
|
|
113
|
+
});
|
|
114
|
+
}, [controllerReturn, id, render]);
|
|
115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_ui3.Box, { children: [
|
|
116
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_ui3.Label, { htmlFor: id, children: label }),
|
|
117
|
+
memoizedRender,
|
|
118
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorMessage, { name })
|
|
119
|
+
] });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/FormFieldCheckbox.tsx
|
|
123
|
+
var import_ui4 = require("@ttoss/ui");
|
|
124
|
+
var import_react_hook_form4 = require("react-hook-form");
|
|
125
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
96
126
|
var FormFieldCheckbox = ({
|
|
97
127
|
label,
|
|
98
128
|
name,
|
|
99
|
-
|
|
129
|
+
...checkboxProps
|
|
100
130
|
}) => {
|
|
101
131
|
const {
|
|
102
132
|
field: { onChange, onBlur, value, ref }
|
|
103
|
-
} = (0,
|
|
133
|
+
} = (0, import_react_hook_form4.useController)({
|
|
104
134
|
name,
|
|
105
135
|
defaultValue: false
|
|
106
136
|
});
|
|
107
137
|
const id = `form-field-checkbox-${name}`;
|
|
108
|
-
return /* @__PURE__ */ (0,
|
|
109
|
-
/* @__PURE__ */ (0,
|
|
110
|
-
/* @__PURE__ */ (0,
|
|
111
|
-
|
|
138
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Box, { children: [
|
|
139
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Flex, { sx: { alignItems: "center" }, children: [
|
|
140
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
141
|
+
import_ui4.Checkbox,
|
|
112
142
|
{
|
|
113
143
|
id,
|
|
114
144
|
ref,
|
|
115
|
-
disabled,
|
|
116
145
|
checked: value,
|
|
117
146
|
onChange,
|
|
118
|
-
onBlur
|
|
147
|
+
onBlur,
|
|
148
|
+
name,
|
|
149
|
+
...checkboxProps
|
|
119
150
|
}
|
|
120
151
|
),
|
|
121
|
-
label && /* @__PURE__ */ (0,
|
|
152
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Label, { "aria-disabled": checkboxProps.disabled, htmlFor: id, children: label })
|
|
122
153
|
] }),
|
|
123
|
-
/* @__PURE__ */ (0,
|
|
154
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorMessage, { name })
|
|
124
155
|
] });
|
|
125
156
|
};
|
|
126
157
|
|
|
127
158
|
// src/FormFieldInput.tsx
|
|
128
|
-
var
|
|
129
|
-
var
|
|
130
|
-
var
|
|
159
|
+
var import_ui5 = require("@ttoss/ui");
|
|
160
|
+
var import_react_hook_form5 = require("react-hook-form");
|
|
161
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
131
162
|
var FormFieldInput = ({
|
|
132
163
|
label,
|
|
133
164
|
name,
|
|
134
|
-
|
|
135
|
-
placeholder
|
|
165
|
+
...inputProps
|
|
136
166
|
}) => {
|
|
137
167
|
const {
|
|
138
168
|
field: { onChange, onBlur, value, ref }
|
|
139
|
-
} = (0,
|
|
169
|
+
} = (0, import_react_hook_form5.useController)({
|
|
140
170
|
name,
|
|
141
171
|
defaultValue: ""
|
|
142
172
|
});
|
|
143
173
|
const id = `form-field-input-${name}`;
|
|
144
|
-
return /* @__PURE__ */ (0,
|
|
145
|
-
label && /* @__PURE__ */ (0,
|
|
146
|
-
/* @__PURE__ */ (0,
|
|
147
|
-
|
|
174
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_ui5.Box, { children: [
|
|
175
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_ui5.Label, { "aria-disabled": inputProps.disabled, htmlFor: id, children: label }),
|
|
176
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
177
|
+
import_ui5.Input,
|
|
148
178
|
{
|
|
149
179
|
ref,
|
|
150
180
|
onChange,
|
|
151
181
|
onBlur,
|
|
152
182
|
value,
|
|
153
183
|
name,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
id
|
|
184
|
+
id,
|
|
185
|
+
...inputProps
|
|
157
186
|
}
|
|
158
187
|
),
|
|
159
|
-
/* @__PURE__ */ (0,
|
|
188
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorMessage, { name })
|
|
160
189
|
] });
|
|
161
190
|
};
|
|
162
191
|
|
|
163
192
|
// src/FormFieldRadio.tsx
|
|
164
|
-
var
|
|
165
|
-
var
|
|
166
|
-
var
|
|
193
|
+
var import_ui6 = require("@ttoss/ui");
|
|
194
|
+
var import_react_hook_form6 = require("react-hook-form");
|
|
195
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
167
196
|
var FormFieldRadio = ({
|
|
168
197
|
label,
|
|
169
198
|
name,
|
|
170
|
-
options
|
|
199
|
+
options,
|
|
200
|
+
...radioProps
|
|
171
201
|
}) => {
|
|
172
202
|
const {
|
|
173
203
|
field: { onChange, onBlur, value, ref }
|
|
174
|
-
} = (0,
|
|
204
|
+
} = (0, import_react_hook_form6.useController)({
|
|
175
205
|
name,
|
|
176
206
|
defaultValue: ""
|
|
177
207
|
});
|
|
178
|
-
return /* @__PURE__ */ (0,
|
|
179
|
-
label && /* @__PURE__ */ (0,
|
|
180
|
-
/* @__PURE__ */ (0,
|
|
208
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui6.Box, { children: [
|
|
209
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui6.Label, { children: label }),
|
|
210
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui6.Box, { children: options.map((option) => {
|
|
181
211
|
const id = `form-field-radio-${name}-${option.value}`;
|
|
182
|
-
return /* @__PURE__ */ (0,
|
|
183
|
-
/* @__PURE__ */ (0,
|
|
184
|
-
|
|
212
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui6.Label, { htmlFor: id, children: [
|
|
213
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
214
|
+
import_ui6.Radio,
|
|
185
215
|
{
|
|
186
216
|
ref,
|
|
187
217
|
onChange,
|
|
@@ -189,62 +219,76 @@ var FormFieldRadio = ({
|
|
|
189
219
|
value: option.value,
|
|
190
220
|
defaultChecked: value === option.value,
|
|
191
221
|
name,
|
|
192
|
-
id
|
|
222
|
+
id,
|
|
223
|
+
...radioProps
|
|
193
224
|
}
|
|
194
225
|
),
|
|
195
226
|
option.label
|
|
196
227
|
] }, id);
|
|
197
228
|
}) }),
|
|
198
|
-
/* @__PURE__ */ (0,
|
|
229
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorMessage, { name })
|
|
199
230
|
] });
|
|
200
231
|
};
|
|
201
232
|
|
|
202
233
|
// src/FormFieldSelect.tsx
|
|
203
|
-
var
|
|
204
|
-
var
|
|
205
|
-
var
|
|
234
|
+
var import_ui7 = require("@ttoss/ui");
|
|
235
|
+
var import_react_hook_form7 = require("react-hook-form");
|
|
236
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
206
237
|
var FormFieldSelect = ({
|
|
207
238
|
label,
|
|
208
239
|
name,
|
|
209
240
|
options,
|
|
210
|
-
|
|
241
|
+
...selectProps
|
|
211
242
|
}) => {
|
|
212
243
|
const {
|
|
213
244
|
field: { onChange, onBlur, value, ref }
|
|
214
|
-
} = (0,
|
|
245
|
+
} = (0, import_react_hook_form7.useController)({
|
|
215
246
|
name,
|
|
216
247
|
defaultValue: ""
|
|
217
248
|
});
|
|
218
249
|
const id = `form-field-select-${name}`;
|
|
219
|
-
return /* @__PURE__ */ (0,
|
|
220
|
-
label && /* @__PURE__ */ (0,
|
|
221
|
-
/* @__PURE__ */ (0,
|
|
222
|
-
|
|
250
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_ui7.Box, { children: [
|
|
251
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_ui7.Label, { htmlFor: id, children: label }),
|
|
252
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
253
|
+
import_ui7.Select,
|
|
223
254
|
{
|
|
224
255
|
ref,
|
|
225
256
|
name,
|
|
226
257
|
onChange,
|
|
227
258
|
onBlur,
|
|
228
259
|
value,
|
|
229
|
-
arrow,
|
|
230
260
|
id,
|
|
261
|
+
...selectProps,
|
|
231
262
|
children: options.map((option) => {
|
|
232
|
-
return /* @__PURE__ */ (0,
|
|
263
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: option.value, children: option.label }, option.label);
|
|
233
264
|
})
|
|
234
265
|
}
|
|
235
266
|
),
|
|
236
|
-
/* @__PURE__ */ (0,
|
|
267
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ErrorMessage, { name })
|
|
237
268
|
] });
|
|
238
269
|
};
|
|
239
270
|
|
|
240
|
-
// src/
|
|
241
|
-
var
|
|
242
|
-
|
|
271
|
+
// src/FormFieldTextarea.tsx
|
|
272
|
+
var import_ui8 = require("@ttoss/ui");
|
|
273
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
274
|
+
var FormFieldTextarea = ({
|
|
275
|
+
label,
|
|
276
|
+
name,
|
|
277
|
+
...textareaProps
|
|
278
|
+
}) => {
|
|
279
|
+
const id = `form-field-textarea-${name}`;
|
|
280
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
281
|
+
FormField,
|
|
282
|
+
{
|
|
283
|
+
label,
|
|
284
|
+
name,
|
|
285
|
+
id,
|
|
286
|
+
render: ({ field }) => {
|
|
287
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_ui8.Textarea, { ...field, ...textareaProps });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
);
|
|
243
291
|
};
|
|
244
|
-
FormField.Input = FormFieldInput;
|
|
245
|
-
FormField.Radio = FormFieldRadio;
|
|
246
|
-
FormField.Select = FormFieldSelect;
|
|
247
|
-
FormField.Checkbox = FormFieldCheckbox;
|
|
248
292
|
// Annotate the CommonJS export names for ESM import in node:
|
|
249
293
|
0 && (module.exports = {
|
|
250
294
|
Form,
|
|
@@ -253,6 +297,7 @@ FormField.Checkbox = FormFieldCheckbox;
|
|
|
253
297
|
FormFieldInput,
|
|
254
298
|
FormFieldRadio,
|
|
255
299
|
FormFieldSelect,
|
|
300
|
+
FormFieldTextarea,
|
|
256
301
|
yup,
|
|
257
302
|
yupResolver
|
|
258
303
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -21,25 +21,25 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@hookform/error-message": "^2.0.1",
|
|
23
23
|
"@hookform/resolvers": "^2.9.10",
|
|
24
|
-
"react-hook-form": "^7.
|
|
24
|
+
"react-hook-form": "^7.41.2",
|
|
25
25
|
"yup": "^0.32.11"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@ttoss/ui": "^1.
|
|
28
|
+
"@ttoss/ui": "^1.27.3",
|
|
29
29
|
"react": "^18.2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@ttoss/config": "^1.26.0",
|
|
33
|
-
"@ttoss/test-utils": "^1.
|
|
34
|
-
"@ttoss/ui": "^1.
|
|
33
|
+
"@ttoss/test-utils": "^1.20.0",
|
|
34
|
+
"@ttoss/ui": "^1.28.0",
|
|
35
35
|
"@types/jest": "^29.2.4",
|
|
36
36
|
"jest": "^29.3.1",
|
|
37
37
|
"react": "^18.2.0",
|
|
38
|
-
"react-hook-form": "^7.
|
|
38
|
+
"react-hook-form": "^7.41.2",
|
|
39
39
|
"yup": "^0.32.11"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "4b7a4d3035f4b4d43b02069df62fcc9ca57c2bc6"
|
|
45
45
|
}
|
package/src/FormField.tsx
CHANGED
|
@@ -1,19 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Box, Label } from '@ttoss/ui';
|
|
3
|
+
import { ErrorMessage } from './ErrorMessage';
|
|
4
|
+
import {
|
|
5
|
+
FieldPath,
|
|
6
|
+
FieldPathValue,
|
|
7
|
+
FieldValues,
|
|
8
|
+
UseControllerReturn,
|
|
9
|
+
useController,
|
|
10
|
+
} from 'react-hook-form';
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
export const FormField = <
|
|
13
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
14
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
|
15
|
+
>({
|
|
16
|
+
label,
|
|
17
|
+
id: idProp,
|
|
18
|
+
name,
|
|
19
|
+
defaultValue,
|
|
20
|
+
render,
|
|
21
|
+
}: {
|
|
22
|
+
label?: string;
|
|
23
|
+
id?: string;
|
|
24
|
+
name: TName;
|
|
25
|
+
defaultValue?: FieldPathValue<TFieldValues, TName>;
|
|
26
|
+
render: (
|
|
27
|
+
props: UseControllerReturn<TFieldValues, TName>
|
|
28
|
+
) => React.ReactElement;
|
|
29
|
+
}) => {
|
|
30
|
+
const controllerReturn = useController<TFieldValues, TName>({
|
|
31
|
+
name,
|
|
32
|
+
defaultValue,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const id = idProp || `form-field-${name}`;
|
|
13
36
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
const memoizedRender = React.useMemo(() => {
|
|
38
|
+
return React.Children.map(render(controllerReturn), (child) => {
|
|
39
|
+
return React.createElement(child.type, { id, ...child.props });
|
|
40
|
+
});
|
|
41
|
+
}, [controllerReturn, id, render]);
|
|
18
42
|
|
|
19
|
-
|
|
43
|
+
return (
|
|
44
|
+
<Box>
|
|
45
|
+
{label && <Label htmlFor={id}>{label}</Label>}
|
|
46
|
+
{memoizedRender}
|
|
47
|
+
<ErrorMessage name={name} />
|
|
48
|
+
</Box>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { Box, Checkbox, Flex, Label } from '@ttoss/ui';
|
|
1
|
+
import { Box, Checkbox, type CheckboxProps, Flex, Label } from '@ttoss/ui';
|
|
2
2
|
import { ErrorMessage } from './ErrorMessage';
|
|
3
|
-
import {
|
|
3
|
+
import { FieldPath, FieldValues, useController } from 'react-hook-form';
|
|
4
4
|
|
|
5
5
|
export const FormFieldCheckbox = <
|
|
6
6
|
TFieldValues extends FieldValues = FieldValues
|
|
7
7
|
>({
|
|
8
8
|
label,
|
|
9
9
|
name,
|
|
10
|
-
|
|
10
|
+
...checkboxProps
|
|
11
11
|
}: {
|
|
12
12
|
label?: string;
|
|
13
|
-
name:
|
|
14
|
-
|
|
15
|
-
}) => {
|
|
13
|
+
name: FieldPath<TFieldValues>;
|
|
14
|
+
} & CheckboxProps) => {
|
|
16
15
|
const {
|
|
17
16
|
field: { onChange, onBlur, value, ref },
|
|
18
17
|
} = useController<any>({
|
|
@@ -28,13 +27,14 @@ export const FormFieldCheckbox = <
|
|
|
28
27
|
<Checkbox
|
|
29
28
|
id={id}
|
|
30
29
|
ref={ref}
|
|
31
|
-
disabled={disabled}
|
|
32
30
|
checked={value}
|
|
33
31
|
onChange={onChange}
|
|
34
32
|
onBlur={onBlur}
|
|
33
|
+
name={name}
|
|
34
|
+
{...checkboxProps}
|
|
35
35
|
/>
|
|
36
36
|
{label && (
|
|
37
|
-
<Label aria-disabled={disabled} htmlFor={id}>
|
|
37
|
+
<Label aria-disabled={checkboxProps.disabled} htmlFor={id}>
|
|
38
38
|
{label}
|
|
39
39
|
</Label>
|
|
40
40
|
)}
|
package/src/FormFieldInput.tsx
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Box, Input, Label } from '@ttoss/ui';
|
|
1
|
+
import { Box, Input, type InputProps, Label } from '@ttoss/ui';
|
|
2
2
|
import { ErrorMessage } from './ErrorMessage';
|
|
3
|
-
import {
|
|
3
|
+
import { FieldPath, FieldValues, useController } from 'react-hook-form';
|
|
4
4
|
|
|
5
|
-
export const FormFieldInput = <
|
|
5
|
+
export const FormFieldInput = <
|
|
6
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
7
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
|
8
|
+
>({
|
|
6
9
|
label,
|
|
7
10
|
name,
|
|
8
|
-
|
|
9
|
-
placeholder,
|
|
11
|
+
...inputProps
|
|
10
12
|
}: {
|
|
11
13
|
label?: string;
|
|
12
|
-
name:
|
|
13
|
-
|
|
14
|
-
placeholder?: string;
|
|
15
|
-
}) => {
|
|
14
|
+
name: TName;
|
|
15
|
+
} & InputProps) => {
|
|
16
16
|
const {
|
|
17
17
|
field: { onChange, onBlur, value, ref },
|
|
18
18
|
} = useController<any>({
|
|
@@ -25,7 +25,7 @@ export const FormFieldInput = <TFieldValues extends FieldValues = FieldValues>({
|
|
|
25
25
|
return (
|
|
26
26
|
<Box>
|
|
27
27
|
{label && (
|
|
28
|
-
<Label aria-disabled={disabled} htmlFor={id}>
|
|
28
|
+
<Label aria-disabled={inputProps.disabled} htmlFor={id}>
|
|
29
29
|
{label}
|
|
30
30
|
</Label>
|
|
31
31
|
)}
|
|
@@ -35,9 +35,8 @@ export const FormFieldInput = <TFieldValues extends FieldValues = FieldValues>({
|
|
|
35
35
|
onBlur={onBlur}
|
|
36
36
|
value={value}
|
|
37
37
|
name={name}
|
|
38
|
-
disabled={disabled}
|
|
39
|
-
placeholder={placeholder}
|
|
40
38
|
id={id}
|
|
39
|
+
{...inputProps}
|
|
41
40
|
/>
|
|
42
41
|
<ErrorMessage name={name} />
|
|
43
42
|
</Box>
|
package/src/FormFieldRadio.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Box, Label, Radio } from '@ttoss/ui';
|
|
1
|
+
import { Box, Label, Radio, type RadioProps } from '@ttoss/ui';
|
|
2
2
|
import { ErrorMessage } from './ErrorMessage';
|
|
3
|
-
import {
|
|
3
|
+
import { FieldPath, FieldValues, useController } from 'react-hook-form';
|
|
4
4
|
|
|
5
5
|
type FormRadioOption = {
|
|
6
6
|
value: string | number;
|
|
@@ -11,11 +11,12 @@ export const FormFieldRadio = <TFieldValues extends FieldValues = FieldValues>({
|
|
|
11
11
|
label,
|
|
12
12
|
name,
|
|
13
13
|
options,
|
|
14
|
+
...radioProps
|
|
14
15
|
}: {
|
|
15
16
|
label?: string;
|
|
16
|
-
name:
|
|
17
|
+
name: FieldPath<TFieldValues>;
|
|
17
18
|
options: FormRadioOption[];
|
|
18
|
-
}) => {
|
|
19
|
+
} & RadioProps) => {
|
|
19
20
|
const {
|
|
20
21
|
field: { onChange, onBlur, value, ref },
|
|
21
22
|
} = useController<any>({
|
|
@@ -40,6 +41,7 @@ export const FormFieldRadio = <TFieldValues extends FieldValues = FieldValues>({
|
|
|
40
41
|
defaultChecked={value === option.value}
|
|
41
42
|
name={name}
|
|
42
43
|
id={id}
|
|
44
|
+
{...radioProps}
|
|
43
45
|
/>
|
|
44
46
|
{option.label}
|
|
45
47
|
</Label>
|
package/src/FormFieldSelect.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Box, Label, Select, type SelectProps } from '@ttoss/ui';
|
|
2
2
|
import { ErrorMessage } from './ErrorMessage';
|
|
3
|
-
import {
|
|
3
|
+
import { FieldPath, FieldValues, useController } from 'react-hook-form';
|
|
4
4
|
|
|
5
5
|
type FormRadioOption = {
|
|
6
6
|
value: string | number;
|
|
@@ -13,13 +13,12 @@ export const FormFieldSelect = <
|
|
|
13
13
|
label,
|
|
14
14
|
name,
|
|
15
15
|
options,
|
|
16
|
-
|
|
16
|
+
...selectProps
|
|
17
17
|
}: {
|
|
18
18
|
label?: string;
|
|
19
|
-
name:
|
|
19
|
+
name: FieldPath<TFieldValues>;
|
|
20
20
|
options: FormRadioOption[];
|
|
21
|
-
|
|
22
|
-
}) => {
|
|
21
|
+
} & SelectProps) => {
|
|
23
22
|
const {
|
|
24
23
|
field: { onChange, onBlur, value, ref },
|
|
25
24
|
} = useController<any>({
|
|
@@ -38,8 +37,8 @@ export const FormFieldSelect = <
|
|
|
38
37
|
onChange={onChange}
|
|
39
38
|
onBlur={onBlur}
|
|
40
39
|
value={value}
|
|
41
|
-
arrow={arrow}
|
|
42
40
|
id={id}
|
|
41
|
+
{...selectProps}
|
|
43
42
|
>
|
|
44
43
|
{options.map((option) => {
|
|
45
44
|
return (
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FieldPath, FieldValues } from 'react-hook-form';
|
|
2
|
+
import { FormField } from './FormField';
|
|
3
|
+
import { Textarea, type TextareaProps } from '@ttoss/ui';
|
|
4
|
+
|
|
5
|
+
export const FormFieldTextarea = <
|
|
6
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
7
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
|
8
|
+
>({
|
|
9
|
+
label,
|
|
10
|
+
name,
|
|
11
|
+
...textareaProps
|
|
12
|
+
}: {
|
|
13
|
+
label?: string;
|
|
14
|
+
name: TName;
|
|
15
|
+
} & TextareaProps) => {
|
|
16
|
+
const id = `form-field-textarea-${name}`;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<FormField
|
|
20
|
+
label={label}
|
|
21
|
+
name={name}
|
|
22
|
+
id={id}
|
|
23
|
+
render={({ field }) => {
|
|
24
|
+
return <Textarea {...field} {...textareaProps} />;
|
|
25
|
+
}}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { FormFieldCheckbox } from './FormFieldCheckbox';
|
|
|
8
8
|
export { FormFieldInput } from './FormFieldInput';
|
|
9
9
|
export { FormFieldRadio } from './FormFieldRadio';
|
|
10
10
|
export { FormFieldSelect } from './FormFieldSelect';
|
|
11
|
+
export { FormFieldTextarea } from './FormFieldTextarea';
|
|
File without changes
|