@ultraviolet/form 6.0.0-beta.9 → 6.0.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.
- package/README.md +5 -6
- package/dist/components/CheckboxField/index.d.ts +1 -1
- package/dist/components/CheckboxField/index.js +25 -21
- package/dist/components/CheckboxGroupField/index.d.ts +4 -4
- package/dist/components/CheckboxGroupField/index.js +50 -35
- package/dist/components/DateInputField/index.d.ts +1 -1
- package/dist/components/DateInputField/index.js +52 -41
- package/dist/components/Form/index.d.ts +1 -1
- package/dist/components/Form/index.js +15 -11
- package/dist/components/KeyValueField/index.d.ts +1 -1
- package/dist/components/KeyValueField/index.js +75 -27
- package/dist/components/NumberInputField/index.d.ts +1 -1
- package/dist/components/NumberInputField/index.js +29 -19
- package/dist/components/RadioField/index.d.ts +1 -1
- package/dist/components/RadioField/index.js +25 -20
- package/dist/components/RadioGroupField/index.d.ts +4 -3
- package/dist/components/RadioGroupField/index.js +21 -13
- package/dist/components/SelectInputField/index.d.ts +1 -1
- package/dist/components/SelectInputField/index.js +28 -17
- package/dist/components/SelectableCardField/index.d.ts +1 -1
- package/dist/components/SelectableCardField/index.js +40 -29
- package/dist/components/SelectableCardGroupField/index.d.ts +1 -1
- package/dist/components/SelectableCardGroupField/index.js +34 -21
- package/dist/components/SelectableCardOptionGroupField/index.d.ts +2 -2
- package/dist/components/SelectableCardOptionGroupField/index.js +26 -22
- package/dist/components/SliderField/index.d.ts +1 -1
- package/dist/components/SliderField/index.js +38 -24
- package/dist/components/Submit/index.d.ts +1 -1
- package/dist/components/Submit/index.js +18 -6
- package/dist/components/SubmitErrorAlert/index.d.ts +1 -1
- package/dist/components/SubmitErrorAlert/index.js +3 -7
- package/dist/components/SwitchButtonField/index.d.ts +4 -3
- package/dist/components/SwitchButtonField/index.js +24 -11
- package/dist/components/TagInputField/index.d.ts +1 -1
- package/dist/components/TagInputField/index.js +21 -14
- package/dist/components/TextAreaField/index.d.ts +1 -1
- package/dist/components/TextAreaField/index.js +35 -27
- package/dist/components/TextInputField/index.d.ts +1 -1
- package/dist/components/TextInputField/index.js +36 -20
- package/dist/components/TimeInputField/index.d.ts +1 -1
- package/dist/components/TimeInputField/index.js +27 -17
- package/dist/components/ToggleField/index.d.ts +1 -1
- package/dist/components/ToggleField/index.js +27 -16
- package/dist/components/ToggleGroupField/index.d.ts +4 -4
- package/dist/components/ToggleGroupField/index.js +61 -0
- package/dist/components/UnitInputField/index.d.ts +1 -1
- package/dist/components/UnitInputField/index.js +27 -23
- package/dist/components/VerificationCodeField/index.d.ts +1 -1
- package/dist/components/VerificationCodeField/index.js +18 -13
- package/dist/components/index.d.ts +1 -0
- package/dist/hooks/useOnFieldChange.js +4 -5
- package/dist/index.js +2 -0
- package/dist/providers/ErrorContext/index.d.ts +1 -1
- package/dist/providers/ErrorContext/index.js +21 -18
- package/dist/utils/validateRegex.js +3 -1
- package/package.json +10 -14
- package/dist/components/CheckboxField/index.cjs +0 -55
- package/dist/components/CheckboxGroupField/index.cjs +0 -80
- package/dist/components/DateInputField/index.cjs +0 -85
- package/dist/components/Form/defaultErrors.cjs +0 -22
- package/dist/components/Form/index.cjs +0 -35
- package/dist/components/KeyValueField/index.cjs +0 -60
- package/dist/components/NumberInputField/index.cjs +0 -59
- package/dist/components/RadioField/index.cjs +0 -64
- package/dist/components/RadioGroupField/index.cjs +0 -45
- package/dist/components/SelectInputField/index.cjs +0 -50
- package/dist/components/SelectableCardField/index.cjs +0 -66
- package/dist/components/SelectableCardGroupField/index.cjs +0 -55
- package/dist/components/SelectableCardOptionGroupField/index.cjs +0 -59
- package/dist/components/SliderField/index.cjs +0 -76
- package/dist/components/Submit/index.cjs +0 -25
- package/dist/components/SubmitErrorAlert/index.cjs +0 -15
- package/dist/components/SwitchButtonField/index.cjs +0 -35
- package/dist/components/TagInputField/index.cjs +0 -51
- package/dist/components/TextAreaField/index.cjs +0 -84
- package/dist/components/TextInputField/index.cjs +0 -62
- package/dist/components/TimeInputField/index.cjs +0 -46
- package/dist/components/ToggleField/index.cjs +0 -55
- package/dist/components/UnitInputField/index.cjs +0 -58
- package/dist/components/VerificationCodeField/index.cjs +0 -48
- package/dist/hooks/useOnFieldChange.cjs +0 -21
- package/dist/index.cjs +0 -78
- package/dist/providers/ErrorContext/index.cjs +0 -34
- package/dist/utils/validateRegex.cjs +0 -4
- package/dist/validators/isInteger.cjs +0 -12
- package/dist/validators/maxDate.cjs +0 -4
- package/dist/validators/minDate.cjs +0 -4
package/README.md
CHANGED
|
@@ -8,17 +8,17 @@ It is using [React Hook Form](https://react-hook-form.com/) under the hood.
|
|
|
8
8
|
## Get Started
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
$ pnpm add @ultraviolet/ui @ultraviolet/form
|
|
11
|
+
$ pnpm add @ultraviolet/ui @ultraviolet/form @ultraviolet/themes
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
### Usage
|
|
15
15
|
|
|
16
|
-
To use the library you need to put a `ThemeProvider` from `@
|
|
16
|
+
To use the library you need to put a `ThemeProvider` from `@ultraviolet/themes` with the theme that comes from the same package or from `@ultraviolet/ui` then wrap all your fields inside a `Form`:
|
|
17
17
|
|
|
18
18
|
```tsx
|
|
19
|
-
import { ThemeProvider } from '@ultraviolet/
|
|
19
|
+
import { ThemeProvider } from '@ultraviolet/themes'
|
|
20
20
|
import { Form, TextInputField } from '@ultraviolet/form'
|
|
21
|
-
import { theme } from '@ultraviolet/ui'
|
|
21
|
+
import { theme } from '@ultraviolet/ui' // or import { theme } from "@ultraviolet/themes
|
|
22
22
|
import { useForm } from '@ultraviolet/form'
|
|
23
23
|
import '@ultraviolet/ui/styles'
|
|
24
24
|
|
|
@@ -167,9 +167,8 @@ pnpm add zod @hookform/resolvers
|
|
|
167
167
|
Here's how you can do it:
|
|
168
168
|
|
|
169
169
|
```tsx
|
|
170
|
-
import { ThemeProvider } from '@
|
|
170
|
+
import { ThemeProvider, theme } from '@ultraviolet/themes'
|
|
171
171
|
import { Form, TextInputField } from '@ultraviolet/form'
|
|
172
|
-
import { theme } from '@ultraviolet/ui'
|
|
173
172
|
import { useForm } from '@ultraviolet/form'
|
|
174
173
|
import { zodResolver } from "@hookform/resolvers/zod"
|
|
175
174
|
import * as z from "zod"
|
|
@@ -6,5 +6,5 @@ type CheckboxFieldProps<TFieldValues extends FieldValues, TFieldName extends Fie
|
|
|
6
6
|
className?: string;
|
|
7
7
|
children?: ReactNode;
|
|
8
8
|
};
|
|
9
|
-
export declare const CheckboxField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, name, label, disabled, required, children, onChange, onBlur, shouldUnregister, validate, "aria-label": ariaLabel, ...props }: CheckboxFieldProps<TFieldValues, TFieldName>) => import("
|
|
9
|
+
export declare const CheckboxField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, name, label, disabled, required, children, onChange, onBlur, shouldUnregister, validate, "aria-label": ariaLabel, ...props }: CheckboxFieldProps<TFieldValues, TFieldName>) => import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Checkbox } from "@ultraviolet/ui";
|
|
4
4
|
import { useController } from "react-hook-form";
|
|
5
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
@@ -17,14 +17,10 @@ const CheckboxField = ({
|
|
|
17
17
|
"aria-label": ariaLabel,
|
|
18
18
|
...props
|
|
19
19
|
}) => {
|
|
20
|
-
const {
|
|
21
|
-
getError
|
|
22
|
-
} = useErrors();
|
|
20
|
+
const { getError } = useErrors();
|
|
23
21
|
const {
|
|
24
22
|
field,
|
|
25
|
-
fieldState: {
|
|
26
|
-
error
|
|
27
|
-
}
|
|
23
|
+
fieldState: { error }
|
|
28
24
|
} = useController({
|
|
29
25
|
control,
|
|
30
26
|
disabled,
|
|
@@ -35,20 +31,28 @@ const CheckboxField = ({
|
|
|
35
31
|
},
|
|
36
32
|
shouldUnregister
|
|
37
33
|
});
|
|
38
|
-
return /* @__PURE__ */ jsx(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
Checkbox,
|
|
36
|
+
{
|
|
37
|
+
...props,
|
|
38
|
+
checked: !!field.value,
|
|
39
|
+
disabled: field.disabled,
|
|
40
|
+
error: getError({ label: label ?? ariaLabel ?? name }, error),
|
|
41
|
+
name: field.name,
|
|
42
|
+
onBlur: (event) => {
|
|
43
|
+
field.onBlur();
|
|
44
|
+
onBlur?.(event);
|
|
45
|
+
},
|
|
46
|
+
onChange: (event) => {
|
|
47
|
+
field.onChange(event.target.checked);
|
|
48
|
+
onChange?.(
|
|
49
|
+
event.target.checked
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
ref: field.ref,
|
|
53
|
+
...children ? { "aria-label": void 0, children } : { "aria-label": ariaLabel }
|
|
54
|
+
}
|
|
55
|
+
);
|
|
52
56
|
};
|
|
53
57
|
export {
|
|
54
58
|
CheckboxField
|
|
@@ -4,8 +4,8 @@ import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
5
|
type CheckboxGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Omit<ComponentProps<typeof CheckboxGroup>, 'value' | 'onChange'>;
|
|
6
6
|
export declare const CheckboxGroupField: {
|
|
7
|
-
<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, children, onChange, error: customError, name, required, shouldUnregister, validate, legend, ...props }: CheckboxGroupFieldProps<TFieldValues, TFieldName>): import("
|
|
8
|
-
Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, required, tooltip, }: Omit<({
|
|
7
|
+
<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, children, onChange, error: customError, name, required, shouldUnregister, validate, legend, ...props }: CheckboxGroupFieldProps<TFieldValues, TFieldName>): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, required, tooltip, style, }: Omit<({
|
|
9
9
|
error?: string | import("react").ReactNode;
|
|
10
10
|
helper?: import("react").ReactNode;
|
|
11
11
|
disabled?: boolean;
|
|
@@ -15,7 +15,7 @@ export declare const CheckboxGroupField: {
|
|
|
15
15
|
required?: boolean;
|
|
16
16
|
'data-testid'?: string;
|
|
17
17
|
tooltip?: string;
|
|
18
|
-
} & (Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onBlur" | "name" | "autoFocus" | "id" | "onClick" | "onFocus" | "tabIndex"> & ({
|
|
18
|
+
} & (Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onBlur" | "name" | "autoFocus" | "id" | "onClick" | "onFocus" | "tabIndex" | "style"> & ({
|
|
19
19
|
children: import("react").ReactNode;
|
|
20
20
|
'aria-label'?: never;
|
|
21
21
|
} | {
|
|
@@ -23,6 +23,6 @@ export declare const CheckboxGroupField: {
|
|
|
23
23
|
'aria-label': string;
|
|
24
24
|
}))) & import("react").RefAttributes<HTMLInputElement>, "onChange" | "checked"> & {
|
|
25
25
|
value: string;
|
|
26
|
-
}) => import("
|
|
26
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
27
27
|
};
|
|
28
28
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { CheckboxGroup } from "@ultraviolet/ui";
|
|
4
4
|
import { useCallback, Children, isValidElement } from "react";
|
|
5
5
|
import { useController } from "react-hook-form";
|
|
@@ -22,35 +22,34 @@ const CheckboxGroupField = ({
|
|
|
22
22
|
legend = "",
|
|
23
23
|
...props
|
|
24
24
|
}) => {
|
|
25
|
-
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
const { getError } = useErrors();
|
|
26
|
+
const checkboxValid = useCallback(
|
|
27
|
+
(value) => {
|
|
28
|
+
const requiredChildren = Children.map(children, (child) => {
|
|
29
|
+
if (isValidElement(child)) {
|
|
30
|
+
if (child.props.required) {
|
|
31
|
+
return child.props.name;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
33
34
|
}
|
|
34
35
|
return null;
|
|
36
|
+
})?.filter(Boolean) ?? [];
|
|
37
|
+
if (requiredChildren.length === 0 && !required) {
|
|
38
|
+
return true;
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
}, [children, required]);
|
|
40
|
+
if (!required && arraysContainSameValues(value, requiredChildren)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (value.length >= Children.count(children)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
},
|
|
48
|
+
[children, required]
|
|
49
|
+
);
|
|
49
50
|
const {
|
|
50
51
|
field,
|
|
51
|
-
fieldState: {
|
|
52
|
-
error
|
|
53
|
-
}
|
|
52
|
+
fieldState: { error }
|
|
54
53
|
} = useController({
|
|
55
54
|
control,
|
|
56
55
|
name,
|
|
@@ -62,17 +61,33 @@ const CheckboxGroupField = ({
|
|
|
62
61
|
},
|
|
63
62
|
shouldUnregister
|
|
64
63
|
});
|
|
65
|
-
return /* @__PURE__ */ jsx(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
return /* @__PURE__ */ jsx(
|
|
65
|
+
CheckboxGroup,
|
|
66
|
+
{
|
|
67
|
+
...props,
|
|
68
|
+
error: getError({ label: legend }, error) ?? customError,
|
|
69
|
+
legend,
|
|
70
|
+
name,
|
|
71
|
+
onChange: (event) => {
|
|
72
|
+
const fieldValue = field.value;
|
|
73
|
+
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
74
|
+
field.onChange(
|
|
75
|
+
fieldValue?.filter(
|
|
76
|
+
(currentValue) => currentValue !== event.currentTarget.value
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
field.onChange([...field.value, event.currentTarget.value]);
|
|
81
|
+
}
|
|
82
|
+
onChange?.(
|
|
83
|
+
event.currentTarget.value
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
required,
|
|
87
|
+
value: field.value,
|
|
88
|
+
children
|
|
73
89
|
}
|
|
74
|
-
|
|
75
|
-
}, required, value: field.value, children });
|
|
90
|
+
);
|
|
76
91
|
};
|
|
77
92
|
CheckboxGroupField.Checkbox = CheckboxGroup.Checkbox;
|
|
78
93
|
export {
|
|
@@ -3,5 +3,5 @@ import type { ComponentProps } from 'react';
|
|
|
3
3
|
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
5
|
type DateInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof DateInput>, 'required' | 'name' | 'onChange' | 'value'>;
|
|
6
|
-
export declare const DateInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ required, name, control, label, format, minDate, maxDate, onChange, onBlur, validate, selectsRange, showMonthYearPicker, shouldUnregister, ...props }: DateInputFieldProps<TFieldValues, TFieldName>) => import("
|
|
6
|
+
export declare const DateInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ required, name, control, label, format, minDate, maxDate, onChange, onBlur, validate, selectsRange, showMonthYearPicker, shouldUnregister, ...props }: DateInputFieldProps<TFieldValues, TFieldName>) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { DateInput } from "@ultraviolet/ui";
|
|
4
4
|
import { useController } from "react-hook-form";
|
|
5
5
|
import { maxDateValidator } from "../../validators/maxDate.js";
|
|
@@ -23,14 +23,10 @@ const DateInputField = ({
|
|
|
23
23
|
shouldUnregister = false,
|
|
24
24
|
...props
|
|
25
25
|
}) => {
|
|
26
|
-
const {
|
|
27
|
-
getError
|
|
28
|
-
} = useErrors();
|
|
26
|
+
const { getError } = useErrors();
|
|
29
27
|
const {
|
|
30
28
|
field,
|
|
31
|
-
fieldState: {
|
|
32
|
-
error
|
|
33
|
-
}
|
|
29
|
+
fieldState: { error }
|
|
34
30
|
} = useController({
|
|
35
31
|
control,
|
|
36
32
|
name,
|
|
@@ -44,41 +40,56 @@ const DateInputField = ({
|
|
|
44
40
|
},
|
|
45
41
|
shouldUnregister
|
|
46
42
|
});
|
|
47
|
-
return /* @__PURE__ */ jsx(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
field.
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
43
|
+
return /* @__PURE__ */ jsx(
|
|
44
|
+
DateInput,
|
|
45
|
+
{
|
|
46
|
+
...props,
|
|
47
|
+
endDate: selectsRange && Array.isArray(field.value) ? field.value[1] : void 0,
|
|
48
|
+
error: getError({ label, maxDate, minDate }, error),
|
|
49
|
+
format: format || ((value) => {
|
|
50
|
+
if (!value) {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
const date = parseDate(value);
|
|
54
|
+
return showMonthYearPicker ? date.toLocaleDateString(void 0, {
|
|
55
|
+
month: "numeric",
|
|
56
|
+
year: "numeric"
|
|
57
|
+
}) : date.toLocaleDateString();
|
|
58
|
+
}),
|
|
59
|
+
label,
|
|
60
|
+
maxDate,
|
|
61
|
+
minDate,
|
|
62
|
+
name: field.name,
|
|
63
|
+
onBlur: (e) => {
|
|
64
|
+
field.onBlur();
|
|
65
|
+
onBlur?.(e);
|
|
66
|
+
},
|
|
67
|
+
onChange: (val) => {
|
|
68
|
+
if (val && val instanceof Date) {
|
|
69
|
+
onChange?.(val);
|
|
70
|
+
const newDate = parseDate(val);
|
|
71
|
+
if (isEmpty(field.value)) {
|
|
72
|
+
field.onChange(newDate);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const currentDate = parseDate(field.value);
|
|
76
|
+
newDate.setHours(currentDate.getHours(), currentDate.getMinutes());
|
|
77
|
+
field.onChange(newDate);
|
|
78
|
+
} else if (Array.isArray(val)) {
|
|
79
|
+
onChange?.(val);
|
|
80
|
+
field.onChange(val);
|
|
81
|
+
} else if (val === null) {
|
|
82
|
+
onChange?.(val);
|
|
83
|
+
field.onChange(val);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
required,
|
|
87
|
+
selectsRange,
|
|
88
|
+
showMonthYearPicker,
|
|
89
|
+
startDate: selectsRange && Array.isArray(field.value) ? field.value[0] : void 0,
|
|
90
|
+
value: Array.isArray(field.value) ? void 0 : field.value
|
|
80
91
|
}
|
|
81
|
-
|
|
92
|
+
);
|
|
82
93
|
};
|
|
83
94
|
export {
|
|
84
95
|
DateInputField
|
|
@@ -9,5 +9,5 @@ type FormProps<TFieldValues extends FieldValues> = {
|
|
|
9
9
|
onSubmit: (data: TFieldValues) => Promise<OnSubmitReturn> | OnSubmitReturn;
|
|
10
10
|
methods: UseFormReturn<TFieldValues>;
|
|
11
11
|
};
|
|
12
|
-
export declare const Form: <TFieldValues extends FieldValues>({ children, methods, errors, onSubmit, name, }: FormProps<TFieldValues>) => import("
|
|
12
|
+
export declare const Form: <TFieldValues extends FieldValues>({ children, methods, errors, onSubmit, name, }: FormProps<TFieldValues>) => import("react/jsx-runtime").JSX.Element;
|
|
13
13
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { FormProvider } from "react-hook-form";
|
|
4
4
|
import { defaultErrors } from "./defaultErrors.js";
|
|
5
5
|
import { ErrorProvider } from "../../providers/ErrorContext/index.js";
|
|
@@ -19,16 +19,20 @@ const Form = ({
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsx(ErrorProvider, { errors: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsx(ErrorProvider, { errors: { ...defaultErrors, ...errors }, children: /* @__PURE__ */ jsx(
|
|
23
|
+
"form",
|
|
24
|
+
{
|
|
25
|
+
name,
|
|
26
|
+
noValidate: true,
|
|
27
|
+
onSubmit: async (e) => {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
e.stopPropagation();
|
|
30
|
+
await handleSubmit(e);
|
|
31
|
+
},
|
|
32
|
+
style: { display: "contents" },
|
|
33
|
+
children
|
|
34
|
+
}
|
|
35
|
+
) }) });
|
|
32
36
|
};
|
|
33
37
|
export {
|
|
34
38
|
Form
|
|
@@ -35,5 +35,5 @@ type KeyValueFieldProps<TFieldValues extends FieldValues, TFieldArrayName extend
|
|
|
35
35
|
/**
|
|
36
36
|
* A React component that allows users to manage key-value pairs
|
|
37
37
|
*/
|
|
38
|
-
export declare const KeyValueField: <TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>>({ name, inputKey, inputValue, addButton, maxSize, readOnly, control, onChange, onBlur, }: KeyValueFieldProps<TFieldValues, TFieldArrayName>) => import("
|
|
38
|
+
export declare const KeyValueField: <TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>>({ name, inputKey, inputValue, addButton, maxSize, readOnly, control, onChange, onBlur, }: KeyValueFieldProps<TFieldValues, TFieldArrayName>) => import("react/jsx-runtime").JSX.Element;
|
|
39
39
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs, jsx } from "
|
|
2
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
3
|
import { DeleteIcon, PlusIcon } from "@ultraviolet/icons";
|
|
4
4
|
import { Stack, Row, Button } from "@ultraviolet/ui";
|
|
5
5
|
import { useFieldArray, useFormContext } from "react-hook-form";
|
|
@@ -15,17 +15,11 @@ const KeyValueField = ({
|
|
|
15
15
|
onChange,
|
|
16
16
|
onBlur
|
|
17
17
|
}) => {
|
|
18
|
-
const {
|
|
19
|
-
fields,
|
|
20
|
-
append,
|
|
21
|
-
remove
|
|
22
|
-
} = useFieldArray({
|
|
18
|
+
const { fields, append, remove } = useFieldArray({
|
|
23
19
|
control,
|
|
24
20
|
name
|
|
25
21
|
});
|
|
26
|
-
const {
|
|
27
|
-
getValues
|
|
28
|
-
} = useFormContext();
|
|
22
|
+
const { getValues } = useFormContext();
|
|
29
23
|
const handleFieldChange = () => {
|
|
30
24
|
onChange?.(getValues(name));
|
|
31
25
|
};
|
|
@@ -35,24 +29,78 @@ const KeyValueField = ({
|
|
|
35
29
|
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
36
30
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
37
31
|
return /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
|
|
38
|
-
fields.length > 0 ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
fields.length > 0 ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(
|
|
33
|
+
Row,
|
|
34
|
+
{
|
|
35
|
+
alignItems: "end",
|
|
36
|
+
gap: 2,
|
|
37
|
+
templateColumns: "1fr 1fr auto",
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ jsx(
|
|
40
|
+
TextInputField,
|
|
41
|
+
{
|
|
42
|
+
label: inputKey.label,
|
|
43
|
+
name: `${name}.${index}.key`,
|
|
44
|
+
onBlur: handleFieldBlur,
|
|
45
|
+
onChange: handleFieldChange,
|
|
46
|
+
readOnly,
|
|
47
|
+
regex: inputKey.regex,
|
|
48
|
+
required: inputKey.required
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
/* @__PURE__ */ jsx(
|
|
52
|
+
TextInputField,
|
|
53
|
+
{
|
|
54
|
+
autoComplete: "off",
|
|
55
|
+
label: inputValue.label,
|
|
56
|
+
name: `${name}.${index}.value`,
|
|
57
|
+
onBlur: handleFieldBlur,
|
|
58
|
+
onChange: handleFieldChange,
|
|
59
|
+
placeholder: inputValue.placeholder,
|
|
60
|
+
readOnly,
|
|
61
|
+
regex: inputValue.regex,
|
|
62
|
+
required: inputValue.required,
|
|
63
|
+
type: inputValue.type
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
/* @__PURE__ */ jsx(
|
|
67
|
+
Button,
|
|
68
|
+
{
|
|
69
|
+
"data-testid": `remove-button-${index}`,
|
|
70
|
+
disabled: readOnly,
|
|
71
|
+
onClick: () => {
|
|
72
|
+
remove(index);
|
|
73
|
+
handleFieldChange();
|
|
74
|
+
},
|
|
75
|
+
sentiment: "danger",
|
|
76
|
+
size: "large",
|
|
77
|
+
variant: "outlined",
|
|
78
|
+
children: /* @__PURE__ */ jsx(DeleteIcon, {})
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
field.id
|
|
84
|
+
)) }) : null,
|
|
85
|
+
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsxs(
|
|
86
|
+
Button,
|
|
87
|
+
{
|
|
88
|
+
"data-testid": "add-button",
|
|
89
|
+
disabled: !canAdd || readOnly,
|
|
90
|
+
fullWidth: addButton.fullWidth,
|
|
91
|
+
onClick: () => {
|
|
92
|
+
append({ key: "", value: "" });
|
|
93
|
+
handleFieldChange();
|
|
94
|
+
},
|
|
95
|
+
sentiment: "primary",
|
|
96
|
+
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
97
|
+
variant: "outlined",
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsx(PlusIcon, {}),
|
|
100
|
+
addButton.name
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
) })
|
|
56
104
|
] });
|
|
57
105
|
};
|
|
58
106
|
export {
|
|
@@ -3,5 +3,5 @@ import type { ComponentProps } from 'react';
|
|
|
3
3
|
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
5
|
type NumberInputProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof NumberInput>, 'onChange'>;
|
|
6
|
-
export declare const NumberInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, max, min, name, onChange, onBlur, step, label, "aria-label": ariaLabel, required, shouldUnregister, validate, ...props }: NumberInputProps<TFieldValues, TFieldName>) => import("
|
|
6
|
+
export declare const NumberInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, max, min, name, onChange, onBlur, step, label, "aria-label": ariaLabel, required, shouldUnregister, validate, ...props }: NumberInputProps<TFieldValues, TFieldName>) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from "
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { NumberInput } from "@ultraviolet/ui";
|
|
4
4
|
import { useController } from "react-hook-form";
|
|
5
5
|
import { isInteger } from "../../validators/isInteger.js";
|
|
@@ -19,14 +19,10 @@ const NumberInputField = ({
|
|
|
19
19
|
validate,
|
|
20
20
|
...props
|
|
21
21
|
}) => {
|
|
22
|
-
const {
|
|
23
|
-
getError
|
|
24
|
-
} = useErrors();
|
|
22
|
+
const { getError } = useErrors();
|
|
25
23
|
const {
|
|
26
24
|
field,
|
|
27
|
-
fieldState: {
|
|
28
|
-
error
|
|
29
|
-
}
|
|
25
|
+
fieldState: { error }
|
|
30
26
|
} = useController({
|
|
31
27
|
control,
|
|
32
28
|
name,
|
|
@@ -41,18 +37,32 @@ const NumberInputField = ({
|
|
|
41
37
|
},
|
|
42
38
|
shouldUnregister
|
|
43
39
|
});
|
|
44
|
-
return /* @__PURE__ */ jsx(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
return /* @__PURE__ */ jsx(
|
|
41
|
+
NumberInput,
|
|
42
|
+
{
|
|
43
|
+
...props,
|
|
44
|
+
"aria-label": ariaLabel,
|
|
45
|
+
error: getError(
|
|
46
|
+
{ isInteger: step, label: label ?? ariaLabel ?? name, max, min },
|
|
47
|
+
error
|
|
48
|
+
),
|
|
49
|
+
label,
|
|
50
|
+
max,
|
|
51
|
+
min,
|
|
52
|
+
name: field.name,
|
|
53
|
+
onBlur: (event) => {
|
|
54
|
+
field.onBlur();
|
|
55
|
+
onBlur?.(event);
|
|
56
|
+
},
|
|
57
|
+
onChange: (newValue) => {
|
|
58
|
+
field.onChange(newValue);
|
|
59
|
+
onChange?.(newValue);
|
|
60
|
+
},
|
|
61
|
+
required,
|
|
62
|
+
step,
|
|
63
|
+
value: field.value
|
|
64
|
+
}
|
|
65
|
+
);
|
|
56
66
|
};
|
|
57
67
|
export {
|
|
58
68
|
NumberInputField
|
|
@@ -3,5 +3,5 @@ import type { ComponentProps } from 'react';
|
|
|
3
3
|
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
5
|
type RadioFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Omit<ComponentProps<typeof Radio>, 'value' | 'onChange'>;
|
|
6
|
-
export declare const RadioField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, disabled, name, onBlur, label, onChange, onFocus, required, value, shouldUnregister, validate, "aria-label": ariaLabel, ...props }: RadioFieldProps<TFieldValues, TFieldName>) => import("
|
|
6
|
+
export declare const RadioField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, disabled, name, onBlur, label, onChange, onFocus, required, value, shouldUnregister, validate, "aria-label": ariaLabel, ...props }: RadioFieldProps<TFieldValues, TFieldName>) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|