@ttoss/forms 0.14.5 → 0.14.6

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 CHANGED
@@ -120,12 +120,21 @@ var FormFieldCheckbox = ({
120
120
  };
121
121
 
122
122
  // src/FormFieldInput.tsx
123
- import { Box as Box4, Input, Label as Label3 } from "@ttoss/ui";
123
+ import {
124
+ Box as Box4,
125
+ Icon,
126
+ Input,
127
+ Label as Label3,
128
+ Text as Text2
129
+ } from "@ttoss/ui";
124
130
  import { useController as useController3 } from "react-hook-form";
131
+ import React3 from "react";
125
132
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
126
133
  var FormFieldInput = ({
127
134
  label,
128
135
  name,
136
+ tooltipIcon,
137
+ showCharacterCounter,
129
138
  ...inputProps
130
139
  }) => {
131
140
  const {
@@ -134,9 +143,45 @@ var FormFieldInput = ({
134
143
  name,
135
144
  defaultValue: ""
136
145
  });
146
+ const characterCounter = React3.useMemo(() => {
147
+ if (!value) {
148
+ return 0;
149
+ }
150
+ return String(value).length;
151
+ }, [value]);
137
152
  const id = `form-field-input-${name}`;
138
153
  return /* @__PURE__ */ jsxs3(Box4, { children: [
139
- label && /* @__PURE__ */ jsx5(Label3, { "aria-disabled": inputProps.disabled, htmlFor: id, children: label }),
154
+ label && /* @__PURE__ */ jsxs3(
155
+ Label3,
156
+ {
157
+ sx: { display: "flex", alignItems: "center" },
158
+ "aria-disabled": inputProps.disabled,
159
+ htmlFor: id,
160
+ children: [
161
+ label,
162
+ tooltipIcon && /* @__PURE__ */ jsx5(
163
+ Text2,
164
+ {
165
+ sx: { marginLeft: "md", fontSize: "xs", lineHeight: 0 },
166
+ variant: "tooltip-icon",
167
+ children: /* @__PURE__ */ jsx5(Icon, { icon: tooltipIcon })
168
+ }
169
+ ),
170
+ showCharacterCounter && /* @__PURE__ */ jsx5(
171
+ Text2,
172
+ {
173
+ sx: {
174
+ marginLeft: "auto",
175
+ fontSize: "xs",
176
+ lineHeight: 0
177
+ },
178
+ variant: "character-counter",
179
+ children: characterCounter
180
+ }
181
+ )
182
+ ]
183
+ }
184
+ ),
140
185
  /* @__PURE__ */ jsx5(
141
186
  Input,
142
187
  {
package/dist/index.d.ts CHANGED
@@ -5,8 +5,7 @@ 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, CheckboxProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
9
- import * as iconify_icon from 'iconify-icon';
8
+ import { BoxProps, CheckboxProps, IconType, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
9
  import * as theme_ui from 'theme-ui';
11
10
 
12
11
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
@@ -30,12 +29,14 @@ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues
30
29
  name: react_hook_form.Path<TFieldValues>;
31
30
  } & CheckboxProps) => JSX.Element;
32
31
 
33
- declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends react_hook_form.Path<TFieldValues> = react_hook_form.Path<TFieldValues>>({ label, name, ...inputProps }: {
32
+ declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends react_hook_form.Path<TFieldValues> = react_hook_form.Path<TFieldValues>>({ label, name, tooltipIcon, showCharacterCounter, ...inputProps }: {
34
33
  label?: string | undefined;
35
34
  name: TName;
35
+ tooltipIcon?: IconType | undefined;
36
+ showCharacterCounter?: boolean | undefined;
36
37
  } & theme_ui.InputProps & {
37
- leadingIcon?: React.ReactNode | iconify_icon.IconifyIcon;
38
- trailingIcon?: React.ReactNode | iconify_icon.IconifyIcon;
38
+ leadingIcon?: IconType | undefined;
39
+ trailingIcon?: IconType | undefined;
39
40
  }) => JSX.Element;
40
41
 
41
42
  type FormRadioOption$1 = {
package/dist/index.js CHANGED
@@ -162,10 +162,13 @@ var FormFieldCheckbox = ({
162
162
  // src/FormFieldInput.tsx
163
163
  var import_ui5 = require("@ttoss/ui");
164
164
  var import_react_hook_form5 = require("react-hook-form");
165
+ var import_react = __toESM(require("react"));
165
166
  var import_jsx_runtime5 = require("react/jsx-runtime");
166
167
  var FormFieldInput = ({
167
168
  label,
168
169
  name,
170
+ tooltipIcon,
171
+ showCharacterCounter,
169
172
  ...inputProps
170
173
  }) => {
171
174
  const {
@@ -174,9 +177,45 @@ var FormFieldInput = ({
174
177
  name,
175
178
  defaultValue: ""
176
179
  });
180
+ const characterCounter = import_react.default.useMemo(() => {
181
+ if (!value) {
182
+ return 0;
183
+ }
184
+ return String(value).length;
185
+ }, [value]);
177
186
  const id = `form-field-input-${name}`;
178
187
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_ui5.Box, { children: [
179
- label && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_ui5.Label, { "aria-disabled": inputProps.disabled, htmlFor: id, children: label }),
188
+ label && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
189
+ import_ui5.Label,
190
+ {
191
+ sx: { display: "flex", alignItems: "center" },
192
+ "aria-disabled": inputProps.disabled,
193
+ htmlFor: id,
194
+ children: [
195
+ label,
196
+ tooltipIcon && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
197
+ import_ui5.Text,
198
+ {
199
+ sx: { marginLeft: "md", fontSize: "xs", lineHeight: 0 },
200
+ variant: "tooltip-icon",
201
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_ui5.Icon, { icon: tooltipIcon })
202
+ }
203
+ ),
204
+ showCharacterCounter && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
205
+ import_ui5.Text,
206
+ {
207
+ sx: {
208
+ marginLeft: "auto",
209
+ fontSize: "xs",
210
+ lineHeight: 0
211
+ },
212
+ variant: "character-counter",
213
+ children: characterCounter
214
+ }
215
+ )
216
+ ]
217
+ }
218
+ ),
180
219
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
181
220
  import_ui5.Input,
182
221
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.14.5",
3
+ "version": "0.14.6",
4
4
  "license": "UNLICENSED",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -31,7 +31,7 @@
31
31
  "devDependencies": {
32
32
  "@ttoss/config": "^1.28.2",
33
33
  "@ttoss/test-utils": "^1.20.4",
34
- "@ttoss/ui": "^1.30.5",
34
+ "@ttoss/ui": "^1.30.6",
35
35
  "@types/jest": "^29.4.0",
36
36
  "jest": "^29.4.3",
37
37
  "react": "^18.2.0",
@@ -41,5 +41,5 @@
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "9a1d05dc6546c74a3f83835e4dcef00bc7040b6b"
44
+ "gitHead": "0a6b947e6dc4386ff80861cbed8c119c6bd39f47"
45
45
  }
@@ -1,6 +1,15 @@
1
- import { Box, Input, type InputProps, Label } from '@ttoss/ui';
1
+ import {
2
+ Box,
3
+ Icon,
4
+ type IconType,
5
+ Input,
6
+ type InputProps,
7
+ Label,
8
+ Text,
9
+ } from '@ttoss/ui';
2
10
  import { ErrorMessage } from './ErrorMessage';
3
11
  import { FieldPath, FieldValues, useController } from 'react-hook-form';
12
+ import React from 'react';
4
13
 
5
14
  export const FormFieldInput = <
6
15
  TFieldValues extends FieldValues = FieldValues,
@@ -8,10 +17,14 @@ export const FormFieldInput = <
8
17
  >({
9
18
  label,
10
19
  name,
20
+ tooltipIcon,
21
+ showCharacterCounter,
11
22
  ...inputProps
12
23
  }: {
13
24
  label?: string;
14
25
  name: TName;
26
+ tooltipIcon?: IconType;
27
+ showCharacterCounter?: boolean;
15
28
  } & InputProps) => {
16
29
  const {
17
30
  field: { onChange, onBlur, value, ref },
@@ -20,15 +33,49 @@ export const FormFieldInput = <
20
33
  defaultValue: '',
21
34
  });
22
35
 
36
+ const characterCounter = React.useMemo(() => {
37
+ if (!value) {
38
+ return 0;
39
+ }
40
+
41
+ return String(value).length;
42
+ }, [value]);
43
+
23
44
  const id = `form-field-input-${name}`;
24
45
 
25
46
  return (
26
47
  <Box>
27
48
  {label && (
28
- <Label aria-disabled={inputProps.disabled} htmlFor={id}>
49
+ <Label
50
+ sx={{ display: 'flex', alignItems: 'center' }}
51
+ aria-disabled={inputProps.disabled}
52
+ htmlFor={id}
53
+ >
29
54
  {label}
55
+ {tooltipIcon && (
56
+ <Text
57
+ sx={{ marginLeft: 'md', fontSize: 'xs', lineHeight: 0 }}
58
+ variant="tooltip-icon"
59
+ >
60
+ <Icon icon={tooltipIcon} />
61
+ </Text>
62
+ )}
63
+
64
+ {showCharacterCounter && (
65
+ <Text
66
+ sx={{
67
+ marginLeft: 'auto',
68
+ fontSize: 'xs',
69
+ lineHeight: 0,
70
+ }}
71
+ variant="character-counter"
72
+ >
73
+ {characterCounter}
74
+ </Text>
75
+ )}
30
76
  </Label>
31
77
  )}
78
+
32
79
  <Input
33
80
  ref={ref}
34
81
  onChange={onChange}
@@ -38,6 +85,7 @@ export const FormFieldInput = <
38
85
  id={id}
39
86
  {...inputProps}
40
87
  />
88
+
41
89
  <ErrorMessage name={name} />
42
90
  </Box>
43
91
  );