@ultraviolet/form 3.3.1 → 3.4.0
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.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
4
|
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const react = require("react");
|
|
5
6
|
const reactHookForm = require("react-hook-form");
|
|
6
7
|
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
8
|
const SliderField = ({
|
|
@@ -17,6 +18,7 @@ const SliderField = ({
|
|
|
17
18
|
label,
|
|
18
19
|
value,
|
|
19
20
|
defaultValue,
|
|
21
|
+
options,
|
|
20
22
|
...props
|
|
21
23
|
}) => {
|
|
22
24
|
const {
|
|
@@ -38,16 +40,35 @@ const SliderField = ({
|
|
|
38
40
|
validate
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
|
-
|
|
43
|
+
const finalValue = react.useMemo(() => {
|
|
44
|
+
if (options && field.value) {
|
|
45
|
+
if (!Array.isArray(field.value)) {
|
|
46
|
+
const processedValue = options.map((option) => option.value).indexOf(field.value);
|
|
47
|
+
return processedValue;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(field.value)) {
|
|
50
|
+
const processedValue = field.value.map((val) => options.map((option) => option.value).indexOf(val));
|
|
51
|
+
return processedValue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return field.value;
|
|
55
|
+
}, [field.value, options]);
|
|
56
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Slider, { name: field.name, value: finalValue, onBlur: (event) => {
|
|
42
57
|
field.onBlur();
|
|
43
58
|
onBlur?.(event);
|
|
44
59
|
}, onChange: (newValue) => {
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
if (options) {
|
|
61
|
+
const processedValue = !Array.isArray(newValue) ? options[newValue].value : newValue.map((val) => val ? options[val].value : options[0].value);
|
|
62
|
+
field.onChange(processedValue);
|
|
63
|
+
onChange?.(processedValue);
|
|
64
|
+
} else {
|
|
65
|
+
field.onChange(newValue);
|
|
66
|
+
onChange?.(newValue);
|
|
67
|
+
}
|
|
47
68
|
}, max, min, error: getError({
|
|
48
69
|
label: label ?? "",
|
|
49
70
|
max,
|
|
50
71
|
min
|
|
51
|
-
}, error), label, required, ...props });
|
|
72
|
+
}, error), label, required, options, ...props });
|
|
52
73
|
};
|
|
53
74
|
exports.SliderField = SliderField;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Slider } from '@ultraviolet/ui';
|
|
2
|
-
import type
|
|
2
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
3
3
|
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
5
|
type SliderFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof Slider>, 'value' | 'onChange'> & {
|
|
6
6
|
suffix?: string | ReactNode[];
|
|
7
7
|
};
|
|
8
|
-
export declare const SliderField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, control, shouldUnregister, max, min, required, validate, onBlur, onChange, label, value, defaultValue, ...props }: SliderFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const SliderField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, control, shouldUnregister, max, min, required, validate, onBlur, onChange, label, value, defaultValue, options, ...props }: SliderFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
9
9
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { Slider } from "@ultraviolet/ui";
|
|
3
|
+
import { useMemo } from "react";
|
|
3
4
|
import { useController } from "react-hook-form";
|
|
4
5
|
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
5
6
|
const SliderField = ({
|
|
@@ -15,6 +16,7 @@ const SliderField = ({
|
|
|
15
16
|
label,
|
|
16
17
|
value,
|
|
17
18
|
defaultValue,
|
|
19
|
+
options,
|
|
18
20
|
...props
|
|
19
21
|
}) => {
|
|
20
22
|
const {
|
|
@@ -36,17 +38,36 @@ const SliderField = ({
|
|
|
36
38
|
validate
|
|
37
39
|
}
|
|
38
40
|
});
|
|
39
|
-
|
|
41
|
+
const finalValue = useMemo(() => {
|
|
42
|
+
if (options && field.value) {
|
|
43
|
+
if (!Array.isArray(field.value)) {
|
|
44
|
+
const processedValue = options.map((option) => option.value).indexOf(field.value);
|
|
45
|
+
return processedValue;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(field.value)) {
|
|
48
|
+
const processedValue = field.value.map((val) => options.map((option) => option.value).indexOf(val));
|
|
49
|
+
return processedValue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return field.value;
|
|
53
|
+
}, [field.value, options]);
|
|
54
|
+
return /* @__PURE__ */ jsx(Slider, { name: field.name, value: finalValue, onBlur: (event) => {
|
|
40
55
|
field.onBlur();
|
|
41
56
|
onBlur?.(event);
|
|
42
57
|
}, onChange: (newValue) => {
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
if (options) {
|
|
59
|
+
const processedValue = !Array.isArray(newValue) ? options[newValue].value : newValue.map((val) => val ? options[val].value : options[0].value);
|
|
60
|
+
field.onChange(processedValue);
|
|
61
|
+
onChange?.(processedValue);
|
|
62
|
+
} else {
|
|
63
|
+
field.onChange(newValue);
|
|
64
|
+
onChange?.(newValue);
|
|
65
|
+
}
|
|
45
66
|
}, max, min, error: getError({
|
|
46
67
|
label: label ?? "",
|
|
47
68
|
max,
|
|
48
69
|
min
|
|
49
|
-
}, error), label, required, ...props });
|
|
70
|
+
}, error), label, required, options, ...props });
|
|
50
71
|
};
|
|
51
72
|
export {
|
|
52
73
|
SliderField
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@emotion/styled": "11.11.5",
|
|
73
73
|
"react-select": "5.8.0",
|
|
74
74
|
"react-hook-form": "7.52.1",
|
|
75
|
-
"@ultraviolet/ui": "1.
|
|
75
|
+
"@ultraviolet/ui": "1.63.0",
|
|
76
76
|
"@ultraviolet/themes": "1.12.2"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|