react-modal-sheet 4.2.0 → 4.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/src/types.tsx CHANGED
@@ -85,6 +85,7 @@ export type SheetBackdropProps = Omit<
85
85
 
86
86
  export type SheetScrollerProps = HTMLAttributes<HTMLDivElement> & {
87
87
  draggableAt?: 'top' | 'bottom' | 'both';
88
+ disableScroll?: boolean;
88
89
  };
89
90
 
90
91
  export interface SheetDragProps {
package/src/utils.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type ForwardedRef, type RefCallback, type RefObject } from 'react';
2
2
  import { IS_SSR } from './constants';
3
+ import type { SheetDetent } from './types';
3
4
 
4
5
  /**
5
6
  * Get the rounded height of the sheet element and log a warning if the
@@ -45,6 +46,39 @@ export function getSnapPoints({
45
46
  return snapPointValues;
46
47
  }
47
48
 
49
+ export function getClosestSnapPoint({
50
+ snapPoints,
51
+ currentY,
52
+ sheetHeight,
53
+ detent,
54
+ }: {
55
+ snapPoints: number[];
56
+ currentY: number;
57
+ sheetHeight: number;
58
+ detent?: SheetDetent;
59
+ }) {
60
+ // Inverse values are the values that can be passed to `animate`
61
+ const snapInverse = snapPoints.map(
62
+ (p) => sheetHeight - Math.min(p, sheetHeight)
63
+ );
64
+
65
+ // Allow snapping to the top of the sheet if detent is set to `content-height`
66
+ if (detent === 'content-height' && !snapInverse.includes(0)) {
67
+ snapInverse.unshift(0);
68
+ }
69
+
70
+ // Get the closest snap point
71
+ const snapTo = getClosest(snapInverse, currentY);
72
+ const snapIndex = snapInverse.indexOf(snapTo);
73
+
74
+ const snapY = validateSnapTo({
75
+ snapTo: getClosest(snapInverse, currentY),
76
+ sheetHeight,
77
+ });
78
+
79
+ return { snapY, snapIndex };
80
+ }
81
+
48
82
  /**
49
83
  * Get the closest number to the goal from the array of numbers.
50
84
  */