@ultraviolet/form 2.13.2 → 2.13.4
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 +17 -35
- package/dist/components/CheckboxGroupField/index.d.ts +32 -0
- package/dist/components/CheckboxGroupField/index.js +24 -35
- package/dist/components/DateField/index.d.ts +16 -0
- package/dist/components/DateField/index.js +33 -53
- 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 +41 -54
- package/dist/components/KeyValueField/index.d.ts +33 -0
- package/dist/components/KeyValueField/index.js +23 -56
- package/dist/components/NumberInputField/index.d.ts +13 -0
- package/dist/components/NumberInputField/index.js +18 -39
- package/dist/components/NumberInputFieldV2/index.d.ts +11 -0
- package/dist/components/NumberInputFieldV2/index.js +20 -46
- package/dist/components/RadioField/index.d.ts +12 -0
- package/dist/components/RadioField/index.js +18 -36
- package/dist/components/RadioGroupField/index.d.ts +28 -0
- package/dist/components/RadioGroupField/index.js +15 -26
- package/dist/components/SelectInputField/index.d.ts +82 -0
- package/dist/components/SelectInputField/index.js +31 -61
- package/dist/components/SelectInputFieldV2/index.d.ts +7 -0
- package/dist/components/SelectInputFieldV2/index.js +18 -52
- package/dist/components/SelectableCardField/index.d.ts +9 -0
- package/dist/components/SelectableCardField/index.js +24 -41
- package/dist/components/SelectableCardGroupField/index.d.ts +42 -0
- package/dist/components/SelectableCardGroupField/index.js +22 -35
- package/dist/components/Submit/index.d.ts +17 -0
- package/dist/components/Submit/index.js +9 -23
- package/dist/components/SubmitErrorAlert/index.d.ts +3 -0
- package/dist/components/SubmitErrorAlert/index.js +7 -11
- package/dist/components/TagInputField/index.d.ts +6 -0
- package/dist/components/TagInputField/index.js +14 -32
- package/dist/components/TextAreaField/index.d.ts +11 -0
- package/dist/components/TextAreaField/index.js +25 -52
- package/dist/components/TextInputField/index.d.ts +18 -0
- package/dist/components/TextInputField/index.js +37 -76
- package/dist/components/TextInputFieldV2/index.d.ts +12 -0
- package/dist/components/TextInputFieldV2/index.js +30 -66
- package/dist/components/TimeField/index.d.ts +9 -0
- package/dist/components/TimeField/index.js +23 -46
- package/dist/components/ToggleField/index.d.ts +10 -0
- package/dist/components/ToggleField/index.js +15 -28
- 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 +4 -20
- package/dist/hooks/useFieldArray.d.ts +21 -0
- package/dist/hooks/useFieldArray.js +6 -9
- package/dist/hooks/useForm.d.ts +23 -0
- package/dist/hooks/useForm.js +7 -19
- package/dist/hooks/useFormState.d.ts +39 -0
- package/dist/hooks/useFormState.js +5 -20
- package/dist/hooks/useOnFieldChange.d.ts +3 -0
- package/dist/hooks/useOnFieldChange.js +6 -6
- 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 +11 -13
- 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 +12 -6
|
@@ -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,
|
|
@@ -23,62 +19,33 @@ const KeyValueField = ({
|
|
|
23
19
|
name,
|
|
24
20
|
control
|
|
25
21
|
});
|
|
26
|
-
const canAdd = fields.length !==
|
|
22
|
+
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
27
23
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
28
|
-
return jsxs(Stack, {
|
|
29
|
-
gap: 3,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
readOnly: readonly,
|
|
38
|
-
required: inputKey.required,
|
|
39
|
-
name: `${name}.${index}.key`,
|
|
40
|
-
label: inputKey.label,
|
|
41
|
-
regex: inputKey.regex
|
|
42
|
-
}), jsx(TextInputField, {
|
|
43
|
-
readOnly: readonly,
|
|
44
|
-
required: inputValue.required,
|
|
45
|
-
name: `${name}.${index}.value`,
|
|
46
|
-
label: inputValue.label,
|
|
47
|
-
placeholder: inputValue.placeholder,
|
|
48
|
-
type: inputValue.type,
|
|
49
|
-
autoComplete: "off",
|
|
50
|
-
regex: inputValue.regex
|
|
51
|
-
}), jsx(Button, {
|
|
52
|
-
disabled: readonly,
|
|
53
|
-
"data-testid": `remove-button-${index}`,
|
|
54
|
-
icon: "delete",
|
|
55
|
-
variant: "outlined",
|
|
56
|
-
sentiment: "danger",
|
|
57
|
-
size: "large",
|
|
58
|
-
onClick: () => remove(index)
|
|
59
|
-
})]
|
|
60
|
-
}, field.id))
|
|
61
|
-
}) : null, jsx(Stack, {
|
|
62
|
-
direction: "row",
|
|
63
|
-
justifyContent: "flex-start",
|
|
64
|
-
children: jsx(Button, {
|
|
24
|
+
return /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
|
|
25
|
+
fields.length ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(Row, { templateColumns: "1fr 1fr auto", gap: 2, alignItems: "end", children: [
|
|
26
|
+
/* @__PURE__ */ jsx(TextInputField, { readOnly: readonly, required: inputKey.required, name: `${name}.${index}.key`, label: inputKey.label, regex: inputKey.regex }),
|
|
27
|
+
/* @__PURE__ */ jsx(TextInputField, { readOnly: readonly, required: inputValue.required, name: `${name}.${index}.value`, label: inputValue.label, placeholder: inputValue.placeholder, type: inputValue.type, autoComplete: "off", regex: inputValue.regex }),
|
|
28
|
+
/* @__PURE__ */ jsx(Button, { disabled: readonly, "data-testid": `remove-button-${index}`, icon: "delete", variant: "outlined", sentiment: "danger", size: "large", onClick: () => remove(index) })
|
|
29
|
+
] }, field.id)) }) : null,
|
|
30
|
+
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsx(
|
|
31
|
+
Button,
|
|
32
|
+
{
|
|
65
33
|
"data-testid": "add-button",
|
|
66
34
|
icon: "plus",
|
|
67
35
|
variant: "filled",
|
|
68
36
|
sentiment: "neutral",
|
|
69
37
|
fullWidth: addButton.fullWidth,
|
|
70
38
|
disabled: !canAdd || readonly,
|
|
71
|
-
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip
|
|
72
|
-
// @ts-expect-error can't infer properly
|
|
73
|
-
,
|
|
39
|
+
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
74
40
|
onClick: () => append({
|
|
75
|
-
key:
|
|
76
|
-
value:
|
|
41
|
+
key: "",
|
|
42
|
+
value: ""
|
|
77
43
|
}),
|
|
78
44
|
children: addButton.name
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
});
|
|
45
|
+
}
|
|
46
|
+
) })
|
|
47
|
+
] });
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
KeyValueField
|
|
82
51
|
};
|
|
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,
|
|
@@ -43,35 +39,18 @@ const NumberInputField = ({
|
|
|
43
39
|
...rules
|
|
44
40
|
}
|
|
45
41
|
});
|
|
46
|
-
return jsx(NumberInput, {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
maxValue: maxValue,
|
|
61
|
-
minValue: minValue,
|
|
62
|
-
onMinCrossed: onMinCrossed,
|
|
63
|
-
onMaxCrossed: onMaxCrossed,
|
|
64
|
-
size: size,
|
|
65
|
-
step: step,
|
|
66
|
-
text: text,
|
|
67
|
-
className: className,
|
|
68
|
-
label: label,
|
|
69
|
-
error: getError({
|
|
70
|
-
label: label ?? '',
|
|
71
|
-
max: maxValue,
|
|
72
|
-
min: minValue
|
|
73
|
-
}, error)
|
|
74
|
-
});
|
|
42
|
+
return /* @__PURE__ */ jsx(NumberInput, { name: field.name, value: field.value, disabled, onBlur: (event) => {
|
|
43
|
+
field.onBlur();
|
|
44
|
+
onBlur?.(event);
|
|
45
|
+
}, onChange: (event) => {
|
|
46
|
+
field.onChange(event ?? null);
|
|
47
|
+
onChange?.(event);
|
|
48
|
+
}, onFocus, maxValue, minValue, onMinCrossed, onMaxCrossed, size, step, text, className, label, error: getError({
|
|
49
|
+
label: label ?? "",
|
|
50
|
+
max: maxValue,
|
|
51
|
+
min: minValue
|
|
52
|
+
}, error) });
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
NumberInputField
|
|
75
56
|
};
|
|
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,8 +21,8 @@ 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,
|
|
@@ -47,43 +46,18 @@ const NumberInputFieldV2 = ({
|
|
|
47
46
|
...rules
|
|
48
47
|
}
|
|
49
48
|
});
|
|
50
|
-
return jsx(NumberInputV2, {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 ?? '',
|
|
75
|
-
max,
|
|
76
|
-
min
|
|
77
|
-
}, error),
|
|
78
|
-
success: success,
|
|
79
|
-
helper: helper,
|
|
80
|
-
tooltip: tooltip,
|
|
81
|
-
unit: unit,
|
|
82
|
-
"aria-label": ariaLabel,
|
|
83
|
-
autoFocus: autoFocus,
|
|
84
|
-
readOnly: readOnly,
|
|
85
|
-
required: required
|
|
86
|
-
});
|
|
49
|
+
return /* @__PURE__ */ jsx(NumberInputV2, { name: field.name, value: field.value, disabled, onBlur: (event) => {
|
|
50
|
+
field.onBlur();
|
|
51
|
+
onBlur?.(event);
|
|
52
|
+
}, onChange: (newValue) => {
|
|
53
|
+
field.onChange(newValue);
|
|
54
|
+
onChange?.(newValue);
|
|
55
|
+
}, max, min, size, step, className, "data-testid": dataTestId, id, label, labelDescription, placeholder, error: getError({
|
|
56
|
+
label: label ?? "",
|
|
57
|
+
max,
|
|
58
|
+
min
|
|
59
|
+
}, error), success, helper, tooltip, unit, "aria-label": ariaLabel, autoFocus, readOnly, required });
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
NumberInputFieldV2
|
|
87
63
|
};
|
|
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 {};
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useErrors } from
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated This component is deprecated, use `RadioGroupField` instead.
|
|
8
|
-
*/
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Radio } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
9
5
|
const RadioField = ({
|
|
10
6
|
className,
|
|
11
|
-
|
|
7
|
+
"data-testid": dataTestId,
|
|
12
8
|
disabled,
|
|
13
9
|
id,
|
|
14
10
|
name,
|
|
15
11
|
onBlur,
|
|
16
|
-
label =
|
|
12
|
+
label = "",
|
|
17
13
|
onChange,
|
|
18
14
|
onFocus,
|
|
19
15
|
required,
|
|
@@ -38,30 +34,16 @@ const RadioField = ({
|
|
|
38
34
|
...rules
|
|
39
35
|
}
|
|
40
36
|
});
|
|
41
|
-
return jsx(Radio, {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
onChange?.(value);
|
|
54
|
-
},
|
|
55
|
-
onBlur: event => {
|
|
56
|
-
field.onBlur();
|
|
57
|
-
onBlur?.(event);
|
|
58
|
-
},
|
|
59
|
-
onFocus: onFocus,
|
|
60
|
-
required: required,
|
|
61
|
-
value: value ?? '',
|
|
62
|
-
label: label,
|
|
63
|
-
tooltip: tooltip
|
|
64
|
-
});
|
|
37
|
+
return /* @__PURE__ */ jsx(Radio, { name: field.name, checked: field.value === value, className, "data-testid": dataTestId, disabled, error: getError({
|
|
38
|
+
label: typeof label === "string" ? label : ""
|
|
39
|
+
}, error), id, onChange: () => {
|
|
40
|
+
field.onChange(value);
|
|
41
|
+
onChange?.(value);
|
|
42
|
+
}, onBlur: (event) => {
|
|
43
|
+
field.onBlur();
|
|
44
|
+
onBlur?.(event);
|
|
45
|
+
}, onFocus, required, value: value ?? "", label, tooltip });
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
RadioField
|
|
65
49
|
};
|
|
66
|
-
|
|
67
|
-
export { RadioField };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RadioGroup } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps, JSX } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type RadioGroupFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof RadioGroup>, 'legend' | 'children' | 'error' | 'helper' | 'direction'>> & {
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const RadioGroupField: {
|
|
9
|
+
<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, legend, name, onChange, required, rules, children, label, error: customError, helper, direction, shouldUnregister, }: RadioGroupFieldProps<TFieldValues, TName>): JSX.Element;
|
|
10
|
+
Radio: ({ onFocus, onBlur, disabled, error, name, value, label, helper, className, autoFocus, onKeyDown, "data-testid": dataTestId, }: Omit<({
|
|
11
|
+
error?: import("react").ReactNode;
|
|
12
|
+
checked?: boolean | undefined;
|
|
13
|
+
value: string | number;
|
|
14
|
+
helper?: import("react").ReactNode;
|
|
15
|
+
className?: string | undefined;
|
|
16
|
+
'data-testid'?: string | undefined;
|
|
17
|
+
tooltip?: string | undefined;
|
|
18
|
+
} & Required<Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "onChange">> & (Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "required" | "onBlur" | "disabled" | "name" | "onFocus" | "autoFocus" | "id" | "onKeyDown"> & ({
|
|
19
|
+
'aria-label': string;
|
|
20
|
+
label?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
'aria-label'?: undefined;
|
|
23
|
+
label: import("react").ReactNode;
|
|
24
|
+
}))) & import("react").RefAttributes<HTMLInputElement>, "required" | "onChange" | "checked"> & {
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useErrors } from
|
|
5
|
-
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { RadioGroup } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
5
|
const RadioGroupField = ({
|
|
7
6
|
className,
|
|
8
|
-
legend =
|
|
7
|
+
legend = "",
|
|
9
8
|
name,
|
|
10
9
|
onChange,
|
|
11
10
|
required,
|
|
12
11
|
rules,
|
|
13
12
|
children,
|
|
14
|
-
label =
|
|
13
|
+
label = "",
|
|
15
14
|
error: customError,
|
|
16
15
|
helper,
|
|
17
16
|
direction,
|
|
@@ -33,24 +32,14 @@ const RadioGroupField = ({
|
|
|
33
32
|
...rules
|
|
34
33
|
}
|
|
35
34
|
});
|
|
36
|
-
return jsx(RadioGroup, {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
required: required,
|
|
44
|
-
value: field.value,
|
|
45
|
-
legend: legend,
|
|
46
|
-
error: getError({
|
|
47
|
-
label
|
|
48
|
-
}, error) ?? customError,
|
|
49
|
-
helper: helper,
|
|
50
|
-
direction: direction,
|
|
51
|
-
children: children
|
|
52
|
-
});
|
|
35
|
+
return /* @__PURE__ */ jsx(RadioGroup, { className, name: field.name, onChange: (event) => {
|
|
36
|
+
field.onChange(event);
|
|
37
|
+
onChange?.(event.target.value);
|
|
38
|
+
}, required, value: field.value, legend, error: getError({
|
|
39
|
+
label
|
|
40
|
+
}, error) ?? customError, helper, direction, children });
|
|
53
41
|
};
|
|
54
42
|
RadioGroupField.Radio = RadioGroup.Radio;
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
export {
|
|
44
|
+
RadioGroupField
|
|
45
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { CSSObject, Theme, css } from '@emotion/react';
|
|
2
|
+
import { SelectInput } from '@ultraviolet/ui';
|
|
3
|
+
import type { ComponentProps, ForwardedRef, ReactNode } from 'react';
|
|
4
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
5
|
+
import type { CommonProps, GroupBase, OptionProps, Props } from 'react-select';
|
|
6
|
+
import type Select from 'react-select';
|
|
7
|
+
import type { BaseFieldProps } from '../../types';
|
|
8
|
+
export type SelectInputType = typeof SelectInput;
|
|
9
|
+
type SelectOption = {
|
|
10
|
+
value: string;
|
|
11
|
+
label: ReactNode;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
description?: string;
|
|
14
|
+
inlineDescription?: string;
|
|
15
|
+
};
|
|
16
|
+
type WithSelectProps = {
|
|
17
|
+
selectProps: SelectProps;
|
|
18
|
+
};
|
|
19
|
+
type SelectStyleProps = {
|
|
20
|
+
error?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Custom styles of the SelectInput. See [React select documentation](https://react-select.com/styles)
|
|
23
|
+
*/
|
|
24
|
+
customStyle: (state: SelectProps & WithSelectProps) => Record<string, CSSObject>;
|
|
25
|
+
animation?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Time of the animation
|
|
28
|
+
*/
|
|
29
|
+
animationDuration?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Show/hide the label inside the component
|
|
32
|
+
*/
|
|
33
|
+
noTopLabel?: boolean;
|
|
34
|
+
theme: Theme;
|
|
35
|
+
};
|
|
36
|
+
type StyledContainerProps = {
|
|
37
|
+
isDisabled?: boolean;
|
|
38
|
+
additionalStyles?: Parameters<typeof css>[0];
|
|
39
|
+
};
|
|
40
|
+
type SelectProps = StyledContainerProps & Omit<Props<SelectOption>, 'value'> & CommonProps<SelectOption, boolean, GroupBase<SelectOption>> & {
|
|
41
|
+
value?: string | SelectOption;
|
|
42
|
+
checked?: boolean;
|
|
43
|
+
error?: string;
|
|
44
|
+
labelId?: string;
|
|
45
|
+
required?: boolean;
|
|
46
|
+
time?: boolean;
|
|
47
|
+
};
|
|
48
|
+
type StateManagedSelect = typeof Select;
|
|
49
|
+
type SelectInputProps = Partial<SelectProps & SelectStyleProps & Pick<ComponentProps<typeof SelectInput>, 'data-testid'> & {
|
|
50
|
+
/**
|
|
51
|
+
* Name of the animation
|
|
52
|
+
*/
|
|
53
|
+
animation?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Play the animation when the value change
|
|
56
|
+
*/
|
|
57
|
+
animationOnChange?: boolean;
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
readOnly?: boolean;
|
|
60
|
+
innerRef?: ForwardedRef<StateManagedSelect>;
|
|
61
|
+
/**
|
|
62
|
+
* Custom components of the SelectInput. See [React select documentation](https://react-select.com/components)
|
|
63
|
+
*/
|
|
64
|
+
customComponents?: SelectProps['components'];
|
|
65
|
+
children: ReactNode;
|
|
66
|
+
emptyState?: ComponentProps<Select>['noOptionsMessage'];
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated This component is deprecated, please use `SelectInputFieldV2` instead
|
|
70
|
+
*/
|
|
71
|
+
export type SelectInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TName>, 'onChange'> & Partial<Pick<SelectInputProps, 'animation' | 'animationDuration' | 'animationOnChange' | 'children' | 'className' | 'disabled' | 'error' | 'id' | 'inputId' | 'isClearable' | 'isLoading' | 'isSearchable' | 'menuPortalTarget' | 'onBlur' | 'onChange' | 'onFocus' | 'options' | 'placeholder' | 'readOnly' | 'required' | 'value' | 'noTopLabel' | 'emptyState' | 'customStyle' | 'data-testid'>> & {
|
|
72
|
+
multiple?: boolean;
|
|
73
|
+
parse?: (value: unknown, name?: string) => unknown;
|
|
74
|
+
format?: (value: unknown, name: string) => unknown;
|
|
75
|
+
maxLength?: number;
|
|
76
|
+
minLength?: number;
|
|
77
|
+
};
|
|
78
|
+
export declare const SelectInputField: {
|
|
79
|
+
<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ animation, animationDuration, animationOnChange, children, className, disabled, format: formatProp, id, inputId, isClearable, isLoading, isSearchable, label, maxLength, menuPortalTarget, minLength, multiple, name, onBlur, onChange, onFocus, options: optionsProp, parse: parseProp, placeholder, readOnly, required, rules, noTopLabel, emptyState, customStyle, shouldUnregister, "data-testid": dataTestId, }: SelectInputFieldProps<TFieldValues, TName>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
80
|
+
Option: (props: Partial<OptionProps<import("@ultraviolet/ui").SelectOption, boolean, GroupBase<import("@ultraviolet/ui").SelectOption>> & import("@ultraviolet/ui").SelectOption>) => import("react").JSX.Element;
|
|
81
|
+
};
|
|
82
|
+
export {};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useErrors } from
|
|
6
|
-
|
|
7
|
-
const identity = x => x;
|
|
8
|
-
// const identity = <T,>(x: T) => x
|
|
9
|
-
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { SelectInput } from "@ultraviolet/ui";
|
|
3
|
+
import { useMemo, Children, useCallback } from "react";
|
|
4
|
+
import { useController } from "react-hook-form";
|
|
5
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
|
+
const identity = (x) => x;
|
|
10
7
|
const SelectInputField = ({
|
|
11
8
|
animation,
|
|
12
9
|
animationDuration,
|
|
@@ -22,7 +19,7 @@ const SelectInputField = ({
|
|
|
22
19
|
isClearable,
|
|
23
20
|
isLoading,
|
|
24
21
|
isSearchable,
|
|
25
|
-
label =
|
|
22
|
+
label = "",
|
|
26
23
|
maxLength,
|
|
27
24
|
menuPortalTarget,
|
|
28
25
|
minLength,
|
|
@@ -41,7 +38,7 @@ const SelectInputField = ({
|
|
|
41
38
|
emptyState,
|
|
42
39
|
customStyle,
|
|
43
40
|
shouldUnregister = false,
|
|
44
|
-
|
|
41
|
+
"data-testid": dataTestId
|
|
45
42
|
}) => {
|
|
46
43
|
const options = useMemo(() => optionsProp || Children.toArray(children).flat().filter(Boolean).map(({
|
|
47
44
|
props: {
|
|
@@ -52,18 +49,18 @@ const SelectInputField = ({
|
|
|
52
49
|
...option,
|
|
53
50
|
label: labelChild
|
|
54
51
|
})), [optionsProp, children]);
|
|
55
|
-
const parse = useMemo(() => multiple ? parseProp : option => parseProp(option?.value ?? null, name), [multiple, parseProp, name]);
|
|
56
|
-
const format = useCallback(val => {
|
|
57
|
-
if (multiple)
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const parse = useMemo(() => multiple ? parseProp : (option) => parseProp(option?.value ?? null, name), [multiple, parseProp, name]);
|
|
53
|
+
const format = useCallback((val) => {
|
|
54
|
+
if (multiple)
|
|
55
|
+
return formatProp(val, name);
|
|
56
|
+
const find = (opts, valueToFind) => opts?.find((option) => option.value === valueToFind);
|
|
57
|
+
let selected = "";
|
|
60
58
|
if (val && options) {
|
|
61
|
-
// TODO: find a proper way to simplify format with recursive options
|
|
62
59
|
selected = find(options, val);
|
|
63
60
|
if (!selected) {
|
|
64
|
-
selected = options.map(curr => find(curr.options, val)).filter(identity);
|
|
61
|
+
selected = options.map((curr) => find(curr.options, val)).filter(identity);
|
|
65
62
|
if (Array.isArray(selected) && selected.length === 0) {
|
|
66
|
-
selected =
|
|
63
|
+
selected = "";
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
66
|
}
|
|
@@ -82,51 +79,24 @@ const SelectInputField = ({
|
|
|
82
79
|
shouldUnregister,
|
|
83
80
|
rules: {
|
|
84
81
|
required,
|
|
85
|
-
minLength: minLength || required ? 1 :
|
|
82
|
+
minLength: minLength || required ? 1 : void 0,
|
|
86
83
|
maxLength,
|
|
87
84
|
...rules
|
|
88
85
|
}
|
|
89
86
|
});
|
|
90
|
-
return jsx(SelectInput, {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}, error),
|
|
102
|
-
id: id,
|
|
103
|
-
inputId: inputId,
|
|
104
|
-
isClearable: isClearable,
|
|
105
|
-
isLoading: isLoading,
|
|
106
|
-
isMulti: multiple,
|
|
107
|
-
customStyle: customStyle,
|
|
108
|
-
isSearchable: isSearchable,
|
|
109
|
-
menuPortalTarget: menuPortalTarget,
|
|
110
|
-
onBlur: event => {
|
|
111
|
-
field.onBlur();
|
|
112
|
-
onBlur?.(event);
|
|
113
|
-
},
|
|
114
|
-
onChange: (event, action) => {
|
|
115
|
-
field.onChange(parse(event));
|
|
116
|
-
onChange?.(event, action);
|
|
117
|
-
},
|
|
118
|
-
onFocus: onFocus,
|
|
119
|
-
options: options,
|
|
120
|
-
placeholder: placeholder,
|
|
121
|
-
readOnly: readOnly,
|
|
122
|
-
noTopLabel: noTopLabel,
|
|
123
|
-
required: required,
|
|
124
|
-
value: format(field.value),
|
|
125
|
-
emptyState: emptyState,
|
|
126
|
-
"data-testid": dataTestId,
|
|
127
|
-
children: children
|
|
128
|
-
});
|
|
87
|
+
return /* @__PURE__ */ jsx(SelectInput, { name: field.name, animation, animationDuration, animationOnChange, className, disabled, error: getError({
|
|
88
|
+
label,
|
|
89
|
+
minLength,
|
|
90
|
+
maxLength
|
|
91
|
+
}, error), id, inputId, isClearable, isLoading, isMulti: multiple, customStyle, isSearchable, menuPortalTarget, onBlur: (event) => {
|
|
92
|
+
field.onBlur();
|
|
93
|
+
onBlur?.(event);
|
|
94
|
+
}, onChange: (event, action) => {
|
|
95
|
+
field.onChange(parse(event));
|
|
96
|
+
onChange?.(event, action);
|
|
97
|
+
}, onFocus, options, placeholder, readOnly, noTopLabel, required, value: format(field.value), emptyState, "data-testid": dataTestId, children });
|
|
129
98
|
};
|
|
130
99
|
SelectInputField.Option = SelectInput.Option;
|
|
131
|
-
|
|
132
|
-
|
|
100
|
+
export {
|
|
101
|
+
SelectInputField
|
|
102
|
+
};
|