@ttoss/forms 0.18.9 → 0.18.11

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
@@ -257,13 +257,12 @@ var FormFieldInput = ({
257
257
  defaultValue,
258
258
  render: ({
259
259
  field,
260
- formState
260
+ fieldState
261
261
  }) => {
262
- const hasError = !!formState.errors[name]?.message;
263
262
  return /* @__PURE__ */jsx5(Input, {
264
263
  ...inputProps,
265
264
  ...field,
266
- "aria-invalid": hasError.valueOf()
265
+ "aria-invalid": fieldState.error ? "true" : void 0
267
266
  });
268
267
  }
269
268
  });
@@ -291,13 +290,12 @@ var FormFieldPassword = ({
291
290
  defaultValue,
292
291
  render: ({
293
292
  field,
294
- formState
293
+ fieldState
295
294
  }) => {
296
- const hasError = !!formState.errors[name]?.message;
297
295
  return /* @__PURE__ */jsx6(InputPassword, {
298
296
  ...inputProps,
299
297
  ...field,
300
- "aria-invalid": hasError.valueOf()
298
+ "aria-invalid": fieldState.error ? "true" : void 0
301
299
  });
302
300
  }
303
301
  });
@@ -451,11 +449,13 @@ var FormFieldTextarea = ({
451
449
  id,
452
450
  sx,
453
451
  render: ({
454
- field
452
+ field,
453
+ fieldState
455
454
  }) => {
456
455
  return /* @__PURE__ */jsx9(Textarea, {
457
456
  ...field,
458
- ...textareaProps
457
+ ...textareaProps,
458
+ "aria-invalid": fieldState.error ? "true" : void 0
459
459
  });
460
460
  }
461
461
  });
@@ -0,0 +1,93 @@
1
+ export { yupResolver } from '@hookform/resolvers/yup';
2
+ import * as react_hook_form from 'react-hook-form';
3
+ import { FieldValues, FieldPath, FieldPathValue, UseControllerReturn } from 'react-hook-form';
4
+ export * from 'react-hook-form';
5
+ import * as yup from 'yup';
6
+ export { yup };
7
+ import * as react_jsx_runtime from 'react/jsx-runtime';
8
+ import * as React from 'react';
9
+ import { BoxProps, FlexProps, CheckboxProps, InputProps, InputPasswordProps, RadioProps, SelectProps, TextareaProps } from '@ttoss/ui';
10
+
11
+ declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
12
+ children?: React.ReactNode;
13
+ onSubmit?: ((data: TFieldValues) => Promise<void> | void) | undefined;
14
+ sx?: BoxProps['sx'];
15
+ } & {
16
+ children: React.ReactNode | React.ReactNode[];
17
+ } & react_hook_form.UseFormReturn<TFieldValues, any, undefined>) => react_jsx_runtime.JSX.Element;
18
+
19
+ type FormFieldProps = {
20
+ sx?: FlexProps['sx'];
21
+ disabled?: boolean;
22
+ tooltip?: boolean;
23
+ onTooltipClick?: () => void;
24
+ };
25
+ type FormFieldCompleteProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
26
+ label?: string;
27
+ id?: string;
28
+ name: TName;
29
+ defaultValue?: FieldPathValue<TFieldValues, TName>;
30
+ render: (props: UseControllerReturn<TFieldValues, TName>) => React.ReactElement;
31
+ } & FormFieldProps;
32
+ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, id: idProp, name, defaultValue, sx, render, ...formFieldProps }: FormFieldCompleteProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
33
+
34
+ declare const FormFieldCheckbox: <TFieldValues extends FieldValues = FieldValues>({ label, name, sx, ...checkboxProps }: {
35
+ label?: string | undefined;
36
+ name: FieldPath<TFieldValues>;
37
+ } & CheckboxProps) => react_jsx_runtime.JSX.Element;
38
+
39
+ type FormFieldInputProps<TName> = {
40
+ label?: string;
41
+ name: TName;
42
+ } & InputProps & FormFieldProps;
43
+ declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, tooltip, onTooltipClick, sx, defaultValue, ...inputProps }: FormFieldInputProps<TName>) => react_jsx_runtime.JSX.Element;
44
+
45
+ type FormFieldPasswordProps<TName> = {
46
+ label?: string;
47
+ name: TName;
48
+ } & InputPasswordProps & FormFieldProps;
49
+ declare const FormFieldPassword: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, tooltip, onTooltipClick, sx, defaultValue, ...inputProps }: FormFieldPasswordProps<TName>) => react_jsx_runtime.JSX.Element;
50
+
51
+ type FormRadioOption$1 = {
52
+ value: string | number;
53
+ label: string;
54
+ };
55
+ declare const FormFieldRadio: <TFieldValues extends FieldValues = FieldValues>({ label, name, options, sx, ...radioProps }: {
56
+ label?: string | undefined;
57
+ name: FieldPath<TFieldValues>;
58
+ options: FormRadioOption$1[];
59
+ } & RadioProps) => react_jsx_runtime.JSX.Element;
60
+
61
+ type FormRadioOption = {
62
+ value: string | number;
63
+ label: string;
64
+ };
65
+ type SelectSwitchProps = (SelectProps & {
66
+ placeholder?: never;
67
+ }) | (SelectProps & {
68
+ defaultValue?: never;
69
+ });
70
+ type FormFieldSelectProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = SelectSwitchProps & FormFieldProps & {
71
+ label?: string;
72
+ name: FieldPath<TFieldValues>;
73
+ options: FormRadioOption[];
74
+ defaultValue?: FieldPathValue<TFieldValues, TName>;
75
+ };
76
+ declare const FormFieldSelect: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, options, sx, ...selectProps }: FormFieldSelectProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
77
+
78
+ declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, name, sx, ...textareaProps }: {
79
+ label?: string | undefined;
80
+ name: TName;
81
+ } & TextareaProps) => react_jsx_runtime.JSX.Element;
82
+
83
+ declare const useFormGroup: () => {
84
+ level: number | undefined;
85
+ levelsLength: number;
86
+ };
87
+ type FormGroupProps = {
88
+ title?: string;
89
+ direction?: 'column' | 'row';
90
+ } & BoxProps;
91
+ declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
92
+
93
+ export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldPassword, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
package/dist/index.js CHANGED
@@ -293,13 +293,12 @@ var FormFieldInput = ({
293
293
  defaultValue,
294
294
  render: ({
295
295
  field,
296
- formState
296
+ fieldState
297
297
  }) => {
298
- const hasError = !!formState.errors[name]?.message;
299
298
  return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_ui5.Input, {
300
299
  ...inputProps,
301
300
  ...field,
302
- "aria-invalid": hasError.valueOf()
301
+ "aria-invalid": fieldState.error ? "true" : void 0
303
302
  });
304
303
  }
305
304
  });
@@ -327,13 +326,12 @@ var FormFieldPassword = ({
327
326
  defaultValue,
328
327
  render: ({
329
328
  field,
330
- formState
329
+ fieldState
331
330
  }) => {
332
- const hasError = !!formState.errors[name]?.message;
333
331
  return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_ui6.InputPassword, {
334
332
  ...inputProps,
335
333
  ...field,
336
- "aria-invalid": hasError.valueOf()
334
+ "aria-invalid": fieldState.error ? "true" : void 0
337
335
  });
338
336
  }
339
337
  });
@@ -487,11 +485,13 @@ var FormFieldTextarea = ({
487
485
  id,
488
486
  sx,
489
487
  render: ({
490
- field
488
+ field,
489
+ fieldState
491
490
  }) => {
492
491
  return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Textarea, {
493
492
  ...field,
494
- ...textareaProps
493
+ ...textareaProps,
494
+ "aria-invalid": fieldState.error ? "true" : void 0
495
495
  });
496
496
  }
497
497
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.18.9",
3
+ "version": "0.18.11",
4
4
  "license": "UNLICENSED",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -27,24 +27,24 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": ">=16.8.0",
30
- "@ttoss/react-i18n": "^1.23.5",
31
- "@ttoss/ui": "^2.0.2"
30
+ "@ttoss/react-i18n": "^1.23.6",
31
+ "@ttoss/ui": "^2.0.3"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/jest": "^29.5.2",
34
+ "@types/jest": "^29.5.3",
35
35
  "@types/react": "^18.2.12",
36
- "jest": "^29.5.0",
36
+ "jest": "^29.6.1",
37
37
  "react": "^18.2.0",
38
38
  "react-error-boundary": "^4.0.9",
39
39
  "react-hook-form": "^7.44.3",
40
40
  "theme-ui": "^0.16.0",
41
- "tsup": "^7.0.0",
41
+ "tsup": "^7.1.0",
42
42
  "yup": "^1.2.0",
43
- "@ttoss/config": "^1.30.4",
44
- "@ttoss/i18n-cli": "^0.6.3",
45
- "@ttoss/react-i18n": "^1.23.5",
46
- "@ttoss/test-utils": "^1.23.5",
47
- "@ttoss/ui": "^2.0.2"
43
+ "@ttoss/config": "^1.30.5",
44
+ "@ttoss/i18n-cli": "^0.6.4",
45
+ "@ttoss/react-i18n": "^1.23.6",
46
+ "@ttoss/test-utils": "^1.23.6",
47
+ "@ttoss/ui": "^2.0.3"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public",
@@ -29,11 +29,13 @@ export const FormFieldInput = <
29
29
  onTooltipClick={onTooltipClick}
30
30
  sx={sx}
31
31
  defaultValue={defaultValue as FieldPathValue<TFieldValues, TName>}
32
- render={({ field, formState }) => {
33
- const hasError = !!formState.errors[name]?.message;
34
-
32
+ render={({ field, fieldState }) => {
35
33
  return (
36
- <Input {...inputProps} {...field} aria-invalid={hasError.valueOf()} />
34
+ <Input
35
+ {...inputProps}
36
+ {...field}
37
+ aria-invalid={fieldState.error ? 'true' : undefined}
38
+ />
37
39
  );
38
40
  }}
39
41
  />
@@ -29,14 +29,12 @@ export const FormFieldPassword = <
29
29
  onTooltipClick={onTooltipClick}
30
30
  sx={sx}
31
31
  defaultValue={defaultValue as FieldPathValue<TFieldValues, TName>}
32
- render={({ field, formState }) => {
33
- const hasError = !!formState.errors[name]?.message;
34
-
32
+ render={({ field, fieldState }) => {
35
33
  return (
36
34
  <InputPassword
37
35
  {...inputProps}
38
36
  {...field}
39
- aria-invalid={hasError.valueOf()}
37
+ aria-invalid={fieldState.error ? 'true' : undefined}
40
38
  />
41
39
  );
42
40
  }}
@@ -22,8 +22,14 @@ export const FormFieldTextarea = <
22
22
  name={name}
23
23
  id={id}
24
24
  sx={sx}
25
- render={({ field }) => {
26
- return <Textarea {...field} {...textareaProps} />;
25
+ render={({ field, fieldState }) => {
26
+ return (
27
+ <Textarea
28
+ {...field}
29
+ {...textareaProps}
30
+ aria-invalid={fieldState.error ? 'true' : undefined}
31
+ />
32
+ );
27
33
  }}
28
34
  />
29
35
  );