@ttoss/forms 0.14.27 → 0.14.28
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 +11 -37
- package/dist/index.d.ts +6 -7
- package/dist/index.js +10 -36
- package/package.json +3 -3
- package/src/ErrorMessage.tsx +3 -1
- package/src/FormFieldInput.tsx +7 -46
package/dist/esm/index.js
CHANGED
|
@@ -39,7 +39,8 @@ import { HelpText } from "@ttoss/ui";
|
|
|
39
39
|
import { ErrorMessage as HookFormErrorMessage } from "@hookform/error-message";
|
|
40
40
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
41
41
|
var ErrorMessage = ({
|
|
42
|
-
name
|
|
42
|
+
name,
|
|
43
|
+
disabled
|
|
43
44
|
}) => {
|
|
44
45
|
const {
|
|
45
46
|
formState: {
|
|
@@ -50,7 +51,8 @@ var ErrorMessage = ({
|
|
|
50
51
|
errors,
|
|
51
52
|
name,
|
|
52
53
|
as: /* @__PURE__ */jsx2(HelpText, {
|
|
53
|
-
negative: true
|
|
54
|
+
negative: true,
|
|
55
|
+
disabled
|
|
54
56
|
})
|
|
55
57
|
});
|
|
56
58
|
};
|
|
@@ -139,15 +141,14 @@ var FormFieldCheckbox = ({
|
|
|
139
141
|
};
|
|
140
142
|
|
|
141
143
|
// src/FormFieldInput.tsx
|
|
142
|
-
import { Box as Box4,
|
|
144
|
+
import { Box as Box4, Input, Label as Label3 } from "@ttoss/ui";
|
|
143
145
|
import { useController as useController3 } from "react-hook-form";
|
|
144
|
-
import React3 from "react";
|
|
145
146
|
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
146
147
|
var FormFieldInput = ({
|
|
147
148
|
label,
|
|
148
149
|
name,
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
tooltip,
|
|
151
|
+
onTooltipClick,
|
|
151
152
|
...inputProps
|
|
152
153
|
}) => {
|
|
153
154
|
const {
|
|
@@ -164,42 +165,15 @@ var FormFieldInput = ({
|
|
|
164
165
|
name,
|
|
165
166
|
defaultValue: ""
|
|
166
167
|
});
|
|
167
|
-
const characterCounter = React3.useMemo(() => {
|
|
168
|
-
if (!value) {
|
|
169
|
-
return 0;
|
|
170
|
-
}
|
|
171
|
-
return String(value).length;
|
|
172
|
-
}, [value]);
|
|
173
168
|
const id = `form-field-input-${name}`;
|
|
174
169
|
const hasError = !!errors[name]?.message;
|
|
175
170
|
return /* @__PURE__ */jsxs3(Box4, {
|
|
176
|
-
children: [label && /* @__PURE__ */
|
|
177
|
-
sx: {
|
|
178
|
-
display: "flex",
|
|
179
|
-
alignItems: "center"
|
|
180
|
-
},
|
|
171
|
+
children: [label && /* @__PURE__ */jsx5(Label3, {
|
|
181
172
|
"aria-disabled": inputProps.disabled,
|
|
182
173
|
htmlFor: id,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
fontSize: "xs",
|
|
187
|
-
lineHeight: 0
|
|
188
|
-
},
|
|
189
|
-
variant: "tooltip-icon",
|
|
190
|
-
children: /* @__PURE__ */jsx5(Icon, {
|
|
191
|
-
icon: tooltipIcon
|
|
192
|
-
})
|
|
193
|
-
}), showCharacterCounter && /* @__PURE__ */jsx5(Text, {
|
|
194
|
-
sx: {
|
|
195
|
-
marginLeft: "auto",
|
|
196
|
-
fontSize: "xs",
|
|
197
|
-
lineHeight: 0,
|
|
198
|
-
color: "underemphasize"
|
|
199
|
-
},
|
|
200
|
-
variant: "character-counter",
|
|
201
|
-
children: characterCounter
|
|
202
|
-
})]
|
|
174
|
+
tooltip,
|
|
175
|
+
onTooltipClick,
|
|
176
|
+
children: label
|
|
203
177
|
}), /* @__PURE__ */jsx5(Input, {
|
|
204
178
|
ref,
|
|
205
179
|
onChange,
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ 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
|
|
8
|
+
import * as _ttoss_ui from '@ttoss/ui';
|
|
9
|
+
import { BoxProps, CheckboxProps, LabelProps, RadioProps, TextareaProps } from '@ttoss/ui';
|
|
9
10
|
import * as theme_ui from 'theme-ui';
|
|
10
11
|
|
|
11
12
|
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
@@ -29,15 +30,13 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
|
|
|
29
30
|
name: FieldPath<TFieldValues>;
|
|
30
31
|
} & CheckboxProps) => JSX.Element;
|
|
31
32
|
|
|
32
|
-
declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name,
|
|
33
|
+
declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, tooltip, onTooltipClick, ...inputProps }: {
|
|
33
34
|
label?: string | undefined;
|
|
34
35
|
name: TName;
|
|
35
|
-
tooltipIcon?: IconType | undefined;
|
|
36
|
-
showCharacterCounter?: boolean | undefined;
|
|
37
36
|
} & theme_ui.InputProps & {
|
|
38
|
-
leadingIcon?: IconType | undefined;
|
|
39
|
-
trailingIcon?: IconType | undefined;
|
|
40
|
-
}) => JSX.Element;
|
|
37
|
+
leadingIcon?: _ttoss_ui.IconType | undefined;
|
|
38
|
+
trailingIcon?: _ttoss_ui.IconType | undefined;
|
|
39
|
+
} & Pick<LabelProps, "tooltip" | "onTooltipClick">) => JSX.Element;
|
|
41
40
|
|
|
42
41
|
type FormRadioOption$1 = {
|
|
43
42
|
value: string | number;
|
package/dist/index.js
CHANGED
|
@@ -88,7 +88,8 @@ var import_ui2 = require("@ttoss/ui");
|
|
|
88
88
|
var import_error_message = require("@hookform/error-message");
|
|
89
89
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
90
90
|
var ErrorMessage = ({
|
|
91
|
-
name
|
|
91
|
+
name,
|
|
92
|
+
disabled
|
|
92
93
|
}) => {
|
|
93
94
|
const {
|
|
94
95
|
formState: {
|
|
@@ -99,7 +100,8 @@ var ErrorMessage = ({
|
|
|
99
100
|
errors,
|
|
100
101
|
name,
|
|
101
102
|
as: /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.HelpText, {
|
|
102
|
-
negative: true
|
|
103
|
+
negative: true,
|
|
104
|
+
disabled
|
|
103
105
|
})
|
|
104
106
|
});
|
|
105
107
|
};
|
|
@@ -190,13 +192,12 @@ var FormFieldCheckbox = ({
|
|
|
190
192
|
// src/FormFieldInput.tsx
|
|
191
193
|
var import_ui5 = require("@ttoss/ui");
|
|
192
194
|
var import_react_hook_form5 = require("react-hook-form");
|
|
193
|
-
var import_react = __toESM(require("react"));
|
|
194
195
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
195
196
|
var FormFieldInput = ({
|
|
196
197
|
label,
|
|
197
198
|
name,
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
tooltip,
|
|
200
|
+
onTooltipClick,
|
|
200
201
|
...inputProps
|
|
201
202
|
}) => {
|
|
202
203
|
const {
|
|
@@ -213,42 +214,15 @@ var FormFieldInput = ({
|
|
|
213
214
|
name,
|
|
214
215
|
defaultValue: ""
|
|
215
216
|
});
|
|
216
|
-
const characterCounter = import_react.default.useMemo(() => {
|
|
217
|
-
if (!value) {
|
|
218
|
-
return 0;
|
|
219
|
-
}
|
|
220
|
-
return String(value).length;
|
|
221
|
-
}, [value]);
|
|
222
217
|
const id = `form-field-input-${name}`;
|
|
223
218
|
const hasError = !!errors[name]?.message;
|
|
224
219
|
return /* @__PURE__ */(0, import_jsx_runtime5.jsxs)(import_ui5.Box, {
|
|
225
|
-
children: [label && /* @__PURE__ */(0, import_jsx_runtime5.
|
|
226
|
-
sx: {
|
|
227
|
-
display: "flex",
|
|
228
|
-
alignItems: "center"
|
|
229
|
-
},
|
|
220
|
+
children: [label && /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_ui5.Label, {
|
|
230
221
|
"aria-disabled": inputProps.disabled,
|
|
231
222
|
htmlFor: id,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
fontSize: "xs",
|
|
236
|
-
lineHeight: 0
|
|
237
|
-
},
|
|
238
|
-
variant: "tooltip-icon",
|
|
239
|
-
children: /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_ui5.Icon, {
|
|
240
|
-
icon: tooltipIcon
|
|
241
|
-
})
|
|
242
|
-
}), showCharacterCounter && /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_ui5.Text, {
|
|
243
|
-
sx: {
|
|
244
|
-
marginLeft: "auto",
|
|
245
|
-
fontSize: "xs",
|
|
246
|
-
lineHeight: 0,
|
|
247
|
-
color: "underemphasize"
|
|
248
|
-
},
|
|
249
|
-
variant: "character-counter",
|
|
250
|
-
children: characterCounter
|
|
251
|
-
})]
|
|
223
|
+
tooltip,
|
|
224
|
+
onTooltipClick,
|
|
225
|
+
children: label
|
|
252
226
|
}), /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_ui5.Input, {
|
|
253
227
|
ref,
|
|
254
228
|
onChange,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.28",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@ttoss/config": "^1.29.3",
|
|
33
33
|
"@ttoss/test-utils": "^1.21.2",
|
|
34
|
-
"@ttoss/ui": "^1.31.
|
|
34
|
+
"@ttoss/ui": "^1.31.15",
|
|
35
35
|
"@types/jest": "^29.5.0",
|
|
36
36
|
"jest": "^29.5.0",
|
|
37
37
|
"react": "^18.2.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "93e161a8af481b0a74c48331c5d193566f3878dc"
|
|
45
45
|
}
|
package/src/ErrorMessage.tsx
CHANGED
|
@@ -4,8 +4,10 @@ import { ErrorMessage as HookFormErrorMessage } from '@hookform/error-message';
|
|
|
4
4
|
|
|
5
5
|
export const ErrorMessage = <TFieldValues extends FieldValues = FieldValues>({
|
|
6
6
|
name,
|
|
7
|
+
disabled,
|
|
7
8
|
}: {
|
|
8
9
|
name: FieldName<TFieldValues>;
|
|
10
|
+
disabled?: boolean;
|
|
9
11
|
}) => {
|
|
10
12
|
const {
|
|
11
13
|
formState: { errors },
|
|
@@ -15,7 +17,7 @@ export const ErrorMessage = <TFieldValues extends FieldValues = FieldValues>({
|
|
|
15
17
|
<HookFormErrorMessage
|
|
16
18
|
errors={errors}
|
|
17
19
|
name={name as any}
|
|
18
|
-
as={<HelpText negative />}
|
|
20
|
+
as={<HelpText negative disabled={disabled} />}
|
|
19
21
|
/>
|
|
20
22
|
);
|
|
21
23
|
};
|
package/src/FormFieldInput.tsx
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Box,
|
|
3
|
-
Icon,
|
|
4
|
-
type IconType,
|
|
5
|
-
Input,
|
|
6
|
-
type InputProps,
|
|
7
|
-
Label,
|
|
8
|
-
Text,
|
|
9
|
-
} from '@ttoss/ui';
|
|
1
|
+
import { Box, Input, type InputProps, Label, type LabelProps } from '@ttoss/ui';
|
|
10
2
|
import { ErrorMessage } from './ErrorMessage';
|
|
11
3
|
import { FieldPath, FieldValues, useController } from 'react-hook-form';
|
|
12
|
-
import React from 'react';
|
|
13
4
|
|
|
14
5
|
export const FormFieldInput = <
|
|
15
6
|
TFieldValues extends FieldValues = FieldValues,
|
|
@@ -17,15 +8,14 @@ export const FormFieldInput = <
|
|
|
17
8
|
>({
|
|
18
9
|
label,
|
|
19
10
|
name,
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
tooltip,
|
|
12
|
+
onTooltipClick,
|
|
22
13
|
...inputProps
|
|
23
14
|
}: {
|
|
24
15
|
label?: string;
|
|
25
16
|
name: TName;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} & InputProps) => {
|
|
17
|
+
} & InputProps &
|
|
18
|
+
Pick<LabelProps, 'tooltip' | 'onTooltipClick'>) => {
|
|
29
19
|
const {
|
|
30
20
|
field: { onChange, onBlur, value, ref },
|
|
31
21
|
formState: { errors },
|
|
@@ -34,14 +24,6 @@ export const FormFieldInput = <
|
|
|
34
24
|
defaultValue: '',
|
|
35
25
|
});
|
|
36
26
|
|
|
37
|
-
const characterCounter = React.useMemo(() => {
|
|
38
|
-
if (!value) {
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return String(value).length;
|
|
43
|
-
}, [value]);
|
|
44
|
-
|
|
45
27
|
const id = `form-field-input-${name}`;
|
|
46
28
|
|
|
47
29
|
const hasError = !!errors[name]?.message;
|
|
@@ -50,33 +32,12 @@ export const FormFieldInput = <
|
|
|
50
32
|
<Box>
|
|
51
33
|
{label && (
|
|
52
34
|
<Label
|
|
53
|
-
sx={{ display: 'flex', alignItems: 'center' }}
|
|
54
35
|
aria-disabled={inputProps.disabled}
|
|
55
36
|
htmlFor={id}
|
|
37
|
+
tooltip={tooltip}
|
|
38
|
+
onTooltipClick={onTooltipClick}
|
|
56
39
|
>
|
|
57
40
|
{label}
|
|
58
|
-
{tooltipIcon && (
|
|
59
|
-
<Text
|
|
60
|
-
sx={{ marginLeft: 'md', fontSize: 'xs', lineHeight: 0 }}
|
|
61
|
-
variant="tooltip-icon"
|
|
62
|
-
>
|
|
63
|
-
<Icon icon={tooltipIcon} />
|
|
64
|
-
</Text>
|
|
65
|
-
)}
|
|
66
|
-
|
|
67
|
-
{showCharacterCounter && (
|
|
68
|
-
<Text
|
|
69
|
-
sx={{
|
|
70
|
-
marginLeft: 'auto',
|
|
71
|
-
fontSize: 'xs',
|
|
72
|
-
lineHeight: 0,
|
|
73
|
-
color: 'underemphasize',
|
|
74
|
-
}}
|
|
75
|
-
variant="character-counter"
|
|
76
|
-
>
|
|
77
|
-
{characterCounter}
|
|
78
|
-
</Text>
|
|
79
|
-
)}
|
|
80
41
|
</Label>
|
|
81
42
|
)}
|
|
82
43
|
|