react-modal-sheet 1.7.0 → 1.8.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 +25 -23
- package/dist/react-modal-sheet.cjs.development.js +38 -25
- 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 +39 -26
- package/dist/react-modal-sheet.esm.js.map +1 -1
- package/dist/sheet.d.ts +1 -0
- package/dist/types.d.ts +5 -3
- package/package.json +1 -1
- package/src/SheetContainer.tsx +6 -8
- package/src/SheetContent.tsx +3 -2
- package/src/SheetHeader.tsx +3 -2
- package/src/sheet.tsx +15 -7
- package/src/types.tsx +5 -2
package/src/SheetContent.tsx
CHANGED
|
@@ -6,8 +6,9 @@ import { useSheetContext } from './context';
|
|
|
6
6
|
import styles from './styles';
|
|
7
7
|
|
|
8
8
|
const SheetContent = React.forwardRef<any, SheetDraggableProps>(
|
|
9
|
-
({ children, style, ...rest }, ref) => {
|
|
9
|
+
({ children, style, disableDrag, ...rest }, ref) => {
|
|
10
10
|
const { dragProps } = useSheetContext();
|
|
11
|
+
const _dragProps = disableDrag ? undefined : dragProps;
|
|
11
12
|
|
|
12
13
|
return (
|
|
13
14
|
<motion.div
|
|
@@ -15,7 +16,7 @@ const SheetContent = React.forwardRef<any, SheetDraggableProps>(
|
|
|
15
16
|
ref={ref}
|
|
16
17
|
className="react-modal-sheet-content"
|
|
17
18
|
style={{ ...styles.content, ...style }}
|
|
18
|
-
{...
|
|
19
|
+
{..._dragProps}
|
|
19
20
|
>
|
|
20
21
|
{children}
|
|
21
22
|
</motion.div>
|
package/src/SheetHeader.tsx
CHANGED
|
@@ -6,8 +6,9 @@ import { useSheetContext } from './context';
|
|
|
6
6
|
import styles from './styles';
|
|
7
7
|
|
|
8
8
|
const SheetHeader = React.forwardRef<any, SheetDraggableProps>(
|
|
9
|
-
({ children, style, ...rest }, ref) => {
|
|
9
|
+
({ children, style, disableDrag, ...rest }, ref) => {
|
|
10
10
|
const { indicatorRotation, dragProps } = useSheetContext();
|
|
11
|
+
const _dragProps = disableDrag ? undefined : dragProps;
|
|
11
12
|
|
|
12
13
|
const indicator1Transform = useTransform(
|
|
13
14
|
indicatorRotation,
|
|
@@ -24,7 +25,7 @@ const SheetHeader = React.forwardRef<any, SheetDraggableProps>(
|
|
|
24
25
|
{...rest}
|
|
25
26
|
ref={ref}
|
|
26
27
|
style={{ ...styles.headerWrapper, ...style }}
|
|
27
|
-
{...
|
|
28
|
+
{..._dragProps}
|
|
28
29
|
>
|
|
29
30
|
{children || (
|
|
30
31
|
<div className="react-modal-sheet-header" style={styles.header}>
|
package/src/sheet.tsx
CHANGED
|
@@ -5,8 +5,10 @@ import { usePreventScroll } from '@react-aria/overlays';
|
|
|
5
5
|
import {
|
|
6
6
|
animate,
|
|
7
7
|
AnimatePresence,
|
|
8
|
+
AnimationOptions,
|
|
8
9
|
PanInfo,
|
|
9
10
|
useMotionValue,
|
|
11
|
+
useReducedMotion,
|
|
10
12
|
} from 'framer-motion';
|
|
11
13
|
|
|
12
14
|
import {
|
|
@@ -40,13 +42,14 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
40
42
|
children,
|
|
41
43
|
isOpen,
|
|
42
44
|
snapPoints,
|
|
43
|
-
detent,
|
|
44
|
-
initialSnap = 0,
|
|
45
45
|
rootId,
|
|
46
46
|
mountPoint,
|
|
47
|
+
style,
|
|
48
|
+
detent = 'full-height',
|
|
49
|
+
initialSnap = 0,
|
|
47
50
|
springConfig = DEFAULT_SPRING_CONFIG,
|
|
48
51
|
disableDrag = false,
|
|
49
|
-
|
|
52
|
+
prefersReducedMotion = false,
|
|
50
53
|
...rest
|
|
51
54
|
},
|
|
52
55
|
ref
|
|
@@ -54,6 +57,11 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
54
57
|
const sheetRef = React.useRef<any>(null);
|
|
55
58
|
const indicatorRotation = useMotionValue(0);
|
|
56
59
|
const windowHeight = useWindowHeight();
|
|
60
|
+
const shouldReduceMotion = useReducedMotion();
|
|
61
|
+
const reduceMotion = Boolean(prefersReducedMotion || shouldReduceMotion);
|
|
62
|
+
const animationOptions: AnimationOptions<number> = reduceMotion
|
|
63
|
+
? { type: 'tween', duration: 0.01 }
|
|
64
|
+
: { type: 'spring', ...springConfig };
|
|
57
65
|
|
|
58
66
|
// NOTE: the inital value for `y` doesn't matter since it is overwritten by
|
|
59
67
|
// the value driven by the `AnimatePresence` component when the sheet is opened
|
|
@@ -134,7 +142,7 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
134
142
|
snapTo = validateSnapTo({ snapTo, sheetHeight });
|
|
135
143
|
|
|
136
144
|
// Update the spring value so that the sheet is animated to the snap point
|
|
137
|
-
animate(y, snapTo,
|
|
145
|
+
animate(y, snapTo, animationOptions);
|
|
138
146
|
|
|
139
147
|
if (snapPoints && onSnap) {
|
|
140
148
|
const snapValue = Math.abs(Math.round(snapPoints[0] - snapTo));
|
|
@@ -173,8 +181,7 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
173
181
|
sheetHeight,
|
|
174
182
|
});
|
|
175
183
|
|
|
176
|
-
animate(y, snapTo,
|
|
177
|
-
|
|
184
|
+
animate(y, snapTo, animationOptions);
|
|
178
185
|
if (onSnap) onSnap(snapIndex);
|
|
179
186
|
if (snapTo >= sheetHeight) onClose();
|
|
180
187
|
}
|
|
@@ -211,7 +218,8 @@ const Sheet = React.forwardRef<any, SheetProps>(
|
|
|
211
218
|
callbacks,
|
|
212
219
|
dragProps,
|
|
213
220
|
windowHeight,
|
|
214
|
-
|
|
221
|
+
animationOptions,
|
|
222
|
+
reduceMotion,
|
|
215
223
|
};
|
|
216
224
|
|
|
217
225
|
const sheet = (
|
package/src/types.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
MotionValue,
|
|
4
4
|
useSpring,
|
|
5
5
|
MotionProps,
|
|
6
|
+
AnimationOptions,
|
|
6
7
|
} from 'framer-motion';
|
|
7
8
|
|
|
8
9
|
export type SheetEvents = {
|
|
@@ -26,6 +27,7 @@ export type SheetProps = {
|
|
|
26
27
|
initialSnap?: number; // index of snap points array
|
|
27
28
|
springConfig?: Parameters<typeof useSpring>[1];
|
|
28
29
|
disableDrag?: boolean;
|
|
30
|
+
prefersReducedMotion?: boolean;
|
|
29
31
|
} & SheetEvents &
|
|
30
32
|
React.HTMLAttributes<HTMLDivElement>;
|
|
31
33
|
|
|
@@ -69,13 +71,14 @@ export type SheetContextType = {
|
|
|
69
71
|
sheetRef: React.MutableRefObject<any>;
|
|
70
72
|
isOpen: boolean;
|
|
71
73
|
snapPoints: SheetProps['snapPoints'];
|
|
72
|
-
detent
|
|
74
|
+
detent: SheetDetent;
|
|
73
75
|
initialSnap: SheetProps['initialSnap'];
|
|
74
76
|
indicatorRotation: MotionValue<number>;
|
|
75
77
|
callbacks: React.MutableRefObject<SheetEvents>;
|
|
76
78
|
dragProps?: SheetDragProps;
|
|
77
79
|
windowHeight: number;
|
|
78
|
-
|
|
80
|
+
animationOptions: AnimationOptions<number>;
|
|
81
|
+
reduceMotion: boolean;
|
|
79
82
|
};
|
|
80
83
|
|
|
81
84
|
type ContainerComponent = React.ForwardRefExoticComponent<
|