@ultraviolet/form 2.13.3 → 2.13.5
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.cjs +53 -0
- package/dist/components/CheckboxField/index.js +15 -32
- package/dist/components/CheckboxGroupField/index.cjs +75 -0
- package/dist/components/CheckboxGroupField/index.js +31 -48
- package/dist/components/DateField/index.cjs +74 -0
- package/dist/components/DateField/index.js +27 -42
- package/dist/components/Form/defaultErrors.cjs +22 -0
- package/dist/components/Form/index.cjs +72 -0
- package/dist/components/Form/index.js +25 -33
- package/dist/components/KeyValueField/index.cjs +51 -0
- package/dist/components/KeyValueField/index.js +14 -48
- package/dist/components/NumberInputField/index.cjs +56 -0
- package/dist/components/NumberInputField/index.js +17 -32
- package/dist/components/NumberInputFieldV2/index.cjs +63 -0
- package/dist/components/NumberInputFieldV2/index.js +17 -37
- package/dist/components/RadioField/index.cjs +49 -0
- package/dist/components/RadioField/index.js +15 -27
- package/dist/components/RadioGroupField/index.cjs +45 -0
- package/dist/components/RadioGroupField/index.js +12 -22
- package/dist/components/SelectInputField/index.cjs +102 -0
- package/dist/components/SelectInputField/index.js +41 -78
- package/dist/components/SelectInputFieldV2/index.cjs +70 -0
- package/dist/components/SelectInputFieldV2/index.js +16 -50
- package/dist/components/SelectableCardField/index.cjs +58 -0
- package/dist/components/SelectableCardField/index.js +20 -42
- package/dist/components/SelectableCardGroupField/index.cjs +56 -0
- package/dist/components/SelectableCardGroupField/index.js +20 -34
- package/dist/components/Submit/index.cjs +26 -0
- package/dist/components/Submit/index.js +5 -19
- package/dist/components/SubmitErrorAlert/index.cjs +14 -0
- package/dist/components/SubmitErrorAlert/index.js +6 -2
- package/dist/components/TagInputField/index.cjs +50 -0
- package/dist/components/TagInputField/index.js +12 -27
- package/dist/components/TextAreaField/index.cjs +70 -0
- package/dist/components/TextAreaField/index.js +22 -50
- package/dist/components/TextInputField/index.cjs +114 -0
- package/dist/components/TextInputField/index.js +31 -71
- package/dist/components/TextInputFieldV2/index.cjs +79 -0
- package/dist/components/TextInputFieldV2/index.js +22 -59
- package/dist/components/TimeField/index.cjs +66 -0
- package/dist/components/TimeField/index.js +17 -42
- package/dist/components/ToggleField/index.cjs +47 -0
- package/dist/components/ToggleField/index.js +10 -24
- package/dist/constants.cjs +4 -0
- package/dist/hooks/useField.cjs +30 -0
- package/dist/hooks/useField.js +10 -3
- package/dist/hooks/useFieldArray.cjs +32 -0
- package/dist/hooks/useFieldArray.js +13 -3
- package/dist/hooks/useForm.cjs +24 -0
- package/dist/hooks/useForm.js +6 -1
- package/dist/hooks/useFormState.cjs +22 -0
- package/dist/hooks/useFormState.js +3 -1
- package/dist/hooks/useOnFieldChange.cjs +21 -0
- package/dist/hooks/useOnFieldChange.js +5 -4
- package/dist/index.cjs +84 -0
- package/dist/providers/ErrorContext/index.cjs +33 -0
- package/dist/providers/ErrorContext/index.js +17 -20
- package/dist/validators/maxDate.cjs +4 -0
- package/dist/validators/minDate.cjs +4 -0
- package/package.json +20 -4
|
@@ -11,59 +11,22 @@ const KeyValueField = ({
|
|
|
11
11
|
readonly = false,
|
|
12
12
|
control
|
|
13
13
|
}) => {
|
|
14
|
-
const {
|
|
14
|
+
const {
|
|
15
|
+
fields,
|
|
16
|
+
append,
|
|
17
|
+
remove
|
|
18
|
+
} = useFieldArray({
|
|
15
19
|
name,
|
|
16
20
|
control
|
|
17
21
|
});
|
|
18
22
|
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
19
23
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
20
24
|
return /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
|
|
21
|
-
fields.length ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
alignItems: "end",
|
|
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,
|
|
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,
|
|
67
30
|
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsx(
|
|
68
31
|
Button,
|
|
69
32
|
{
|
|
@@ -74,7 +37,10 @@ const KeyValueField = ({
|
|
|
74
37
|
fullWidth: addButton.fullWidth,
|
|
75
38
|
disabled: !canAdd || readonly,
|
|
76
39
|
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
77
|
-
onClick: () => append({
|
|
40
|
+
onClick: () => append({
|
|
41
|
+
key: "",
|
|
42
|
+
value: ""
|
|
43
|
+
}),
|
|
78
44
|
children: addButton.name
|
|
79
45
|
}
|
|
80
46
|
) })
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
|
+
const NumberInputField = ({
|
|
8
|
+
disabled,
|
|
9
|
+
maxValue,
|
|
10
|
+
minValue,
|
|
11
|
+
name,
|
|
12
|
+
onChange,
|
|
13
|
+
onBlur,
|
|
14
|
+
onFocus,
|
|
15
|
+
onMaxCrossed,
|
|
16
|
+
onMinCrossed,
|
|
17
|
+
required,
|
|
18
|
+
size,
|
|
19
|
+
step,
|
|
20
|
+
text,
|
|
21
|
+
rules,
|
|
22
|
+
className,
|
|
23
|
+
label,
|
|
24
|
+
shouldUnregister = false
|
|
25
|
+
}) => {
|
|
26
|
+
const {
|
|
27
|
+
getError
|
|
28
|
+
} = index.useErrors();
|
|
29
|
+
const {
|
|
30
|
+
field,
|
|
31
|
+
fieldState: {
|
|
32
|
+
error
|
|
33
|
+
}
|
|
34
|
+
} = reactHookForm.useController({
|
|
35
|
+
name,
|
|
36
|
+
shouldUnregister,
|
|
37
|
+
rules: {
|
|
38
|
+
max: maxValue,
|
|
39
|
+
min: minValue,
|
|
40
|
+
required,
|
|
41
|
+
...rules
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInput, { name: field.name, value: field.value, disabled, onBlur: (event) => {
|
|
45
|
+
field.onBlur();
|
|
46
|
+
onBlur?.(event);
|
|
47
|
+
}, onChange: (event) => {
|
|
48
|
+
field.onChange(event ?? null);
|
|
49
|
+
onChange?.(event);
|
|
50
|
+
}, onFocus, maxValue, minValue, onMinCrossed, onMaxCrossed, size, step, text, className, label, error: getError({
|
|
51
|
+
label: label ?? "",
|
|
52
|
+
max: maxValue,
|
|
53
|
+
min: minValue
|
|
54
|
+
}, error) });
|
|
55
|
+
};
|
|
56
|
+
exports.NumberInputField = NumberInputField;
|
|
@@ -21,10 +21,14 @@ const NumberInputField = ({
|
|
|
21
21
|
label,
|
|
22
22
|
shouldUnregister = false
|
|
23
23
|
}) => {
|
|
24
|
-
const {
|
|
24
|
+
const {
|
|
25
|
+
getError
|
|
26
|
+
} = useErrors();
|
|
25
27
|
const {
|
|
26
28
|
field,
|
|
27
|
-
fieldState: {
|
|
29
|
+
fieldState: {
|
|
30
|
+
error
|
|
31
|
+
}
|
|
28
32
|
} = useController({
|
|
29
33
|
name,
|
|
30
34
|
shouldUnregister,
|
|
@@ -35,36 +39,17 @@ const NumberInputField = ({
|
|
|
35
39
|
...rules
|
|
36
40
|
}
|
|
37
41
|
});
|
|
38
|
-
return /* @__PURE__ */ jsx(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
);
|
|
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) });
|
|
68
53
|
};
|
|
69
54
|
export {
|
|
70
55
|
NumberInputField
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
|
+
const NumberInputFieldV2 = ({
|
|
8
|
+
disabled,
|
|
9
|
+
max = Number.MAX_SAFE_INTEGER,
|
|
10
|
+
min = 0,
|
|
11
|
+
name,
|
|
12
|
+
onChange,
|
|
13
|
+
onBlur,
|
|
14
|
+
size,
|
|
15
|
+
step,
|
|
16
|
+
unit,
|
|
17
|
+
tooltip,
|
|
18
|
+
className,
|
|
19
|
+
label,
|
|
20
|
+
labelDescription,
|
|
21
|
+
id,
|
|
22
|
+
placeholder,
|
|
23
|
+
success,
|
|
24
|
+
helper,
|
|
25
|
+
rules,
|
|
26
|
+
"aria-label": ariaLabel,
|
|
27
|
+
"data-testid": dataTestId,
|
|
28
|
+
required,
|
|
29
|
+
autoFocus,
|
|
30
|
+
readOnly,
|
|
31
|
+
shouldUnregister = false
|
|
32
|
+
}) => {
|
|
33
|
+
const {
|
|
34
|
+
getError
|
|
35
|
+
} = index.useErrors();
|
|
36
|
+
const {
|
|
37
|
+
field,
|
|
38
|
+
fieldState: {
|
|
39
|
+
error
|
|
40
|
+
}
|
|
41
|
+
} = reactHookForm.useController({
|
|
42
|
+
name,
|
|
43
|
+
shouldUnregister,
|
|
44
|
+
rules: {
|
|
45
|
+
max,
|
|
46
|
+
min,
|
|
47
|
+
required,
|
|
48
|
+
...rules
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInputV2, { name: field.name, value: field.value, disabled, onBlur: (event) => {
|
|
52
|
+
field.onBlur();
|
|
53
|
+
onBlur?.(event);
|
|
54
|
+
}, onChange: (newValue) => {
|
|
55
|
+
field.onChange(newValue);
|
|
56
|
+
onChange?.(newValue);
|
|
57
|
+
}, max, min, size, step, className, "data-testid": dataTestId, id, label, labelDescription, placeholder, error: getError({
|
|
58
|
+
label: label ?? "",
|
|
59
|
+
max,
|
|
60
|
+
min
|
|
61
|
+
}, error), success, helper, tooltip, unit, "aria-label": ariaLabel, autoFocus, readOnly, required });
|
|
62
|
+
};
|
|
63
|
+
exports.NumberInputFieldV2 = NumberInputFieldV2;
|
|
@@ -28,10 +28,14 @@ const NumberInputFieldV2 = ({
|
|
|
28
28
|
readOnly,
|
|
29
29
|
shouldUnregister = false
|
|
30
30
|
}) => {
|
|
31
|
-
const {
|
|
31
|
+
const {
|
|
32
|
+
getError
|
|
33
|
+
} = useErrors();
|
|
32
34
|
const {
|
|
33
35
|
field,
|
|
34
|
-
fieldState: {
|
|
36
|
+
fieldState: {
|
|
37
|
+
error
|
|
38
|
+
}
|
|
35
39
|
} = useController({
|
|
36
40
|
name,
|
|
37
41
|
shouldUnregister,
|
|
@@ -42,41 +46,17 @@ const NumberInputFieldV2 = ({
|
|
|
42
46
|
...rules
|
|
43
47
|
}
|
|
44
48
|
});
|
|
45
|
-
return /* @__PURE__ */ jsx(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
field.onChange(newValue);
|
|
57
|
-
onChange?.(newValue);
|
|
58
|
-
},
|
|
59
|
-
max,
|
|
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
|
-
);
|
|
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 });
|
|
80
60
|
};
|
|
81
61
|
export {
|
|
82
62
|
NumberInputFieldV2
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
|
+
const RadioField = ({
|
|
8
|
+
className,
|
|
9
|
+
"data-testid": dataTestId,
|
|
10
|
+
disabled,
|
|
11
|
+
id,
|
|
12
|
+
name,
|
|
13
|
+
onBlur,
|
|
14
|
+
label = "",
|
|
15
|
+
onChange,
|
|
16
|
+
onFocus,
|
|
17
|
+
required,
|
|
18
|
+
value,
|
|
19
|
+
rules,
|
|
20
|
+
tooltip,
|
|
21
|
+
shouldUnregister = false
|
|
22
|
+
}) => {
|
|
23
|
+
const {
|
|
24
|
+
getError
|
|
25
|
+
} = index.useErrors();
|
|
26
|
+
const {
|
|
27
|
+
field,
|
|
28
|
+
fieldState: {
|
|
29
|
+
error
|
|
30
|
+
}
|
|
31
|
+
} = reactHookForm.useController({
|
|
32
|
+
name,
|
|
33
|
+
shouldUnregister,
|
|
34
|
+
rules: {
|
|
35
|
+
required,
|
|
36
|
+
...rules
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Radio, { name: field.name, checked: field.value === value, className, "data-testid": dataTestId, disabled, error: getError({
|
|
40
|
+
label: typeof label === "string" ? label : ""
|
|
41
|
+
}, error), id, onChange: () => {
|
|
42
|
+
field.onChange(value);
|
|
43
|
+
onChange?.(value);
|
|
44
|
+
}, onBlur: (event) => {
|
|
45
|
+
field.onBlur();
|
|
46
|
+
onBlur?.(event);
|
|
47
|
+
}, onFocus, required, value: value ?? "", label, tooltip });
|
|
48
|
+
};
|
|
49
|
+
exports.RadioField = RadioField;
|
|
@@ -18,10 +18,14 @@ const RadioField = ({
|
|
|
18
18
|
tooltip,
|
|
19
19
|
shouldUnregister = false
|
|
20
20
|
}) => {
|
|
21
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
getError
|
|
23
|
+
} = useErrors();
|
|
22
24
|
const {
|
|
23
25
|
field,
|
|
24
|
-
fieldState: {
|
|
26
|
+
fieldState: {
|
|
27
|
+
error
|
|
28
|
+
}
|
|
25
29
|
} = useController({
|
|
26
30
|
name,
|
|
27
31
|
shouldUnregister,
|
|
@@ -30,31 +34,15 @@ const RadioField = ({
|
|
|
30
34
|
...rules
|
|
31
35
|
}
|
|
32
36
|
});
|
|
33
|
-
return /* @__PURE__ */ jsx(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
id,
|
|
43
|
-
onChange: () => {
|
|
44
|
-
field.onChange(value);
|
|
45
|
-
onChange?.(value);
|
|
46
|
-
},
|
|
47
|
-
onBlur: (event) => {
|
|
48
|
-
field.onBlur();
|
|
49
|
-
onBlur?.(event);
|
|
50
|
-
},
|
|
51
|
-
onFocus,
|
|
52
|
-
required,
|
|
53
|
-
value: value ?? "",
|
|
54
|
-
label,
|
|
55
|
-
tooltip
|
|
56
|
-
}
|
|
57
|
-
);
|
|
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 });
|
|
58
46
|
};
|
|
59
47
|
export {
|
|
60
48
|
RadioField
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
|
+
const RadioGroupField = ({
|
|
8
|
+
className,
|
|
9
|
+
legend = "",
|
|
10
|
+
name,
|
|
11
|
+
onChange,
|
|
12
|
+
required,
|
|
13
|
+
rules,
|
|
14
|
+
children,
|
|
15
|
+
label = "",
|
|
16
|
+
error: customError,
|
|
17
|
+
helper,
|
|
18
|
+
direction,
|
|
19
|
+
shouldUnregister = false
|
|
20
|
+
}) => {
|
|
21
|
+
const {
|
|
22
|
+
getError
|
|
23
|
+
} = index.useErrors();
|
|
24
|
+
const {
|
|
25
|
+
field,
|
|
26
|
+
fieldState: {
|
|
27
|
+
error
|
|
28
|
+
}
|
|
29
|
+
} = reactHookForm.useController({
|
|
30
|
+
name,
|
|
31
|
+
shouldUnregister,
|
|
32
|
+
rules: {
|
|
33
|
+
required,
|
|
34
|
+
...rules
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.RadioGroup, { className, name: field.name, onChange: (event) => {
|
|
38
|
+
field.onChange(event);
|
|
39
|
+
onChange?.(event.target.value);
|
|
40
|
+
}, required, value: field.value, legend, error: getError({
|
|
41
|
+
label
|
|
42
|
+
}, error) ?? customError, helper, direction, children });
|
|
43
|
+
};
|
|
44
|
+
RadioGroupField.Radio = ui.RadioGroup.Radio;
|
|
45
|
+
exports.RadioGroupField = RadioGroupField;
|
|
@@ -16,10 +16,14 @@ const RadioGroupField = ({
|
|
|
16
16
|
direction,
|
|
17
17
|
shouldUnregister = false
|
|
18
18
|
}) => {
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
getError
|
|
21
|
+
} = useErrors();
|
|
20
22
|
const {
|
|
21
23
|
field,
|
|
22
|
-
fieldState: {
|
|
24
|
+
fieldState: {
|
|
25
|
+
error
|
|
26
|
+
}
|
|
23
27
|
} = useController({
|
|
24
28
|
name,
|
|
25
29
|
shouldUnregister,
|
|
@@ -28,26 +32,12 @@ const RadioGroupField = ({
|
|
|
28
32
|
...rules
|
|
29
33
|
}
|
|
30
34
|
});
|
|
31
|
-
return /* @__PURE__ */ jsx(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
field.onChange(event);
|
|
38
|
-
onChange?.(
|
|
39
|
-
event.target.value
|
|
40
|
-
);
|
|
41
|
-
},
|
|
42
|
-
required,
|
|
43
|
-
value: field.value,
|
|
44
|
-
legend,
|
|
45
|
-
error: getError({ label }, error) ?? customError,
|
|
46
|
-
helper,
|
|
47
|
-
direction,
|
|
48
|
-
children
|
|
49
|
-
}
|
|
50
|
-
);
|
|
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 });
|
|
51
41
|
};
|
|
52
42
|
RadioGroupField.Radio = RadioGroup.Radio;
|
|
53
43
|
export {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const reactHookForm = require("react-hook-form");
|
|
7
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
8
|
+
const identity = (x) => x;
|
|
9
|
+
const SelectInputField = ({
|
|
10
|
+
animation,
|
|
11
|
+
animationDuration,
|
|
12
|
+
animationOnChange,
|
|
13
|
+
children,
|
|
14
|
+
className,
|
|
15
|
+
disabled,
|
|
16
|
+
// error: errorProp,
|
|
17
|
+
format: formatProp = identity,
|
|
18
|
+
// formatOnBlur,
|
|
19
|
+
id,
|
|
20
|
+
inputId,
|
|
21
|
+
isClearable,
|
|
22
|
+
isLoading,
|
|
23
|
+
isSearchable,
|
|
24
|
+
label = "",
|
|
25
|
+
maxLength,
|
|
26
|
+
menuPortalTarget,
|
|
27
|
+
minLength,
|
|
28
|
+
multiple,
|
|
29
|
+
name,
|
|
30
|
+
onBlur,
|
|
31
|
+
onChange,
|
|
32
|
+
onFocus,
|
|
33
|
+
options: optionsProp,
|
|
34
|
+
parse: parseProp = identity,
|
|
35
|
+
placeholder,
|
|
36
|
+
readOnly,
|
|
37
|
+
required,
|
|
38
|
+
rules,
|
|
39
|
+
noTopLabel,
|
|
40
|
+
emptyState,
|
|
41
|
+
customStyle,
|
|
42
|
+
shouldUnregister = false,
|
|
43
|
+
"data-testid": dataTestId
|
|
44
|
+
}) => {
|
|
45
|
+
const options = React.useMemo(() => optionsProp || React.Children.toArray(children).flat().filter(Boolean).map(({
|
|
46
|
+
props: {
|
|
47
|
+
children: labelChild,
|
|
48
|
+
...option
|
|
49
|
+
}
|
|
50
|
+
}) => ({
|
|
51
|
+
...option,
|
|
52
|
+
label: labelChild
|
|
53
|
+
})), [optionsProp, children]);
|
|
54
|
+
const parse = React.useMemo(() => multiple ? parseProp : (option) => parseProp(option?.value ?? null, name), [multiple, parseProp, name]);
|
|
55
|
+
const format = React.useCallback((val) => {
|
|
56
|
+
if (multiple)
|
|
57
|
+
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
|
+
const {
|
|
75
|
+
field,
|
|
76
|
+
fieldState: {
|
|
77
|
+
error
|
|
78
|
+
}
|
|
79
|
+
} = reactHookForm.useController({
|
|
80
|
+
name,
|
|
81
|
+
shouldUnregister,
|
|
82
|
+
rules: {
|
|
83
|
+
required,
|
|
84
|
+
minLength: minLength || required ? 1 : void 0,
|
|
85
|
+
maxLength,
|
|
86
|
+
...rules
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectInput, { name: field.name, animation, animationDuration, animationOnChange, className, disabled, error: getError({
|
|
90
|
+
label,
|
|
91
|
+
minLength,
|
|
92
|
+
maxLength
|
|
93
|
+
}, error), id, inputId, isClearable, isLoading, isMulti: multiple, customStyle, isSearchable, menuPortalTarget, onBlur: (event) => {
|
|
94
|
+
field.onBlur();
|
|
95
|
+
onBlur?.(event);
|
|
96
|
+
}, onChange: (event, action) => {
|
|
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 });
|
|
100
|
+
};
|
|
101
|
+
SelectInputField.Option = ui.SelectInput.Option;
|
|
102
|
+
exports.SelectInputField = SelectInputField;
|