@ultraviolet/form 2.13.4 → 2.13.6

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.
Files changed (33) hide show
  1. package/dist/components/CheckboxField/index.cjs +53 -0
  2. package/dist/components/CheckboxGroupField/index.cjs +75 -0
  3. package/dist/components/DateField/index.cjs +74 -0
  4. package/dist/components/Form/defaultErrors.cjs +22 -0
  5. package/dist/components/Form/index.cjs +72 -0
  6. package/dist/components/KeyValueField/index.cjs +51 -0
  7. package/dist/components/NumberInputField/index.cjs +56 -0
  8. package/dist/components/NumberInputFieldV2/index.cjs +63 -0
  9. package/dist/components/RadioField/index.cjs +49 -0
  10. package/dist/components/RadioGroupField/index.cjs +45 -0
  11. package/dist/components/SelectInputField/index.cjs +102 -0
  12. package/dist/components/SelectInputFieldV2/index.cjs +70 -0
  13. package/dist/components/SelectableCardField/index.cjs +58 -0
  14. package/dist/components/SelectableCardGroupField/index.cjs +56 -0
  15. package/dist/components/Submit/index.cjs +26 -0
  16. package/dist/components/SubmitErrorAlert/index.cjs +14 -0
  17. package/dist/components/TagInputField/index.cjs +50 -0
  18. package/dist/components/TextAreaField/index.cjs +70 -0
  19. package/dist/components/TextInputField/index.cjs +114 -0
  20. package/dist/components/TextInputFieldV2/index.cjs +79 -0
  21. package/dist/components/TimeField/index.cjs +66 -0
  22. package/dist/components/ToggleField/index.cjs +47 -0
  23. package/dist/constants.cjs +4 -0
  24. package/dist/hooks/useField.cjs +30 -0
  25. package/dist/hooks/useFieldArray.cjs +32 -0
  26. package/dist/hooks/useForm.cjs +24 -0
  27. package/dist/hooks/useFormState.cjs +22 -0
  28. package/dist/hooks/useOnFieldChange.cjs +21 -0
  29. package/dist/index.cjs +84 -0
  30. package/dist/providers/ErrorContext/index.cjs +33 -0
  31. package/dist/validators/maxDate.cjs +4 -0
  32. package/dist/validators/minDate.cjs +4 -0
  33. package/package.json +23 -5
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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 reactHookForm = require("react-hook-form");
6
+ const index = require("../../providers/ErrorContext/index.cjs");
7
+ const TextAreaField = ({
8
+ autoFocus,
9
+ clearable,
10
+ className,
11
+ tabIndex,
12
+ "data-testid": dataTestId,
13
+ disabled,
14
+ helper,
15
+ label,
16
+ labelDescription,
17
+ onChange,
18
+ minLength,
19
+ maxLength,
20
+ name,
21
+ onFocus,
22
+ onBlur,
23
+ placeholder,
24
+ readOnly,
25
+ required,
26
+ rows,
27
+ success,
28
+ tooltip,
29
+ validate,
30
+ regex: regexes
31
+ }) => {
32
+ const {
33
+ getError
34
+ } = index.useErrors();
35
+ const {
36
+ field,
37
+ fieldState: {
38
+ error
39
+ }
40
+ } = reactHookForm.useController({
41
+ name,
42
+ rules: {
43
+ required,
44
+ validate: {
45
+ ...regexes ? {
46
+ pattern: (value) => regexes.every((regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value)))
47
+ } : {},
48
+ ...validate
49
+ },
50
+ minLength,
51
+ maxLength
52
+ }
53
+ });
54
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.TextArea, { autoFocus, className, clearable, "data-testid": dataTestId, disabled, error: getError({
55
+ regex: regexes,
56
+ minLength,
57
+ maxLength,
58
+ label,
59
+ value: field.value
60
+ }, error), helper, label, labelDescription, minLength, maxLength, name, onBlur: (event) => {
61
+ onBlur?.(event);
62
+ field.onBlur();
63
+ }, onChange: (event) => {
64
+ field.onChange(event);
65
+ onChange?.(event);
66
+ }, onFocus: (event) => {
67
+ onFocus?.(event);
68
+ }, placeholder, readOnly, required, rows, success, tabIndex, tooltip, value: field.value });
69
+ };
70
+ exports.TextAreaField = TextAreaField;
@@ -0,0 +1,114 @@
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 TextInputField = ({
8
+ autoCapitalize,
9
+ autoComplete,
10
+ autoCorrect,
11
+ autoFocus,
12
+ autoSave,
13
+ className,
14
+ cols,
15
+ disabled,
16
+ fillAvailable,
17
+ generated,
18
+ id,
19
+ label = "",
20
+ multiline,
21
+ name,
22
+ noTopLabel,
23
+ notice,
24
+ onChange,
25
+ onFocus,
26
+ onKeyDown,
27
+ onKeyUp,
28
+ onBlur,
29
+ placeholder,
30
+ random,
31
+ readOnly,
32
+ required,
33
+ resizable,
34
+ rows,
35
+ type,
36
+ unit,
37
+ size,
38
+ rules,
39
+ valid,
40
+ parse,
41
+ format,
42
+ formatOnBlur = false,
43
+ regex: regexes,
44
+ min,
45
+ max,
46
+ minLength,
47
+ maxLength,
48
+ validate,
49
+ defaultValue,
50
+ customError,
51
+ innerRef,
52
+ shouldUnregister = false,
53
+ "data-testid": dataTestId
54
+ }) => {
55
+ const {
56
+ getError
57
+ } = index.useErrors();
58
+ const {
59
+ field,
60
+ fieldState: {
61
+ error
62
+ }
63
+ } = reactHookForm.useController({
64
+ name,
65
+ defaultValue,
66
+ shouldUnregister,
67
+ rules: {
68
+ required,
69
+ validate: {
70
+ ...regexes ? {
71
+ pattern: (value) => regexes.every((regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value)))
72
+ } : {},
73
+ ...validate
74
+ },
75
+ minLength,
76
+ maxLength,
77
+ max,
78
+ min,
79
+ ...rules
80
+ }
81
+ });
82
+ const transformedValue = () => {
83
+ if (format && !formatOnBlur) {
84
+ return format(field.value);
85
+ }
86
+ return field.value;
87
+ };
88
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.TextInput, { name: field.name, autoCapitalize, autoComplete, autoCorrect, autoFocus, autoSave, className, cols, disabled, error: customError ?? getError({
89
+ regex: regexes,
90
+ minLength,
91
+ maxLength,
92
+ label,
93
+ min,
94
+ max,
95
+ value: field.value
96
+ }, error), fillAvailable, generated, id, label, multiline, notice, required, onBlur: (event) => {
97
+ field.onBlur();
98
+ onBlur?.(event);
99
+ if (formatOnBlur && format) {
100
+ field.onChange(format(field.value));
101
+ }
102
+ }, onChange: (event) => {
103
+ if (parse) {
104
+ field.onChange(parse(event));
105
+ onChange?.(parse(event));
106
+ } else {
107
+ field.onChange(event);
108
+ onChange?.(event);
109
+ }
110
+ }, onFocus: (event) => {
111
+ onFocus?.(event);
112
+ }, onKeyUp, onKeyDown, placeholder, random, readOnly, resizable, rows, type, noTopLabel, unit, valid, size, value: transformedValue(), ref: innerRef, "data-testid": dataTestId });
113
+ };
114
+ exports.TextInputField = TextInputField;
@@ -0,0 +1,79 @@
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 TextInputField = ({
8
+ validate,
9
+ regex: regexes,
10
+ id,
11
+ className,
12
+ tabIndex,
13
+ onChange,
14
+ placeholder,
15
+ disabled = false,
16
+ readOnly = false,
17
+ success,
18
+ helper,
19
+ tooltip,
20
+ label,
21
+ autoFocus,
22
+ required = false,
23
+ "data-testid": dataTestId,
24
+ name,
25
+ onFocus,
26
+ onBlur,
27
+ clearable = false,
28
+ labelDescription,
29
+ type = "text",
30
+ prefix,
31
+ suffix,
32
+ size = "large",
33
+ loading,
34
+ onRandomize,
35
+ minLength,
36
+ maxLength,
37
+ "aria-labelledby": ariaLabelledBy,
38
+ "aria-label": ariaLabel,
39
+ autoComplete
40
+ }) => {
41
+ const {
42
+ getError
43
+ } = index.useErrors();
44
+ const {
45
+ field,
46
+ fieldState: {
47
+ error
48
+ }
49
+ } = reactHookForm.useController({
50
+ name,
51
+ rules: {
52
+ required,
53
+ validate: {
54
+ ...regexes ? {
55
+ pattern: (value) => regexes.every((regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value)))
56
+ } : {},
57
+ ...validate
58
+ },
59
+ minLength,
60
+ maxLength
61
+ }
62
+ });
63
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.TextInputV2, { autoFocus, className, clearable, "data-testid": dataTestId, disabled, error: getError({
64
+ regex: regexes,
65
+ // minLength,
66
+ // maxLength,
67
+ label: label ?? "",
68
+ value: field.value
69
+ }, error), helper, label, loading, labelDescription, minLength, maxLength, name, onBlur: (event) => {
70
+ onBlur?.(event);
71
+ field.onBlur();
72
+ }, onChange: (event) => {
73
+ field.onChange(event);
74
+ onChange?.(event);
75
+ }, onFocus: (event) => {
76
+ onFocus?.(event);
77
+ }, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete });
78
+ };
79
+ exports.TextInputField = TextInputField;
@@ -0,0 +1,66 @@
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 parseTime = (date) => {
7
+ const timeStr = date && typeof date !== "string" ? date.toLocaleTimeString().slice(0, -3) : "";
8
+ return {
9
+ label: timeStr,
10
+ value: timeStr
11
+ };
12
+ };
13
+ const TimeField = ({
14
+ required,
15
+ name,
16
+ schedule,
17
+ placeholder,
18
+ disabled,
19
+ readOnly,
20
+ onBlur,
21
+ onFocus,
22
+ onChange,
23
+ isLoading,
24
+ isClearable,
25
+ inputId,
26
+ id,
27
+ animation,
28
+ animationDuration,
29
+ animationOnChange,
30
+ className,
31
+ isSearchable,
32
+ rules,
33
+ options,
34
+ "data-testid": dataTestId,
35
+ shouldUnregister = false,
36
+ noTopLabel
37
+ }) => {
38
+ const {
39
+ field,
40
+ fieldState: {
41
+ error
42
+ }
43
+ } = reactHookForm.useController({
44
+ name,
45
+ shouldUnregister,
46
+ rules: {
47
+ required,
48
+ ...rules
49
+ }
50
+ });
51
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.TimeInput, { name: field.name, placeholder, schedule, required, value: parseTime(field.value), onChange: (val) => {
52
+ if (!val)
53
+ return;
54
+ onChange?.(val);
55
+ const [hours, minutes] = val.value.split(":");
56
+ const date = field.value ? new Date(field.value) : /* @__PURE__ */ new Date();
57
+ date.setHours(Number(hours), Number(minutes), 0);
58
+ field.onChange(date);
59
+ }, onBlur: (event) => {
60
+ field.onBlur();
61
+ onBlur?.(event);
62
+ }, onFocus: (event) => {
63
+ onFocus?.(event);
64
+ }, error: error?.message, disabled, readOnly, animation, animationDuration, animationOnChange, className, isLoading, isClearable, isSearchable, inputId, id, options, "data-testid": dataTestId, noTopLabel });
65
+ };
66
+ exports.TimeField = TimeField;
@@ -0,0 +1,47 @@
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 ToggleField = ({
7
+ className,
8
+ disabled,
9
+ label,
10
+ name,
11
+ onChange,
12
+ required,
13
+ size,
14
+ tooltip,
15
+ rules,
16
+ labelPosition,
17
+ parse,
18
+ format,
19
+ "data-testid": dataTestId,
20
+ shouldUnregister = false
21
+ }) => {
22
+ const {
23
+ field
24
+ } = reactHookForm.useController({
25
+ name,
26
+ shouldUnregister,
27
+ rules: {
28
+ required,
29
+ ...rules
30
+ }
31
+ });
32
+ const transformedValue = () => {
33
+ if (format) {
34
+ return format(field.value);
35
+ }
36
+ return field.value;
37
+ };
38
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Toggle, { name: field.name, ref: field.ref, checked: transformedValue(), tooltip, onChange: (event) => {
39
+ if (parse) {
40
+ field.onChange(parse(event.target.checked));
41
+ } else {
42
+ field.onChange(event);
43
+ }
44
+ onChange?.(event);
45
+ }, label, size, disabled, labelPosition, className, required, "data-testid": dataTestId });
46
+ };
47
+ exports.ToggleField = ToggleField;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const FORM_ERROR = "FINAL_FORM/form-error";
4
+ exports.FORM_ERROR = FORM_ERROR;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const reactHookForm = require("react-hook-form");
4
+ const useFieldDeprecated = (name, options) => {
5
+ const {
6
+ getValues
7
+ } = reactHookForm.useFormContext();
8
+ const {
9
+ field,
10
+ fieldState
11
+ } = reactHookForm.useController({
12
+ name,
13
+ rules: {
14
+ validate: options?.validate
15
+ }
16
+ });
17
+ return {
18
+ input: {
19
+ value: getValues(name),
20
+ onChange: field.onChange
21
+ },
22
+ meta: {
23
+ error: fieldState.error?.message,
24
+ touched: fieldState.isTouched,
25
+ invalid: fieldState.invalid,
26
+ dirty: fieldState.isDirty
27
+ }
28
+ };
29
+ };
30
+ exports.useFieldDeprecated = useFieldDeprecated;