@ttoss/forms 0.29.2 → 0.29.3

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,10 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { PatternFormatProps } from 'react-number-format';
3
- import { F as FormFieldPatternFormatProps } from '../FormFieldPatternFormat-CkcL14ho.js';
3
+ import { F as FormFieldPatternFormatProps } from '../FormFieldPatternFormat-CXU5e0oh.js';
4
4
 
5
5
  type FormFieldCNPJProps = {
6
6
  label: string;
7
7
  name: string;
8
+ warning?: string | React.ReactNode;
8
9
  } & Partial<PatternFormatProps>;
9
10
  declare const isCnpjValid: (cnpj: any) => boolean;
10
11
  declare const FormFieldCNPJ: ({ label, name, ...patternFormatProps }: FormFieldCNPJProps) => react_jsx_runtime.JSX.Element;
@@ -12,6 +13,7 @@ declare const FormFieldCNPJ: ({ label, name, ...patternFormatProps }: FormFieldC
12
13
  type FormFieldPhoneProps = {
13
14
  label: string;
14
15
  name: string;
16
+ warning?: string | React.ReactNode;
15
17
  } & Partial<PatternFormatProps>;
16
18
  declare const FormFieldPhone: ({ label, name, ...patternFormatProps }: FormFieldPhoneProps) => react_jsx_runtime.JSX.Element;
17
19
 
@@ -4,7 +4,8 @@ import { PatternFormatProps } from 'react-number-format';
4
4
  type FormFieldPatternFormatProps = {
5
5
  label?: string;
6
6
  name: string;
7
+ warning?: string | React.ReactNode;
7
8
  } & PatternFormatProps;
8
- declare const FormFieldPatternFormat: ({ label, name, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
9
+ declare const FormFieldPatternFormat: ({ label, name, warning, ...patternFormatProps }: FormFieldPatternFormatProps) => react_jsx_runtime.JSX.Element;
9
10
 
10
11
  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-MXGOGSWG.js";
2
+ import { FormField, FormFieldCNPJ, FormFieldPatternFormat, isCnpjValid } from "../chunk-KEIHNDHT.js";
3
3
 
4
4
  // src/Brazil/FormFieldPhone.tsx
5
5
  import { Input } from "@ttoss/ui";
@@ -13,6 +13,7 @@ var FormFieldPhone = ({
13
13
  return /* @__PURE__ */jsx(FormField, {
14
14
  name,
15
15
  label,
16
+ warning: patternFormatProps.warning,
16
17
  render: ({
17
18
  field
18
19
  }) => {
@@ -1,5 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Form, useForm, yupResolver } from "../chunk-MXGOGSWG.js";
2
+ import { Form, useForm, yupResolver } from "../chunk-KEIHNDHT.js";
3
3
 
4
4
  // src/MultistepForm/MultistepForm.tsx
5
5
  import { Flex as Flex6 } from "@ttoss/ui";
@@ -26,9 +26,9 @@ var Form = ({
26
26
 
27
27
  // src/FormErrorMessage.tsx
28
28
  import { ErrorMessage } from "@hookform/error-message";
29
- import { useFormContext } from "react-hook-form";
30
29
  import { FormattedMessage } from "@ttoss/react-i18n";
31
30
  import { HelpText } from "@ttoss/ui";
31
+ import { useFormContext } from "react-hook-form";
32
32
  import { jsx as jsx2 } from "react/jsx-runtime";
33
33
  var isMessageDescriptor = possibleMessageDescriptor => {
34
34
  return possibleMessageDescriptor !== void 0 && possibleMessageDescriptor.defaultMessage !== void 0;
@@ -70,7 +70,7 @@ var FormErrorMessage = ({
70
70
  // src/FormField.tsx
71
71
  import { Checkbox, Flex, Label, Switch } from "@ttoss/ui";
72
72
  import * as React from "react";
73
- import { useController } from "react-hook-form";
73
+ import { useController, useFormContext as useFormContext2 } from "react-hook-form";
74
74
  import { jsx as jsx3, jsxs } from "react/jsx-runtime";
75
75
  var FormField = ({
76
76
  label,
@@ -82,12 +82,19 @@ var FormField = ({
82
82
  onTooltipClick,
83
83
  sx,
84
84
  css,
85
- render
85
+ render,
86
+ warning
86
87
  }) => {
87
88
  const controllerReturn = useController({
88
89
  name,
89
90
  defaultValue
90
91
  });
92
+ const {
93
+ formState: {
94
+ errors
95
+ }
96
+ } = useFormContext2();
97
+ const hasError = !!errors[name];
91
98
  const uniqueId = React.useId();
92
99
  const id = idProp || `form-field-${name}-${uniqueId}`;
93
100
  const memoizedRender = React.useMemo(() => {
@@ -104,7 +111,13 @@ var FormField = ({
104
111
  tooltip,
105
112
  onTooltipClick,
106
113
  children: [/* @__PURE__ */jsx3(Flex, {
107
- children: React.createElement(child.type, {
114
+ children: warning ? React.createElement(child.type, {
115
+ id,
116
+ ...childProps,
117
+ ...(warning ? {
118
+ trailingIcon: "warning-alt"
119
+ } : {})
120
+ }) : React.createElement(child.type, {
108
121
  id,
109
122
  ...childProps
110
123
  })
@@ -123,13 +136,19 @@ var FormField = ({
123
136
  tooltip,
124
137
  onTooltipClick,
125
138
  children: label
126
- }), React.createElement(child.type, {
139
+ }), warning ? React.createElement(child.type, {
140
+ id,
141
+ ...childProps,
142
+ ...(warning ? {
143
+ trailingIcon: "warning-alt"
144
+ } : {})
145
+ }) : React.createElement(child.type, {
127
146
  id,
128
147
  ...childProps
129
148
  })]
130
149
  });
131
150
  });
132
- }, [render, controllerReturn, label, disabled, id, tooltip, onTooltipClick]);
151
+ }, [render, controllerReturn, label, disabled, id, tooltip, onTooltipClick, warning]);
133
152
  return /* @__PURE__ */jsxs(Flex, {
134
153
  sx: {
135
154
  flexDirection: "column",
@@ -140,6 +159,15 @@ var FormField = ({
140
159
  css,
141
160
  children: [memoizedRender, /* @__PURE__ */jsx3(FormErrorMessage, {
142
161
  name
162
+ }), warning && !hasError && /* @__PURE__ */jsx3(Flex, {
163
+ sx: {
164
+ color: "feedback.text.caution.default",
165
+ fontSize: "sm",
166
+ gap: "2",
167
+ paddingBottom: "1",
168
+ alignItems: "center"
169
+ },
170
+ children: warning
143
171
  })]
144
172
  });
145
173
  };
@@ -181,11 +209,13 @@ import { jsx as jsx5 } from "react/jsx-runtime";
181
209
  var FormFieldPatternFormat = ({
182
210
  label,
183
211
  name,
212
+ warning,
184
213
  ...patternFormatProps
185
214
  }) => {
186
215
  return /* @__PURE__ */jsx5(FormField, {
187
216
  name,
188
217
  label,
218
+ warning,
189
219
  render: ({
190
220
  field,
191
221
  fieldState
@@ -215,6 +245,7 @@ var FormFieldCreditCardNumber = ({
215
245
  return /* @__PURE__ */jsx6(FormFieldPatternFormat, {
216
246
  name,
217
247
  label,
248
+ warning: formFieldPatternFormatProps.warning,
218
249
  format: "#### #### #### ####",
219
250
  placeholder: "1234 1234 1234 1234",
220
251
  ...formFieldPatternFormatProps
@@ -228,6 +259,7 @@ import { jsx as jsx7 } from "react/jsx-runtime";
228
259
  var FormFieldNumericFormat = ({
229
260
  label,
230
261
  name,
262
+ warning,
231
263
  tooltip,
232
264
  onTooltipClick,
233
265
  ...numericFormatProps
@@ -235,6 +267,7 @@ var FormFieldNumericFormat = ({
235
267
  return /* @__PURE__ */jsx7(FormField, {
236
268
  label,
237
269
  name,
270
+ warning,
238
271
  tooltip,
239
272
  onTooltipClick,
240
273
  render: ({
@@ -267,6 +300,7 @@ var FormFieldCurrencyInput = ({
267
300
  return /* @__PURE__ */jsx8(FormFieldNumericFormat, {
268
301
  name,
269
302
  label,
303
+ warning: formFieldNumericFormatProps.warning,
270
304
  fixedDecimalScale: true,
271
305
  decimalScale: 2,
272
306
  prefix,
@@ -296,6 +330,7 @@ var FormFieldInput = ({
296
330
  disabled: inputProps.disabled,
297
331
  tooltip,
298
332
  onTooltipClick,
333
+ warning: inputProps.warning,
299
334
  sx,
300
335
  defaultValue,
301
336
  render: ({
@@ -329,6 +364,7 @@ var FormFieldPassword = ({
329
364
  disabled: inputProps.disabled,
330
365
  tooltip,
331
366
  onTooltipClick,
367
+ warning: inputProps.warning,
332
368
  sx,
333
369
  defaultValue,
334
370
  render: ({
@@ -415,6 +451,7 @@ var FormFieldSelect = ({
415
451
  disabled,
416
452
  tooltip,
417
453
  onTooltipClick,
454
+ warning: selectProps.warning,
418
455
  sx,
419
456
  css,
420
457
  render: ({
@@ -467,6 +504,7 @@ import { jsx as jsx14 } from "react/jsx-runtime";
467
504
  var FormFieldTextarea = ({
468
505
  label,
469
506
  name,
507
+ warning,
470
508
  sx,
471
509
  ...textareaProps
472
510
  }) => {
@@ -476,6 +514,7 @@ var FormFieldTextarea = ({
476
514
  name,
477
515
  id,
478
516
  sx,
517
+ warning,
479
518
  render: ({
480
519
  field,
481
520
  fieldState
@@ -709,6 +748,7 @@ var FormFieldCNPJ = ({
709
748
  return /* @__PURE__ */jsx16(FormField, {
710
749
  name,
711
750
  label,
751
+ warning: patternFormatProps.warning,
712
752
  render: ({
713
753
  field
714
754
  }) => {
@@ -749,6 +789,6 @@ import * as yup2 from "yup";
749
789
 
750
790
  // src/index.ts
751
791
  import { yupResolver } from "@hookform/resolvers/yup";
752
- import { Controller, FormProvider as FormProvider2, useController as useController2, useFieldArray, useForm, useFormContext as useFormContext2, useFormState, useWatch } from "react-hook-form";
792
+ import { Controller, FormProvider as FormProvider2, useController as useController2, useFieldArray, useForm, useFormContext as useFormContext3, useFormState, useWatch } from "react-hook-form";
753
793
  export * from "react-hook-form";
754
- export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldPatternFormat, FormFieldCreditCardNumber, FormFieldNumericFormat, FormFieldCurrencyInput, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, useFormGroup, FormGroup, isCnpjValid, FormFieldCNPJ, yup2 as yup, yupResolver, Controller, FormProvider2 as FormProvider, useController2 as useController, useFieldArray, useForm, useFormContext2 as useFormContext, useFormState, useWatch };
794
+ export { Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldPatternFormat, FormFieldCreditCardNumber, FormFieldNumericFormat, FormFieldCurrencyInput, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, useFormGroup, FormGroup, isCnpjValid, FormFieldCNPJ, yup2 as yup, yupResolver, Controller, FormProvider2 as FormProvider, useController2 as useController, useFieldArray, useForm, useFormContext3 as useFormContext, useFormState, useWatch };
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-MXGOGSWG.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-KEIHNDHT.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
2
  import { BoxProps, SxProp, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@ttoss/ui';
3
- import * as React from 'react';
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-CkcL14ho.js';
8
- export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-CkcL14ho.js';
7
+ import { F as FormFieldPatternFormatProps } from './FormFieldPatternFormat-CXU5e0oh.js';
8
+ export { a as FormFieldPatternFormat } from './FormFieldPatternFormat-CXU5e0oh.js';
9
9
  import { NumericFormatProps } from 'react-number-format';
10
10
  import './typings.d-HZBqJJjn.js';
11
11
  import * as yup from 'yup';
@@ -13,7 +13,7 @@ export { yup };
13
13
  export { yupResolver } from '@hookform/resolvers/yup';
14
14
 
15
15
  declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
16
- children?: React.ReactNode;
16
+ children?: React$1.ReactNode;
17
17
  onSubmit?: (data: TFieldValues) => Promise<void> | void;
18
18
  sx?: BoxProps["sx"];
19
19
  } & FormProviderProps<TFieldValues>) => react_jsx_runtime.JSX.Element;
@@ -24,18 +24,19 @@ declare const FormErrorMessage: <TFieldValues extends FieldValues = FieldValues>
24
24
  }) => react_jsx_runtime.JSX.Element;
25
25
 
26
26
  type FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
27
- label?: React.ReactNode;
27
+ label?: React$1.ReactNode;
28
28
  id?: string;
29
29
  name: TName;
30
30
  defaultValue?: FieldPathValue<TFieldValues, TName>;
31
31
  disabled?: boolean;
32
- tooltip?: string | React.ReactNode;
32
+ tooltip?: string | React$1.ReactNode;
33
33
  onTooltipClick?: () => void;
34
+ warning?: string | React$1.ReactNode;
34
35
  } & SxProp;
35
36
  type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
36
- render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
37
+ render: (props: UseControllerReturn<TFieldValues, TName>) => React$1.ReactElement;
37
38
  } & FormFieldProps<TFieldValues, TName>;
38
- declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled, tooltip, onTooltipClick, sx, css, render, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
39
+ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, disabled, tooltip, onTooltipClick, sx, css, render, warning, }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
39
40
 
40
41
  declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, tooltip, onTooltipClick, ...checkboxProps }: FormFieldProps<TFieldValues, TName> & CheckboxProps) => react_jsx_runtime.JSX.Element;
41
42
 
@@ -48,17 +49,16 @@ declare const FormFieldCreditCardNumber: ({ label, name, ...formFieldPatternForm
48
49
  type FormFieldNumericFormatProps = {
49
50
  label?: string;
50
51
  name: string;
51
- tooltip?: string | React.ReactNode;
52
+ warning?: string | React$1.ReactNode;
53
+ tooltip?: string | React$1.ReactNode;
52
54
  onTooltipClick?: () => void;
53
55
  } & NumericFormatProps;
54
- declare const FormFieldNumericFormat: ({ label, name, tooltip, onTooltipClick, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
56
+ declare const FormFieldNumericFormat: ({ label, name, warning, tooltip, onTooltipClick, ...numericFormatProps }: FormFieldNumericFormatProps) => react_jsx_runtime.JSX.Element;
55
57
 
56
58
  type FormFieldCurrencyInputProps = {
57
59
  label?: string;
58
60
  name: string;
59
61
  prefix: string;
60
- decimalSeparator: string;
61
- thousandSeparator: string;
62
62
  } & FormFieldNumericFormatProps;
63
63
  declare const FormFieldCurrencyInput: ({ label, name, prefix, decimalSeparator, thousandSeparator, ...formFieldNumericFormatProps }: FormFieldCurrencyInputProps) => react_jsx_runtime.JSX.Element;
64
64
 
@@ -87,9 +87,10 @@ declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues>(
87
87
 
88
88
  declare const FormFieldSwitch: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, tooltip, onTooltipClick, ...switchProps }: FormFieldProps<TFieldValues, TName> & SwitchProps) => react_jsx_runtime.JSX.Element;
89
89
 
90
- declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, ...textareaProps }: {
90
+ declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, warning, sx, ...textareaProps }: {
91
91
  label?: string;
92
92
  name: TName;
93
+ warning?: string | React.ReactNode;
93
94
  } & TextareaProps) => react_jsx_runtime.JSX.Element;
94
95
 
95
96
  declare const useFormGroup: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.29.2",
3
+ "version": "0.29.3",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
42
- "@ttoss/react-i18n": "^2.0.9",
43
- "@ttoss/ui": "^5.4.0"
42
+ "@ttoss/ui": "^5.5.0",
43
+ "@ttoss/react-i18n": "^2.0.10"
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/react-i18n": "^2.0.9",
54
- "@ttoss/i18n-cli": "^0.7.26",
55
53
  "@ttoss/config": "^1.35.2",
56
54
  "@ttoss/react-icons": "^0.4.9",
57
- "@ttoss/ui": "^5.4.0",
58
- "@ttoss/test-utils": "^2.1.22"
55
+ "@ttoss/react-i18n": "^2.0.10",
56
+ "@ttoss/i18n-cli": "^0.7.27",
57
+ "@ttoss/test-utils": "^2.1.22",
58
+ "@ttoss/ui": "^5.5.0"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",