@ultraviolet/form 2.13.1 → 2.13.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.
- package/dist/components/CheckboxField/index.d.ts +10 -0
- package/dist/components/CheckboxField/index.js +40 -41
- package/dist/components/CheckboxGroupField/index.d.ts +32 -0
- package/dist/components/CheckboxGroupField/index.js +59 -53
- package/dist/components/DateField/index.d.ts +16 -0
- package/dist/components/DateField/index.js +53 -58
- package/dist/components/Form/defaultErrors.d.ts +2 -0
- package/dist/components/Form/defaultErrors.js +20 -19
- package/dist/components/Form/index.d.ts +69 -0
- package/dist/components/Form/index.js +52 -57
- package/dist/components/KeyValueField/index.d.ts +33 -0
- package/dist/components/KeyValueField/index.js +61 -60
- package/dist/components/NumberInputField/index.d.ts +13 -0
- package/dist/components/NumberInputField/index.js +39 -45
- package/dist/components/NumberInputFieldV2/index.d.ts +11 -0
- package/dist/components/NumberInputFieldV2/index.js +45 -51
- package/dist/components/RadioField/index.d.ts +12 -0
- package/dist/components/RadioField/index.js +36 -42
- package/dist/components/RadioGroupField/index.d.ts +28 -0
- package/dist/components/RadioGroupField/index.js +31 -32
- package/dist/components/SelectInputField/index.d.ts +82 -0
- package/dist/components/SelectInputField/index.js +90 -83
- package/dist/components/SelectInputFieldV2/index.d.ts +7 -0
- package/dist/components/SelectInputFieldV2/index.js +60 -60
- package/dist/components/SelectableCardField/index.d.ts +9 -0
- package/dist/components/SelectableCardField/index.js +49 -44
- package/dist/components/SelectableCardGroupField/index.d.ts +42 -0
- package/dist/components/SelectableCardGroupField/index.js +42 -41
- package/dist/components/Submit/index.d.ts +17 -0
- package/dist/components/Submit/index.js +27 -27
- package/dist/components/SubmitErrorAlert/index.d.ts +3 -0
- package/dist/components/SubmitErrorAlert/index.js +9 -17
- package/dist/components/TagInputField/index.d.ts +6 -0
- package/dist/components/TagInputField/index.js +35 -38
- package/dist/components/TextAreaField/index.d.ts +11 -0
- package/dist/components/TextAreaField/index.js +57 -56
- package/dist/components/TextInputField/index.d.ts +18 -0
- package/dist/components/TextInputField/index.js +82 -81
- package/dist/components/TextInputFieldV2/index.d.ts +12 -0
- package/dist/components/TextInputFieldV2/index.js +73 -72
- package/dist/components/TimeField/index.d.ts +9 -0
- package/dist/components/TimeField/index.js +51 -49
- package/dist/components/ToggleField/index.d.ts +10 -0
- package/dist/components/ToggleField/index.js +32 -31
- package/dist/components/ToggleGroupField/index.d.ts +26 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +4 -3
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useField.d.ts +34 -0
- package/dist/hooks/useField.js +7 -30
- package/dist/hooks/useFieldArray.d.ts +21 -0
- package/dist/hooks/useFieldArray.js +9 -22
- package/dist/hooks/useForm.d.ts +23 -0
- package/dist/hooks/useForm.js +8 -25
- package/dist/hooks/useFormState.d.ts +39 -0
- package/dist/hooks/useFormState.js +6 -23
- package/dist/hooks/useOnFieldChange.d.ts +3 -0
- package/dist/hooks/useOnFieldChange.js +10 -11
- package/dist/index.d.ts +7 -555
- package/dist/index.js +66 -29
- package/dist/mocks/index.d.ts +1 -0
- package/dist/mocks/mockErrors.d.ts +3 -0
- package/dist/providers/ErrorContext/index.d.ts +14 -0
- package/dist/providers/ErrorContext/index.js +30 -29
- package/dist/providers/index.d.ts +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/validators/index.d.ts +5 -0
- package/dist/validators/maxDate.d.ts +1 -0
- package/dist/validators/maxDate.js +4 -3
- package/dist/validators/minDate.d.ts +1 -0
- package/dist/validators/minDate.js +4 -3
- package/package.json +17 -11
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ErrorProvider } from
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import { useForm, FormProvider } from "react-hook-form";
|
|
4
|
+
import { FORM_ERROR } from "../../constants.js";
|
|
5
|
+
import { defaultErrors } from "./defaultErrors.js";
|
|
6
|
+
import { ErrorProvider } from "../../providers/ErrorContext/index.js";
|
|
7
|
+
const FormSubmitContext = React.createContext(
|
|
8
|
+
{}
|
|
9
|
+
);
|
|
9
10
|
const Form = ({
|
|
10
11
|
children,
|
|
11
12
|
methods: methodsProp,
|
|
@@ -16,10 +17,10 @@ const Form = ({
|
|
|
16
17
|
}) => {
|
|
17
18
|
const methodsHook = useForm({
|
|
18
19
|
defaultValues: initialValues,
|
|
19
|
-
mode:
|
|
20
|
+
mode: "onChange"
|
|
20
21
|
});
|
|
21
22
|
const methods = !methodsProp ? methodsHook : methodsProp;
|
|
22
|
-
const handleSubmit = methods.handleSubmit(async values => {
|
|
23
|
+
const handleSubmit = methods.handleSubmit(async (values) => {
|
|
23
24
|
const result = await onRawSubmit(values, {
|
|
24
25
|
reset: methods.reset,
|
|
25
26
|
resetFieldState: methods.resetField,
|
|
@@ -27,57 +28,51 @@ const Form = ({
|
|
|
27
28
|
change: methods.setValue
|
|
28
29
|
});
|
|
29
30
|
if (result === null) {
|
|
30
|
-
methods.setError(
|
|
31
|
-
type:
|
|
31
|
+
methods.setError("root.submit", {
|
|
32
|
+
type: "custom"
|
|
32
33
|
});
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
if (result && typeof result !==
|
|
36
|
-
methods.setError(
|
|
37
|
-
type:
|
|
38
|
-
message: typeof result ===
|
|
36
|
+
if (result && typeof result !== "boolean" && typeof result !== "number") {
|
|
37
|
+
methods.setError("root.submit", {
|
|
38
|
+
type: "custom",
|
|
39
|
+
message: typeof result === "object" ? result[FORM_ERROR] : result
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
|
-
const formSubmitContextValue = useMemo(
|
|
43
|
-
handleSubmit
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
});
|
|
43
|
+
const formSubmitContextValue = useMemo(
|
|
44
|
+
() => ({ handleSubmit }),
|
|
45
|
+
[handleSubmit]
|
|
46
|
+
);
|
|
47
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsx(FormSubmitContext.Provider, { value: formSubmitContextValue, children: /* @__PURE__ */ jsx(ErrorProvider, { errors: { ...defaultErrors, ...errors }, children: /* @__PURE__ */ jsx(
|
|
48
|
+
"form",
|
|
49
|
+
{
|
|
50
|
+
onSubmit: async (e) => {
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
e.stopPropagation();
|
|
53
|
+
await handleSubmit(e);
|
|
54
|
+
},
|
|
55
|
+
name,
|
|
56
|
+
noValidate: true,
|
|
57
|
+
children: typeof children === "function" ? children({
|
|
58
|
+
values: methods.watch(),
|
|
59
|
+
hasValidationErrors: !methods.formState.isValid,
|
|
60
|
+
errors: methods.formState.errors,
|
|
61
|
+
submitting: methods.formState.isSubmitting,
|
|
62
|
+
pristine: !methods.formState.isDirty,
|
|
63
|
+
handleSubmit,
|
|
64
|
+
submitError: !!methods.formState.errors?.root?.["submit"],
|
|
65
|
+
valid: methods.formState.isValid,
|
|
66
|
+
form: {
|
|
67
|
+
change: methods.setValue,
|
|
68
|
+
reset: methods.reset,
|
|
69
|
+
submit: handleSubmit
|
|
70
|
+
}
|
|
71
|
+
}) : children
|
|
72
|
+
}
|
|
73
|
+
) }) }) });
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
Form,
|
|
77
|
+
FormSubmitContext
|
|
81
78
|
};
|
|
82
|
-
|
|
83
|
-
export { Form, FormSubmitContext };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Button } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { Control, FieldArrayPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import { TextInputField as TextInputFieldV2 } from '../TextInputFieldV2';
|
|
5
|
+
type InputKeyProps = {
|
|
6
|
+
label: ComponentProps<typeof TextInputFieldV2>['label'];
|
|
7
|
+
required?: ComponentProps<typeof TextInputFieldV2>['required'];
|
|
8
|
+
regex?: ComponentProps<typeof TextInputFieldV2>['regex'];
|
|
9
|
+
};
|
|
10
|
+
type InputValueProps = {
|
|
11
|
+
type?: ComponentProps<typeof TextInputFieldV2>['type'];
|
|
12
|
+
placeholder?: ComponentProps<typeof TextInputFieldV2>['placeholder'];
|
|
13
|
+
} & InputKeyProps;
|
|
14
|
+
type AddButtonProps = {
|
|
15
|
+
name: ComponentProps<typeof Button>['children'];
|
|
16
|
+
fullWidth?: ComponentProps<typeof Button>['fullWidth'];
|
|
17
|
+
tooltip?: string;
|
|
18
|
+
maxSizeReachedTooltip?: string;
|
|
19
|
+
};
|
|
20
|
+
type KeyValueFieldProps<TFieldValues extends FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues>> = {
|
|
21
|
+
name: TFieldArrayName;
|
|
22
|
+
inputKey: InputKeyProps;
|
|
23
|
+
inputValue: InputValueProps;
|
|
24
|
+
addButton: AddButtonProps;
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
readonly?: boolean;
|
|
27
|
+
control?: Control<TFieldValues>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A React component that allows users to manage key-value pairs
|
|
31
|
+
*/
|
|
32
|
+
export declare const KeyValueField: <TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>>({ name, inputKey, inputValue, addButton, maxSize, readonly, control, }: KeyValueFieldProps<TFieldValues, TFieldArrayName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
33
|
+
export {};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A React component that allows users to manage key-value pairs
|
|
8
|
-
*/
|
|
1
|
+
import { jsxs, jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Stack, Row, Button } from "@ultraviolet/ui";
|
|
3
|
+
import { useFieldArray } from "react-hook-form";
|
|
4
|
+
import { TextInputField } from "../TextInputFieldV2/index.js";
|
|
9
5
|
const KeyValueField = ({
|
|
10
6
|
name,
|
|
11
7
|
inputKey,
|
|
@@ -15,70 +11,75 @@ const KeyValueField = ({
|
|
|
15
11
|
readonly = false,
|
|
16
12
|
control
|
|
17
13
|
}) => {
|
|
18
|
-
const {
|
|
19
|
-
fields,
|
|
20
|
-
append,
|
|
21
|
-
remove
|
|
22
|
-
} = useFieldArray({
|
|
14
|
+
const { fields, append, remove } = useFieldArray({
|
|
23
15
|
name,
|
|
24
16
|
control
|
|
25
17
|
});
|
|
26
|
-
const canAdd = fields.length !==
|
|
18
|
+
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
27
19
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
28
|
-
return jsxs(Stack, {
|
|
29
|
-
gap: 3,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
children: fields.map((field, index) => jsxs(Row, {
|
|
20
|
+
return /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
|
|
21
|
+
fields.length ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(
|
|
22
|
+
Row,
|
|
23
|
+
{
|
|
33
24
|
templateColumns: "1fr 1fr auto",
|
|
34
25
|
gap: 2,
|
|
35
26
|
alignItems: "end",
|
|
36
|
-
children: [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsx(
|
|
29
|
+
TextInputField,
|
|
30
|
+
{
|
|
31
|
+
readOnly: readonly,
|
|
32
|
+
required: inputKey.required,
|
|
33
|
+
name: `${name}.${index}.key`,
|
|
34
|
+
label: inputKey.label,
|
|
35
|
+
regex: inputKey.regex
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
39
|
+
TextInputField,
|
|
40
|
+
{
|
|
41
|
+
readOnly: readonly,
|
|
42
|
+
required: inputValue.required,
|
|
43
|
+
name: `${name}.${index}.value`,
|
|
44
|
+
label: inputValue.label,
|
|
45
|
+
placeholder: inputValue.placeholder,
|
|
46
|
+
type: inputValue.type,
|
|
47
|
+
autoComplete: "off",
|
|
48
|
+
regex: inputValue.regex
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
/* @__PURE__ */ jsx(
|
|
52
|
+
Button,
|
|
53
|
+
{
|
|
54
|
+
disabled: readonly,
|
|
55
|
+
"data-testid": `remove-button-${index}`,
|
|
56
|
+
icon: "delete",
|
|
57
|
+
variant: "outlined",
|
|
58
|
+
sentiment: "danger",
|
|
59
|
+
size: "large",
|
|
60
|
+
onClick: () => remove(index)
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
field.id
|
|
66
|
+
)) }) : null,
|
|
67
|
+
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsx(
|
|
68
|
+
Button,
|
|
69
|
+
{
|
|
65
70
|
"data-testid": "add-button",
|
|
66
71
|
icon: "plus",
|
|
67
72
|
variant: "filled",
|
|
68
73
|
sentiment: "neutral",
|
|
69
74
|
fullWidth: addButton.fullWidth,
|
|
70
75
|
disabled: !canAdd || readonly,
|
|
71
|
-
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip
|
|
72
|
-
|
|
73
|
-
,
|
|
74
|
-
onClick: () => append({
|
|
75
|
-
key: '',
|
|
76
|
-
value: ''
|
|
77
|
-
}),
|
|
76
|
+
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
77
|
+
onClick: () => append({ key: "", value: "" }),
|
|
78
78
|
children: addButton.name
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
});
|
|
79
|
+
}
|
|
80
|
+
) })
|
|
81
|
+
] });
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
KeyValueField
|
|
82
85
|
};
|
|
83
|
-
|
|
84
|
-
export { KeyValueField };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NumberInput } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps, FocusEventHandler } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type NumberInputValueFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof NumberInput>, 'disabled' | 'maxValue' | 'minValue' | 'onMaxCrossed' | 'onMinCrossed' | 'size' | 'step' | 'text' | 'className'>> & {
|
|
6
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
7
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated This component is deprecated, use `NumberInputFieldV2` instead.
|
|
11
|
+
*/
|
|
12
|
+
export declare const NumberInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, maxValue, minValue, name, onChange, onBlur, onFocus, onMaxCrossed, onMinCrossed, required, size, step, text, rules, className, label, shouldUnregister, }: NumberInputValueFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useErrors } from
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated This component is deprecated, use `NumberInputFieldV2` instead.
|
|
8
|
-
*/
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { NumberInput } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
9
5
|
const NumberInputField = ({
|
|
10
6
|
disabled,
|
|
11
7
|
maxValue,
|
|
@@ -25,14 +21,10 @@ const NumberInputField = ({
|
|
|
25
21
|
label,
|
|
26
22
|
shouldUnregister = false
|
|
27
23
|
}) => {
|
|
28
|
-
const {
|
|
29
|
-
getError
|
|
30
|
-
} = useErrors();
|
|
24
|
+
const { getError } = useErrors();
|
|
31
25
|
const {
|
|
32
26
|
field,
|
|
33
|
-
fieldState: {
|
|
34
|
-
error
|
|
35
|
-
}
|
|
27
|
+
fieldState: { error }
|
|
36
28
|
} = useController({
|
|
37
29
|
name,
|
|
38
30
|
shouldUnregister,
|
|
@@ -43,35 +35,37 @@ const NumberInputField = ({
|
|
|
43
35
|
...rules
|
|
44
36
|
}
|
|
45
37
|
});
|
|
46
|
-
return jsx(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
onBlur
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
38
|
+
return /* @__PURE__ */ jsx(
|
|
39
|
+
NumberInput,
|
|
40
|
+
{
|
|
41
|
+
name: field.name,
|
|
42
|
+
value: field.value,
|
|
43
|
+
disabled,
|
|
44
|
+
onBlur: (event) => {
|
|
45
|
+
field.onBlur();
|
|
46
|
+
onBlur?.(event);
|
|
47
|
+
},
|
|
48
|
+
onChange: (event) => {
|
|
49
|
+
field.onChange(event ?? null);
|
|
50
|
+
onChange?.(event);
|
|
51
|
+
},
|
|
52
|
+
onFocus,
|
|
53
|
+
maxValue,
|
|
54
|
+
minValue,
|
|
55
|
+
onMinCrossed,
|
|
56
|
+
onMaxCrossed,
|
|
57
|
+
size,
|
|
58
|
+
step,
|
|
59
|
+
text,
|
|
60
|
+
className,
|
|
61
|
+
label,
|
|
62
|
+
error: getError(
|
|
63
|
+
{ label: label ?? "", max: maxValue, min: minValue },
|
|
64
|
+
error
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
NumberInputField
|
|
75
71
|
};
|
|
76
|
-
|
|
77
|
-
export { NumberInputField };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NumberInputV2 } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type NumberInputV2Props<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof NumberInputV2>, 'disabled' | 'id' | 'onBlur' | 'onChange' | 'onFocus' | 'value' | 'data-testid' | 'label' | 'tooltip' | 'unit' | 'size' | 'step' | 'className' | 'placeholder' | 'error' | 'success' | 'helper' | 'labelDescription' | 'aria-label' | 'autoFocus' | 'readOnly' | 'min' | 'max'>> & {
|
|
6
|
+
className?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const NumberInputFieldV2: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, max, min, name, onChange, onBlur, size, step, unit, tooltip, className, label, labelDescription, id, placeholder, success, helper, rules, "aria-label": ariaLabel, "data-testid": dataTestId, required, autoFocus, readOnly, shouldUnregister, }: NumberInputV2Props<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useErrors } from
|
|
5
|
-
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { NumberInputV2 } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
5
|
const NumberInputFieldV2 = ({
|
|
7
6
|
disabled,
|
|
8
7
|
max = Number.MAX_SAFE_INTEGER,
|
|
@@ -22,21 +21,17 @@ const NumberInputFieldV2 = ({
|
|
|
22
21
|
success,
|
|
23
22
|
helper,
|
|
24
23
|
rules,
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
"aria-label": ariaLabel,
|
|
25
|
+
"data-testid": dataTestId,
|
|
27
26
|
required,
|
|
28
27
|
autoFocus,
|
|
29
28
|
readOnly,
|
|
30
29
|
shouldUnregister = false
|
|
31
30
|
}) => {
|
|
32
|
-
const {
|
|
33
|
-
getError
|
|
34
|
-
} = useErrors();
|
|
31
|
+
const { getError } = useErrors();
|
|
35
32
|
const {
|
|
36
33
|
field,
|
|
37
|
-
fieldState: {
|
|
38
|
-
error
|
|
39
|
-
}
|
|
34
|
+
fieldState: { error }
|
|
40
35
|
} = useController({
|
|
41
36
|
name,
|
|
42
37
|
shouldUnregister,
|
|
@@ -47,43 +42,42 @@ const NumberInputFieldV2 = ({
|
|
|
47
42
|
...rules
|
|
48
43
|
}
|
|
49
44
|
});
|
|
50
|
-
return jsx(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
onBlur
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
min: min,
|
|
65
|
-
size: size,
|
|
66
|
-
step: step,
|
|
67
|
-
className: className,
|
|
68
|
-
"data-testid": dataTestId,
|
|
69
|
-
id: id,
|
|
70
|
-
label: label,
|
|
71
|
-
labelDescription: labelDescription,
|
|
72
|
-
placeholder: placeholder,
|
|
73
|
-
error: getError({
|
|
74
|
-
label: label ?? '',
|
|
45
|
+
return /* @__PURE__ */ jsx(
|
|
46
|
+
NumberInputV2,
|
|
47
|
+
{
|
|
48
|
+
name: field.name,
|
|
49
|
+
value: field.value,
|
|
50
|
+
disabled,
|
|
51
|
+
onBlur: (event) => {
|
|
52
|
+
field.onBlur();
|
|
53
|
+
onBlur?.(event);
|
|
54
|
+
},
|
|
55
|
+
onChange: (newValue) => {
|
|
56
|
+
field.onChange(newValue);
|
|
57
|
+
onChange?.(newValue);
|
|
58
|
+
},
|
|
75
59
|
max,
|
|
76
|
-
min
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
60
|
+
min,
|
|
61
|
+
size,
|
|
62
|
+
step,
|
|
63
|
+
className,
|
|
64
|
+
"data-testid": dataTestId,
|
|
65
|
+
id,
|
|
66
|
+
label,
|
|
67
|
+
labelDescription,
|
|
68
|
+
placeholder,
|
|
69
|
+
error: getError({ label: label ?? "", max, min }, error),
|
|
70
|
+
success,
|
|
71
|
+
helper,
|
|
72
|
+
tooltip,
|
|
73
|
+
unit,
|
|
74
|
+
"aria-label": ariaLabel,
|
|
75
|
+
autoFocus,
|
|
76
|
+
readOnly,
|
|
77
|
+
required
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
NumberInputFieldV2
|
|
87
83
|
};
|
|
88
|
-
|
|
89
|
-
export { NumberInputFieldV2 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Radio } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type RadioFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TName>, 'label'> & Partial<Pick<ComponentProps<typeof Radio>, 'disabled' | 'id' | 'onBlur' | 'onFocus' | 'data-testid' | 'tooltip' | 'label'>> & {
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated This component is deprecated, use `RadioGroupField` instead.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RadioField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, "data-testid": dataTestId, disabled, id, name, onBlur, label, onChange, onFocus, required, value, rules, tooltip, shouldUnregister, }: RadioFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|