@ultraviolet/form 6.2.0 → 6.2.2
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/_virtual/{_@oxc-project_runtime@0.114.0 → _@oxc-project_runtime@0.115.0}/helpers/asyncToGenerator.js +5 -3
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/defineProperty.js +19 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.114.0 → _@oxc-project_runtime@0.115.0}/helpers/objectSpread2.js +8 -4
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.js +22 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutPropertiesLoose.js +17 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.114.0 → _@oxc-project_runtime@0.115.0}/helpers/toPrimitive.js +8 -4
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/toPropertyKey.js +17 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.114.0 → _@oxc-project_runtime@0.115.0}/helpers/typeof.js +5 -3
- package/dist/_virtual/_rolldown/runtime.js +2 -1
- package/dist/components/CheckboxField/index.js +59 -51
- package/dist/components/CheckboxGroupField/index.js +67 -59
- package/dist/components/DateInputField/index.js +94 -84
- package/dist/components/FileInputField/index.js +64 -60
- package/dist/components/Form/defaultErrors.js +25 -21
- package/dist/components/Form/index.d.ts +2 -1
- package/dist/components/Form/index.d.ts.map +1 -1
- package/dist/components/Form/index.js +41 -31
- package/dist/components/KeyValueField/index.js +88 -86
- package/dist/components/NumberInputField/index.js +66 -57
- package/dist/components/RadioField/index.js +65 -57
- package/dist/components/RadioGroupField/index.js +50 -42
- package/dist/components/SelectInputField/index.js +56 -48
- package/dist/components/SelectableCardField/index.js +64 -58
- package/dist/components/SelectableCardGroupField/SelectableCardGroupField.js +56 -48
- package/dist/components/SelectableCardGroupField/index.js +9 -0
- package/dist/components/SelectableCardOptionGroupField/index.js +61 -53
- package/dist/components/SliderField/index.js +83 -75
- package/dist/components/Submit/index.js +22 -18
- package/dist/components/SubmitErrorAlert/index.js +15 -11
- package/dist/components/SwitchButtonField/index.js +47 -41
- package/dist/components/TagInputField/index.js +54 -45
- package/dist/components/TextAreaField/index.js +78 -72
- package/dist/components/TextInputField/index.js +67 -61
- package/dist/components/TimeInputField/index.js +50 -46
- package/dist/components/ToggleField/index.js +63 -55
- package/dist/components/ToggleGroupField/index.js +53 -45
- package/dist/components/UnitInputField/index.js +61 -53
- package/dist/components/VerificationCodeField/index.js +47 -39
- package/dist/components/compositions/CodeEditorField/index.js +48 -42
- package/dist/components/compositions/CustomerSatisfactionField/index.js +17 -13
- package/dist/components/compositions/OfferListField/index.js +54 -48
- package/dist/components/compositions/OptionSelectorField/index.js +53 -45
- package/dist/components/compositions/PlansField/index.js +25 -21
- package/dist/components/compositions/index.js +17 -5
- package/dist/components/index.js +59 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/useOnFieldChange.js +25 -24
- package/dist/index.js +14 -1
- package/dist/providers/ErrorContext/index.js +28 -24
- package/dist/providers/index.js +11 -0
- package/dist/utils/validateRegex.js +7 -3
- package/dist/validators/isInteger.js +11 -7
- package/dist/validators/maxDate.js +7 -3
- package/dist/validators/minDate.js +7 -3
- package/package.json +6 -6
- package/dist/_virtual/_@oxc-project_runtime@0.114.0/helpers/defineProperty.js +0 -15
- package/dist/_virtual/_@oxc-project_runtime@0.114.0/helpers/objectWithoutProperties.js +0 -18
- package/dist/_virtual/_@oxc-project_runtime@0.114.0/helpers/objectWithoutPropertiesLoose.js +0 -15
- package/dist/_virtual/_@oxc-project_runtime@0.114.0/helpers/toPropertyKey.js +0 -12
|
@@ -1,85 +1,91 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
-
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import { __esmMin, __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
+
import { _objectWithoutProperties, init_objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.js";
|
|
4
|
+
import { _objectSpread2, init_objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.js";
|
|
5
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { init_providers } from "../../providers/index.js";
|
|
7
|
+
import { init_validateRegex, validateRegex } from "../../utils/validateRegex.js";
|
|
7
8
|
import { TextArea } from "@ultraviolet/ui";
|
|
8
9
|
import { useController } from "react-hook-form";
|
|
9
10
|
import { jsx } from "react/jsx-runtime";
|
|
10
11
|
|
|
11
12
|
//#region src/components/TextAreaField/index.tsx
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (submitOnEnter && event.key === "Enter" && !event.shiftKey) {
|
|
47
|
-
event.preventDefault();
|
|
48
|
-
event.stopPropagation();
|
|
49
|
-
const { form } = event.currentTarget;
|
|
50
|
-
if (form) {
|
|
51
|
-
const submitEvent = new Event("submit", {
|
|
52
|
-
bubbles: true,
|
|
53
|
-
cancelable: true
|
|
54
|
-
});
|
|
55
|
-
form.dispatchEvent(submitEvent);
|
|
13
|
+
var _excluded, TextAreaField;
|
|
14
|
+
var init_TextAreaField = __esmMin(() => {
|
|
15
|
+
init_providers();
|
|
16
|
+
init_validateRegex();
|
|
17
|
+
init_objectWithoutProperties();
|
|
18
|
+
init_objectSpread2();
|
|
19
|
+
_excluded = [
|
|
20
|
+
"control",
|
|
21
|
+
"label",
|
|
22
|
+
"onChange",
|
|
23
|
+
"minLength",
|
|
24
|
+
"maxLength",
|
|
25
|
+
"name",
|
|
26
|
+
"onBlur",
|
|
27
|
+
"onKeyDown",
|
|
28
|
+
"required",
|
|
29
|
+
"regex",
|
|
30
|
+
"submitOnEnter",
|
|
31
|
+
"validate",
|
|
32
|
+
"aria-label"
|
|
33
|
+
];
|
|
34
|
+
TextAreaField = (_ref) => {
|
|
35
|
+
var _ref2;
|
|
36
|
+
let { control, label, onChange, minLength, maxLength, name, onBlur, onKeyDown, required, regex: regexes, submitOnEnter, validate, "aria-label": ariaLabel } = _ref;
|
|
37
|
+
let props = _objectWithoutProperties(_ref, _excluded);
|
|
38
|
+
const { getError } = useErrors();
|
|
39
|
+
const { field, fieldState: { error } } = useController({
|
|
40
|
+
control,
|
|
41
|
+
name,
|
|
42
|
+
rules: {
|
|
43
|
+
maxLength,
|
|
44
|
+
minLength,
|
|
45
|
+
required,
|
|
46
|
+
validate: _objectSpread2(_objectSpread2({}, regexes ? { pattern: (value) => validateRegex(value, regexes) } : {}), validate)
|
|
56
47
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
});
|
|
49
|
+
const onKeyDownHandler = (event) => {
|
|
50
|
+
if (submitOnEnter && event.key === "Enter" && !event.shiftKey) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
event.stopPropagation();
|
|
53
|
+
const { form } = event.currentTarget;
|
|
54
|
+
if (form) {
|
|
55
|
+
const submitEvent = new Event("submit", {
|
|
56
|
+
bubbles: true,
|
|
57
|
+
cancelable: true
|
|
58
|
+
});
|
|
59
|
+
form.dispatchEvent(submitEvent);
|
|
60
|
+
}
|
|
61
|
+
} else onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
62
|
+
};
|
|
63
|
+
return /* @__PURE__ */ jsx(TextArea, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
64
|
+
error: getError({
|
|
65
|
+
label: (_ref2 = label !== null && label !== void 0 ? label : ariaLabel) !== null && _ref2 !== void 0 ? _ref2 : name,
|
|
66
|
+
maxLength,
|
|
67
|
+
minLength,
|
|
68
|
+
regex: regexes,
|
|
69
|
+
value: field.value
|
|
70
|
+
}, error),
|
|
62
71
|
maxLength,
|
|
63
72
|
minLength,
|
|
64
|
-
|
|
73
|
+
name,
|
|
74
|
+
onBlur: (event) => {
|
|
75
|
+
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
76
|
+
field.onBlur();
|
|
77
|
+
},
|
|
78
|
+
onChange: (event) => {
|
|
79
|
+
field.onChange(event);
|
|
80
|
+
onChange === null || onChange === void 0 || onChange(event);
|
|
81
|
+
},
|
|
82
|
+
onKeyDown: onKeyDownHandler,
|
|
83
|
+
required,
|
|
65
84
|
value: field.value
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
name,
|
|
70
|
-
onBlur: (event) => {
|
|
71
|
-
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
72
|
-
field.onBlur();
|
|
73
|
-
},
|
|
74
|
-
onChange: (event) => {
|
|
75
|
-
field.onChange(event);
|
|
76
|
-
onChange === null || onChange === void 0 || onChange(event);
|
|
77
|
-
},
|
|
78
|
-
onKeyDown: onKeyDownHandler,
|
|
79
|
-
required,
|
|
80
|
-
value: field.value
|
|
81
|
-
}, label ? { label } : { "aria-label": ariaLabel }));
|
|
82
|
-
};
|
|
85
|
+
}, label ? { label } : { "aria-label": ariaLabel }));
|
|
86
|
+
};
|
|
87
|
+
});
|
|
83
88
|
|
|
84
89
|
//#endregion
|
|
85
|
-
|
|
90
|
+
init_TextAreaField();
|
|
91
|
+
export { TextAreaField, init_TextAreaField };
|
|
@@ -1,73 +1,79 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
-
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import { __esmMin, __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
+
import { _objectWithoutProperties, init_objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.js";
|
|
4
|
+
import { _objectSpread2, init_objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.js";
|
|
5
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { init_providers } from "../../providers/index.js";
|
|
7
|
+
import { init_validateRegex, validateRegex } from "../../utils/validateRegex.js";
|
|
7
8
|
import { TextInput } from "@ultraviolet/ui";
|
|
8
9
|
import { useController } from "react-hook-form";
|
|
9
10
|
import { jsx } from "react/jsx-runtime";
|
|
10
11
|
|
|
11
12
|
//#region src/components/TextInputField/index.tsx
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
var _excluded, TextInputField;
|
|
14
|
+
var init_TextInputField = __esmMin(() => {
|
|
15
|
+
init_providers();
|
|
16
|
+
init_validateRegex();
|
|
17
|
+
init_objectWithoutProperties();
|
|
18
|
+
init_objectSpread2();
|
|
19
|
+
_excluded = [
|
|
20
|
+
"regex",
|
|
21
|
+
"onChange",
|
|
22
|
+
"label",
|
|
23
|
+
"required",
|
|
24
|
+
"name",
|
|
25
|
+
"onBlur",
|
|
26
|
+
"minLength",
|
|
27
|
+
"maxLength",
|
|
28
|
+
"aria-label",
|
|
29
|
+
"shouldUnregister",
|
|
30
|
+
"validate",
|
|
31
|
+
"control"
|
|
32
|
+
];
|
|
33
|
+
TextInputField = (_ref) => {
|
|
34
|
+
var _ref2;
|
|
35
|
+
var _field$value;
|
|
36
|
+
let { regex: regexes, onChange, label, required = false, name, onBlur, minLength, maxLength, "aria-label": ariaLabel, shouldUnregister, validate, control } = _ref;
|
|
37
|
+
let props = _objectWithoutProperties(_ref, _excluded);
|
|
38
|
+
const { getError } = useErrors();
|
|
39
|
+
const { field, fieldState: { error } } = useController({
|
|
40
|
+
control,
|
|
41
|
+
name,
|
|
42
|
+
rules: {
|
|
43
|
+
maxLength,
|
|
44
|
+
minLength,
|
|
45
|
+
required,
|
|
46
|
+
validate: _objectSpread2(_objectSpread2({}, regexes ? { pattern: (value) => validateRegex(value, regexes) } : {}), validate)
|
|
47
|
+
},
|
|
48
|
+
shouldUnregister
|
|
49
|
+
});
|
|
50
|
+
return /* @__PURE__ */ jsx(TextInput, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
51
|
+
"aria-label": ariaLabel,
|
|
52
|
+
error: getError({
|
|
53
|
+
label: (_ref2 = label !== null && label !== void 0 ? label : ariaLabel) !== null && _ref2 !== void 0 ? _ref2 : name,
|
|
54
|
+
maxLength,
|
|
55
|
+
minLength,
|
|
56
|
+
regex: regexes,
|
|
57
|
+
value: field.value
|
|
58
|
+
}, error),
|
|
59
|
+
label,
|
|
39
60
|
maxLength,
|
|
40
61
|
minLength,
|
|
62
|
+
name,
|
|
63
|
+
onBlur: (event) => {
|
|
64
|
+
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
65
|
+
field.onBlur();
|
|
66
|
+
},
|
|
67
|
+
onChange: (event) => {
|
|
68
|
+
field.onChange(event);
|
|
69
|
+
onChange === null || onChange === void 0 || onChange(event.target.value);
|
|
70
|
+
},
|
|
41
71
|
required,
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return /* @__PURE__ */ jsx(TextInput, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
47
|
-
"aria-label": ariaLabel,
|
|
48
|
-
error: getError({
|
|
49
|
-
label: (_ref2 = label !== null && label !== void 0 ? label : ariaLabel) !== null && _ref2 !== void 0 ? _ref2 : name,
|
|
50
|
-
maxLength,
|
|
51
|
-
minLength,
|
|
52
|
-
regex: regexes,
|
|
53
|
-
value: field.value
|
|
54
|
-
}, error),
|
|
55
|
-
label,
|
|
56
|
-
maxLength,
|
|
57
|
-
minLength,
|
|
58
|
-
name,
|
|
59
|
-
onBlur: (event) => {
|
|
60
|
-
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
61
|
-
field.onBlur();
|
|
62
|
-
},
|
|
63
|
-
onChange: (event) => {
|
|
64
|
-
field.onChange(event);
|
|
65
|
-
onChange === null || onChange === void 0 || onChange(event.target.value);
|
|
66
|
-
},
|
|
67
|
-
required,
|
|
68
|
-
value: (_field$value = field.value) !== null && _field$value !== void 0 ? _field$value : ""
|
|
69
|
-
}));
|
|
70
|
-
};
|
|
72
|
+
value: (_field$value = field.value) !== null && _field$value !== void 0 ? _field$value : ""
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
75
|
+
});
|
|
71
76
|
|
|
72
77
|
//#endregion
|
|
73
|
-
|
|
78
|
+
init_TextInputField();
|
|
79
|
+
export { TextInputField, init_TextInputField };
|
|
@@ -1,56 +1,60 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
-
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import { __esmMin, __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
+
import { _objectWithoutProperties, init_objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.js";
|
|
4
|
+
import { _objectSpread2, init_objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.js";
|
|
5
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
|
+
import { init_providers } from "../../providers/index.js";
|
|
6
7
|
import { TimeInput } from "@ultraviolet/ui";
|
|
7
8
|
import { useController } from "react-hook-form";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
|
|
10
11
|
//#region src/components/TimeInputField/index.tsx
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
12
|
+
var _excluded, TimeInputField;
|
|
13
|
+
var init_TimeInputField = __esmMin(() => {
|
|
14
|
+
init_providers();
|
|
15
|
+
init_objectWithoutProperties();
|
|
16
|
+
init_objectSpread2();
|
|
17
|
+
_excluded = [
|
|
18
|
+
"onChange",
|
|
19
|
+
"label",
|
|
20
|
+
"required",
|
|
21
|
+
"name",
|
|
22
|
+
"onBlur",
|
|
23
|
+
"aria-label",
|
|
24
|
+
"shouldUnregister",
|
|
25
|
+
"control"
|
|
26
|
+
];
|
|
27
|
+
TimeInputField = (_ref) => {
|
|
28
|
+
var _ref2;
|
|
29
|
+
let { onChange, label, required = false, name, onBlur, "aria-label": ariaLabel, shouldUnregister, control } = _ref;
|
|
30
|
+
let props = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
+
const { getError } = useErrors();
|
|
32
|
+
const { field, fieldState: { error } } = useController({
|
|
33
|
+
control,
|
|
34
|
+
name,
|
|
35
|
+
rules: { required },
|
|
36
|
+
shouldUnregister
|
|
37
|
+
});
|
|
38
|
+
return /* @__PURE__ */ jsx(TimeInput, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
39
|
+
error: getError({
|
|
40
|
+
label: (_ref2 = label !== null && label !== void 0 ? label : ariaLabel) !== null && _ref2 !== void 0 ? _ref2 : name,
|
|
41
|
+
value: field.value
|
|
42
|
+
}, error),
|
|
43
|
+
label,
|
|
44
|
+
onBlur: (event) => {
|
|
45
|
+
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
46
|
+
field.onBlur();
|
|
47
|
+
},
|
|
48
|
+
onChange: (value) => {
|
|
49
|
+
field.onChange(value);
|
|
50
|
+
onChange === null || onChange === void 0 || onChange(value);
|
|
51
|
+
},
|
|
52
|
+
required,
|
|
39
53
|
value: field.value
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
44
|
-
field.onBlur();
|
|
45
|
-
},
|
|
46
|
-
onChange: (value) => {
|
|
47
|
-
field.onChange(value);
|
|
48
|
-
onChange === null || onChange === void 0 || onChange(value);
|
|
49
|
-
},
|
|
50
|
-
required,
|
|
51
|
-
value: field.value
|
|
52
|
-
}));
|
|
53
|
-
};
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
56
|
+
});
|
|
54
57
|
|
|
55
58
|
//#endregion
|
|
56
|
-
|
|
59
|
+
init_TimeInputField();
|
|
60
|
+
export { TimeInputField, init_TimeInputField };
|
|
@@ -1,65 +1,73 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
-
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import { __esmMin, __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
+
import { _objectWithoutProperties, init_objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.js";
|
|
4
|
+
import { _objectSpread2, init_objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.js";
|
|
5
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
|
+
import { init_providers } from "../../providers/index.js";
|
|
6
7
|
import { Toggle } from "@ultraviolet/ui";
|
|
7
8
|
import { useController } from "react-hook-form";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
|
|
10
11
|
//#region src/components/ToggleField/index.tsx
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
12
|
+
var _excluded, ToggleField;
|
|
13
|
+
var init_ToggleField = __esmMin(() => {
|
|
14
|
+
init_providers();
|
|
15
|
+
init_objectWithoutProperties();
|
|
16
|
+
init_objectSpread2();
|
|
17
|
+
_excluded = [
|
|
18
|
+
"label",
|
|
19
|
+
"name",
|
|
20
|
+
"control",
|
|
21
|
+
"onChange",
|
|
22
|
+
"onBlur",
|
|
23
|
+
"onFocus",
|
|
24
|
+
"required",
|
|
25
|
+
"parse",
|
|
26
|
+
"format",
|
|
27
|
+
"shouldUnregister",
|
|
28
|
+
"validate",
|
|
29
|
+
"aria-label"
|
|
30
|
+
];
|
|
31
|
+
ToggleField = (_ref) => {
|
|
32
|
+
let { label, name, control, onChange, onBlur, onFocus, required, parse, format, shouldUnregister = false, validate, "aria-label": ariaLabel } = _ref;
|
|
33
|
+
let props = _objectWithoutProperties(_ref, _excluded);
|
|
34
|
+
const { field, fieldState: { error } } = useController({
|
|
35
|
+
control,
|
|
36
|
+
name,
|
|
37
|
+
rules: {
|
|
38
|
+
required,
|
|
39
|
+
validate
|
|
40
|
+
},
|
|
41
|
+
shouldUnregister
|
|
42
|
+
});
|
|
43
|
+
const { getError } = useErrors();
|
|
44
|
+
const transformedValue = () => {
|
|
45
|
+
if (format) return format(field.value);
|
|
46
|
+
return field.value;
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ jsx(Toggle, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
49
|
+
checked: transformedValue(),
|
|
50
|
+
error: getError({ label: typeof label === "string" ? label : ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : name }, error),
|
|
51
|
+
label,
|
|
52
|
+
name: field.name,
|
|
53
|
+
onBlur: (event) => {
|
|
54
|
+
field.onBlur();
|
|
55
|
+
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
56
|
+
},
|
|
57
|
+
onChange: (event) => {
|
|
58
|
+
if (parse) field.onChange(parse(event.target.checked));
|
|
59
|
+
else field.onChange(event);
|
|
60
|
+
onChange === null || onChange === void 0 || onChange(event.target.checked);
|
|
61
|
+
},
|
|
62
|
+
onFocus: (event) => {
|
|
63
|
+
onFocus === null || onFocus === void 0 || onFocus(event);
|
|
64
|
+
},
|
|
65
|
+
ref: field.ref,
|
|
66
|
+
required
|
|
67
|
+
}));
|
|
41
68
|
};
|
|
42
|
-
|
|
43
|
-
checked: transformedValue(),
|
|
44
|
-
error: getError({ label: typeof label === "string" ? label : ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : name }, error),
|
|
45
|
-
label,
|
|
46
|
-
name: field.name,
|
|
47
|
-
onBlur: (event) => {
|
|
48
|
-
field.onBlur();
|
|
49
|
-
onBlur === null || onBlur === void 0 || onBlur(event);
|
|
50
|
-
},
|
|
51
|
-
onChange: (event) => {
|
|
52
|
-
if (parse) field.onChange(parse(event.target.checked));
|
|
53
|
-
else field.onChange(event);
|
|
54
|
-
onChange === null || onChange === void 0 || onChange(event.target.checked);
|
|
55
|
-
},
|
|
56
|
-
onFocus: (event) => {
|
|
57
|
-
onFocus === null || onFocus === void 0 || onFocus(event);
|
|
58
|
-
},
|
|
59
|
-
ref: field.ref,
|
|
60
|
-
required
|
|
61
|
-
}));
|
|
62
|
-
};
|
|
69
|
+
});
|
|
63
70
|
|
|
64
71
|
//#endregion
|
|
65
|
-
|
|
72
|
+
init_ToggleField();
|
|
73
|
+
export { ToggleField, init_ToggleField };
|
|
@@ -1,54 +1,62 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
-
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.
|
|
4
|
-
import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import { __esmMin, __name } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
+
import { _objectWithoutProperties, init_objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectWithoutProperties.js";
|
|
4
|
+
import { _objectSpread2, init_objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.115.0/helpers/objectSpread2.js";
|
|
5
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
|
+
import { init_providers } from "../../providers/index.js";
|
|
6
7
|
import { ToggleGroup } from "@ultraviolet/ui";
|
|
7
8
|
import { useController } from "react-hook-form";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
|
|
10
11
|
//#region src/components/ToggleGroupField/index.tsx
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
name,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
12
|
+
var _excluded, ToggleGroupFieldComponent, ToggleGroupField;
|
|
13
|
+
var init_ToggleGroupField = __esmMin(() => {
|
|
14
|
+
init_providers();
|
|
15
|
+
init_objectWithoutProperties();
|
|
16
|
+
init_objectSpread2();
|
|
17
|
+
_excluded = [
|
|
18
|
+
"legend",
|
|
19
|
+
"control",
|
|
20
|
+
"onChange",
|
|
21
|
+
"error",
|
|
22
|
+
"name",
|
|
23
|
+
"required",
|
|
24
|
+
"shouldUnregister",
|
|
25
|
+
"validate"
|
|
26
|
+
];
|
|
27
|
+
ToggleGroupFieldComponent = (_ref) => {
|
|
28
|
+
let { legend = "", control, onChange, error: customError, name, required = false, shouldUnregister = false, validate } = _ref;
|
|
29
|
+
let props = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
const { getError } = useErrors();
|
|
31
|
+
const { field, fieldState: { error } } = useController({
|
|
32
|
+
control,
|
|
33
|
+
name,
|
|
34
|
+
rules: { validate: _objectSpread2(_objectSpread2({}, required ? { required: (value) => value.length > 0 } : void 0), validate) },
|
|
35
|
+
shouldUnregister
|
|
36
|
+
});
|
|
37
|
+
const value = field.value;
|
|
38
|
+
return /* @__PURE__ */ jsx(ToggleGroup, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
39
|
+
error: customError !== null && customError !== void 0 ? customError : getError({ label: legend }, error),
|
|
40
|
+
legend,
|
|
41
|
+
name: field.name,
|
|
42
|
+
onChange: (event) => {
|
|
43
|
+
if (value.includes(event.currentTarget.value)) {
|
|
44
|
+
const newValue = value.filter((currentValue) => currentValue !== event.currentTarget.value);
|
|
45
|
+
field.onChange(newValue);
|
|
46
|
+
onChange === null || onChange === void 0 || onChange(newValue);
|
|
47
|
+
} else {
|
|
48
|
+
const newValue = [...value, event.currentTarget.value];
|
|
49
|
+
field.onChange(newValue);
|
|
50
|
+
onChange === null || onChange === void 0 || onChange(newValue);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
required,
|
|
54
|
+
value
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
ToggleGroupField = Object.assign(ToggleGroupFieldComponent, { Toggle: ToggleGroup.Toggle });
|
|
58
|
+
});
|
|
52
59
|
|
|
53
60
|
//#endregion
|
|
54
|
-
|
|
61
|
+
init_ToggleGroupField();
|
|
62
|
+
export { ToggleGroupField, init_ToggleGroupField };
|