@ultraviolet/form 6.0.0-beta.11 → 6.0.0-beta.13
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.
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const ui = require("@ultraviolet/ui");
|
|
6
|
+
const reactHookForm = require("react-hook-form");
|
|
7
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
8
|
+
const ToggleGroupField = ({
|
|
9
|
+
legend = "",
|
|
10
|
+
control,
|
|
11
|
+
onChange,
|
|
12
|
+
error: customError,
|
|
13
|
+
name,
|
|
14
|
+
required = false,
|
|
15
|
+
shouldUnregister = false,
|
|
16
|
+
validate,
|
|
17
|
+
...props
|
|
18
|
+
}) => {
|
|
19
|
+
const {
|
|
20
|
+
getError
|
|
21
|
+
} = index.useErrors();
|
|
22
|
+
const {
|
|
23
|
+
field,
|
|
24
|
+
fieldState: {
|
|
25
|
+
error
|
|
26
|
+
}
|
|
27
|
+
} = reactHookForm.useController({
|
|
28
|
+
control,
|
|
29
|
+
name,
|
|
30
|
+
rules: {
|
|
31
|
+
validate: {
|
|
32
|
+
...required ? {
|
|
33
|
+
required: (value2) => value2.length > 0
|
|
34
|
+
} : void 0,
|
|
35
|
+
...validate
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
shouldUnregister
|
|
39
|
+
});
|
|
40
|
+
const value = field.value;
|
|
41
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.ToggleGroup, { ...props, error: customError ?? getError({
|
|
42
|
+
label: legend
|
|
43
|
+
}, error), legend, name: field.name, onChange: (event) => {
|
|
44
|
+
if (value.includes(event.currentTarget.value)) {
|
|
45
|
+
const newValue = value.filter((currentValue) => currentValue !== event.currentTarget.value);
|
|
46
|
+
field.onChange(newValue);
|
|
47
|
+
onChange?.(newValue);
|
|
48
|
+
} else {
|
|
49
|
+
const newValue = [...value, event.currentTarget.value];
|
|
50
|
+
field.onChange(newValue);
|
|
51
|
+
onChange?.(newValue);
|
|
52
|
+
}
|
|
53
|
+
}, required, value });
|
|
54
|
+
};
|
|
55
|
+
ToggleGroupField.Toggle = ui.ToggleGroup.Toggle;
|
|
56
|
+
exports.ToggleGroupField = ToggleGroupField;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
3
|
+
import { ToggleGroup } from "@ultraviolet/ui";
|
|
4
|
+
import { useController } from "react-hook-form";
|
|
5
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
6
|
+
const ToggleGroupField = ({
|
|
7
|
+
legend = "",
|
|
8
|
+
control,
|
|
9
|
+
onChange,
|
|
10
|
+
error: customError,
|
|
11
|
+
name,
|
|
12
|
+
required = false,
|
|
13
|
+
shouldUnregister = false,
|
|
14
|
+
validate,
|
|
15
|
+
...props
|
|
16
|
+
}) => {
|
|
17
|
+
const {
|
|
18
|
+
getError
|
|
19
|
+
} = useErrors();
|
|
20
|
+
const {
|
|
21
|
+
field,
|
|
22
|
+
fieldState: {
|
|
23
|
+
error
|
|
24
|
+
}
|
|
25
|
+
} = useController({
|
|
26
|
+
control,
|
|
27
|
+
name,
|
|
28
|
+
rules: {
|
|
29
|
+
validate: {
|
|
30
|
+
...required ? {
|
|
31
|
+
required: (value2) => value2.length > 0
|
|
32
|
+
} : void 0,
|
|
33
|
+
...validate
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
shouldUnregister
|
|
37
|
+
});
|
|
38
|
+
const value = field.value;
|
|
39
|
+
return /* @__PURE__ */ jsx(ToggleGroup, { ...props, error: customError ?? getError({
|
|
40
|
+
label: legend
|
|
41
|
+
}, error), legend, name: field.name, onChange: (event) => {
|
|
42
|
+
if (value.includes(event.currentTarget.value)) {
|
|
43
|
+
const newValue = value.filter((currentValue) => currentValue !== event.currentTarget.value);
|
|
44
|
+
field.onChange(newValue);
|
|
45
|
+
onChange?.(newValue);
|
|
46
|
+
} else {
|
|
47
|
+
const newValue = [...value, event.currentTarget.value];
|
|
48
|
+
field.onChange(newValue);
|
|
49
|
+
onChange?.(newValue);
|
|
50
|
+
}
|
|
51
|
+
}, required, value });
|
|
52
|
+
};
|
|
53
|
+
ToggleGroupField.Toggle = ToggleGroup.Toggle;
|
|
54
|
+
export {
|
|
55
|
+
ToggleGroupField
|
|
56
|
+
};
|
|
@@ -19,5 +19,6 @@ export { TextAreaField } from './TextAreaField';
|
|
|
19
19
|
export { TextInputField } from './TextInputField';
|
|
20
20
|
export { TimeInputField } from './TimeInputField';
|
|
21
21
|
export { ToggleField } from './ToggleField';
|
|
22
|
+
export { ToggleGroupField } from './ToggleGroupField';
|
|
22
23
|
export { UnitInputField } from './UnitInputField';
|
|
23
24
|
export { VerificationCodeField } from './VerificationCodeField';
|
package/dist/index.cjs
CHANGED
|
@@ -24,8 +24,9 @@ const index$i = require("./components/TextAreaField/index.cjs");
|
|
|
24
24
|
const index$j = require("./components/TextInputField/index.cjs");
|
|
25
25
|
const index$k = require("./components/TimeInputField/index.cjs");
|
|
26
26
|
const index$l = require("./components/ToggleField/index.cjs");
|
|
27
|
-
const index$m = require("./components/
|
|
28
|
-
const index$n = require("./components/
|
|
27
|
+
const index$m = require("./components/ToggleGroupField/index.cjs");
|
|
28
|
+
const index$n = require("./components/UnitInputField/index.cjs");
|
|
29
|
+
const index$o = require("./components/VerificationCodeField/index.cjs");
|
|
29
30
|
Object.defineProperty(exports, "useController", {
|
|
30
31
|
enumerable: true,
|
|
31
32
|
get: () => reactHookForm.useController
|
|
@@ -74,5 +75,6 @@ exports.TextAreaField = index$i.TextAreaField;
|
|
|
74
75
|
exports.TextInputField = index$j.TextInputField;
|
|
75
76
|
exports.TimeInputField = index$k.TimeInputField;
|
|
76
77
|
exports.ToggleField = index$l.ToggleField;
|
|
77
|
-
exports.
|
|
78
|
-
exports.
|
|
78
|
+
exports.ToggleGroupField = index$m.ToggleGroupField;
|
|
79
|
+
exports.UnitInputField = index$n.UnitInputField;
|
|
80
|
+
exports.VerificationCodeField = index$o.VerificationCodeField;
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { TextAreaField } from "./components/TextAreaField/index.js";
|
|
|
22
22
|
import { TextInputField } from "./components/TextInputField/index.js";
|
|
23
23
|
import { TimeInputField } from "./components/TimeInputField/index.js";
|
|
24
24
|
import { ToggleField } from "./components/ToggleField/index.js";
|
|
25
|
+
import { ToggleGroupField } from "./components/ToggleGroupField/index.js";
|
|
25
26
|
import { UnitInputField } from "./components/UnitInputField/index.js";
|
|
26
27
|
import { VerificationCodeField } from "./components/VerificationCodeField/index.js";
|
|
27
28
|
export {
|
|
@@ -47,6 +48,7 @@ export {
|
|
|
47
48
|
TextInputField,
|
|
48
49
|
TimeInputField,
|
|
49
50
|
ToggleField,
|
|
51
|
+
ToggleGroupField,
|
|
50
52
|
UnitInputField,
|
|
51
53
|
VerificationCodeField,
|
|
52
54
|
useController,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.13",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@emotion/styled": "11.14.1",
|
|
56
56
|
"react": "18.x || 19.x",
|
|
57
57
|
"react-dom": "18.x || 19.x",
|
|
58
|
-
"@ultraviolet/ui": "3.0.0-beta.
|
|
58
|
+
"@ultraviolet/ui": "3.0.0-beta.24"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@babel/core": "7.28.4",
|
|
@@ -66,14 +66,14 @@
|
|
|
66
66
|
"@types/react-dom": "19.2.2",
|
|
67
67
|
"react": "19.2.0",
|
|
68
68
|
"react-dom": "19.2.0",
|
|
69
|
-
"@ultraviolet/ui": "3.0.0-beta.
|
|
69
|
+
"@ultraviolet/ui": "3.0.0-beta.24",
|
|
70
70
|
"@utils/test": "0.0.1"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@babel/runtime": "7.28.4",
|
|
74
74
|
"react-hook-form": "7.55.0",
|
|
75
|
-
"@ultraviolet/icons": "5.0.0-beta.
|
|
76
|
-
"@ultraviolet/themes": "3.0.0-beta.
|
|
75
|
+
"@ultraviolet/icons": "5.0.0-beta.9",
|
|
76
|
+
"@ultraviolet/themes": "3.0.0-beta.3"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
|