react-modal-sheet 1.10.1 → 1.11.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 +9 -3
- package/dist/react-modal-sheet.cjs.development.js +15 -5
- package/dist/react-modal-sheet.cjs.development.js.map +1 -1
- package/dist/react-modal-sheet.cjs.production.min.js +1 -1
- package/dist/react-modal-sheet.cjs.production.min.js.map +1 -1
- package/dist/react-modal-sheet.esm.js +16 -6
- package/dist/react-modal-sheet.esm.js.map +1 -1
- package/dist/sheet.d.ts +264 -1
- package/dist/types.d.ts +3 -3
- package/package.json +16 -7
- package/src/sheet.tsx +22 -6
- package/src/styles.ts +0 -1
- package/src/types.tsx +4 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { DragHandlers, MotionValue, MotionProps,
|
|
2
|
+
import { DragHandlers, MotionValue, MotionProps, Transition, Spring, motion } from 'framer-motion';
|
|
3
3
|
export declare type SheetEvents = {
|
|
4
4
|
onOpenStart?: () => void;
|
|
5
5
|
onOpenEnd?: () => void;
|
|
@@ -23,7 +23,7 @@ export declare type SheetProps = {
|
|
|
23
23
|
springConfig?: Omit<Spring, 'type'>;
|
|
24
24
|
disableDrag?: boolean;
|
|
25
25
|
prefersReducedMotion?: boolean;
|
|
26
|
-
} & SheetEvents & React.
|
|
26
|
+
} & SheetEvents & React.ComponentPropsWithoutRef<typeof motion.div>;
|
|
27
27
|
export declare type SheetContainerProps = Omit<CommonProps, 'initial' | 'animate' | 'exit' | 'onAnimationComplete'> & {
|
|
28
28
|
children: React.ReactNode;
|
|
29
29
|
};
|
|
@@ -52,7 +52,7 @@ export declare type SheetContextType = {
|
|
|
52
52
|
callbacks: React.MutableRefObject<SheetEvents>;
|
|
53
53
|
dragProps?: SheetDragProps;
|
|
54
54
|
windowHeight: number;
|
|
55
|
-
animationOptions:
|
|
55
|
+
animationOptions: Transition;
|
|
56
56
|
reduceMotion: boolean;
|
|
57
57
|
};
|
|
58
58
|
declare type ContainerComponent = React.ForwardRefExoticComponent<SheetContainerProps & React.RefAttributes<any>>;
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.11.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "react-modal-sheet",
|
|
5
5
|
"description": "Flexible bottom sheet component for your React apps",
|
|
6
6
|
"author": "Teemu Taskula",
|
|
7
7
|
"repository": "https://github.com/Temzasse/react-modal-sheet",
|
|
8
|
+
"homepage": "https://temzasse.github.io/react-modal-sheet",
|
|
8
9
|
"keywords": [
|
|
9
10
|
"react",
|
|
10
11
|
"modal",
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
"release": "np"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"framer-motion": ">=
|
|
36
|
+
"framer-motion": ">=6",
|
|
36
37
|
"react": ">=16"
|
|
37
38
|
},
|
|
38
39
|
"husky": {
|
|
@@ -50,19 +51,27 @@
|
|
|
50
51
|
"yarn": true
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@types/react": "18.
|
|
54
|
-
"@types/react-dom": "18.
|
|
54
|
+
"@types/react": "18.2.12",
|
|
55
|
+
"@types/react-dom": "18.2.5",
|
|
55
56
|
"@types/styled-components": "5.1.26",
|
|
56
57
|
"csstype": "3.1.1",
|
|
57
|
-
"framer-motion": "
|
|
58
|
+
"framer-motion": "10.12.16",
|
|
59
|
+
"history": "5.0.0",
|
|
58
60
|
"husky": "4.2.5",
|
|
61
|
+
"parcel": "2.8.3",
|
|
59
62
|
"react": "18.2.0",
|
|
63
|
+
"react-aria": "3.25.0",
|
|
60
64
|
"react-dom": "18.2.0",
|
|
65
|
+
"react-icons": "4.2.0",
|
|
66
|
+
"react-router": "6.0.0-beta.0",
|
|
67
|
+
"react-router-dom": "6.0.0-beta.0",
|
|
68
|
+
"react-stately": "3.23.0",
|
|
69
|
+
"react-use": "17.1.1",
|
|
61
70
|
"styled-components": "5.3.6",
|
|
62
71
|
"tsdx": "0.14.1",
|
|
63
|
-
"typescript": "
|
|
72
|
+
"typescript": "5.1.3"
|
|
64
73
|
},
|
|
65
74
|
"dependencies": {
|
|
66
|
-
"@react-aria/utils": "3.
|
|
75
|
+
"@react-aria/utils": "3.17.0"
|
|
67
76
|
}
|
|
68
77
|
}
|
package/src/sheet.tsx
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as ReactDOM from 'react-dom';
|
|
3
|
-
|
|
4
3
|
import {
|
|
5
4
|
animate,
|
|
6
5
|
AnimatePresence,
|
|
7
|
-
|
|
6
|
+
motion,
|
|
8
7
|
PanInfo,
|
|
8
|
+
Transition,
|
|
9
9
|
useMotionValue,
|
|
10
10
|
useReducedMotion,
|
|
11
|
+
useTransform,
|
|
11
12
|
} from 'framer-motion';
|
|
12
13
|
|
|
13
14
|
import {
|
|
@@ -59,7 +60,7 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
59
60
|
const windowHeight = useWindowHeight();
|
|
60
61
|
const shouldReduceMotion = useReducedMotion();
|
|
61
62
|
const reduceMotion = Boolean(prefersReducedMotion || shouldReduceMotion);
|
|
62
|
-
const animationOptions:
|
|
63
|
+
const animationOptions: Transition = reduceMotion
|
|
63
64
|
? { type: 'tween', duration: 0.01 }
|
|
64
65
|
: { type: 'spring', ...springConfig };
|
|
65
66
|
|
|
@@ -68,6 +69,14 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
68
69
|
// and after that it is driven by the gestures and/or snapping
|
|
69
70
|
const y = useMotionValue(0);
|
|
70
71
|
|
|
72
|
+
const zIndex = useTransform(y, value =>
|
|
73
|
+
value >= windowHeight ? -1 : 9999999
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const visibility = useTransform(y, value =>
|
|
77
|
+
value >= windowHeight ? 'hidden' : 'visible'
|
|
78
|
+
);
|
|
79
|
+
|
|
71
80
|
// Keep the callback fns up-to-date so that they can be accessed inside
|
|
72
81
|
// the effect without including them to the dependencies array
|
|
73
82
|
const callbacks = React.useRef({
|
|
@@ -150,7 +159,10 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
150
159
|
onSnap(snapIndex);
|
|
151
160
|
}
|
|
152
161
|
|
|
153
|
-
|
|
162
|
+
const roundedSheetHeight = Math.round(sheetHeight);
|
|
163
|
+
const shouldClose = snapTo >= roundedSheetHeight;
|
|
164
|
+
|
|
165
|
+
if (shouldClose) onClose();
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
// Reset indicator rotation after dragging
|
|
@@ -225,7 +237,11 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
225
237
|
|
|
226
238
|
const sheet = (
|
|
227
239
|
<SheetContext.Provider value={context}>
|
|
228
|
-
<div
|
|
240
|
+
<motion.div
|
|
241
|
+
{...rest}
|
|
242
|
+
ref={ref}
|
|
243
|
+
style={{ ...styles.wrapper, zIndex, visibility, ...style }}
|
|
244
|
+
>
|
|
229
245
|
<AnimatePresence>
|
|
230
246
|
{/* NOTE: AnimatePresence requires us to set keys to children */}
|
|
231
247
|
{isOpen
|
|
@@ -234,7 +250,7 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
234
250
|
)
|
|
235
251
|
: null}
|
|
236
252
|
</AnimatePresence>
|
|
237
|
-
</div>
|
|
253
|
+
</motion.div>
|
|
238
254
|
</SheetContext.Provider>
|
|
239
255
|
);
|
|
240
256
|
|
package/src/styles.ts
CHANGED
package/src/types.tsx
CHANGED
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
DragHandlers,
|
|
3
3
|
MotionValue,
|
|
4
4
|
MotionProps,
|
|
5
|
-
|
|
5
|
+
Transition,
|
|
6
6
|
Spring,
|
|
7
|
+
motion,
|
|
7
8
|
} from 'framer-motion';
|
|
8
9
|
|
|
9
10
|
export type SheetEvents = {
|
|
@@ -33,7 +34,7 @@ export type SheetProps = {
|
|
|
33
34
|
disableDrag?: boolean;
|
|
34
35
|
prefersReducedMotion?: boolean;
|
|
35
36
|
} & SheetEvents &
|
|
36
|
-
React.
|
|
37
|
+
React.ComponentPropsWithoutRef<typeof motion.div>;
|
|
37
38
|
|
|
38
39
|
export type SheetContainerProps = Omit<
|
|
39
40
|
CommonProps,
|
|
@@ -82,7 +83,7 @@ export type SheetContextType = {
|
|
|
82
83
|
callbacks: React.MutableRefObject<SheetEvents>;
|
|
83
84
|
dragProps?: SheetDragProps;
|
|
84
85
|
windowHeight: number;
|
|
85
|
-
animationOptions:
|
|
86
|
+
animationOptions: Transition;
|
|
86
87
|
reduceMotion: boolean;
|
|
87
88
|
};
|
|
88
89
|
|