@blockle/blocks-react 1.2.0 → 1.3.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.
- package/dist/components/feedback/Spinner/Spinner.js +1 -0
- package/dist/components/feedback/Spinner/Spinner.test.d.ts +1 -0
- package/dist/components/form/Radio/RadioGroup.test.d.ts +1 -0
- package/dist/components/form/Slider/Slider.d.ts +0 -1
- package/dist/components/form/Slider/Slider.js +2 -3
- package/dist/hooks/useControlledValue/useControlledValue.d.ts +5 -0
- package/dist/hooks/useControlledValue/useControlledValue.js +7 -11
- package/dist/hooks/useControlledValue/useControlledValue.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
|
-
import { classnames,
|
|
3
|
+
import { classnames, clampAndRoundValue } from "@blockle/blocks-core";
|
|
4
4
|
import { useRef, useCallback } from "react";
|
|
5
5
|
import { useComponentStyles } from "../../../hooks/useComponentStyles/useComponentStyles.js";
|
|
6
6
|
import { useControlledValue } from "../../../hooks/useControlledValue/useControlledValue.js";
|
|
@@ -30,7 +30,6 @@ const Slider = ({
|
|
|
30
30
|
size,
|
|
31
31
|
colorScheme,
|
|
32
32
|
disabled,
|
|
33
|
-
precision = 2,
|
|
34
33
|
...restProps
|
|
35
34
|
}) => {
|
|
36
35
|
const baseClass = useComponentStyles("slider", {
|
|
@@ -49,7 +48,7 @@ const Slider = ({
|
|
|
49
48
|
defaultValue,
|
|
50
49
|
value,
|
|
51
50
|
onChange,
|
|
52
|
-
transformValue: (value2) =>
|
|
51
|
+
transformValue: (value2) => clampAndRoundValue(value2, min, max, step)
|
|
53
52
|
});
|
|
54
53
|
usePointerProgress({
|
|
55
54
|
container: containerRef,
|
|
@@ -3,6 +3,11 @@ type ControlledValue<T> = {
|
|
|
3
3
|
defaultValue: T;
|
|
4
4
|
onChange?: (value: T) => void;
|
|
5
5
|
transformValue?: (value: T) => T;
|
|
6
|
+
} | {
|
|
7
|
+
value: T;
|
|
8
|
+
defaultValue?: T;
|
|
9
|
+
onChange: (value: T) => void;
|
|
10
|
+
transformValue?: (value: T) => T;
|
|
6
11
|
};
|
|
7
12
|
export declare function useControlledValue<T>({ defaultValue, value, onChange, transformValue, }: ControlledValue<T>): [T, (value: T) => void];
|
|
8
13
|
export {};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useState, useCallback
|
|
2
|
+
import { useState, useCallback } from "react";
|
|
3
|
+
function noopTransform(value) {
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
3
6
|
function useControlledValue({
|
|
4
7
|
defaultValue,
|
|
5
8
|
value,
|
|
6
9
|
onChange,
|
|
7
|
-
transformValue
|
|
10
|
+
transformValue = noopTransform
|
|
8
11
|
}) {
|
|
9
12
|
const [internValue, setInternValue] = useState(defaultValue);
|
|
10
13
|
const currentValue = (onChange ? value : internValue) ?? defaultValue;
|
|
11
14
|
const setValue = useCallback(
|
|
12
15
|
function setValue2(value2) {
|
|
13
|
-
const nextValue = transformValue
|
|
16
|
+
const nextValue = transformValue(value2);
|
|
14
17
|
if (onChange) {
|
|
15
18
|
onChange(nextValue);
|
|
16
19
|
} else {
|
|
@@ -19,14 +22,7 @@ function useControlledValue({
|
|
|
19
22
|
},
|
|
20
23
|
[onChange, transformValue]
|
|
21
24
|
);
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (onChange && value === void 0) {
|
|
25
|
-
console.error("Slider is in controlled mode but no value is provided");
|
|
26
|
-
}
|
|
27
|
-
}, []);
|
|
28
|
-
}
|
|
29
|
-
return [currentValue, setValue];
|
|
25
|
+
return [transformValue(currentValue), setValue];
|
|
30
26
|
}
|
|
31
27
|
export {
|
|
32
28
|
useControlledValue
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|