react-modal-sheet 4.4.0 → 5.0.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/README.md +244 -191
- package/dist/index.d.mts +39 -31
- package/dist/index.d.ts +39 -31
- package/dist/index.js +856 -670
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +794 -609
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
- package/src/SheetBackdrop.tsx +7 -5
- package/src/SheetContainer.tsx +29 -22
- package/src/SheetContent.tsx +76 -14
- package/src/SheetHeader.tsx +15 -12
- package/src/constants.ts +5 -3
- package/src/context.tsx +2 -42
- package/src/hooks/use-dimensions.ts +4 -4
- package/src/hooks/use-drag-constraints.ts +3 -3
- package/src/hooks/use-modal-effect.ts +19 -23
- package/src/hooks/use-resize-observer.ts +31 -0
- package/src/hooks/use-scroll-position.ts +72 -0
- package/src/hooks/use-sheet-state.ts +63 -0
- package/src/hooks/use-virtual-keyboard.ts +153 -0
- package/src/index.tsx +10 -8
- package/src/sheet.tsx +239 -209
- package/src/snap.ts +226 -0
- package/src/styles.ts +3 -3
- package/src/types.tsx +54 -59
- package/src/utils.ts +2 -150
- package/src/SheetScroller.tsx +0 -96
- package/src/hooks/use-event-callbacks.ts +0 -44
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { EasingDefinition, motion, MotionProps, MotionValue } from 'motion/react';
|
|
2
|
-
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes } from 'react';
|
|
2
|
+
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes, RefObject } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
onOpenStart?: () => void;
|
|
6
|
-
onOpenEnd?: () => void;
|
|
7
|
-
onCloseStart?: () => void;
|
|
8
|
-
onCloseEnd?: () => void;
|
|
9
|
-
onSnap?: (index: number) => void;
|
|
10
|
-
}
|
|
11
|
-
type SheetDetent = 'full-height' | 'content-height';
|
|
4
|
+
type SheetDetent = 'default' | 'full' | 'content';
|
|
12
5
|
type CommonProps = MotionProps & {
|
|
13
6
|
className?: string;
|
|
14
7
|
};
|
|
@@ -18,57 +11,72 @@ interface SheetTweenConfig {
|
|
|
18
11
|
duration: number;
|
|
19
12
|
}
|
|
20
13
|
type SheetProps = {
|
|
21
|
-
|
|
14
|
+
avoidKeyboard?: boolean;
|
|
22
15
|
children: ReactNode;
|
|
23
|
-
onClose: () => void;
|
|
24
|
-
/** @deprecated Use `modalEffectRootId` instead! */
|
|
25
|
-
rootId?: string;
|
|
26
|
-
modalEffectRootId?: string;
|
|
27
|
-
mountPoint?: Element;
|
|
28
|
-
snapPoints?: number[];
|
|
29
16
|
detent?: SheetDetent;
|
|
30
|
-
|
|
31
|
-
tweenConfig?: SheetTweenConfig;
|
|
17
|
+
disableDismiss?: boolean;
|
|
32
18
|
disableDrag?: boolean;
|
|
33
19
|
disableScrollLocking?: boolean;
|
|
34
|
-
prefersReducedMotion?: boolean;
|
|
35
|
-
dragVelocityThreshold?: number;
|
|
36
20
|
dragCloseThreshold?: number;
|
|
21
|
+
dragVelocityThreshold?: number;
|
|
22
|
+
initialSnap?: number;
|
|
23
|
+
isOpen: boolean;
|
|
24
|
+
modalEffectRootId?: string;
|
|
37
25
|
modalEffectThreshold?: number;
|
|
38
|
-
|
|
26
|
+
mountPoint?: Element;
|
|
27
|
+
prefersReducedMotion?: boolean;
|
|
28
|
+
snapPoints?: number[];
|
|
29
|
+
tweenConfig?: SheetTweenConfig;
|
|
30
|
+
onClose: () => void;
|
|
31
|
+
onCloseEnd?: () => void;
|
|
32
|
+
onCloseStart?: () => void;
|
|
33
|
+
onOpenEnd?: () => void;
|
|
34
|
+
onOpenStart?: () => void;
|
|
35
|
+
onSnap?: (index: number) => void;
|
|
36
|
+
} & MotionDivProps;
|
|
39
37
|
type SheetContainerProps = Omit<CommonProps, 'initial' | 'animate' | 'exit' | 'onAnimationComplete'> & {
|
|
40
38
|
children: ReactNode;
|
|
41
39
|
};
|
|
42
|
-
type SheetDraggableProps =
|
|
40
|
+
type SheetDraggableProps = MotionDivProps & {
|
|
43
41
|
children?: ReactNode;
|
|
44
42
|
disableDrag?: boolean;
|
|
45
43
|
};
|
|
46
44
|
type SheetBackdropProps = Omit<CommonProps, 'initial' | 'animate' | 'exit'>;
|
|
47
|
-
type
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
type SheetStateInfo = {
|
|
46
|
+
scrollPosition?: 'top' | 'bottom' | 'middle';
|
|
47
|
+
currentSnap?: number;
|
|
48
|
+
};
|
|
49
|
+
type SheetContentScrollableProps = MotionDivProps & {
|
|
50
|
+
disableDrag?: boolean | ((args: SheetStateInfo) => boolean);
|
|
51
|
+
disableScroll?: boolean | ((args: SheetStateInfo) => boolean);
|
|
52
|
+
scrollRef?: RefObject<HTMLDivElement | null>;
|
|
53
|
+
};
|
|
54
|
+
type SheetSnapPoint = {
|
|
55
|
+
snapIndex: number;
|
|
56
|
+
snapValue: number;
|
|
57
|
+
snapValueY: number;
|
|
51
58
|
};
|
|
52
59
|
type ContainerComponent = ForwardRefExoticComponent<SheetContainerProps & RefAttributes<any>>;
|
|
53
60
|
type DraggableComponent = ForwardRefExoticComponent<SheetDraggableProps & RefAttributes<any>>;
|
|
54
61
|
type BackdropComponent = ForwardRefExoticComponent<SheetBackdropProps & RefAttributes<any>>;
|
|
55
62
|
type SheetComponent = ForwardRefExoticComponent<SheetProps & RefAttributes<any>>;
|
|
56
|
-
type
|
|
63
|
+
type ContentScrollableComponent = ForwardRefExoticComponent<SheetContentScrollableProps & RefAttributes<any>>;
|
|
57
64
|
interface SheetCompoundComponent {
|
|
58
65
|
Container: ContainerComponent;
|
|
59
66
|
Header: DraggableComponent;
|
|
60
|
-
Content:
|
|
67
|
+
Content: ContentScrollableComponent;
|
|
61
68
|
Backdrop: BackdropComponent;
|
|
62
|
-
Scroller: ScrollerComponent;
|
|
63
69
|
}
|
|
64
70
|
type SheetCompound = SheetComponent & SheetCompoundComponent;
|
|
65
71
|
|
|
66
72
|
interface SheetRef {
|
|
67
73
|
y: MotionValue<number>;
|
|
68
|
-
|
|
74
|
+
yInverted: MotionValue<number>;
|
|
75
|
+
height: number;
|
|
76
|
+
snapTo: (index: number) => Promise<void>;
|
|
69
77
|
}
|
|
70
78
|
declare const Sheet: SheetCompound;
|
|
71
79
|
type SheetHeaderProps = SheetDraggableProps;
|
|
72
80
|
type SheetContentProps = SheetDraggableProps;
|
|
73
81
|
|
|
74
|
-
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetHeaderProps, type SheetProps, type SheetRef, type
|
|
82
|
+
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetHeaderProps, type SheetProps, type SheetRef, type SheetSnapPoint, type SheetStateInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { EasingDefinition, motion, MotionProps, MotionValue } from 'motion/react';
|
|
2
|
-
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes } from 'react';
|
|
2
|
+
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes, RefObject } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
onOpenStart?: () => void;
|
|
6
|
-
onOpenEnd?: () => void;
|
|
7
|
-
onCloseStart?: () => void;
|
|
8
|
-
onCloseEnd?: () => void;
|
|
9
|
-
onSnap?: (index: number) => void;
|
|
10
|
-
}
|
|
11
|
-
type SheetDetent = 'full-height' | 'content-height';
|
|
4
|
+
type SheetDetent = 'default' | 'full' | 'content';
|
|
12
5
|
type CommonProps = MotionProps & {
|
|
13
6
|
className?: string;
|
|
14
7
|
};
|
|
@@ -18,57 +11,72 @@ interface SheetTweenConfig {
|
|
|
18
11
|
duration: number;
|
|
19
12
|
}
|
|
20
13
|
type SheetProps = {
|
|
21
|
-
|
|
14
|
+
avoidKeyboard?: boolean;
|
|
22
15
|
children: ReactNode;
|
|
23
|
-
onClose: () => void;
|
|
24
|
-
/** @deprecated Use `modalEffectRootId` instead! */
|
|
25
|
-
rootId?: string;
|
|
26
|
-
modalEffectRootId?: string;
|
|
27
|
-
mountPoint?: Element;
|
|
28
|
-
snapPoints?: number[];
|
|
29
16
|
detent?: SheetDetent;
|
|
30
|
-
|
|
31
|
-
tweenConfig?: SheetTweenConfig;
|
|
17
|
+
disableDismiss?: boolean;
|
|
32
18
|
disableDrag?: boolean;
|
|
33
19
|
disableScrollLocking?: boolean;
|
|
34
|
-
prefersReducedMotion?: boolean;
|
|
35
|
-
dragVelocityThreshold?: number;
|
|
36
20
|
dragCloseThreshold?: number;
|
|
21
|
+
dragVelocityThreshold?: number;
|
|
22
|
+
initialSnap?: number;
|
|
23
|
+
isOpen: boolean;
|
|
24
|
+
modalEffectRootId?: string;
|
|
37
25
|
modalEffectThreshold?: number;
|
|
38
|
-
|
|
26
|
+
mountPoint?: Element;
|
|
27
|
+
prefersReducedMotion?: boolean;
|
|
28
|
+
snapPoints?: number[];
|
|
29
|
+
tweenConfig?: SheetTweenConfig;
|
|
30
|
+
onClose: () => void;
|
|
31
|
+
onCloseEnd?: () => void;
|
|
32
|
+
onCloseStart?: () => void;
|
|
33
|
+
onOpenEnd?: () => void;
|
|
34
|
+
onOpenStart?: () => void;
|
|
35
|
+
onSnap?: (index: number) => void;
|
|
36
|
+
} & MotionDivProps;
|
|
39
37
|
type SheetContainerProps = Omit<CommonProps, 'initial' | 'animate' | 'exit' | 'onAnimationComplete'> & {
|
|
40
38
|
children: ReactNode;
|
|
41
39
|
};
|
|
42
|
-
type SheetDraggableProps =
|
|
40
|
+
type SheetDraggableProps = MotionDivProps & {
|
|
43
41
|
children?: ReactNode;
|
|
44
42
|
disableDrag?: boolean;
|
|
45
43
|
};
|
|
46
44
|
type SheetBackdropProps = Omit<CommonProps, 'initial' | 'animate' | 'exit'>;
|
|
47
|
-
type
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
type SheetStateInfo = {
|
|
46
|
+
scrollPosition?: 'top' | 'bottom' | 'middle';
|
|
47
|
+
currentSnap?: number;
|
|
48
|
+
};
|
|
49
|
+
type SheetContentScrollableProps = MotionDivProps & {
|
|
50
|
+
disableDrag?: boolean | ((args: SheetStateInfo) => boolean);
|
|
51
|
+
disableScroll?: boolean | ((args: SheetStateInfo) => boolean);
|
|
52
|
+
scrollRef?: RefObject<HTMLDivElement | null>;
|
|
53
|
+
};
|
|
54
|
+
type SheetSnapPoint = {
|
|
55
|
+
snapIndex: number;
|
|
56
|
+
snapValue: number;
|
|
57
|
+
snapValueY: number;
|
|
51
58
|
};
|
|
52
59
|
type ContainerComponent = ForwardRefExoticComponent<SheetContainerProps & RefAttributes<any>>;
|
|
53
60
|
type DraggableComponent = ForwardRefExoticComponent<SheetDraggableProps & RefAttributes<any>>;
|
|
54
61
|
type BackdropComponent = ForwardRefExoticComponent<SheetBackdropProps & RefAttributes<any>>;
|
|
55
62
|
type SheetComponent = ForwardRefExoticComponent<SheetProps & RefAttributes<any>>;
|
|
56
|
-
type
|
|
63
|
+
type ContentScrollableComponent = ForwardRefExoticComponent<SheetContentScrollableProps & RefAttributes<any>>;
|
|
57
64
|
interface SheetCompoundComponent {
|
|
58
65
|
Container: ContainerComponent;
|
|
59
66
|
Header: DraggableComponent;
|
|
60
|
-
Content:
|
|
67
|
+
Content: ContentScrollableComponent;
|
|
61
68
|
Backdrop: BackdropComponent;
|
|
62
|
-
Scroller: ScrollerComponent;
|
|
63
69
|
}
|
|
64
70
|
type SheetCompound = SheetComponent & SheetCompoundComponent;
|
|
65
71
|
|
|
66
72
|
interface SheetRef {
|
|
67
73
|
y: MotionValue<number>;
|
|
68
|
-
|
|
74
|
+
yInverted: MotionValue<number>;
|
|
75
|
+
height: number;
|
|
76
|
+
snapTo: (index: number) => Promise<void>;
|
|
69
77
|
}
|
|
70
78
|
declare const Sheet: SheetCompound;
|
|
71
79
|
type SheetHeaderProps = SheetDraggableProps;
|
|
72
80
|
type SheetContentProps = SheetDraggableProps;
|
|
73
81
|
|
|
74
|
-
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetHeaderProps, type SheetProps, type SheetRef, type
|
|
82
|
+
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetHeaderProps, type SheetProps, type SheetRef, type SheetSnapPoint, type SheetStateInfo };
|