@ultraviolet/form 2.13.4 → 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/CheckboxGroupField/index.cjs +75 -0
- package/dist/components/DateField/index.cjs +74 -0
- package/dist/components/Form/defaultErrors.cjs +22 -0
- package/dist/components/Form/index.cjs +72 -0
- package/dist/components/KeyValueField/index.cjs +51 -0
- package/dist/components/NumberInputField/index.cjs +56 -0
- package/dist/components/NumberInputFieldV2/index.cjs +63 -0
- package/dist/components/RadioField/index.cjs +49 -0
- package/dist/components/RadioGroupField/index.cjs +45 -0
- package/dist/components/SelectInputField/index.cjs +102 -0
- package/dist/components/SelectInputFieldV2/index.cjs +70 -0
- package/dist/components/SelectableCardField/index.cjs +58 -0
- package/dist/components/SelectableCardGroupField/index.cjs +56 -0
- package/dist/components/Submit/index.cjs +26 -0
- package/dist/components/SubmitErrorAlert/index.cjs +14 -0
- package/dist/components/TagInputField/index.cjs +50 -0
- package/dist/components/TextAreaField/index.cjs +70 -0
- package/dist/components/TextInputField/index.cjs +114 -0
- package/dist/components/TextInputFieldV2/index.cjs +79 -0
- package/dist/components/TimeField/index.cjs +66 -0
- package/dist/components/ToggleField/index.cjs +47 -0
- package/dist/constants.cjs +4 -0
- package/dist/hooks/useField.cjs +30 -0
- package/dist/hooks/useFieldArray.cjs +32 -0
- package/dist/hooks/useForm.cjs +24 -0
- package/dist/hooks/useFormState.cjs +22 -0
- package/dist/hooks/useOnFieldChange.cjs +21 -0
- package/dist/index.cjs +84 -0
- package/dist/providers/ErrorContext/index.cjs +33 -0
- package/dist/validators/maxDate.cjs +4 -0
- package/dist/validators/minDate.cjs +4 -0
- package/package.json +19 -3
|
@@ -0,0 +1,53 @@
|
|
|
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 CheckboxField = ({
|
|
8
|
+
id,
|
|
9
|
+
name,
|
|
10
|
+
label,
|
|
11
|
+
size,
|
|
12
|
+
progress,
|
|
13
|
+
disabled,
|
|
14
|
+
required,
|
|
15
|
+
className,
|
|
16
|
+
children,
|
|
17
|
+
onChange,
|
|
18
|
+
onBlur,
|
|
19
|
+
onFocus,
|
|
20
|
+
rules,
|
|
21
|
+
helper,
|
|
22
|
+
tooltip,
|
|
23
|
+
"data-testid": dataTestId,
|
|
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
|
+
disabled,
|
|
37
|
+
shouldUnregister,
|
|
38
|
+
rules: {
|
|
39
|
+
required,
|
|
40
|
+
...rules
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { id, name: field.name, onChange: (event) => {
|
|
44
|
+
field.onChange(event.target.checked);
|
|
45
|
+
onChange?.(event.target.checked);
|
|
46
|
+
}, onBlur: (event) => {
|
|
47
|
+
field.onBlur();
|
|
48
|
+
onBlur?.(event);
|
|
49
|
+
}, onFocus, size, progress, disabled: field.disabled, checked: !!field.value, error: getError({
|
|
50
|
+
label: label ?? ""
|
|
51
|
+
}, error), ref: field.ref, className, required, "data-testid": dataTestId, helper, tooltip, children });
|
|
52
|
+
};
|
|
53
|
+
exports.CheckboxField = CheckboxField;
|
|
@@ -0,0 +1,75 @@
|
|
|
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 arraysContainSameValues = (array1, array2) => {
|
|
9
|
+
if (array1.length === 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return array2.every((value) => array1.includes(value));
|
|
13
|
+
};
|
|
14
|
+
const CheckboxGroupField = ({
|
|
15
|
+
legend,
|
|
16
|
+
className,
|
|
17
|
+
helper,
|
|
18
|
+
direction,
|
|
19
|
+
children,
|
|
20
|
+
onChange,
|
|
21
|
+
label = "",
|
|
22
|
+
error: customError,
|
|
23
|
+
name,
|
|
24
|
+
required = false,
|
|
25
|
+
shouldUnregister = false,
|
|
26
|
+
rules
|
|
27
|
+
}) => {
|
|
28
|
+
const {
|
|
29
|
+
getError
|
|
30
|
+
} = index.useErrors();
|
|
31
|
+
const validate = React.useCallback((value) => {
|
|
32
|
+
const requiredChildren = React.Children.map(children, (child) => {
|
|
33
|
+
if (React.isValidElement(child)) {
|
|
34
|
+
if (child.props.required) {
|
|
35
|
+
return child.props.name;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
})?.filter(Boolean) ?? [];
|
|
41
|
+
if (!required && arraysContainSameValues(value, requiredChildren)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (value.length >= React.Children.count(children)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}, [children, required]);
|
|
49
|
+
const {
|
|
50
|
+
field,
|
|
51
|
+
fieldState: {
|
|
52
|
+
error
|
|
53
|
+
}
|
|
54
|
+
} = reactHookForm.useController({
|
|
55
|
+
name,
|
|
56
|
+
shouldUnregister,
|
|
57
|
+
rules: {
|
|
58
|
+
validate,
|
|
59
|
+
...rules
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.CheckboxGroup, { legend, name, value: field.value, onChange: (event) => {
|
|
63
|
+
const fieldValue = field.value;
|
|
64
|
+
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
65
|
+
field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
|
|
66
|
+
} else {
|
|
67
|
+
field.onChange([...field.value, event.currentTarget.value]);
|
|
68
|
+
}
|
|
69
|
+
onChange?.(event.currentTarget.value);
|
|
70
|
+
}, error: getError({
|
|
71
|
+
label
|
|
72
|
+
}, error) ?? customError, className, direction, helper, required, children });
|
|
73
|
+
};
|
|
74
|
+
CheckboxGroupField.Checkbox = ui.CheckboxGroup.Checkbox;
|
|
75
|
+
exports.CheckboxGroupField = CheckboxGroupField;
|
|
@@ -0,0 +1,74 @@
|
|
|
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 maxDate = require("../../validators/maxDate.cjs");
|
|
7
|
+
const minDate = require("../../validators/minDate.cjs");
|
|
8
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
9
|
+
const parseDate = (value) => typeof value === "string" ? new Date(value) : value;
|
|
10
|
+
const isEmpty = (value) => typeof value === "string" ? value === "" : value === void 0;
|
|
11
|
+
const DateField = ({
|
|
12
|
+
required,
|
|
13
|
+
name,
|
|
14
|
+
label = "",
|
|
15
|
+
format,
|
|
16
|
+
locale,
|
|
17
|
+
maxDate: maxDate$1,
|
|
18
|
+
minDate: minDate$1,
|
|
19
|
+
disabled,
|
|
20
|
+
onChange,
|
|
21
|
+
onBlur,
|
|
22
|
+
onFocus,
|
|
23
|
+
rules,
|
|
24
|
+
autoFocus = false,
|
|
25
|
+
excludeDates,
|
|
26
|
+
selectsRange,
|
|
27
|
+
"data-testid": dataTestId,
|
|
28
|
+
shouldUnregister = false
|
|
29
|
+
}) => {
|
|
30
|
+
const {
|
|
31
|
+
getError
|
|
32
|
+
} = index.useErrors();
|
|
33
|
+
const {
|
|
34
|
+
field,
|
|
35
|
+
fieldState: {
|
|
36
|
+
error
|
|
37
|
+
}
|
|
38
|
+
} = reactHookForm.useController({
|
|
39
|
+
name,
|
|
40
|
+
shouldUnregister,
|
|
41
|
+
rules: {
|
|
42
|
+
...rules,
|
|
43
|
+
validate: {
|
|
44
|
+
...rules?.validate,
|
|
45
|
+
minDate: minDate.minDateValidator(minDate$1),
|
|
46
|
+
maxDate: maxDate.maxDateValidator(maxDate$1)
|
|
47
|
+
},
|
|
48
|
+
required
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.DateInput, { name: field.name, label, value: field.value, format: format || ((value) => value ? parseDate(value).toLocaleDateString() : ""), locale, required, onChange: (val) => {
|
|
52
|
+
if (val && val instanceof Date) {
|
|
53
|
+
onChange?.(val);
|
|
54
|
+
const newDate = parseDate(val);
|
|
55
|
+
if (isEmpty(field.value)) {
|
|
56
|
+
field.onChange(newDate);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const currentDate = parseDate(field.value);
|
|
60
|
+
newDate.setHours(currentDate.getHours(), currentDate.getMinutes());
|
|
61
|
+
field.onChange(newDate);
|
|
62
|
+
} else if (Array.isArray(val)) {
|
|
63
|
+
field.onChange(val);
|
|
64
|
+
}
|
|
65
|
+
}, onBlur: (e) => {
|
|
66
|
+
field.onBlur();
|
|
67
|
+
onBlur?.(e);
|
|
68
|
+
}, onFocus, maxDate: maxDate$1, minDate: minDate$1, error: getError({
|
|
69
|
+
minDate: minDate$1,
|
|
70
|
+
maxDate: maxDate$1,
|
|
71
|
+
label
|
|
72
|
+
}, error), disabled, autoFocus, excludeDates, selectsRange, "data-testid": dataTestId, startDate: selectsRange && Array.isArray(field.value) ? field.value[0] : void 0, endDate: selectsRange && Array.isArray(field.value) ? field.value[1] : void 0 });
|
|
73
|
+
};
|
|
74
|
+
exports.DateField = DateField;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const defaultErrors = {
|
|
4
|
+
maxDate: () => "",
|
|
5
|
+
maxLength: () => "",
|
|
6
|
+
minLength: () => "",
|
|
7
|
+
max: () => "",
|
|
8
|
+
min: () => "",
|
|
9
|
+
required: () => "",
|
|
10
|
+
pattern: () => "",
|
|
11
|
+
deps: () => "",
|
|
12
|
+
value: () => "",
|
|
13
|
+
onBlur: () => "",
|
|
14
|
+
disabled: () => "",
|
|
15
|
+
onChange: () => "",
|
|
16
|
+
validate: () => "",
|
|
17
|
+
setValueAs: () => "",
|
|
18
|
+
valueAsDate: () => "",
|
|
19
|
+
valueAsNumber: () => "",
|
|
20
|
+
shouldUnregister: () => ""
|
|
21
|
+
};
|
|
22
|
+
exports.defaultErrors = defaultErrors;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const constants = require("../../constants.cjs");
|
|
7
|
+
const defaultErrors = require("./defaultErrors.cjs");
|
|
8
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
9
|
+
const _interopDefaultCompat = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
10
|
+
const React__default = /* @__PURE__ */ _interopDefaultCompat(React);
|
|
11
|
+
const FormSubmitContext = React__default.default.createContext({});
|
|
12
|
+
const Form = ({
|
|
13
|
+
children,
|
|
14
|
+
methods: methodsProp,
|
|
15
|
+
initialValues,
|
|
16
|
+
errors,
|
|
17
|
+
onRawSubmit,
|
|
18
|
+
name
|
|
19
|
+
}) => {
|
|
20
|
+
const methodsHook = reactHookForm.useForm({
|
|
21
|
+
defaultValues: initialValues,
|
|
22
|
+
mode: "onChange"
|
|
23
|
+
});
|
|
24
|
+
const methods = !methodsProp ? methodsHook : methodsProp;
|
|
25
|
+
const handleSubmit = methods.handleSubmit(async (values) => {
|
|
26
|
+
const result = await onRawSubmit(values, {
|
|
27
|
+
reset: methods.reset,
|
|
28
|
+
resetFieldState: methods.resetField,
|
|
29
|
+
restart: () => methods.reset(initialValues),
|
|
30
|
+
change: methods.setValue
|
|
31
|
+
});
|
|
32
|
+
if (result === null) {
|
|
33
|
+
methods.setError("root.submit", {
|
|
34
|
+
type: "custom"
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (result && typeof result !== "boolean" && typeof result !== "number") {
|
|
39
|
+
methods.setError("root.submit", {
|
|
40
|
+
type: "custom",
|
|
41
|
+
message: typeof result === "object" ? result[constants.FORM_ERROR] : result
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const formSubmitContextValue = React.useMemo(() => ({
|
|
46
|
+
handleSubmit
|
|
47
|
+
}), [handleSubmit]);
|
|
48
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children: /* @__PURE__ */ jsxRuntime.jsx(FormSubmitContext.Provider, { value: formSubmitContextValue, children: /* @__PURE__ */ jsxRuntime.jsx(index.ErrorProvider, { errors: {
|
|
49
|
+
...defaultErrors.defaultErrors,
|
|
50
|
+
...errors
|
|
51
|
+
}, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit: async (e) => {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
await handleSubmit(e);
|
|
55
|
+
}, name, noValidate: true, children: typeof children === "function" ? children({
|
|
56
|
+
values: methods.watch(),
|
|
57
|
+
hasValidationErrors: !methods.formState.isValid,
|
|
58
|
+
errors: methods.formState.errors,
|
|
59
|
+
submitting: methods.formState.isSubmitting,
|
|
60
|
+
pristine: !methods.formState.isDirty,
|
|
61
|
+
handleSubmit,
|
|
62
|
+
submitError: !!methods.formState.errors?.root?.["submit"],
|
|
63
|
+
valid: methods.formState.isValid,
|
|
64
|
+
form: {
|
|
65
|
+
change: methods.setValue,
|
|
66
|
+
reset: methods.reset,
|
|
67
|
+
submit: handleSubmit
|
|
68
|
+
}
|
|
69
|
+
}) : children }) }) }) });
|
|
70
|
+
};
|
|
71
|
+
exports.Form = Form;
|
|
72
|
+
exports.FormSubmitContext = FormSubmitContext;
|
|
@@ -0,0 +1,51 @@
|
|
|
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("../TextInputFieldV2/index.cjs");
|
|
7
|
+
const KeyValueField = ({
|
|
8
|
+
name,
|
|
9
|
+
inputKey,
|
|
10
|
+
inputValue,
|
|
11
|
+
addButton,
|
|
12
|
+
maxSize = 100,
|
|
13
|
+
readonly = false,
|
|
14
|
+
control
|
|
15
|
+
}) => {
|
|
16
|
+
const {
|
|
17
|
+
fields,
|
|
18
|
+
append,
|
|
19
|
+
remove
|
|
20
|
+
} = reactHookForm.useFieldArray({
|
|
21
|
+
name,
|
|
22
|
+
control
|
|
23
|
+
});
|
|
24
|
+
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
25
|
+
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
26
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { gap: 3, children: [
|
|
27
|
+
fields.length ? /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { gap: 3, children: fields.map((field, index$1) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Row, { templateColumns: "1fr 1fr auto", gap: 2, alignItems: "end", children: [
|
|
28
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { readOnly: readonly, required: inputKey.required, name: `${name}.${index$1}.key`, label: inputKey.label, regex: inputKey.regex }),
|
|
29
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { readOnly: readonly, required: inputValue.required, name: `${name}.${index$1}.value`, label: inputValue.label, placeholder: inputValue.placeholder, type: inputValue.type, autoComplete: "off", regex: inputValue.regex }),
|
|
30
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: readonly, "data-testid": `remove-button-${index$1}`, icon: "delete", variant: "outlined", sentiment: "danger", size: "large", onClick: () => remove(index$1) })
|
|
31
|
+
] }, field.id)) }) : null,
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
33
|
+
ui.Button,
|
|
34
|
+
{
|
|
35
|
+
"data-testid": "add-button",
|
|
36
|
+
icon: "plus",
|
|
37
|
+
variant: "filled",
|
|
38
|
+
sentiment: "neutral",
|
|
39
|
+
fullWidth: addButton.fullWidth,
|
|
40
|
+
disabled: !canAdd || readonly,
|
|
41
|
+
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
42
|
+
onClick: () => append({
|
|
43
|
+
key: "",
|
|
44
|
+
value: ""
|
|
45
|
+
}),
|
|
46
|
+
children: addButton.name
|
|
47
|
+
}
|
|
48
|
+
) })
|
|
49
|
+
] });
|
|
50
|
+
};
|
|
51
|
+
exports.KeyValueField = KeyValueField;
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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;
|