@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
|
@@ -40,50 +40,40 @@ const SelectInputField = ({
|
|
|
40
40
|
shouldUnregister = false,
|
|
41
41
|
"data-testid": dataTestId
|
|
42
42
|
}) => {
|
|
43
|
-
const options = useMemo(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
options,
|
|
65
|
-
val
|
|
66
|
-
);
|
|
67
|
-
if (!selected) {
|
|
68
|
-
selected = options.map(
|
|
69
|
-
(curr) => find(
|
|
70
|
-
curr.options,
|
|
71
|
-
val
|
|
72
|
-
)
|
|
73
|
-
).filter(identity);
|
|
74
|
-
if (Array.isArray(selected) && selected.length === 0) {
|
|
75
|
-
selected = "";
|
|
76
|
-
}
|
|
43
|
+
const options = useMemo(() => optionsProp || Children.toArray(children).flat().filter(Boolean).map(({
|
|
44
|
+
props: {
|
|
45
|
+
children: labelChild,
|
|
46
|
+
...option
|
|
47
|
+
}
|
|
48
|
+
}) => ({
|
|
49
|
+
...option,
|
|
50
|
+
label: labelChild
|
|
51
|
+
})), [optionsProp, children]);
|
|
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 = "";
|
|
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 = "";
|
|
77
64
|
}
|
|
78
65
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
66
|
+
}
|
|
67
|
+
return formatProp(selected, name);
|
|
68
|
+
}, [formatProp, multiple, name, options]);
|
|
69
|
+
const {
|
|
70
|
+
getError
|
|
71
|
+
} = useErrors();
|
|
84
72
|
const {
|
|
85
73
|
field,
|
|
86
|
-
fieldState: {
|
|
74
|
+
fieldState: {
|
|
75
|
+
error
|
|
76
|
+
}
|
|
87
77
|
} = useController({
|
|
88
78
|
name,
|
|
89
79
|
shouldUnregister,
|
|
@@ -94,44 +84,17 @@ const SelectInputField = ({
|
|
|
94
84
|
...rules
|
|
95
85
|
}
|
|
96
86
|
});
|
|
97
|
-
return /* @__PURE__ */ jsx(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
inputId,
|
|
109
|
-
isClearable,
|
|
110
|
-
isLoading,
|
|
111
|
-
isMulti: multiple,
|
|
112
|
-
customStyle,
|
|
113
|
-
isSearchable,
|
|
114
|
-
menuPortalTarget,
|
|
115
|
-
onBlur: (event) => {
|
|
116
|
-
field.onBlur();
|
|
117
|
-
onBlur?.(event);
|
|
118
|
-
},
|
|
119
|
-
onChange: (event, action) => {
|
|
120
|
-
field.onChange(parse(event));
|
|
121
|
-
onChange?.(event, action);
|
|
122
|
-
},
|
|
123
|
-
onFocus,
|
|
124
|
-
options,
|
|
125
|
-
placeholder,
|
|
126
|
-
readOnly,
|
|
127
|
-
noTopLabel,
|
|
128
|
-
required,
|
|
129
|
-
value: format(field.value),
|
|
130
|
-
emptyState,
|
|
131
|
-
"data-testid": dataTestId,
|
|
132
|
-
children
|
|
133
|
-
}
|
|
134
|
-
);
|
|
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 });
|
|
135
98
|
};
|
|
136
99
|
SelectInputField.Option = SelectInput.Option;
|
|
137
100
|
export {
|
|
@@ -0,0 +1,70 @@
|
|
|
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 SelectInputFieldV2 = ({
|
|
9
|
+
autofocus,
|
|
10
|
+
className,
|
|
11
|
+
id,
|
|
12
|
+
label = "",
|
|
13
|
+
onFocus,
|
|
14
|
+
onBlur,
|
|
15
|
+
placeholder,
|
|
16
|
+
readOnly,
|
|
17
|
+
required,
|
|
18
|
+
size,
|
|
19
|
+
"data-testid": dataTestId,
|
|
20
|
+
disabled,
|
|
21
|
+
placeholderSearch,
|
|
22
|
+
helper,
|
|
23
|
+
options,
|
|
24
|
+
emptyState,
|
|
25
|
+
onChange,
|
|
26
|
+
searchable,
|
|
27
|
+
clearable,
|
|
28
|
+
multiselect,
|
|
29
|
+
descriptionDirection,
|
|
30
|
+
footer,
|
|
31
|
+
labelDescription,
|
|
32
|
+
success,
|
|
33
|
+
loadMore,
|
|
34
|
+
isLoading,
|
|
35
|
+
selectAll,
|
|
36
|
+
selectAllGroup,
|
|
37
|
+
name,
|
|
38
|
+
"aria-label": ariaLabel,
|
|
39
|
+
optionalInfoPlacement,
|
|
40
|
+
rules,
|
|
41
|
+
shouldUnregister = false
|
|
42
|
+
}) => {
|
|
43
|
+
const {
|
|
44
|
+
field,
|
|
45
|
+
fieldState: {
|
|
46
|
+
error
|
|
47
|
+
}
|
|
48
|
+
} = reactHookForm.useController({
|
|
49
|
+
name,
|
|
50
|
+
shouldUnregister,
|
|
51
|
+
rules: {
|
|
52
|
+
required,
|
|
53
|
+
...rules
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const {
|
|
57
|
+
getError
|
|
58
|
+
} = index.useErrors();
|
|
59
|
+
const handleChange = React.useCallback((value) => {
|
|
60
|
+
onChange?.(value);
|
|
61
|
+
field.onChange(value);
|
|
62
|
+
}, [onChange, field]);
|
|
63
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectInputV2, { name: field.name, options, required, size, "data-testid": dataTestId, className, disabled, id, label, onFocus, onBlur: (event) => {
|
|
64
|
+
field.onBlur();
|
|
65
|
+
onBlur?.(event);
|
|
66
|
+
}, placeholder, readOnly, multiselect, value: field.value, placeholderSearch, helper, emptyState, searchable, clearable, descriptionDirection, footer, labelDescription, error: getError({
|
|
67
|
+
label
|
|
68
|
+
}, error), success, loadMore, isLoading, selectAll, selectAllGroup, autofocus, optionalInfoPlacement, "aria-label": ariaLabel, onChange: handleChange });
|
|
69
|
+
};
|
|
70
|
+
exports.SelectInputFieldV2 = SelectInputFieldV2;
|
|
@@ -40,7 +40,9 @@ const SelectInputFieldV2 = ({
|
|
|
40
40
|
}) => {
|
|
41
41
|
const {
|
|
42
42
|
field,
|
|
43
|
-
fieldState: {
|
|
43
|
+
fieldState: {
|
|
44
|
+
error
|
|
45
|
+
}
|
|
44
46
|
} = useController({
|
|
45
47
|
name,
|
|
46
48
|
shouldUnregister,
|
|
@@ -49,55 +51,19 @@ const SelectInputFieldV2 = ({
|
|
|
49
51
|
...rules
|
|
50
52
|
}
|
|
51
53
|
});
|
|
52
|
-
const {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
required,
|
|
66
|
-
size,
|
|
67
|
-
"data-testid": dataTestId,
|
|
68
|
-
className,
|
|
69
|
-
disabled,
|
|
70
|
-
id,
|
|
71
|
-
label,
|
|
72
|
-
onFocus,
|
|
73
|
-
onBlur: (event) => {
|
|
74
|
-
field.onBlur();
|
|
75
|
-
onBlur?.(event);
|
|
76
|
-
},
|
|
77
|
-
placeholder,
|
|
78
|
-
readOnly,
|
|
79
|
-
multiselect,
|
|
80
|
-
value: field.value,
|
|
81
|
-
placeholderSearch,
|
|
82
|
-
helper,
|
|
83
|
-
emptyState,
|
|
84
|
-
searchable,
|
|
85
|
-
clearable,
|
|
86
|
-
descriptionDirection,
|
|
87
|
-
footer,
|
|
88
|
-
labelDescription,
|
|
89
|
-
error: getError({ label }, error),
|
|
90
|
-
success,
|
|
91
|
-
loadMore,
|
|
92
|
-
isLoading,
|
|
93
|
-
selectAll,
|
|
94
|
-
selectAllGroup,
|
|
95
|
-
autofocus,
|
|
96
|
-
optionalInfoPlacement,
|
|
97
|
-
"aria-label": ariaLabel,
|
|
98
|
-
onChange: handleChange
|
|
99
|
-
}
|
|
100
|
-
);
|
|
54
|
+
const {
|
|
55
|
+
getError
|
|
56
|
+
} = useErrors();
|
|
57
|
+
const handleChange = useCallback((value) => {
|
|
58
|
+
onChange?.(value);
|
|
59
|
+
field.onChange(value);
|
|
60
|
+
}, [onChange, field]);
|
|
61
|
+
return /* @__PURE__ */ jsx(SelectInputV2, { name: field.name, options, required, size, "data-testid": dataTestId, className, disabled, id, label, onFocus, onBlur: (event) => {
|
|
62
|
+
field.onBlur();
|
|
63
|
+
onBlur?.(event);
|
|
64
|
+
}, placeholder, readOnly, multiselect, value: field.value, placeholderSearch, helper, emptyState, searchable, clearable, descriptionDirection, footer, labelDescription, error: getError({
|
|
65
|
+
label
|
|
66
|
+
}, error), success, loadMore, isLoading, selectAll, selectAllGroup, autofocus, optionalInfoPlacement, "aria-label": ariaLabel, onChange: handleChange });
|
|
101
67
|
};
|
|
102
68
|
export {
|
|
103
69
|
SelectInputFieldV2
|
|
@@ -0,0 +1,58 @@
|
|
|
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 SelectableCardField = ({
|
|
7
|
+
name,
|
|
8
|
+
value,
|
|
9
|
+
onChange,
|
|
10
|
+
showTick,
|
|
11
|
+
type,
|
|
12
|
+
disabled,
|
|
13
|
+
children,
|
|
14
|
+
className,
|
|
15
|
+
onFocus,
|
|
16
|
+
onBlur,
|
|
17
|
+
required,
|
|
18
|
+
tooltip,
|
|
19
|
+
id,
|
|
20
|
+
label,
|
|
21
|
+
rules,
|
|
22
|
+
shouldUnregister = false,
|
|
23
|
+
"data-testid": dataTestId
|
|
24
|
+
}) => {
|
|
25
|
+
const {
|
|
26
|
+
field,
|
|
27
|
+
fieldState: {
|
|
28
|
+
error
|
|
29
|
+
}
|
|
30
|
+
} = reactHookForm.useController({
|
|
31
|
+
name,
|
|
32
|
+
shouldUnregister,
|
|
33
|
+
rules: {
|
|
34
|
+
required,
|
|
35
|
+
...rules
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const isChecked = type === "checkbox" && Array.isArray(field.value) && value ? (field.value ?? []).includes(value) : field.value === value;
|
|
39
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectableCard, { isError: !!error, showTick, checked: isChecked, className, disabled, onChange: (event) => {
|
|
40
|
+
if (type === "checkbox") {
|
|
41
|
+
const fieldValue = field.value ?? [];
|
|
42
|
+
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
43
|
+
field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
|
|
44
|
+
} else {
|
|
45
|
+
field.onChange([...fieldValue, event.currentTarget.value]);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
field.onChange(event);
|
|
49
|
+
}
|
|
50
|
+
onChange?.(event);
|
|
51
|
+
}, onBlur: (event) => {
|
|
52
|
+
field.onBlur();
|
|
53
|
+
onBlur?.(event);
|
|
54
|
+
}, onFocus: (event) => {
|
|
55
|
+
onFocus?.(event);
|
|
56
|
+
}, type, id, tooltip, label, value: value ?? "", name: field.name, "data-testid": dataTestId, children });
|
|
57
|
+
};
|
|
58
|
+
exports.SelectableCardField = SelectableCardField;
|
|
@@ -22,7 +22,9 @@ const SelectableCardField = ({
|
|
|
22
22
|
}) => {
|
|
23
23
|
const {
|
|
24
24
|
field,
|
|
25
|
-
fieldState: {
|
|
25
|
+
fieldState: {
|
|
26
|
+
error
|
|
27
|
+
}
|
|
26
28
|
} = useController({
|
|
27
29
|
name,
|
|
28
30
|
shouldUnregister,
|
|
@@ -32,48 +34,24 @@ const SelectableCardField = ({
|
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
const isChecked = type === "checkbox" && Array.isArray(field.value) && value ? (field.value ?? []).includes(value) : field.value === value;
|
|
35
|
-
return /* @__PURE__ */ jsx(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const fieldValue = field.value ?? [];
|
|
46
|
-
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
47
|
-
field.onChange(
|
|
48
|
-
fieldValue?.filter(
|
|
49
|
-
(currentValue) => currentValue !== event.currentTarget.value
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
} else {
|
|
53
|
-
field.onChange([...fieldValue, event.currentTarget.value]);
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
field.onChange(event);
|
|
57
|
-
}
|
|
58
|
-
onChange?.(event);
|
|
59
|
-
},
|
|
60
|
-
onBlur: (event) => {
|
|
61
|
-
field.onBlur();
|
|
62
|
-
onBlur?.(event);
|
|
63
|
-
},
|
|
64
|
-
onFocus: (event) => {
|
|
65
|
-
onFocus?.(event);
|
|
66
|
-
},
|
|
67
|
-
type,
|
|
68
|
-
id,
|
|
69
|
-
tooltip,
|
|
70
|
-
label,
|
|
71
|
-
value: value ?? "",
|
|
72
|
-
name: field.name,
|
|
73
|
-
"data-testid": dataTestId,
|
|
74
|
-
children
|
|
37
|
+
return /* @__PURE__ */ jsx(SelectableCard, { isError: !!error, showTick, checked: isChecked, className, disabled, onChange: (event) => {
|
|
38
|
+
if (type === "checkbox") {
|
|
39
|
+
const fieldValue = field.value ?? [];
|
|
40
|
+
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
41
|
+
field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
|
|
42
|
+
} else {
|
|
43
|
+
field.onChange([...fieldValue, event.currentTarget.value]);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
field.onChange(event);
|
|
75
47
|
}
|
|
76
|
-
|
|
48
|
+
onChange?.(event);
|
|
49
|
+
}, onBlur: (event) => {
|
|
50
|
+
field.onBlur();
|
|
51
|
+
onBlur?.(event);
|
|
52
|
+
}, onFocus: (event) => {
|
|
53
|
+
onFocus?.(event);
|
|
54
|
+
}, type, id, tooltip, label, value: value ?? "", name: field.name, "data-testid": dataTestId, children });
|
|
77
55
|
};
|
|
78
56
|
export {
|
|
79
57
|
SelectableCardField
|
|
@@ -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 SelectableCardGroupField = ({
|
|
8
|
+
className,
|
|
9
|
+
legend,
|
|
10
|
+
name,
|
|
11
|
+
onChange,
|
|
12
|
+
required = false,
|
|
13
|
+
rules,
|
|
14
|
+
children,
|
|
15
|
+
label = "",
|
|
16
|
+
error: customError,
|
|
17
|
+
helper,
|
|
18
|
+
columns = 1,
|
|
19
|
+
showTick,
|
|
20
|
+
type = "radio",
|
|
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.SelectableCardGroup, { legend, name, type, showTick, value: field.value, onChange: (event) => {
|
|
40
|
+
if (type === "checkbox") {
|
|
41
|
+
const fieldValue = field.value ?? [];
|
|
42
|
+
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
43
|
+
field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
|
|
44
|
+
} else {
|
|
45
|
+
field.onChange([...fieldValue, event.currentTarget.value]);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
field.onChange(event);
|
|
49
|
+
}
|
|
50
|
+
onChange?.(event);
|
|
51
|
+
}, error: getError({
|
|
52
|
+
label
|
|
53
|
+
}, error) ?? customError, className, columns, helper, required, children });
|
|
54
|
+
};
|
|
55
|
+
SelectableCardGroupField.Card = ui.SelectableCardGroup.Card;
|
|
56
|
+
exports.SelectableCardGroupField = SelectableCardGroupField;
|
|
@@ -18,10 +18,14 @@ const SelectableCardGroupField = ({
|
|
|
18
18
|
type = "radio",
|
|
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,39 +34,21 @@ const SelectableCardGroupField = ({
|
|
|
30
34
|
...rules
|
|
31
35
|
}
|
|
32
36
|
});
|
|
33
|
-
return /* @__PURE__ */ jsx(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const fieldValue = field.value ?? [];
|
|
44
|
-
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
45
|
-
field.onChange(
|
|
46
|
-
fieldValue?.filter(
|
|
47
|
-
(currentValue) => currentValue !== event.currentTarget.value
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
} else {
|
|
51
|
-
field.onChange([...fieldValue, event.currentTarget.value]);
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
field.onChange(event);
|
|
55
|
-
}
|
|
56
|
-
onChange?.(event);
|
|
57
|
-
},
|
|
58
|
-
error: getError({ label }, error) ?? customError,
|
|
59
|
-
className,
|
|
60
|
-
columns,
|
|
61
|
-
helper,
|
|
62
|
-
required,
|
|
63
|
-
children
|
|
37
|
+
return /* @__PURE__ */ jsx(SelectableCardGroup, { legend, name, type, showTick, value: field.value, onChange: (event) => {
|
|
38
|
+
if (type === "checkbox") {
|
|
39
|
+
const fieldValue = field.value ?? [];
|
|
40
|
+
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
41
|
+
field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
|
|
42
|
+
} else {
|
|
43
|
+
field.onChange([...fieldValue, event.currentTarget.value]);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
field.onChange(event);
|
|
64
47
|
}
|
|
65
|
-
|
|
48
|
+
onChange?.(event);
|
|
49
|
+
}, error: getError({
|
|
50
|
+
label
|
|
51
|
+
}, error) ?? customError, className, columns, helper, required, children });
|
|
66
52
|
};
|
|
67
53
|
SelectableCardGroupField.Card = SelectableCardGroup.Card;
|
|
68
54
|
export {
|
|
@@ -0,0 +1,26 @@
|
|
|
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 Submit = ({
|
|
7
|
+
children,
|
|
8
|
+
className,
|
|
9
|
+
disabled = false,
|
|
10
|
+
icon,
|
|
11
|
+
iconPosition,
|
|
12
|
+
size,
|
|
13
|
+
variant = "filled",
|
|
14
|
+
sentiment = "primary",
|
|
15
|
+
tooltip,
|
|
16
|
+
fullWidth,
|
|
17
|
+
onClick
|
|
18
|
+
}) => {
|
|
19
|
+
const {
|
|
20
|
+
isSubmitting,
|
|
21
|
+
isValid
|
|
22
|
+
} = reactHookForm.useFormState();
|
|
23
|
+
const isDisabled = disabled || isSubmitting || !isValid;
|
|
24
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { className, disabled: isDisabled, icon, iconPosition, isLoading: isSubmitting, size, type: "submit", variant, sentiment, tooltip, fullWidth, onClick, children });
|
|
25
|
+
};
|
|
26
|
+
exports.Submit = Submit;
|
|
@@ -14,26 +14,12 @@ const Submit = ({
|
|
|
14
14
|
fullWidth,
|
|
15
15
|
onClick
|
|
16
16
|
}) => {
|
|
17
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
isSubmitting,
|
|
19
|
+
isValid
|
|
20
|
+
} = useFormState();
|
|
18
21
|
const isDisabled = disabled || isSubmitting || !isValid;
|
|
19
|
-
return /* @__PURE__ */ jsx(
|
|
20
|
-
Button,
|
|
21
|
-
{
|
|
22
|
-
className,
|
|
23
|
-
disabled: isDisabled,
|
|
24
|
-
icon,
|
|
25
|
-
iconPosition,
|
|
26
|
-
isLoading: isSubmitting,
|
|
27
|
-
size,
|
|
28
|
-
type: "submit",
|
|
29
|
-
variant,
|
|
30
|
-
sentiment,
|
|
31
|
-
tooltip,
|
|
32
|
-
fullWidth,
|
|
33
|
-
onClick,
|
|
34
|
-
children
|
|
35
|
-
}
|
|
36
|
-
);
|
|
22
|
+
return /* @__PURE__ */ jsx(Button, { className, disabled: isDisabled, icon, iconPosition, isLoading: isSubmitting, size, type: "submit", variant, sentiment, tooltip, fullWidth, onClick, children });
|
|
37
23
|
};
|
|
38
24
|
export {
|
|
39
25
|
Submit
|
|
@@ -0,0 +1,14 @@
|
|
|
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 SubmitErrorAlert = ({
|
|
7
|
+
className
|
|
8
|
+
}) => {
|
|
9
|
+
const {
|
|
10
|
+
errors
|
|
11
|
+
} = reactHookForm.useFormState();
|
|
12
|
+
return errors?.root?.["submit"]?.message ? /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { className, sentiment: "danger", children: errors.root["submit"].message }) : null;
|
|
13
|
+
};
|
|
14
|
+
exports.SubmitErrorAlert = SubmitErrorAlert;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { Alert } from "@ultraviolet/ui";
|
|
3
3
|
import { useFormState } from "react-hook-form";
|
|
4
|
-
const SubmitErrorAlert = ({
|
|
5
|
-
|
|
4
|
+
const SubmitErrorAlert = ({
|
|
5
|
+
className
|
|
6
|
+
}) => {
|
|
7
|
+
const {
|
|
8
|
+
errors
|
|
9
|
+
} = useFormState();
|
|
6
10
|
return errors?.root?.["submit"]?.message ? /* @__PURE__ */ jsx(Alert, { className, sentiment: "danger", children: errors.root["submit"].message }) : null;
|
|
7
11
|
};
|
|
8
12
|
export {
|
|
@@ -0,0 +1,50 @@
|
|
|
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 TagInputField = ({
|
|
8
|
+
className,
|
|
9
|
+
disabled,
|
|
10
|
+
id,
|
|
11
|
+
name,
|
|
12
|
+
onChange,
|
|
13
|
+
placeholder,
|
|
14
|
+
required,
|
|
15
|
+
rules,
|
|
16
|
+
variant,
|
|
17
|
+
shouldUnregister = false,
|
|
18
|
+
"data-testid": dataTestId,
|
|
19
|
+
clearable,
|
|
20
|
+
label,
|
|
21
|
+
labelDescription,
|
|
22
|
+
size,
|
|
23
|
+
success,
|
|
24
|
+
readOnly,
|
|
25
|
+
tooltip
|
|
26
|
+
}) => {
|
|
27
|
+
const {
|
|
28
|
+
getError
|
|
29
|
+
} = index.useErrors();
|
|
30
|
+
const {
|
|
31
|
+
field,
|
|
32
|
+
fieldState: {
|
|
33
|
+
error
|
|
34
|
+
}
|
|
35
|
+
} = reactHookForm.useController({
|
|
36
|
+
name,
|
|
37
|
+
rules: {
|
|
38
|
+
required,
|
|
39
|
+
shouldUnregister,
|
|
40
|
+
...rules
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.TagInput, { name: field.name, className, disabled, id, onChange: (newTags) => {
|
|
44
|
+
field.onChange(newTags);
|
|
45
|
+
onChange?.(newTags);
|
|
46
|
+
}, placeholder, variant, value: field.value, "data-testid": dataTestId, clearable, label, labelDescription, size, success, error: getError({
|
|
47
|
+
label: label ?? ""
|
|
48
|
+
}, error), readOnly, tooltip });
|
|
49
|
+
};
|
|
50
|
+
exports.TagInputField = TagInputField;
|