@ttoss/forms 0.29.15 → 0.30.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.
@@ -1,11 +1,20 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ThemeUIStyleObject, Theme, SxProp } from '@ttoss/ui';
2
3
  import { PatternFormatProps } from 'react-number-format';
3
- import { F as FormFieldPatternFormatProps } from '../FormFieldPatternFormat-CXU5e0oh.js';
4
+ import { F as FormFieldPatternFormatProps } from '../FormFieldPatternFormat-3gBOUVd9.js';
4
5
 
5
6
  type FormFieldCNPJProps = {
6
7
  label: string;
7
8
  name: string;
8
9
  warning?: string | React.ReactNode;
10
+ inputTooltip?: {
11
+ render: string | React.ReactNode;
12
+ place: 'bottom' | 'top' | 'left' | 'right';
13
+ openOnClick?: boolean;
14
+ clickable?: boolean;
15
+ variant?: 'info' | 'warning' | 'success' | 'error';
16
+ sx?: ThemeUIStyleObject<Theme>;
17
+ } & SxProp;
9
18
  } & Partial<PatternFormatProps>;
10
19
  declare const isCnpjValid: (cnpj: any) => boolean;
11
20
  declare const FormFieldCNPJ: ({ label, name, ...patternFormatProps }: FormFieldCNPJProps) => react_jsx_runtime.JSX.Element;
@@ -14,6 +23,14 @@ type FormFieldPhoneProps = {
14
23
  label: string;
15
24
  name: string;
16
25
  warning?: string | React.ReactNode;
26
+ inputTooltip?: {
27
+ render: string | React.ReactNode;
28
+ place: 'bottom' | 'top' | 'left' | 'right';
29
+ openOnClick?: boolean;
30
+ clickable?: boolean;
31
+ variant?: 'info' | 'warning' | 'success' | 'error';
32
+ sx?: ThemeUIStyleObject<Theme>;
33
+ } & SxProp;
17
34
  } & Partial<PatternFormatProps>;
18
35
  declare const FormFieldPhone: ({ label, name, ...patternFormatProps }: FormFieldPhoneProps) => react_jsx_runtime.JSX.Element;
19
36
 
@@ -0,0 +1,20 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ThemeUIStyleObject, Theme } from '@ttoss/ui';
3
+ import { PatternFormatProps } from 'react-number-format';
4
+
5
+ type FormFieldPatternFormatProps = {
6
+ label?: string;
7
+ name: string;
8
+ warning?: string | React.ReactNode;
9
+ inputTooltip?: {
10
+ render: string | React.ReactNode;
11
+ place: 'bottom' | 'top' | 'left' | 'right';
12
+ openOnClick?: boolean;
13
+ clickable?: boolean;
14
+ variant?: 'info' | 'warning' | 'success' | 'error';
15
+ sx?: ThemeUIStyleObject<Theme>;
16
+ };
17
+ } & PatternFormatProps;
18
+ declare const FormFieldPatternFormat: ({ label, name, warning, inputTooltip, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
19
+
20
+ export { type FormFieldPatternFormatProps as F, FormFieldPatternFormat as a };
@@ -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-CK3E7LSM.js";
2
+ import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-AZFECRBC.js";
3
3
 
4
4
  // src/Brazil/FormFieldPhone.tsx
5
5
  import { Input } from "@ttoss/ui";
@@ -14,6 +14,7 @@ var FormFieldPhone = ({
14
14
  name,
15
15
  label,
16
16
  warning: patternFormatProps.warning,
17
+ inputTooltip: patternFormatProps.inputTooltip,
17
18
  render: ({
18
19
  field
19
20
  }) => {
@@ -1,5 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Form, useForm, yupResolver } from "../chunk-CK3E7LSM.js";
2
+ import { Form, useForm, yupResolver } from "../chunk-AZFECRBC.js";
3
3
 
4
4
  // src/MultistepForm/MultistepForm.tsx
5
5
  import { Flex as Flex6 } from "@ttoss/ui";
@@ -68,10 +68,10 @@ var FormErrorMessage = ({
68
68
  };
69
69
 
70
70
  // src/FormField.tsx
71
- import { Checkbox, Flex, Label, Switch } from "@ttoss/ui";
71
+ import { Checkbox, Flex, Label, Switch, Tooltip } from "@ttoss/ui";
72
72
  import * as React from "react";
73
73
  import { useController, useFormContext as useFormContext2 } from "react-hook-form";
74
- import { jsx as jsx3, jsxs } from "react/jsx-runtime";
74
+ import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
75
75
  var FormField = ({
76
76
  label,
77
77
  id: idProp,
@@ -79,6 +79,7 @@ var FormField = ({
79
79
  defaultValue,
80
80
  disabled,
81
81
  tooltip,
82
+ inputTooltip,
82
83
  sx,
83
84
  css,
84
85
  render,
@@ -96,37 +97,100 @@ var FormField = ({
96
97
  const hasError = !!errors[name];
97
98
  const uniqueId = React.useId();
98
99
  const id = idProp || `form-field-${name}-${uniqueId}`;
100
+ const tooltipId = `${id}-tooltip`;
101
+ const [showInputTooltip, setShowInputTooltip] = React.useState(false);
102
+ const inputRef = React.useRef(null);
103
+ React.useEffect(() => {
104
+ if (!inputTooltip) return;
105
+ const handleClickOutside = event => {
106
+ if (inputRef.current && !inputRef.current.contains(event.target)) {
107
+ setShowInputTooltip(false);
108
+ }
109
+ };
110
+ const handleEscapeKey = event => {
111
+ if (event.key === "Escape") {
112
+ setShowInputTooltip(false);
113
+ }
114
+ };
115
+ if (showInputTooltip) {
116
+ document.addEventListener("mousedown", handleClickOutside);
117
+ document.addEventListener("keydown", handleEscapeKey);
118
+ }
119
+ return () => {
120
+ document.removeEventListener("mousedown", handleClickOutside);
121
+ document.removeEventListener("keydown", handleEscapeKey);
122
+ };
123
+ }, [showInputTooltip, inputTooltip]);
99
124
  const memoizedRender = React.useMemo(() => {
100
125
  return React.Children.map(render(controllerReturn), child => {
101
126
  if (!React.isValidElement(child)) {
102
127
  return null;
103
128
  }
104
129
  const childProps = child.props;
130
+ const inputProps = {
131
+ ...childProps,
132
+ ref: inputRef,
133
+ onClick: e => {
134
+ childProps.onClick?.(e);
135
+ if (inputTooltip) {
136
+ setShowInputTooltip(true);
137
+ }
138
+ },
139
+ onFocus: e => {
140
+ childProps.onFocus?.(e);
141
+ if (inputTooltip && !inputTooltip.openOnClick) {
142
+ setShowInputTooltip(true);
143
+ }
144
+ },
145
+ onBlur: e => {
146
+ childProps.onBlur?.(e);
147
+ if (inputTooltip && !inputTooltip.openOnClick) {
148
+ setShowInputTooltip(false);
149
+ }
150
+ },
151
+ ...(inputTooltip && showInputTooltip ? {
152
+ "data-tooltip-id": tooltipId
153
+ } : {})
154
+ };
105
155
  if (label && [Checkbox, Switch].some(component => {
106
156
  return child.type === component;
107
157
  })) {
108
- return /* @__PURE__ */jsxs(Label, {
109
- "aria-disabled": disabled,
110
- tooltip,
111
- children: [/* @__PURE__ */jsx3(Flex, {
112
- children: warning ? React.createElement(child.type, {
113
- id,
114
- ...childProps,
115
- ...(warning ? {
116
- trailingIcon: "warning-alt"
117
- } : {})
118
- }) : React.createElement(child.type, {
119
- id,
120
- ...childProps
158
+ return /* @__PURE__ */jsxs(Fragment, {
159
+ children: [/* @__PURE__ */jsxs(Label, {
160
+ "aria-disabled": disabled,
161
+ tooltip,
162
+ children: [/* @__PURE__ */jsx3(Flex, {
163
+ children: warning ? React.createElement(child.type, {
164
+ id,
165
+ ...inputProps,
166
+ ...(warning ? {
167
+ trailingIcon: "warning-alt"
168
+ } : {})
169
+ }) : React.createElement(child.type, {
170
+ id,
171
+ ...inputProps
172
+ })
173
+ }), label]
174
+ }), inputTooltip && showInputTooltip && /* @__PURE__ */jsx3(Flex, {
175
+ sx: {
176
+ width: "full",
177
+ fontSize: "sm"
178
+ },
179
+ children: /* @__PURE__ */jsx3(Tooltip, {
180
+ id: tooltipId,
181
+ place: inputTooltip.place,
182
+ clickable: inputTooltip.clickable,
183
+ isOpen: showInputTooltip,
184
+ variant: inputTooltip.variant,
185
+ children: inputTooltip.render
121
186
  })
122
- }), label]
187
+ })]
123
188
  });
124
189
  }
125
190
  return /* @__PURE__ */jsxs(Flex, {
126
191
  sx: {
127
- width: "100%",
128
- flexDirection: "column",
129
- gap: "1"
192
+ width: "full",
193
+ flexDirection: "column"
130
194
  },
131
195
  children: [label && /* @__PURE__ */jsx3(Label, {
132
196
  "aria-disabled": disabled,
@@ -135,17 +199,31 @@ var FormField = ({
135
199
  children: label
136
200
  }), warning ? React.createElement(child.type, {
137
201
  id,
138
- ...childProps,
202
+ ...inputProps,
139
203
  ...(warning ? {
140
204
  trailingIcon: "warning-alt"
141
205
  } : {})
142
206
  }) : React.createElement(child.type, {
143
207
  id,
144
- ...childProps
208
+ ...inputProps
209
+ }), inputTooltip && showInputTooltip && /* @__PURE__ */jsx3(Flex, {
210
+ sx: {
211
+ width: "full",
212
+ fontSize: "sm"
213
+ },
214
+ children: /* @__PURE__ */jsx3(Tooltip, {
215
+ id: tooltipId,
216
+ place: inputTooltip.place,
217
+ clickable: inputTooltip.clickable,
218
+ isOpen: showInputTooltip,
219
+ variant: inputTooltip.variant,
220
+ sx: inputTooltip.sx,
221
+ children: inputTooltip.render
222
+ })
145
223
  })]
146
224
  });
147
225
  });
148
- }, [render, controllerReturn, label, disabled, id, tooltip, warning]);
226
+ }, [render, controllerReturn, label, disabled, id, tooltip, warning, inputTooltip, showInputTooltip, tooltipId]);
149
227
  return /* @__PURE__ */jsxs(Flex, {
150
228
  sx: {
151
229
  flexDirection: "column",
@@ -206,12 +284,14 @@ var FormFieldPatternFormat = ({
206
284
  label,
207
285
  name,
208
286
  warning,
287
+ inputTooltip,
209
288
  ...patternFormatProps
210
289
  }) => {
211
290
  return /* @__PURE__ */jsx5(FormField, {
212
291
  name,
213
292
  label,
214
293
  warning,
294
+ inputTooltip,
215
295
  render: ({
216
296
  field,
217
297
  fieldState
@@ -257,6 +337,7 @@ var FormFieldNumericFormat = ({
257
337
  name,
258
338
  warning,
259
339
  tooltip,
340
+ inputTooltip,
260
341
  ...numericFormatProps
261
342
  }) => {
262
343
  return /* @__PURE__ */jsx7(FormField, {
@@ -264,6 +345,7 @@ var FormFieldNumericFormat = ({
264
345
  name,
265
346
  warning,
266
347
  tooltip,
348
+ inputTooltip,
267
349
  render: ({
268
350
  field
269
351
  }) => {
@@ -323,6 +405,7 @@ var FormFieldInput = ({
323
405
  disabled: inputProps.disabled,
324
406
  tooltip,
325
407
  warning: inputProps.warning,
408
+ inputTooltip: inputProps.inputTooltip,
326
409
  sx,
327
410
  defaultValue,
328
411
  render: ({
@@ -355,6 +438,7 @@ var FormFieldPassword = ({
355
438
  disabled: inputProps.disabled,
356
439
  tooltip,
357
440
  warning: inputProps.warning,
441
+ inputTooltip: inputProps.inputTooltip,
358
442
  sx,
359
443
  defaultValue,
360
444
  render: ({
@@ -437,6 +521,7 @@ var FormFieldSelect = ({
437
521
  defaultValue,
438
522
  disabled,
439
523
  tooltip,
524
+ inputTooltip: selectProps.inputTooltip,
440
525
  warning: selectProps.warning,
441
526
  sx,
442
527
  css,
@@ -489,6 +574,7 @@ var FormFieldTextarea = ({
489
574
  label,
490
575
  name,
491
576
  warning,
577
+ inputTooltip,
492
578
  sx,
493
579
  ...textareaProps
494
580
  }) => {
@@ -499,6 +585,7 @@ var FormFieldTextarea = ({
499
585
  id,
500
586
  sx,
501
587
  warning,
588
+ inputTooltip,
502
589
  render: ({
503
590
  field,
504
591
  fieldState
@@ -733,6 +820,7 @@ var FormFieldCNPJ = ({
733
820
  name,
734
821
  label,
735
822
  warning: patternFormatProps.warning,
823
+ inputTooltip: patternFormatProps.inputTooltip,
736
824
  render: ({
737
825
  field
738
826
  }) => {
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-CK3E7LSM.js";
2
+ import { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-AZFECRBC.js";
3
3
  export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@ttoss/ui';
2
+ import { BoxProps, ThemeUIStyleObject, Theme, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@ttoss/ui';
3
3
  import * as React$1 from 'react';
4
4
  import { FieldValues, FormProviderProps, FieldName, FieldPath, FieldPathValue, UseControllerReturn } from 'react-hook-form';
5
5
  export * from 'react-hook-form';
6
6
  export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
7
- import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-CXU5e0oh.js';
8
- export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-CXU5e0oh.js';
7
+ import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-3gBOUVd9.js';
8
+ export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-3gBOUVd9.js';
9
9
  import { NumericFormatProps } from 'react-number-format';
10
10
  import './typings.d-HZBqJJjn.js';
11
11
  import * as yup from 'yup';
@@ -35,12 +35,20 @@ type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extend
35
35
  openOnClick?: boolean;
36
36
  clickable?: boolean;
37
37
  };
38
+ inputTooltip?: {
39
+ render: string | React$1.ReactNode;
40
+ place: 'bottom' | 'top' | 'left' | 'right';
41
+ openOnClick?: boolean;
42
+ clickable?: boolean;
43
+ variant?: 'info' | 'warning' | 'success' | 'error';
44
+ sx?: ThemeUIStyleObject<Theme>;
45
+ } & SxProp;
38
46
  warning?: string | React$1.ReactNode;
39
47
  } & SxProp;
40
48
  type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
41
49
  render: (props: UseControllerReturn<TFieldValues, TName>) => React$1.ReactElement;
42
50
  } & FormFieldProps<TFieldValues, TName>;
43
- declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled, tooltip, sx, css, render, warning, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
51
+ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled, tooltip, inputTooltip, sx, css, render, warning, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
44
52
 
45
53
  declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, tooltip, ...checkboxProps }: FormFieldProps<TFieldValues, TName> & CheckboxProps) => react_jsx_runtime.JSX.Element;
46
54
 
@@ -60,8 +68,16 @@ type FormFieldNumericFormatProps = {
60
68
  openOnClick?: boolean;
61
69
  clickable?: boolean;
62
70
  };
71
+ inputTooltip?: {
72
+ render: string | React$1.ReactNode;
73
+ place: 'bottom' | 'top' | 'left' | 'right';
74
+ openOnClick?: boolean;
75
+ clickable?: boolean;
76
+ variant?: 'info' | 'warning' | 'success' | 'error';
77
+ sx?: ThemeUIStyleObject<Theme>;
78
+ } & SxProp;
63
79
  } & NumericFormatProps;
64
- declare const FormFieldNumericFormat: ({ label, name, warning, tooltip, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
80
+ declare const FormFieldNumericFormat: ({ label, name, warning, tooltip, inputTooltip, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
65
81
 
66
82
  type FormFieldCurrencyInputProps = {
67
83
  label?: string;
@@ -95,10 +111,18 @@ declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>(
95
111
 
96
112
  declare const FormFieldSwitch: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, tooltip, ...switchProps }: FormFieldProps<TFieldValues, TName> & SwitchProps) => react_jsx_runtime.JSX.Element;
97
113
 
98
- declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, warning, sx, ...textareaProps }: {
114
+ declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, warning, inputTooltip, sx, ...textareaProps }: {
99
115
  label?: string;
100
116
  name: TName;
101
117
  warning?: string | React.ReactNode;
118
+ inputTooltip?: {
119
+ render: string | React.ReactNode;
120
+ place: "bottom" | "top" | "left" | "right";
121
+ openOnClick?: boolean;
122
+ clickable?: boolean;
123
+ variant?: "info" | "warning" | "success" | "error";
124
+ sx?: ThemeUIStyleObject<Theme>;
125
+ };
102
126
  } & TextareaProps) => react_jsx_runtime.JSX.Element;
103
127
 
104
128
  declare const useFormGroup: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.29.15",
3
+ "version": "0.30.0",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -40,7 +40,7 @@
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
42
42
  "@ttoss/react-i18n": "^2.0.11",
43
- "@ttoss/ui": "^5.6.1"
43
+ "@ttoss/ui": "^5.8.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/jest": "^29.5.14",
@@ -50,12 +50,12 @@
50
50
  "react-error-boundary": "^5.0.0",
51
51
  "tsup": "^8.3.5",
52
52
  "yup": "^1.6.1",
53
- "@ttoss/i18n-cli": "^0.7.28",
54
- "@ttoss/test-utils": "^2.1.23",
55
53
  "@ttoss/config": "^1.35.3",
56
- "@ttoss/ui": "^5.6.1",
54
+ "@ttoss/react-i18n": "^2.0.11",
57
55
  "@ttoss/react-icons": "^0.4.11",
58
- "@ttoss/react-i18n": "^2.0.11"
56
+ "@ttoss/i18n-cli": "^0.7.28",
57
+ "@ttoss/test-utils": "^2.1.23",
58
+ "@ttoss/ui": "^5.8.0"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",
@@ -1,11 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { PatternFormatProps } from 'react-number-format';
3
-
4
- type FormFieldPatternFormatProps = {
5
- label?: string;
6
- name: string;
7
- warning?: string | React.ReactNode;
8
- } & PatternFormatProps;
9
- declare const FormFieldPatternFormat: ({ label, name, warning, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
10
-
11
- export { type FormFieldPatternFormatProps as F, FormFieldPatternFormat as a };