react-modal-sheet 5.1.0 → 5.1.2
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/README.md +38 -0
- package/dist/index.d.mts +7 -9
- package/dist/index.d.ts +7 -9
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/SheetBackdrop.tsx +1 -1
- package/src/index.tsx +2 -0
- package/src/sheet.tsx +10 -3
- package/src/snap.ts +17 -1
- package/src/types.tsx +7 -8
- package/src/utils.ts +21 -0
package/src/snap.ts
CHANGED
|
@@ -43,8 +43,24 @@ export function computeSnapPoints({
|
|
|
43
43
|
snapPointsProp: number[];
|
|
44
44
|
sheetHeight: number;
|
|
45
45
|
}): SheetSnapPoint[] {
|
|
46
|
+
if (snapPointsProp[0] !== 0) {
|
|
47
|
+
console.error(
|
|
48
|
+
'First snap point should be 0 to ensure the sheet can be fully closed. ' +
|
|
49
|
+
`Got: [${snapPointsProp.join(', ')}]`
|
|
50
|
+
);
|
|
51
|
+
snapPointsProp.unshift(0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (snapPointsProp[snapPointsProp.length - 1] !== 1) {
|
|
55
|
+
console.error(
|
|
56
|
+
'Last snap point should be 1 to ensure the sheet can be fully opened. ' +
|
|
57
|
+
`Got: [${snapPointsProp.join(', ')}]`
|
|
58
|
+
);
|
|
59
|
+
snapPointsProp.push(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
if (sheetHeight <= 0) {
|
|
47
|
-
console.
|
|
63
|
+
console.error(
|
|
48
64
|
`Sheet height is ${sheetHeight}, cannot compute snap points. ` +
|
|
49
65
|
'Make sure the sheet is mounted and has a valid height.'
|
|
50
66
|
);
|
package/src/types.tsx
CHANGED
|
@@ -21,14 +21,13 @@ export type SheetDetent = 'default' | 'full' | 'content';
|
|
|
21
21
|
|
|
22
22
|
type CommonProps = {
|
|
23
23
|
className?: string;
|
|
24
|
-
style?: CSSProperties;
|
|
25
24
|
unstyled?: boolean;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
type MotionCommonProps = Omit<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
type MotionCommonProps = Omit<
|
|
28
|
+
ComponentPropsWithoutRef<typeof motion.div>,
|
|
29
|
+
'initial' | 'animate' | 'exit'
|
|
30
|
+
>;
|
|
32
31
|
|
|
33
32
|
export interface SheetTweenConfig {
|
|
34
33
|
ease: EasingDefinition;
|
|
@@ -59,20 +58,20 @@ export type SheetProps = {
|
|
|
59
58
|
onOpenEnd?: () => void;
|
|
60
59
|
onOpenStart?: () => void;
|
|
61
60
|
onSnap?: (index: number) => void;
|
|
62
|
-
} &
|
|
61
|
+
} & MotionCommonProps;
|
|
63
62
|
|
|
64
63
|
export type SheetContainerProps = MotionCommonProps &
|
|
65
64
|
CommonProps & {
|
|
66
65
|
children: ReactNode;
|
|
67
66
|
};
|
|
68
67
|
|
|
69
|
-
export type SheetHeaderProps =
|
|
68
|
+
export type SheetHeaderProps = MotionCommonProps &
|
|
70
69
|
CommonProps & {
|
|
71
70
|
children?: ReactNode;
|
|
72
71
|
disableDrag?: boolean;
|
|
73
72
|
};
|
|
74
73
|
|
|
75
|
-
export type SheetContentProps =
|
|
74
|
+
export type SheetContentProps = MotionCommonProps &
|
|
76
75
|
CommonProps & {
|
|
77
76
|
disableDrag?: boolean | ((args: SheetStateInfo) => boolean);
|
|
78
77
|
disableScroll?: boolean | ((args: SheetStateInfo) => boolean);
|
package/src/utils.ts
CHANGED
|
@@ -67,3 +67,24 @@ const isIPad = cached(function () {
|
|
|
67
67
|
export const isIOS = cached(function () {
|
|
68
68
|
return isIPhone() || isIPad();
|
|
69
69
|
});
|
|
70
|
+
|
|
71
|
+
/** Wait for an element to be rendered and visible */
|
|
72
|
+
export function waitForElement(
|
|
73
|
+
className: string,
|
|
74
|
+
interval = 50,
|
|
75
|
+
maxAttempts = 20
|
|
76
|
+
) {
|
|
77
|
+
return new Promise<HTMLElement | null>((resolve) => {
|
|
78
|
+
let attempts = 0;
|
|
79
|
+
const timer = setInterval(() => {
|
|
80
|
+
const element = document.getElementsByClassName(
|
|
81
|
+
className
|
|
82
|
+
)[0] as HTMLElement;
|
|
83
|
+
attempts++;
|
|
84
|
+
if (element || attempts >= maxAttempts) {
|
|
85
|
+
clearInterval(timer);
|
|
86
|
+
resolve(element);
|
|
87
|
+
}
|
|
88
|
+
}, interval);
|
|
89
|
+
});
|
|
90
|
+
}
|