@marcoschwartz/lite-ui 0.18.0 → 0.18.1
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/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2944,15 +2944,22 @@ var Slider = ({
|
|
|
2944
2944
|
setInternalValue(newValue);
|
|
2945
2945
|
onChange?.(newValue);
|
|
2946
2946
|
};
|
|
2947
|
-
const
|
|
2947
|
+
const handleRangeStart = (clientX, handle) => {
|
|
2948
2948
|
if (disabled) return;
|
|
2949
|
-
e.preventDefault();
|
|
2950
2949
|
setIsDragging(handle);
|
|
2951
2950
|
};
|
|
2952
|
-
const
|
|
2951
|
+
const handleRangeMouseDown = (e, handle) => {
|
|
2952
|
+
e.preventDefault();
|
|
2953
|
+
handleRangeStart(e.clientX, handle);
|
|
2954
|
+
};
|
|
2955
|
+
const handleRangeTouchStart = (e, handle) => {
|
|
2956
|
+
e.preventDefault();
|
|
2957
|
+
handleRangeStart(e.touches[0].clientX, handle);
|
|
2958
|
+
};
|
|
2959
|
+
const updateRangeValue = (clientX) => {
|
|
2953
2960
|
if (!isDragging || !trackRef.current || disabled) return;
|
|
2954
2961
|
const rect = trackRef.current.getBoundingClientRect();
|
|
2955
|
-
const percentage2 = Math.max(0, Math.min(100, (
|
|
2962
|
+
const percentage2 = Math.max(0, Math.min(100, (clientX - rect.left) / rect.width * 100));
|
|
2956
2963
|
const newValue = Math.round(percentage2 / 100 * (max - min) / step) * step + min;
|
|
2957
2964
|
if (isDragging === "min") {
|
|
2958
2965
|
const newMin = Math.min(newValue, rangeValue[1] - step);
|
|
@@ -2966,16 +2973,28 @@ var Slider = ({
|
|
|
2966
2973
|
onRangeChange?.(newRange);
|
|
2967
2974
|
}
|
|
2968
2975
|
};
|
|
2969
|
-
const
|
|
2976
|
+
const handleRangeMouseMove = (e) => {
|
|
2977
|
+
updateRangeValue(e.clientX);
|
|
2978
|
+
};
|
|
2979
|
+
const handleRangeTouchMove = (e) => {
|
|
2980
|
+
if (e.touches.length > 0) {
|
|
2981
|
+
updateRangeValue(e.touches[0].clientX);
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2984
|
+
const handleRangeEnd = () => {
|
|
2970
2985
|
setIsDragging(null);
|
|
2971
2986
|
};
|
|
2972
2987
|
React18.useEffect(() => {
|
|
2973
2988
|
if (isDragging) {
|
|
2974
2989
|
document.addEventListener("mousemove", handleRangeMouseMove);
|
|
2975
|
-
document.addEventListener("mouseup",
|
|
2990
|
+
document.addEventListener("mouseup", handleRangeEnd);
|
|
2991
|
+
document.addEventListener("touchmove", handleRangeTouchMove);
|
|
2992
|
+
document.addEventListener("touchend", handleRangeEnd);
|
|
2976
2993
|
return () => {
|
|
2977
2994
|
document.removeEventListener("mousemove", handleRangeMouseMove);
|
|
2978
|
-
document.removeEventListener("mouseup",
|
|
2995
|
+
document.removeEventListener("mouseup", handleRangeEnd);
|
|
2996
|
+
document.removeEventListener("touchmove", handleRangeTouchMove);
|
|
2997
|
+
document.removeEventListener("touchend", handleRangeEnd);
|
|
2979
2998
|
};
|
|
2980
2999
|
}
|
|
2981
3000
|
}, [isDragging, rangeValue]);
|
|
@@ -3012,6 +3031,7 @@ var Slider = ({
|
|
|
3012
3031
|
`,
|
|
3013
3032
|
style: { left: `${minPercentage}%` },
|
|
3014
3033
|
onMouseDown: (e) => handleRangeMouseDown(e, "min"),
|
|
3034
|
+
onTouchStart: (e) => handleRangeTouchStart(e, "min"),
|
|
3015
3035
|
role: "slider",
|
|
3016
3036
|
"aria-label": `${label ? label + " " : ""}minimum value`,
|
|
3017
3037
|
"aria-valuemin": min,
|
|
@@ -3028,6 +3048,7 @@ var Slider = ({
|
|
|
3028
3048
|
`,
|
|
3029
3049
|
style: { left: `${maxPercentage}%` },
|
|
3030
3050
|
onMouseDown: (e) => handleRangeMouseDown(e, "max"),
|
|
3051
|
+
onTouchStart: (e) => handleRangeTouchStart(e, "max"),
|
|
3031
3052
|
role: "slider",
|
|
3032
3053
|
"aria-label": `${label ? label + " " : ""}maximum value`,
|
|
3033
3054
|
"aria-valuemin": rangeValue[0],
|