react-modal-sheet 1.10.2 → 1.11.1
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 +10 -4
- package/dist/react-modal-sheet.cjs.development.js +27 -12
- 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 +28 -13
- 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 +21 -8
- package/src/styles.ts +0 -1
- package/src/types.tsx +4 -3
- package/src/utils.ts +12 -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.1",
|
|
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({
|
|
@@ -123,9 +132,9 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
123
132
|
let snapTo = 0;
|
|
124
133
|
|
|
125
134
|
if (snapPoints) {
|
|
126
|
-
const snapToValues = snapPoints
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
const snapToValues = snapPoints.map(
|
|
136
|
+
p => sheetHeight - Math.min(p, sheetHeight)
|
|
137
|
+
);
|
|
129
138
|
|
|
130
139
|
// Allow snapping to the top of the sheet if detent is set to `content-height`
|
|
131
140
|
if (detent === 'content-height' && !snapToValues.includes(0)) {
|
|
@@ -228,7 +237,11 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
228
237
|
|
|
229
238
|
const sheet = (
|
|
230
239
|
<SheetContext.Provider value={context}>
|
|
231
|
-
<div
|
|
240
|
+
<motion.div
|
|
241
|
+
{...rest}
|
|
242
|
+
ref={ref}
|
|
243
|
+
style={{ ...styles.wrapper, zIndex, visibility, ...style }}
|
|
244
|
+
>
|
|
232
245
|
<AnimatePresence>
|
|
233
246
|
{/* NOTE: AnimatePresence requires us to set keys to children */}
|
|
234
247
|
{isOpen
|
|
@@ -237,7 +250,7 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
237
250
|
)
|
|
238
251
|
: null}
|
|
239
252
|
</AnimatePresence>
|
|
240
|
-
</div>
|
|
253
|
+
</motion.div>
|
|
241
254
|
</SheetContext.Provider>
|
|
242
255
|
);
|
|
243
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
|
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
3
|
export function getClosest(nums: number[], goal: number) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
let closest = nums[0];
|
|
5
|
+
let minDifference = Math.abs(nums[0] - goal);
|
|
6
|
+
|
|
7
|
+
for (let i = 1; i < nums.length; i++) {
|
|
8
|
+
const difference = Math.abs(nums[i] - goal);
|
|
9
|
+
if (difference < minDifference) {
|
|
10
|
+
closest = nums[i];
|
|
11
|
+
minDifference = difference;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return closest;
|
|
7
16
|
}
|
|
8
17
|
|
|
9
18
|
const highlightId = 'react-modal-sheet-highlight';
|