@ultraviolet/form 4.0.0-beta.9 → 4.0.1
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 +191 -3
- package/dist/components/CheckboxField/index.cjs +13 -13
- package/dist/components/CheckboxField/index.js +13 -13
- package/dist/components/CheckboxGroupField/index.cjs +7 -7
- package/dist/components/CheckboxGroupField/index.d.ts +1 -3
- package/dist/components/CheckboxGroupField/index.js +7 -7
- package/dist/components/{DateField → DateInputField}/index.cjs +18 -18
- package/dist/components/DateInputField/index.d.ts +7 -0
- package/dist/components/{DateField → DateInputField}/index.js +18 -18
- package/dist/components/Form/defaultErrors.cjs +10 -10
- package/dist/components/Form/defaultErrors.js +10 -10
- package/dist/components/Form/index.cjs +5 -5
- package/dist/components/Form/index.js +5 -5
- package/dist/components/KeyValueField/index.cjs +11 -11
- package/dist/components/KeyValueField/index.d.ts +6 -6
- package/dist/components/KeyValueField/index.js +11 -11
- package/dist/components/NumberInputField/index.cjs +26 -26
- package/dist/components/NumberInputField/index.d.ts +3 -9
- package/dist/components/NumberInputField/index.js +26 -26
- package/dist/components/RadioField/index.cjs +8 -8
- package/dist/components/RadioField/index.d.ts +1 -4
- package/dist/components/RadioField/index.js +8 -8
- package/dist/components/RadioGroupField/index.cjs +7 -7
- package/dist/components/RadioGroupField/index.d.ts +17 -7
- package/dist/components/RadioGroupField/index.js +7 -7
- package/dist/components/SelectInputField/index.cjs +21 -73
- package/dist/components/SelectInputField/index.d.ts +3 -81
- package/dist/components/SelectInputField/index.js +22 -74
- package/dist/components/SelectableCardField/index.cjs +8 -8
- package/dist/components/SelectableCardField/index.js +8 -8
- package/dist/components/SelectableCardGroupField/index.cjs +7 -7
- package/dist/components/SelectableCardGroupField/index.js +7 -7
- package/dist/components/SelectableCardOptionGroupField/index.cjs +9 -9
- package/dist/components/SelectableCardOptionGroupField/index.d.ts +3 -3
- package/dist/components/SelectableCardOptionGroupField/index.js +9 -9
- package/dist/components/SliderField/index.cjs +9 -9
- package/dist/components/SliderField/index.d.ts +1 -1
- package/dist/components/SliderField/index.js +9 -9
- package/dist/components/Submit/index.cjs +1 -1
- package/dist/components/Submit/index.js +1 -1
- package/dist/components/SwitchButtonField/index.cjs +8 -9
- package/dist/components/SwitchButtonField/index.d.ts +11 -2
- package/dist/components/SwitchButtonField/index.js +8 -9
- package/dist/components/TagInputField/index.cjs +6 -6
- package/dist/components/TagInputField/index.js +6 -6
- package/dist/components/TextAreaField/index.cjs +8 -8
- package/dist/components/TextAreaField/index.js +8 -8
- package/dist/components/TextInputField/index.cjs +23 -77
- package/dist/components/TextInputField/index.d.ts +5 -11
- package/dist/components/TextInputField/index.js +23 -77
- package/dist/components/{TimeInputFieldV2 → TimeInputField}/index.cjs +6 -6
- package/dist/components/TimeInputField/index.d.ts +11 -0
- package/dist/components/{TimeInputFieldV2 → TimeInputField}/index.js +7 -7
- package/dist/components/ToggleField/index.cjs +7 -7
- package/dist/components/ToggleField/index.js +7 -7
- package/dist/components/UnitInputField/index.cjs +10 -10
- package/dist/components/UnitInputField/index.js +10 -10
- package/dist/components/VerificationCodeField/index.cjs +4 -4
- package/dist/components/VerificationCodeField/index.js +4 -4
- package/dist/components/index.d.ts +11 -15
- package/dist/index.cjs +45 -53
- package/dist/index.d.ts +5 -5
- package/dist/index.js +15 -23
- package/dist/providers/index.d.ts +1 -1
- package/dist/validators/index.d.ts +1 -1
- package/package.json +10 -10
- package/dist/components/DateField/index.d.ts +0 -7
- 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,
|
|
@@ -20,30 +20,30 @@ const KeyValueField = ({
|
|
|
20
20
|
append,
|
|
21
21
|
remove
|
|
22
22
|
} = reactHookForm.useFieldArray({
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
control,
|
|
24
|
+
name
|
|
25
25
|
});
|
|
26
26
|
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
27
27
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
28
28
|
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { gap: 3, children: [
|
|
29
|
-
fields.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { gap: 3, children: fields.map((field, index$1) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Row, {
|
|
30
|
-
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, {
|
|
31
|
-
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, {
|
|
32
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, {
|
|
29
|
+
fields.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { gap: 3, children: fields.map((field, index$1) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Row, { alignItems: "end", gap: 2, templateColumns: "1fr 1fr auto", children: [
|
|
30
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { label: inputKey.label, name: `${name}.${index$1}.key`, readOnly, regex: inputKey.regex, required: inputKey.required }),
|
|
31
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { autoComplete: "off", label: inputValue.label, name: `${name}.${index$1}.value`, placeholder: inputValue.placeholder, readOnly, regex: inputValue.regex, required: inputValue.required, type: inputValue.type }),
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { "data-testid": `remove-button-${index$1}`, disabled: readOnly, onClick: () => remove(index$1), sentiment: "danger", size: "large", variant: "outlined", children: /* @__PURE__ */ jsxRuntime.jsx(icons.DeleteIcon, {}) })
|
|
33
33
|
] }, field.id)) }) : null,
|
|
34
34
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
35
35
|
ui.Button,
|
|
36
36
|
{
|
|
37
37
|
"data-testid": "add-button",
|
|
38
|
-
variant: "outlined",
|
|
39
|
-
sentiment: "primary",
|
|
40
|
-
fullWidth: addButton.fullWidth,
|
|
41
38
|
disabled: !canAdd || readOnly,
|
|
42
|
-
|
|
39
|
+
fullWidth: addButton.fullWidth,
|
|
43
40
|
onClick: () => append({
|
|
44
41
|
key: "",
|
|
45
42
|
value: ""
|
|
46
43
|
}),
|
|
44
|
+
sentiment: "primary",
|
|
45
|
+
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
46
|
+
variant: "outlined",
|
|
47
47
|
children: [
|
|
48
48
|
/* @__PURE__ */ jsxRuntime.jsx(icons.PlusIcon, {}),
|
|
49
49
|
addButton.name
|
|
@@ -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,
|
|
@@ -18,30 +18,30 @@ const KeyValueField = ({
|
|
|
18
18
|
append,
|
|
19
19
|
remove
|
|
20
20
|
} = useFieldArray({
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
control,
|
|
22
|
+
name
|
|
23
23
|
});
|
|
24
24
|
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
25
25
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
26
26
|
return /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
|
|
27
|
-
fields.length > 0 ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(Row, {
|
|
28
|
-
/* @__PURE__ */ jsx(TextInputField, {
|
|
29
|
-
/* @__PURE__ */ jsx(TextInputField, {
|
|
30
|
-
/* @__PURE__ */ jsx(Button, {
|
|
27
|
+
fields.length > 0 ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(Row, { alignItems: "end", gap: 2, templateColumns: "1fr 1fr auto", children: [
|
|
28
|
+
/* @__PURE__ */ jsx(TextInputField, { label: inputKey.label, name: `${name}.${index}.key`, readOnly, regex: inputKey.regex, required: inputKey.required }),
|
|
29
|
+
/* @__PURE__ */ jsx(TextInputField, { autoComplete: "off", label: inputValue.label, name: `${name}.${index}.value`, placeholder: inputValue.placeholder, readOnly, regex: inputValue.regex, required: inputValue.required, type: inputValue.type }),
|
|
30
|
+
/* @__PURE__ */ jsx(Button, { "data-testid": `remove-button-${index}`, disabled: readOnly, onClick: () => remove(index), sentiment: "danger", size: "large", variant: "outlined", children: /* @__PURE__ */ jsx(DeleteIcon, {}) })
|
|
31
31
|
] }, field.id)) }) : null,
|
|
32
32
|
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsxs(
|
|
33
33
|
Button,
|
|
34
34
|
{
|
|
35
35
|
"data-testid": "add-button",
|
|
36
|
-
variant: "outlined",
|
|
37
|
-
sentiment: "primary",
|
|
38
|
-
fullWidth: addButton.fullWidth,
|
|
39
36
|
disabled: !canAdd || readOnly,
|
|
40
|
-
|
|
37
|
+
fullWidth: addButton.fullWidth,
|
|
41
38
|
onClick: () => append({
|
|
42
39
|
key: "",
|
|
43
40
|
value: ""
|
|
44
41
|
}),
|
|
42
|
+
sentiment: "primary",
|
|
43
|
+
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
44
|
+
variant: "outlined",
|
|
45
45
|
children: [
|
|
46
46
|
/* @__PURE__ */ jsx(PlusIcon, {}),
|
|
47
47
|
addButton.name
|
|
@@ -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
|
|
@@ -34,26 +30,30 @@ const NumberInputField = ({
|
|
|
34
30
|
error
|
|
35
31
|
}
|
|
36
32
|
} = reactHookForm.useController({
|
|
37
|
-
name,
|
|
38
|
-
shouldUnregister,
|
|
39
33
|
control,
|
|
34
|
+
name,
|
|
40
35
|
rules: {
|
|
41
|
-
max
|
|
42
|
-
min
|
|
36
|
+
max,
|
|
37
|
+
min,
|
|
43
38
|
required,
|
|
44
|
-
validate
|
|
45
|
-
|
|
39
|
+
validate: {
|
|
40
|
+
...validate,
|
|
41
|
+
isInteger: isInteger.isInteger(step)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
shouldUnregister
|
|
46
45
|
});
|
|
47
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInput, {
|
|
46
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInput, { ...props, "aria-label": ariaLabel, error: getError({
|
|
47
|
+
isInteger: step,
|
|
48
|
+
label: label ?? ariaLabel ?? name,
|
|
49
|
+
max,
|
|
50
|
+
min
|
|
51
|
+
}, error), label, max, min, name: field.name, onBlur: (event) => {
|
|
48
52
|
field.onBlur();
|
|
49
53
|
onBlur?.(event);
|
|
50
|
-
}, onChange: (
|
|
51
|
-
field.onChange(
|
|
52
|
-
onChange?.(
|
|
53
|
-
},
|
|
54
|
-
label: label ?? "",
|
|
55
|
-
max: maxValue,
|
|
56
|
-
min: minValue
|
|
57
|
-
}, error) });
|
|
54
|
+
}, onChange: (newValue) => {
|
|
55
|
+
field.onChange(newValue);
|
|
56
|
+
onChange?.(newValue);
|
|
57
|
+
}, required, step, value: field.value });
|
|
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
|
|
@@ -32,27 +28,31 @@ const NumberInputField = ({
|
|
|
32
28
|
error
|
|
33
29
|
}
|
|
34
30
|
} = useController({
|
|
35
|
-
name,
|
|
36
|
-
shouldUnregister,
|
|
37
31
|
control,
|
|
32
|
+
name,
|
|
38
33
|
rules: {
|
|
39
|
-
max
|
|
40
|
-
min
|
|
34
|
+
max,
|
|
35
|
+
min,
|
|
41
36
|
required,
|
|
42
|
-
validate
|
|
43
|
-
|
|
37
|
+
validate: {
|
|
38
|
+
...validate,
|
|
39
|
+
isInteger: isInteger(step)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
shouldUnregister
|
|
44
43
|
});
|
|
45
|
-
return /* @__PURE__ */ jsx(NumberInput, {
|
|
44
|
+
return /* @__PURE__ */ jsx(NumberInput, { ...props, "aria-label": ariaLabel, error: getError({
|
|
45
|
+
isInteger: step,
|
|
46
|
+
label: label ?? ariaLabel ?? name,
|
|
47
|
+
max,
|
|
48
|
+
min
|
|
49
|
+
}, error), label, max, min, name: field.name, onBlur: (event) => {
|
|
46
50
|
field.onBlur();
|
|
47
51
|
onBlur?.(event);
|
|
48
|
-
}, onChange: (
|
|
49
|
-
field.onChange(
|
|
50
|
-
onChange?.(
|
|
51
|
-
},
|
|
52
|
-
label: label ?? "",
|
|
53
|
-
max: maxValue,
|
|
54
|
-
min: minValue
|
|
55
|
-
}, error) });
|
|
52
|
+
}, onChange: (newValue) => {
|
|
53
|
+
field.onChange(newValue);
|
|
54
|
+
onChange?.(newValue);
|
|
55
|
+
}, required, step, value: field.value });
|
|
56
56
|
};
|
|
57
57
|
export {
|
|
58
58
|
NumberInputField
|
|
@@ -30,13 +30,13 @@ const RadioField = ({
|
|
|
30
30
|
error
|
|
31
31
|
}
|
|
32
32
|
} = reactHookForm.useController({
|
|
33
|
-
name,
|
|
34
33
|
control,
|
|
35
|
-
|
|
34
|
+
name,
|
|
36
35
|
rules: {
|
|
37
36
|
required,
|
|
38
37
|
validate
|
|
39
|
-
}
|
|
38
|
+
},
|
|
39
|
+
shouldUnregister
|
|
40
40
|
});
|
|
41
41
|
const errorLabel = react.useMemo(() => {
|
|
42
42
|
if (label && typeof label === "string") {
|
|
@@ -47,14 +47,14 @@ const RadioField = ({
|
|
|
47
47
|
}
|
|
48
48
|
return name;
|
|
49
49
|
}, [label, name, ariaLabel]);
|
|
50
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Radio, { ...props,
|
|
50
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Radio, { ...props, checked: field.value === value, disabled, error: getError({
|
|
51
51
|
label: errorLabel
|
|
52
|
-
}, error),
|
|
53
|
-
field.onChange(value);
|
|
54
|
-
onChange?.(value);
|
|
55
|
-
}, onBlur: (event) => {
|
|
52
|
+
}, error), name: field.name, onBlur: (event) => {
|
|
56
53
|
field.onBlur();
|
|
57
54
|
onBlur?.(event);
|
|
55
|
+
}, onChange: () => {
|
|
56
|
+
field.onChange(value);
|
|
57
|
+
onChange?.(value);
|
|
58
58
|
}, onFocus, required, value: value ?? "", ...label ? {
|
|
59
59
|
label
|
|
60
60
|
} : {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Radio } from '@ultraviolet/ui';
|
|
2
|
-
import {
|
|
2
|
+
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
|
-
/**
|
|
7
|
-
* @deprecated This component is deprecated, use `RadioGroupField` instead.
|
|
8
|
-
*/
|
|
9
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("@emotion/react/jsx-runtime").JSX.Element;
|
|
10
7
|
export {};
|
|
@@ -28,13 +28,13 @@ const RadioField = ({
|
|
|
28
28
|
error
|
|
29
29
|
}
|
|
30
30
|
} = useController({
|
|
31
|
-
name,
|
|
32
31
|
control,
|
|
33
|
-
|
|
32
|
+
name,
|
|
34
33
|
rules: {
|
|
35
34
|
required,
|
|
36
35
|
validate
|
|
37
|
-
}
|
|
36
|
+
},
|
|
37
|
+
shouldUnregister
|
|
38
38
|
});
|
|
39
39
|
const errorLabel = useMemo(() => {
|
|
40
40
|
if (label && typeof label === "string") {
|
|
@@ -45,14 +45,14 @@ const RadioField = ({
|
|
|
45
45
|
}
|
|
46
46
|
return name;
|
|
47
47
|
}, [label, name, ariaLabel]);
|
|
48
|
-
return /* @__PURE__ */ jsx(Radio, { ...props,
|
|
48
|
+
return /* @__PURE__ */ jsx(Radio, { ...props, checked: field.value === value, disabled, error: getError({
|
|
49
49
|
label: errorLabel
|
|
50
|
-
}, error),
|
|
51
|
-
field.onChange(value);
|
|
52
|
-
onChange?.(value);
|
|
53
|
-
}, onBlur: (event) => {
|
|
50
|
+
}, error), name: field.name, onBlur: (event) => {
|
|
54
51
|
field.onBlur();
|
|
55
52
|
onBlur?.(event);
|
|
53
|
+
}, onChange: () => {
|
|
54
|
+
field.onChange(value);
|
|
55
|
+
onChange?.(value);
|
|
56
56
|
}, onFocus, required, value: value ?? "", ...label ? {
|
|
57
57
|
label
|
|
58
58
|
} : {
|
|
@@ -26,20 +26,20 @@ const RadioGroupField = ({
|
|
|
26
26
|
error
|
|
27
27
|
}
|
|
28
28
|
} = reactHookForm.useController({
|
|
29
|
-
name,
|
|
30
29
|
control,
|
|
31
|
-
|
|
30
|
+
name,
|
|
32
31
|
rules: {
|
|
33
32
|
required,
|
|
34
33
|
validate
|
|
35
|
-
}
|
|
34
|
+
},
|
|
35
|
+
shouldUnregister
|
|
36
36
|
});
|
|
37
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.RadioGroup, { ...props,
|
|
37
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.RadioGroup, { ...props, error: getError({
|
|
38
|
+
label: legend
|
|
39
|
+
}, error) ?? customError, legend, name: field.name, onChange: (event) => {
|
|
38
40
|
field.onChange(event);
|
|
39
41
|
onChange?.(event.target.value);
|
|
40
|
-
}, required, value: field.value,
|
|
41
|
-
label: legend
|
|
42
|
-
}, error) ?? customError, legend, children });
|
|
42
|
+
}, required, value: field.value, children });
|
|
43
43
|
};
|
|
44
44
|
RadioGroupField.Radio = ui.RadioGroup.Radio;
|
|
45
45
|
exports.RadioGroupField = RadioGroupField;
|
|
@@ -5,15 +5,25 @@ import type { BaseFieldProps } from '../../types';
|
|
|
5
5
|
type RadioGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Omit<ComponentProps<typeof RadioGroup>, 'value' | 'onChange' | 'legend'> & Partial<Pick<ComponentProps<typeof RadioGroup>, 'legend'>>;
|
|
6
6
|
export declare const RadioGroupField: {
|
|
7
7
|
<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, name, onChange, required, children, error: customError, shouldUnregister, validate, legend, ...props }: RadioGroupFieldProps<TFieldValues, TFieldName>): JSX.Element;
|
|
8
|
-
Radio: ({ onFocus, onBlur, disabled, error,
|
|
9
|
-
error?: import("react").ReactNode;
|
|
8
|
+
Radio: ({ onFocus, onBlur, disabled, error, value, label, helper, className, autoFocus, onKeyDown, tooltip, "data-testid": dataTestId, }: {
|
|
10
9
|
value: string | number;
|
|
10
|
+
onBlur?: import("react").FocusEventHandler<HTMLInputElement> | undefined;
|
|
11
|
+
disabled?: boolean | undefined | undefined;
|
|
12
|
+
className?: string | undefined;
|
|
13
|
+
ref?: import("react").Ref<HTMLInputElement> | undefined;
|
|
14
|
+
label?: import("react").ReactNode;
|
|
15
|
+
autoFocus?: boolean | undefined | undefined;
|
|
16
|
+
id?: string | undefined | undefined;
|
|
17
|
+
onClick?: import("react").MouseEventHandler<HTMLInputElement> | undefined;
|
|
18
|
+
onFocus?: import("react").FocusEventHandler<HTMLInputElement> | undefined;
|
|
19
|
+
tabIndex?: number | undefined | undefined;
|
|
20
|
+
error?: import("react").ReactNode;
|
|
11
21
|
helper?: import("react").ReactNode;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
'data-testid'?: string | undefined;
|
|
23
|
+
tooltip?: string | undefined;
|
|
24
|
+
'aria-label'?: string | undefined;
|
|
25
|
+
key?: import("react").Key | null | undefined;
|
|
26
|
+
onKeyDown?: import("react").KeyboardEventHandler<HTMLInputElement> | undefined;
|
|
17
27
|
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
18
28
|
};
|
|
19
29
|
export {};
|
|
@@ -24,20 +24,20 @@ const RadioGroupField = ({
|
|
|
24
24
|
error
|
|
25
25
|
}
|
|
26
26
|
} = useController({
|
|
27
|
-
name,
|
|
28
27
|
control,
|
|
29
|
-
|
|
28
|
+
name,
|
|
30
29
|
rules: {
|
|
31
30
|
required,
|
|
32
31
|
validate
|
|
33
|
-
}
|
|
32
|
+
},
|
|
33
|
+
shouldUnregister
|
|
34
34
|
});
|
|
35
|
-
return /* @__PURE__ */ jsx(RadioGroup, { ...props,
|
|
35
|
+
return /* @__PURE__ */ jsx(RadioGroup, { ...props, error: getError({
|
|
36
|
+
label: legend
|
|
37
|
+
}, error) ?? customError, legend, name: field.name, onChange: (event) => {
|
|
36
38
|
field.onChange(event);
|
|
37
39
|
onChange?.(event.target.value);
|
|
38
|
-
}, required, value: field.value,
|
|
39
|
-
label: legend
|
|
40
|
-
}, error) ?? customError, legend, children });
|
|
40
|
+
}, required, value: field.value, children });
|
|
41
41
|
};
|
|
42
42
|
RadioGroupField.Radio = RadioGroup.Radio;
|
|
43
43
|
export {
|
|
@@ -6,97 +6,45 @@ 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: {
|
|
77
25
|
error
|
|
78
26
|
}
|
|
79
27
|
} = reactHookForm.useController({
|
|
28
|
+
control,
|
|
80
29
|
name,
|
|
81
|
-
shouldUnregister,
|
|
82
30
|
rules: {
|
|
83
31
|
required,
|
|
84
|
-
minLength: minLength || required ? 1 : void 0,
|
|
85
|
-
maxLength,
|
|
86
32
|
validate
|
|
87
|
-
}
|
|
33
|
+
},
|
|
34
|
+
shouldUnregister
|
|
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, { "aria-label": ariaLabel, error: getError({
|
|
44
|
+
label: label ?? ariaLabel ?? name
|
|
45
|
+
}, error), label, multiselect, name: field.name, onBlur: (event) => {
|
|
94
46
|
field.onBlur();
|
|
95
47
|
onBlur?.(event);
|
|
96
|
-
}, onChange:
|
|
97
|
-
field.onChange(parse(event));
|
|
98
|
-
onChange?.(event, action);
|
|
99
|
-
}, onFocus, options, placeholder, readOnly, noTopLabel, required, value: format(field.value), emptyState, "data-testid": dataTestId, children });
|
|
48
|
+
}, onChange: handleChange, required, value: field.value, ...props });
|
|
100
49
|
};
|
|
101
|
-
SelectInputField.Option = ui.SelectInput.Option;
|
|
102
50
|
exports.SelectInputField = SelectInputField;
|