@lumx/react 4.20.0-next.5 → 4.20.1-next.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/index.js +48 -3
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -19487,6 +19487,27 @@ const computeValueFromPercent = (percent, min, max, precision = 0) => Number((mi
|
|
|
19487
19487
|
*/
|
|
19488
19488
|
const computePercentFromValue = (value, min, max) => Number((value - min) / (max - min));
|
|
19489
19489
|
|
|
19490
|
+
/**
|
|
19491
|
+
* Type guard checking whether an event is a touch event (native or React synthetic).
|
|
19492
|
+
*
|
|
19493
|
+
* @param event The interaction event.
|
|
19494
|
+
* @return Whether the event is a touch event.
|
|
19495
|
+
*/
|
|
19496
|
+
const isTouchEvent = event => 'touches' in event;
|
|
19497
|
+
|
|
19498
|
+
/**
|
|
19499
|
+
* Read the horizontal page position from either a mouse or touch event.
|
|
19500
|
+
*
|
|
19501
|
+
* @param event The interaction event.
|
|
19502
|
+
* @return The page X position.
|
|
19503
|
+
*/
|
|
19504
|
+
const getPageX = event => {
|
|
19505
|
+
if (isTouchEvent(event)) {
|
|
19506
|
+
return (event.touches[0] ?? event.changedTouches[0]).pageX;
|
|
19507
|
+
}
|
|
19508
|
+
return event.pageX;
|
|
19509
|
+
};
|
|
19510
|
+
|
|
19490
19511
|
/**
|
|
19491
19512
|
* Slider component.
|
|
19492
19513
|
*
|
|
@@ -19571,7 +19592,7 @@ const Slider = forwardRef((props, ref) => {
|
|
|
19571
19592
|
width,
|
|
19572
19593
|
left
|
|
19573
19594
|
} = slider.getBoundingClientRect();
|
|
19574
|
-
let percent = (event
|
|
19595
|
+
let percent = (getPageX(event) - left - window.pageXOffset) / width;
|
|
19575
19596
|
percent = clamp(percent, 0, 1);
|
|
19576
19597
|
if (steps) {
|
|
19577
19598
|
percent = findClosestStep(percent);
|
|
@@ -19580,19 +19601,22 @@ const Slider = forwardRef((props, ref) => {
|
|
|
19580
19601
|
};
|
|
19581
19602
|
|
|
19582
19603
|
/**
|
|
19583
|
-
* Register a handler for the mouse move event.
|
|
19604
|
+
* Register a handler for the mouse/touch move event.
|
|
19584
19605
|
*/
|
|
19585
19606
|
const handleMove = useEventCallback(event => {
|
|
19586
19607
|
const {
|
|
19587
19608
|
current: slider
|
|
19588
19609
|
} = sliderRef;
|
|
19589
19610
|
if (!slider || !onChange) return;
|
|
19611
|
+
if (isTouchEvent(event)) {
|
|
19612
|
+
event.preventDefault();
|
|
19613
|
+
}
|
|
19590
19614
|
const newValue = getPercentValue(event, slider);
|
|
19591
19615
|
onChange(computeValueFromPercent(newValue, min, max, precision), name, event);
|
|
19592
19616
|
});
|
|
19593
19617
|
|
|
19594
19618
|
/**
|
|
19595
|
-
* Register a handler for the mouse up event.
|
|
19619
|
+
* Register a handler for the mouse up/touch end/touch cancel event.
|
|
19596
19620
|
* Clean a all listeners.
|
|
19597
19621
|
*/
|
|
19598
19622
|
const handleEnd = useEventCallback(() => {
|
|
@@ -19600,6 +19624,7 @@ const Slider = forwardRef((props, ref) => {
|
|
|
19600
19624
|
document.body.removeEventListener('mouseup', handleEnd);
|
|
19601
19625
|
document.body.removeEventListener('touchmove', handleMove);
|
|
19602
19626
|
document.body.removeEventListener('touchend', handleEnd);
|
|
19627
|
+
document.body.removeEventListener('touchcancel', handleEnd);
|
|
19603
19628
|
});
|
|
19604
19629
|
|
|
19605
19630
|
/**
|
|
@@ -19645,6 +19670,25 @@ const Slider = forwardRef((props, ref) => {
|
|
|
19645
19670
|
document.body.addEventListener('mousemove', handleMove);
|
|
19646
19671
|
document.body.addEventListener('mouseup', handleEnd);
|
|
19647
19672
|
});
|
|
19673
|
+
|
|
19674
|
+
/**
|
|
19675
|
+
* Register a handler for the touchStart event.
|
|
19676
|
+
*/
|
|
19677
|
+
const handleTouchStart = useEventCallback(event => {
|
|
19678
|
+
const {
|
|
19679
|
+
current: slider
|
|
19680
|
+
} = sliderRef;
|
|
19681
|
+
if (isAnyDisabled || !slider) return;
|
|
19682
|
+
const newValue = getPercentValue(event, slider);
|
|
19683
|
+
if (onChange) {
|
|
19684
|
+
onChange(computeValueFromPercent(newValue, min, max, precision), name, event);
|
|
19685
|
+
}
|
|
19686
|
+
document.body.addEventListener('touchmove', handleMove, {
|
|
19687
|
+
passive: false
|
|
19688
|
+
});
|
|
19689
|
+
document.body.addEventListener('touchend', handleEnd);
|
|
19690
|
+
document.body.addEventListener('touchcancel', handleEnd);
|
|
19691
|
+
});
|
|
19648
19692
|
const percentString = `${computePercentFromValue(value, min, max) * 100}%`;
|
|
19649
19693
|
return /*#__PURE__*/jsxs("div", {
|
|
19650
19694
|
ref: ref,
|
|
@@ -19654,6 +19698,7 @@ const Slider = forwardRef((props, ref) => {
|
|
|
19654
19698
|
'has-label': Boolean(label)
|
|
19655
19699
|
})),
|
|
19656
19700
|
onMouseDown: handleMouseDown,
|
|
19701
|
+
onTouchStart: handleTouchStart,
|
|
19657
19702
|
children: [label && /*#__PURE__*/jsx(InputLabel, {
|
|
19658
19703
|
id: sliderLabelId,
|
|
19659
19704
|
htmlFor: sliderId,
|