@ultraviolet/form 4.0.0-beta.10 → 4.0.0-beta.12
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/KeyValueField/index.cjs +1 -1
- package/dist/components/KeyValueField/index.d.ts +6 -6
- package/dist/components/KeyValueField/index.js +1 -1
- package/dist/components/NumberInputField/index.cjs +24 -24
- package/dist/components/NumberInputField/index.d.ts +3 -9
- package/dist/components/NumberInputField/index.js +24 -24
- package/dist/components/SelectInputField/index.cjs +19 -71
- package/dist/components/SelectInputField/index.d.ts +3 -81
- package/dist/components/SelectInputField/index.js +20 -72
- package/dist/components/SelectableCardOptionGroupField/index.d.ts +3 -3
- package/dist/components/TextInputField/index.cjs +19 -73
- package/dist/components/TextInputField/index.d.ts +5 -11
- package/dist/components/TextInputField/index.js +19 -73
- package/dist/components/{TimeInputFieldV2 → TimeInputField}/index.cjs +3 -3
- package/dist/components/TimeInputField/index.d.ts +11 -0
- package/dist/components/{TimeInputFieldV2 → TimeInputField}/index.js +4 -4
- package/dist/components/index.d.ts +2 -6
- package/dist/index.cjs +36 -44
- package/dist/index.js +3 -11
- package/package.json +3 -3
- package/dist/components/NumberInputFieldV2/index.cjs +0 -59
- package/dist/components/NumberInputFieldV2/index.d.ts +0 -7
- package/dist/components/NumberInputFieldV2/index.js +0 -59
- package/dist/components/SelectInputFieldV2/index.cjs +0 -50
- package/dist/components/SelectInputFieldV2/index.d.ts +0 -7
- package/dist/components/SelectInputFieldV2/index.js +0 -50
- package/dist/components/TextInputFieldV2/index.cjs +0 -62
- package/dist/components/TextInputFieldV2/index.d.ts +0 -12
- package/dist/components/TextInputFieldV2/index.js +0 -62
- package/dist/components/TimeField/index.cjs +0 -68
- package/dist/components/TimeField/index.d.ts +0 -7
- package/dist/components/TimeField/index.js +0 -68
- package/dist/components/TimeInputFieldV2/index.d.ts +0 -11
|
@@ -5,7 +5,7 @@ const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
5
5
|
const icons = require("@ultraviolet/icons");
|
|
6
6
|
const ui = require("@ultraviolet/ui");
|
|
7
7
|
const reactHookForm = require("react-hook-form");
|
|
8
|
-
const index = require("../
|
|
8
|
+
const index = require("../TextInputField/index.cjs");
|
|
9
9
|
const KeyValueField = ({
|
|
10
10
|
name,
|
|
11
11
|
inputKey,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Button } from '@ultraviolet/ui';
|
|
2
2
|
import type { ComponentProps } from 'react';
|
|
3
3
|
import type { Control, FieldArrayPath, FieldValues } from 'react-hook-form';
|
|
4
|
-
import { TextInputField
|
|
4
|
+
import { TextInputField } from '../TextInputField';
|
|
5
5
|
type InputKeyProps = {
|
|
6
|
-
label: ComponentProps<typeof
|
|
7
|
-
required?: ComponentProps<typeof
|
|
8
|
-
regex?: ComponentProps<typeof
|
|
6
|
+
label: ComponentProps<typeof TextInputField>['label'];
|
|
7
|
+
required?: ComponentProps<typeof TextInputField>['required'];
|
|
8
|
+
regex?: ComponentProps<typeof TextInputField>['regex'];
|
|
9
9
|
};
|
|
10
10
|
type InputValueProps = {
|
|
11
|
-
type?: ComponentProps<typeof
|
|
12
|
-
placeholder?: ComponentProps<typeof
|
|
11
|
+
type?: ComponentProps<typeof TextInputField>['type'];
|
|
12
|
+
placeholder?: ComponentProps<typeof TextInputField>['placeholder'];
|
|
13
13
|
} & InputKeyProps;
|
|
14
14
|
type AddButtonProps = {
|
|
15
15
|
name: ComponentProps<typeof Button>['children'];
|
|
@@ -3,7 +3,7 @@ import { jsxs, jsx } from "@emotion/react/jsx-runtime";
|
|
|
3
3
|
import { DeleteIcon, PlusIcon } from "@ultraviolet/icons";
|
|
4
4
|
import { Stack, Row, Button } from "@ultraviolet/ui";
|
|
5
5
|
import { useFieldArray } from "react-hook-form";
|
|
6
|
-
import { TextInputField } from "../
|
|
6
|
+
import { TextInputField } from "../TextInputField/index.js";
|
|
7
7
|
const KeyValueField = ({
|
|
8
8
|
name,
|
|
9
9
|
inputKey,
|
|
@@ -4,26 +4,22 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
4
4
|
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const ui = require("@ultraviolet/ui");
|
|
6
6
|
const reactHookForm = require("react-hook-form");
|
|
7
|
+
const isInteger = require("../../validators/isInteger.cjs");
|
|
7
8
|
const index = require("../../providers/ErrorContext/index.cjs");
|
|
8
9
|
const NumberInputField = ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
control,
|
|
11
|
+
max = Number.MAX_SAFE_INTEGER,
|
|
12
|
+
min = 0,
|
|
12
13
|
name,
|
|
13
14
|
onChange,
|
|
14
15
|
onBlur,
|
|
15
|
-
onFocus,
|
|
16
|
-
onMaxCrossed,
|
|
17
|
-
onMinCrossed,
|
|
18
|
-
required,
|
|
19
|
-
size,
|
|
20
16
|
step,
|
|
21
|
-
text,
|
|
22
|
-
className,
|
|
23
17
|
label,
|
|
18
|
+
"aria-label": ariaLabel,
|
|
19
|
+
required,
|
|
24
20
|
shouldUnregister = false,
|
|
25
21
|
validate,
|
|
26
|
-
|
|
22
|
+
...props
|
|
27
23
|
}) => {
|
|
28
24
|
const {
|
|
29
25
|
getError
|
|
@@ -35,25 +31,29 @@ const NumberInputField = ({
|
|
|
35
31
|
}
|
|
36
32
|
} = reactHookForm.useController({
|
|
37
33
|
name,
|
|
38
|
-
shouldUnregister,
|
|
39
34
|
control,
|
|
35
|
+
shouldUnregister,
|
|
40
36
|
rules: {
|
|
41
|
-
max
|
|
42
|
-
min
|
|
37
|
+
max,
|
|
38
|
+
min,
|
|
43
39
|
required,
|
|
44
|
-
validate
|
|
40
|
+
validate: {
|
|
41
|
+
...validate,
|
|
42
|
+
isInteger: isInteger.isInteger(step)
|
|
43
|
+
}
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInput, { name: field.name, value: field.value,
|
|
46
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInput, { ...props, name: field.name, value: field.value, onBlur: (event) => {
|
|
48
47
|
field.onBlur();
|
|
49
48
|
onBlur?.(event);
|
|
50
|
-
}, onChange: (
|
|
51
|
-
field.onChange(
|
|
52
|
-
onChange?.(
|
|
53
|
-
},
|
|
54
|
-
label: label ??
|
|
55
|
-
max
|
|
56
|
-
min
|
|
57
|
-
|
|
49
|
+
}, onChange: (newValue) => {
|
|
50
|
+
field.onChange(newValue);
|
|
51
|
+
onChange?.(newValue);
|
|
52
|
+
}, max, min, step, label, error: getError({
|
|
53
|
+
label: label ?? ariaLabel ?? name,
|
|
54
|
+
max,
|
|
55
|
+
min,
|
|
56
|
+
isInteger: step
|
|
57
|
+
}, error), "aria-label": ariaLabel, required });
|
|
58
58
|
};
|
|
59
59
|
exports.NumberInputField = NumberInputField;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { NumberInput } from '@ultraviolet/ui';
|
|
2
|
-
import type { ComponentProps
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
3
|
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated This component is deprecated, use `NumberInputFieldV2` instead.
|
|
11
|
-
*/
|
|
12
|
-
export declare const NumberInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, maxValue, minValue, name, onChange, onBlur, onFocus, onMaxCrossed, onMinCrossed, required, size, step, text, className, label, shouldUnregister, validate, control, }: NumberInputValueFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
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("@emotion/react/jsx-runtime").JSX.Element;
|
|
13
7
|
export {};
|
|
@@ -2,26 +2,22 @@
|
|
|
2
2
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
3
3
|
import { NumberInput } from "@ultraviolet/ui";
|
|
4
4
|
import { useController } from "react-hook-form";
|
|
5
|
+
import { isInteger } from "../../validators/isInteger.js";
|
|
5
6
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
7
|
const NumberInputField = ({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
control,
|
|
9
|
+
max = Number.MAX_SAFE_INTEGER,
|
|
10
|
+
min = 0,
|
|
10
11
|
name,
|
|
11
12
|
onChange,
|
|
12
13
|
onBlur,
|
|
13
|
-
onFocus,
|
|
14
|
-
onMaxCrossed,
|
|
15
|
-
onMinCrossed,
|
|
16
|
-
required,
|
|
17
|
-
size,
|
|
18
14
|
step,
|
|
19
|
-
text,
|
|
20
|
-
className,
|
|
21
15
|
label,
|
|
16
|
+
"aria-label": ariaLabel,
|
|
17
|
+
required,
|
|
22
18
|
shouldUnregister = false,
|
|
23
19
|
validate,
|
|
24
|
-
|
|
20
|
+
...props
|
|
25
21
|
}) => {
|
|
26
22
|
const {
|
|
27
23
|
getError
|
|
@@ -33,26 +29,30 @@ const NumberInputField = ({
|
|
|
33
29
|
}
|
|
34
30
|
} = useController({
|
|
35
31
|
name,
|
|
36
|
-
shouldUnregister,
|
|
37
32
|
control,
|
|
33
|
+
shouldUnregister,
|
|
38
34
|
rules: {
|
|
39
|
-
max
|
|
40
|
-
min
|
|
35
|
+
max,
|
|
36
|
+
min,
|
|
41
37
|
required,
|
|
42
|
-
validate
|
|
38
|
+
validate: {
|
|
39
|
+
...validate,
|
|
40
|
+
isInteger: isInteger(step)
|
|
41
|
+
}
|
|
43
42
|
}
|
|
44
43
|
});
|
|
45
|
-
return /* @__PURE__ */ jsx(NumberInput, { name: field.name, value: field.value,
|
|
44
|
+
return /* @__PURE__ */ jsx(NumberInput, { ...props, name: field.name, value: field.value, onBlur: (event) => {
|
|
46
45
|
field.onBlur();
|
|
47
46
|
onBlur?.(event);
|
|
48
|
-
}, onChange: (
|
|
49
|
-
field.onChange(
|
|
50
|
-
onChange?.(
|
|
51
|
-
},
|
|
52
|
-
label: label ??
|
|
53
|
-
max
|
|
54
|
-
min
|
|
55
|
-
|
|
47
|
+
}, onChange: (newValue) => {
|
|
48
|
+
field.onChange(newValue);
|
|
49
|
+
onChange?.(newValue);
|
|
50
|
+
}, max, min, step, label, error: getError({
|
|
51
|
+
label: label ?? ariaLabel ?? name,
|
|
52
|
+
max,
|
|
53
|
+
min,
|
|
54
|
+
isInteger: step
|
|
55
|
+
}, error), "aria-label": ariaLabel, required });
|
|
56
56
|
};
|
|
57
57
|
export {
|
|
58
58
|
NumberInputField
|
|
@@ -6,71 +6,19 @@ const ui = require("@ultraviolet/ui");
|
|
|
6
6
|
const react = require("react");
|
|
7
7
|
const reactHookForm = require("react-hook-form");
|
|
8
8
|
const index = require("../../providers/ErrorContext/index.cjs");
|
|
9
|
-
const identity = (x) => x;
|
|
10
9
|
const SelectInputField = ({
|
|
11
|
-
animation,
|
|
12
|
-
animationDuration,
|
|
13
|
-
animationOnChange,
|
|
14
|
-
children,
|
|
15
|
-
className,
|
|
16
|
-
disabled,
|
|
17
|
-
// error: errorProp,
|
|
18
|
-
format: formatProp = identity,
|
|
19
|
-
// formatOnBlur,
|
|
20
|
-
id,
|
|
21
|
-
inputId,
|
|
22
|
-
isClearable,
|
|
23
|
-
isLoading,
|
|
24
|
-
isSearchable,
|
|
25
10
|
label = "",
|
|
26
|
-
maxLength,
|
|
27
|
-
menuPortalTarget,
|
|
28
|
-
minLength,
|
|
29
|
-
multiple,
|
|
30
|
-
name,
|
|
31
11
|
onBlur,
|
|
32
|
-
onChange,
|
|
33
|
-
onFocus,
|
|
34
|
-
options: optionsProp,
|
|
35
|
-
parse: parseProp = identity,
|
|
36
|
-
placeholder,
|
|
37
|
-
readOnly,
|
|
38
12
|
required,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
customStyle,
|
|
13
|
+
name,
|
|
14
|
+
"aria-label": ariaLabel,
|
|
42
15
|
shouldUnregister = false,
|
|
43
|
-
|
|
44
|
-
validate
|
|
16
|
+
control,
|
|
17
|
+
validate,
|
|
18
|
+
onChange,
|
|
19
|
+
multiselect,
|
|
20
|
+
...props
|
|
45
21
|
}) => {
|
|
46
|
-
const options = react.useMemo(() => optionsProp || react.Children.toArray(children).flat().filter(Boolean).map(({
|
|
47
|
-
props: {
|
|
48
|
-
children: labelChild,
|
|
49
|
-
...option
|
|
50
|
-
}
|
|
51
|
-
}) => ({
|
|
52
|
-
...option,
|
|
53
|
-
label: labelChild
|
|
54
|
-
})), [optionsProp, children]);
|
|
55
|
-
const parse = react.useMemo(() => multiple ? parseProp : (option) => parseProp(option?.value ?? null, name), [multiple, parseProp, name]);
|
|
56
|
-
const format = react.useCallback((val) => {
|
|
57
|
-
if (multiple) return formatProp(val, name);
|
|
58
|
-
const find = (opts, valueToFind) => opts?.find((option) => option.value === valueToFind);
|
|
59
|
-
let selected = "";
|
|
60
|
-
if (val && options) {
|
|
61
|
-
selected = find(options, val);
|
|
62
|
-
if (!selected) {
|
|
63
|
-
selected = options.map((curr) => find(curr.options, val)).filter(identity);
|
|
64
|
-
if (Array.isArray(selected) && selected.length === 0) {
|
|
65
|
-
selected = "";
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return formatProp(selected, name);
|
|
70
|
-
}, [formatProp, multiple, name, options]);
|
|
71
|
-
const {
|
|
72
|
-
getError
|
|
73
|
-
} = index.useErrors();
|
|
74
22
|
const {
|
|
75
23
|
field,
|
|
76
24
|
fieldState: {
|
|
@@ -78,25 +26,25 @@ const SelectInputField = ({
|
|
|
78
26
|
}
|
|
79
27
|
} = reactHookForm.useController({
|
|
80
28
|
name,
|
|
29
|
+
control,
|
|
81
30
|
shouldUnregister,
|
|
82
31
|
rules: {
|
|
83
32
|
required,
|
|
84
|
-
minLength: minLength || required ? 1 : void 0,
|
|
85
|
-
maxLength,
|
|
86
33
|
validate
|
|
87
34
|
}
|
|
88
35
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
36
|
+
const {
|
|
37
|
+
getError
|
|
38
|
+
} = index.useErrors();
|
|
39
|
+
const handleChange = react.useCallback((value) => {
|
|
40
|
+
onChange?.(value);
|
|
41
|
+
field.onChange(value);
|
|
42
|
+
}, [onChange, field]);
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectInput, { name: field.name, multiselect, required, onBlur: (event) => {
|
|
94
44
|
field.onBlur();
|
|
95
45
|
onBlur?.(event);
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}, onFocus, options, placeholder, readOnly, noTopLabel, required, value: format(field.value), emptyState, "data-testid": dataTestId, children });
|
|
46
|
+
}, value: field.value, error: getError({
|
|
47
|
+
label: label ?? ariaLabel ?? name
|
|
48
|
+
}, error), label, "aria-label": ariaLabel, onChange: handleChange, ...props });
|
|
100
49
|
};
|
|
101
|
-
SelectInputField.Option = ui.SelectInput.Option;
|
|
102
50
|
exports.SelectInputField = SelectInputField;
|
|
@@ -1,85 +1,7 @@
|
|
|
1
|
-
import type { CSSObject, Theme, css } from '@emotion/react';
|
|
2
1
|
import { SelectInput } from '@ultraviolet/ui';
|
|
3
|
-
import type
|
|
2
|
+
import { type ComponentProps } from 'react';
|
|
4
3
|
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
4
|
import type { BaseFieldProps } from '../../types';
|
|
8
|
-
|
|
9
|
-
|
|
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, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, '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
|
-
/**
|
|
79
|
-
* @deprecated use SelectInputFieldV2 component instead
|
|
80
|
-
*/
|
|
81
|
-
export declare const SelectInputField: {
|
|
82
|
-
<TFieldValues extends FieldValues, TFieldName 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, noTopLabel, emptyState, customStyle, shouldUnregister, "data-testid": dataTestId, validate, }: SelectInputFieldProps<TFieldValues, TFieldName>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
83
|
-
Option: (props: Partial<OptionProps<import("@ultraviolet/ui").SelectOption> & import("@ultraviolet/ui").SelectOption>) => import("react").JSX.Element;
|
|
84
|
-
};
|
|
5
|
+
type SelectInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof SelectInput>, 'value' | 'onChange'>;
|
|
6
|
+
export declare const SelectInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, onBlur, required, name, "aria-label": ariaLabel, shouldUnregister, control, validate, onChange, multiselect, ...props }: SelectInputFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
85
7
|
export {};
|
|
@@ -1,74 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
3
3
|
import { SelectInput } from "@ultraviolet/ui";
|
|
4
|
-
import {
|
|
4
|
+
import { useCallback } from "react";
|
|
5
5
|
import { useController } from "react-hook-form";
|
|
6
6
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
7
|
-
const identity = (x) => x;
|
|
8
7
|
const SelectInputField = ({
|
|
9
|
-
animation,
|
|
10
|
-
animationDuration,
|
|
11
|
-
animationOnChange,
|
|
12
|
-
children,
|
|
13
|
-
className,
|
|
14
|
-
disabled,
|
|
15
|
-
// error: errorProp,
|
|
16
|
-
format: formatProp = identity,
|
|
17
|
-
// formatOnBlur,
|
|
18
|
-
id,
|
|
19
|
-
inputId,
|
|
20
|
-
isClearable,
|
|
21
|
-
isLoading,
|
|
22
|
-
isSearchable,
|
|
23
8
|
label = "",
|
|
24
|
-
maxLength,
|
|
25
|
-
menuPortalTarget,
|
|
26
|
-
minLength,
|
|
27
|
-
multiple,
|
|
28
|
-
name,
|
|
29
9
|
onBlur,
|
|
30
|
-
onChange,
|
|
31
|
-
onFocus,
|
|
32
|
-
options: optionsProp,
|
|
33
|
-
parse: parseProp = identity,
|
|
34
|
-
placeholder,
|
|
35
|
-
readOnly,
|
|
36
10
|
required,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
customStyle,
|
|
11
|
+
name,
|
|
12
|
+
"aria-label": ariaLabel,
|
|
40
13
|
shouldUnregister = false,
|
|
41
|
-
|
|
42
|
-
validate
|
|
14
|
+
control,
|
|
15
|
+
validate,
|
|
16
|
+
onChange,
|
|
17
|
+
multiselect,
|
|
18
|
+
...props
|
|
43
19
|
}) => {
|
|
44
|
-
const options = useMemo(() => optionsProp || Children.toArray(children).flat().filter(Boolean).map(({
|
|
45
|
-
props: {
|
|
46
|
-
children: labelChild,
|
|
47
|
-
...option
|
|
48
|
-
}
|
|
49
|
-
}) => ({
|
|
50
|
-
...option,
|
|
51
|
-
label: labelChild
|
|
52
|
-
})), [optionsProp, children]);
|
|
53
|
-
const parse = useMemo(() => multiple ? parseProp : (option) => parseProp(option?.value ?? null, name), [multiple, parseProp, name]);
|
|
54
|
-
const format = useCallback((val) => {
|
|
55
|
-
if (multiple) return formatProp(val, name);
|
|
56
|
-
const find = (opts, valueToFind) => opts?.find((option) => option.value === valueToFind);
|
|
57
|
-
let selected = "";
|
|
58
|
-
if (val && options) {
|
|
59
|
-
selected = find(options, val);
|
|
60
|
-
if (!selected) {
|
|
61
|
-
selected = options.map((curr) => find(curr.options, val)).filter(identity);
|
|
62
|
-
if (Array.isArray(selected) && selected.length === 0) {
|
|
63
|
-
selected = "";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return formatProp(selected, name);
|
|
68
|
-
}, [formatProp, multiple, name, options]);
|
|
69
|
-
const {
|
|
70
|
-
getError
|
|
71
|
-
} = useErrors();
|
|
72
20
|
const {
|
|
73
21
|
field,
|
|
74
22
|
fieldState: {
|
|
@@ -76,27 +24,27 @@ const SelectInputField = ({
|
|
|
76
24
|
}
|
|
77
25
|
} = useController({
|
|
78
26
|
name,
|
|
27
|
+
control,
|
|
79
28
|
shouldUnregister,
|
|
80
29
|
rules: {
|
|
81
30
|
required,
|
|
82
|
-
minLength: minLength || required ? 1 : void 0,
|
|
83
|
-
maxLength,
|
|
84
31
|
validate
|
|
85
32
|
}
|
|
86
33
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
34
|
+
const {
|
|
35
|
+
getError
|
|
36
|
+
} = useErrors();
|
|
37
|
+
const handleChange = useCallback((value) => {
|
|
38
|
+
onChange?.(value);
|
|
39
|
+
field.onChange(value);
|
|
40
|
+
}, [onChange, field]);
|
|
41
|
+
return /* @__PURE__ */ jsx(SelectInput, { name: field.name, multiselect, required, onBlur: (event) => {
|
|
92
42
|
field.onBlur();
|
|
93
43
|
onBlur?.(event);
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}, onFocus, options, placeholder, readOnly, noTopLabel, required, value: format(field.value), emptyState, "data-testid": dataTestId, children });
|
|
44
|
+
}, value: field.value, error: getError({
|
|
45
|
+
label: label ?? ariaLabel ?? name
|
|
46
|
+
}, error), label, "aria-label": ariaLabel, onChange: handleChange, ...props });
|
|
98
47
|
};
|
|
99
|
-
SelectInputField.Option = SelectInput.Option;
|
|
100
48
|
export {
|
|
101
49
|
SelectInputField
|
|
102
50
|
};
|
|
@@ -11,9 +11,9 @@ export declare const SelectableCardOptionGroupField: {
|
|
|
11
11
|
value: string;
|
|
12
12
|
className?: string;
|
|
13
13
|
children?: import("react").ReactNode;
|
|
14
|
-
options: ComponentProps<typeof import("@ultraviolet/ui").
|
|
15
|
-
optionValue?: ComponentProps<typeof import("@ultraviolet/ui").
|
|
16
|
-
optionPlaceholder?: ComponentProps<typeof import("@ultraviolet/ui").
|
|
14
|
+
options: ComponentProps<typeof import("@ultraviolet/ui").SelectInput>["options"];
|
|
15
|
+
optionValue?: ComponentProps<typeof import("@ultraviolet/ui").SelectInput>["value"];
|
|
16
|
+
optionPlaceholder?: ComponentProps<typeof import("@ultraviolet/ui").SelectInput>["placeholder"];
|
|
17
17
|
image?: import("react").ReactNode;
|
|
18
18
|
labelDescription?: ComponentProps<typeof import("@ultraviolet/ui").Label>["labelDescription"];
|
|
19
19
|
id?: string;
|