@gfazioli/mantine-picker 1.0.2 → 1.0.3
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/cjs/Picker.cjs +53 -23
- package/dist/cjs/Picker.cjs.map +1 -1
- package/dist/esm/Picker.mjs +53 -23
- package/dist/esm/Picker.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cjs/Picker.cjs
CHANGED
|
@@ -230,18 +230,18 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
230
230
|
if (wrapPath < directPath) {
|
|
231
231
|
if (targetIndex > currentDataIndex) {
|
|
232
232
|
return currentRoundedPos - wrapPath;
|
|
233
|
-
} else {
|
|
234
|
-
return currentRoundedPos + wrapPath;
|
|
235
233
|
}
|
|
234
|
+
return currentRoundedPos + wrapPath;
|
|
236
235
|
}
|
|
237
236
|
if (targetIndex > currentDataIndex) {
|
|
238
237
|
return currentRoundedPos + directPath;
|
|
239
|
-
} else {
|
|
240
|
-
return currentRoundedPos - directPath;
|
|
241
238
|
}
|
|
239
|
+
return currentRoundedPos - directPath;
|
|
242
240
|
};
|
|
243
241
|
const animateToPosition = (targetPosition) => {
|
|
244
|
-
if (targetPosition === currentPosition || isAnimating)
|
|
242
|
+
if (targetPosition === currentPosition || isAnimating) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
245
|
let clampedTargetPosition = targetPosition;
|
|
246
246
|
if (!loop) {
|
|
247
247
|
clampedTargetPosition = Math.max(0, Math.min(data.length - 1, targetPosition));
|
|
@@ -284,7 +284,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
284
284
|
animationRef.current = requestAnimationFrame(animate2);
|
|
285
285
|
};
|
|
286
286
|
const applyMomentum = () => {
|
|
287
|
-
if (velocity === 0 || disabled)
|
|
287
|
+
if (velocity === 0 || disabled) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
288
290
|
setIsMomentumScrolling(true);
|
|
289
291
|
let currentVelocity = velocity * (momentum || 0.95);
|
|
290
292
|
let currentPos = currentPosition;
|
|
@@ -302,8 +304,12 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
302
304
|
newPos = maxPos - (newPos - maxPos) * 0.2;
|
|
303
305
|
currentVelocity *= -0.5;
|
|
304
306
|
}
|
|
305
|
-
if (Math.abs(newPos - minPos) < 0.1)
|
|
306
|
-
|
|
307
|
+
if (Math.abs(newPos - minPos) < 0.1) {
|
|
308
|
+
newPos = minPos;
|
|
309
|
+
}
|
|
310
|
+
if (Math.abs(newPos - maxPos) < 0.1) {
|
|
311
|
+
newPos = maxPos;
|
|
312
|
+
}
|
|
307
313
|
if (newPos === minPos || newPos === maxPos) {
|
|
308
314
|
currentVelocity *= 0.7;
|
|
309
315
|
}
|
|
@@ -369,7 +375,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
369
375
|
const halfVisible = Math.floor((visibleItems || 5) / 2);
|
|
370
376
|
const handleMouseDown = (e) => {
|
|
371
377
|
const isInteractionDisabled = disabled || readOnly;
|
|
372
|
-
if (isAnimating || isInteractionDisabled || isMomentumScrolling)
|
|
378
|
+
if (isAnimating || isInteractionDisabled || isMomentumScrolling) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
373
381
|
if (momentumAnimationRef.current !== null) {
|
|
374
382
|
cancelAnimationFrame(momentumAnimationRef.current);
|
|
375
383
|
setIsMomentumScrolling(false);
|
|
@@ -384,7 +392,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
384
392
|
};
|
|
385
393
|
const handleTouchStart = (e) => {
|
|
386
394
|
const isInteractionDisabled = disabled || readOnly;
|
|
387
|
-
if (isAnimating || isInteractionDisabled || isMomentumScrolling)
|
|
395
|
+
if (isAnimating || isInteractionDisabled || isMomentumScrolling) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
388
398
|
if (momentumAnimationRef.current !== null) {
|
|
389
399
|
cancelAnimationFrame(momentumAnimationRef.current);
|
|
390
400
|
setIsMomentumScrolling(false);
|
|
@@ -397,7 +407,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
397
407
|
lastMovePosition.current = currentPosition;
|
|
398
408
|
};
|
|
399
409
|
const clampPosition = (position) => {
|
|
400
|
-
if (loop)
|
|
410
|
+
if (loop) {
|
|
411
|
+
return position;
|
|
412
|
+
}
|
|
401
413
|
if (position < 0) {
|
|
402
414
|
return position * 0.3;
|
|
403
415
|
} else if (position > data.length - 1) {
|
|
@@ -407,7 +419,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
407
419
|
};
|
|
408
420
|
const handleMouseMove = (e) => {
|
|
409
421
|
const isInteractionDisabled = disabled || readOnly;
|
|
410
|
-
if (!isDragging || isInteractionDisabled)
|
|
422
|
+
if (!isDragging || isInteractionDisabled) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
411
425
|
const currentTime = performance.now();
|
|
412
426
|
const newY = e.clientY;
|
|
413
427
|
const deltaY = newY - lastY;
|
|
@@ -428,7 +442,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
428
442
|
};
|
|
429
443
|
const handleTouchMove = (e) => {
|
|
430
444
|
const isInteractionDisabled = disabled || readOnly;
|
|
431
|
-
if (!isDragging || isInteractionDisabled)
|
|
445
|
+
if (!isDragging || isInteractionDisabled) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
432
448
|
const currentTime = performance.now();
|
|
433
449
|
const newY = e.touches[0].clientY;
|
|
434
450
|
const deltaY = newY - lastY;
|
|
@@ -449,7 +465,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
449
465
|
};
|
|
450
466
|
const handleMouseUp = () => {
|
|
451
467
|
const isInteractionDisabled = disabled || readOnly;
|
|
452
|
-
if (!isDragging || isInteractionDisabled)
|
|
468
|
+
if (!isDragging || isInteractionDisabled) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
453
471
|
setIsDragging(false);
|
|
454
472
|
setDragOffset(0);
|
|
455
473
|
if (Math.abs(velocity) > 0.05) {
|
|
@@ -473,7 +491,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
473
491
|
};
|
|
474
492
|
const handleTouchEnd = () => {
|
|
475
493
|
const isInteractionDisabled = disabled || readOnly;
|
|
476
|
-
if (!isDragging || isInteractionDisabled)
|
|
494
|
+
if (!isDragging || isInteractionDisabled) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
477
497
|
setIsDragging(false);
|
|
478
498
|
setDragOffset(0);
|
|
479
499
|
if (Math.abs(velocity) > 0.05) {
|
|
@@ -516,7 +536,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
516
536
|
const handleWheel = React.useCallback(
|
|
517
537
|
(e) => {
|
|
518
538
|
const isInteractionDisabled = disabled || readOnly;
|
|
519
|
-
if (isAnimating || isInteractionDisabled || isMomentumScrolling)
|
|
539
|
+
if (isAnimating || isInteractionDisabled || isMomentumScrolling) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
520
542
|
if (momentumAnimationRef.current !== null) {
|
|
521
543
|
cancelAnimationFrame(momentumAnimationRef.current);
|
|
522
544
|
setIsMomentumScrolling(false);
|
|
@@ -529,7 +551,7 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
529
551
|
let newPosition = prev + delta / (itemHeight || 40) * 0.05;
|
|
530
552
|
if (!loop) {
|
|
531
553
|
if (newPosition < 0) {
|
|
532
|
-
newPosition
|
|
554
|
+
newPosition *= 0.3;
|
|
533
555
|
} else if (newPosition > data.length - 1) {
|
|
534
556
|
newPosition = data.length - 1 + (newPosition - (data.length - 1)) * 0.3;
|
|
535
557
|
}
|
|
@@ -599,13 +621,15 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
599
621
|
const handleKeyDown = React.useCallback(
|
|
600
622
|
(e) => {
|
|
601
623
|
const isInteractionDisabled = disabled || readOnly;
|
|
602
|
-
if (isInteractionDisabled)
|
|
624
|
+
if (isInteractionDisabled) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
603
627
|
if (momentumAnimationRef.current !== null) {
|
|
604
628
|
cancelAnimationFrame(momentumAnimationRef.current);
|
|
605
629
|
setIsMomentumScrolling(false);
|
|
606
630
|
}
|
|
607
631
|
switch (e.key) {
|
|
608
|
-
case "ArrowUp":
|
|
632
|
+
case "ArrowUp": {
|
|
609
633
|
e.preventDefault();
|
|
610
634
|
let prevPosition = Math.round(currentPosition) - 1;
|
|
611
635
|
if (!loop) {
|
|
@@ -613,7 +637,8 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
613
637
|
}
|
|
614
638
|
animateToPosition(prevPosition);
|
|
615
639
|
break;
|
|
616
|
-
|
|
640
|
+
}
|
|
641
|
+
case "ArrowDown": {
|
|
617
642
|
e.preventDefault();
|
|
618
643
|
let nextPosition = Math.round(currentPosition) + 1;
|
|
619
644
|
if (!loop) {
|
|
@@ -621,6 +646,7 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
621
646
|
}
|
|
622
647
|
animateToPosition(nextPosition);
|
|
623
648
|
break;
|
|
649
|
+
}
|
|
624
650
|
case "Home":
|
|
625
651
|
e.preventDefault();
|
|
626
652
|
animateToPosition(0);
|
|
@@ -629,7 +655,7 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
629
655
|
e.preventDefault();
|
|
630
656
|
animateToPosition(data.length - 1);
|
|
631
657
|
break;
|
|
632
|
-
case "PageUp":
|
|
658
|
+
case "PageUp": {
|
|
633
659
|
e.preventDefault();
|
|
634
660
|
let pageUpPosition = Math.round(currentPosition) - 5;
|
|
635
661
|
if (loop) {
|
|
@@ -639,7 +665,8 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
639
665
|
}
|
|
640
666
|
animateToPosition(pageUpPosition);
|
|
641
667
|
break;
|
|
642
|
-
|
|
668
|
+
}
|
|
669
|
+
case "PageDown": {
|
|
643
670
|
e.preventDefault();
|
|
644
671
|
let pageDownPosition = Math.round(currentPosition) + 5;
|
|
645
672
|
if (loop) {
|
|
@@ -649,6 +676,7 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
649
676
|
}
|
|
650
677
|
animateToPosition(pageDownPosition);
|
|
651
678
|
break;
|
|
679
|
+
}
|
|
652
680
|
}
|
|
653
681
|
},
|
|
654
682
|
[currentPosition, data.length, loop, disabled, readOnly, isMomentumScrolling]
|
|
@@ -663,7 +691,9 @@ const Picker = core.polymorphicFactory((_props, ref) => {
|
|
|
663
691
|
};
|
|
664
692
|
const handleItemClick = (clickedIndex, virtualIndex) => {
|
|
665
693
|
const isInteractionDisabled = disabled || readOnly;
|
|
666
|
-
if (isDragging || isAnimating || isInteractionDisabled || isMomentumScrolling)
|
|
694
|
+
if (isDragging || isAnimating || isInteractionDisabled || isMomentumScrolling) {
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
667
697
|
if (momentumAnimationRef.current !== null) {
|
|
668
698
|
cancelAnimationFrame(momentumAnimationRef.current);
|
|
669
699
|
setIsMomentumScrolling(false);
|