react-modal-sheet 5.0.0 → 5.1.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 +91 -0
- package/dist/index.d.mts +22 -18
- package/dist/index.d.ts +22 -18
- package/dist/index.js +197 -114
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
- package/src/SheetBackdrop.tsx +14 -3
- package/src/SheetContainer.tsx +5 -3
- package/src/SheetContent.tsx +8 -7
- package/src/SheetDragIndicator.tsx +52 -0
- package/src/SheetHeader.tsx +20 -23
- package/src/index.tsx +6 -4
- package/src/sheet.tsx +11 -3
- package/src/styles.ts +92 -51
- package/src/types.tsx +42 -33
- package/src/utils.ts +8 -1
package/dist/index.mjs
CHANGED
|
@@ -1,104 +1,123 @@
|
|
|
1
|
-
import { motion,
|
|
2
|
-
import React4, {
|
|
1
|
+
import { motion, useMotionValue, useTransform, useReducedMotion, animate } from 'motion/react';
|
|
2
|
+
import React4, { createContext, forwardRef, useRef, useState, useImperativeHandle, useContext, useCallback, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import useMeasure from 'react-use-measure';
|
|
5
5
|
import { transform } from 'motion';
|
|
6
6
|
|
|
7
7
|
// src/SheetBackdrop.tsx
|
|
8
|
+
var SheetContext = createContext(
|
|
9
|
+
void 0
|
|
10
|
+
);
|
|
11
|
+
function useSheetContext() {
|
|
12
|
+
const context = useContext(SheetContext);
|
|
13
|
+
if (!context) throw new Error("Sheet context error");
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
8
16
|
|
|
9
17
|
// src/styles.ts
|
|
10
18
|
var styles = {
|
|
11
19
|
root: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
base: {
|
|
21
|
+
position: "fixed",
|
|
22
|
+
top: 0,
|
|
23
|
+
bottom: 0,
|
|
24
|
+
left: 0,
|
|
25
|
+
right: 0,
|
|
26
|
+
overflow: "hidden",
|
|
27
|
+
pointerEvents: "none"
|
|
28
|
+
},
|
|
29
|
+
decorative: {}
|
|
19
30
|
},
|
|
20
31
|
backdrop: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
base: {
|
|
33
|
+
zIndex: 1,
|
|
34
|
+
position: "fixed",
|
|
35
|
+
top: 0,
|
|
36
|
+
left: 0,
|
|
37
|
+
width: "100%",
|
|
38
|
+
height: "100%",
|
|
39
|
+
touchAction: "none",
|
|
40
|
+
userSelect: "none"
|
|
41
|
+
},
|
|
42
|
+
decorative: {
|
|
43
|
+
backgroundColor: "rgba(0, 0, 0, 0.2)",
|
|
44
|
+
border: "none",
|
|
45
|
+
WebkitTapHighlightColor: "transparent"
|
|
46
|
+
}
|
|
32
47
|
},
|
|
33
48
|
container: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
base: {
|
|
50
|
+
zIndex: 2,
|
|
51
|
+
position: "absolute",
|
|
52
|
+
left: 0,
|
|
53
|
+
bottom: 0,
|
|
54
|
+
width: "100%",
|
|
55
|
+
pointerEvents: "auto",
|
|
56
|
+
display: "flex",
|
|
57
|
+
flexDirection: "column"
|
|
58
|
+
},
|
|
59
|
+
decorative: {
|
|
60
|
+
backgroundColor: "#fff",
|
|
61
|
+
borderTopRightRadius: "8px",
|
|
62
|
+
borderTopLeftRadius: "8px",
|
|
63
|
+
boxShadow: "0px -2px 16px rgba(0, 0, 0, 0.3)"
|
|
64
|
+
}
|
|
46
65
|
},
|
|
47
66
|
headerWrapper: {
|
|
48
|
-
|
|
67
|
+
base: {
|
|
68
|
+
width: "100%"
|
|
69
|
+
},
|
|
70
|
+
decorative: {}
|
|
49
71
|
},
|
|
50
72
|
header: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
73
|
+
base: {
|
|
74
|
+
width: "100%",
|
|
75
|
+
position: "relative"
|
|
76
|
+
},
|
|
77
|
+
decorative: {
|
|
78
|
+
height: "40px",
|
|
79
|
+
display: "flex",
|
|
80
|
+
alignItems: "center",
|
|
81
|
+
justifyContent: "center"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
indicatorWrapper: {
|
|
85
|
+
base: {
|
|
86
|
+
display: "flex"
|
|
87
|
+
},
|
|
88
|
+
decorative: {}
|
|
57
89
|
},
|
|
58
90
|
indicator: {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
91
|
+
base: {
|
|
92
|
+
display: "inline-block"
|
|
93
|
+
},
|
|
94
|
+
decorative: {
|
|
95
|
+
width: "18px",
|
|
96
|
+
height: "4px",
|
|
97
|
+
borderRadius: "99px",
|
|
98
|
+
backgroundColor: "#ddd"
|
|
99
|
+
}
|
|
63
100
|
},
|
|
64
101
|
content: {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
102
|
+
base: {
|
|
103
|
+
minHeight: "0px",
|
|
104
|
+
position: "relative",
|
|
105
|
+
flexGrow: 1,
|
|
106
|
+
display: "flex",
|
|
107
|
+
flexDirection: "column"
|
|
108
|
+
},
|
|
109
|
+
decorative: {}
|
|
70
110
|
},
|
|
71
111
|
scroller: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
112
|
+
base: {
|
|
113
|
+
height: "100%",
|
|
114
|
+
overflowY: "auto",
|
|
115
|
+
overscrollBehaviorY: "none"
|
|
116
|
+
},
|
|
117
|
+
decorative: {}
|
|
75
118
|
}
|
|
76
119
|
};
|
|
77
120
|
|
|
78
|
-
// src/SheetBackdrop.tsx
|
|
79
|
-
var isClickable = (props) => !!props.onClick || !!props.onTap;
|
|
80
|
-
var SheetBackdrop = forwardRef(
|
|
81
|
-
({ style, className = "", ...rest }, ref) => {
|
|
82
|
-
const clickable = isClickable(rest);
|
|
83
|
-
const Comp = clickable ? motion.button : motion.div;
|
|
84
|
-
const pointerEvents = clickable ? "auto" : "none";
|
|
85
|
-
return /* @__PURE__ */ React4.createElement(
|
|
86
|
-
Comp,
|
|
87
|
-
{
|
|
88
|
-
...rest,
|
|
89
|
-
ref,
|
|
90
|
-
className: `react-modal-sheet-backdrop ${className}`,
|
|
91
|
-
style: { ...styles.backdrop, ...style, pointerEvents },
|
|
92
|
-
initial: { opacity: 0 },
|
|
93
|
-
animate: { opacity: 1 },
|
|
94
|
-
exit: { opacity: 0 },
|
|
95
|
-
transition: { duration: 1 }
|
|
96
|
-
}
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
SheetBackdrop.displayName = "SheetBackdrop";
|
|
101
|
-
|
|
102
121
|
// src/constants.ts
|
|
103
122
|
var DEFAULT_HEIGHT = "calc(100% - env(safe-area-inset-top) - 34px)";
|
|
104
123
|
var IS_SSR = typeof window === "undefined";
|
|
@@ -112,16 +131,11 @@ var REDUCED_MOTION_TWEEN_CONFIG = {
|
|
|
112
131
|
};
|
|
113
132
|
var DEFAULT_DRAG_CLOSE_THRESHOLD = 0.6;
|
|
114
133
|
var DEFAULT_DRAG_VELOCITY_THRESHOLD = 500;
|
|
115
|
-
var SheetContext = createContext(
|
|
116
|
-
void 0
|
|
117
|
-
);
|
|
118
|
-
function useSheetContext() {
|
|
119
|
-
const context = useContext(SheetContext);
|
|
120
|
-
if (!context) throw new Error("Sheet context error");
|
|
121
|
-
return context;
|
|
122
|
-
}
|
|
123
134
|
|
|
124
135
|
// src/utils.ts
|
|
136
|
+
function applyStyles(styles2, unstyled) {
|
|
137
|
+
return unstyled ? styles2.base : { ...styles2.base, ...styles2.decorative };
|
|
138
|
+
}
|
|
125
139
|
function isAscendingOrder(arr) {
|
|
126
140
|
for (let i = 0; i < arr.length; i++) {
|
|
127
141
|
if (arr[i + 1] < arr[i]) return false;
|
|
@@ -168,12 +182,42 @@ var isIOS = cached(function() {
|
|
|
168
182
|
return isIPhone() || isIPad();
|
|
169
183
|
});
|
|
170
184
|
|
|
171
|
-
// src/
|
|
185
|
+
// src/SheetBackdrop.tsx
|
|
186
|
+
var isClickable = (props) => !!props.onClick || !!props.onTap;
|
|
187
|
+
var SheetBackdrop = forwardRef(
|
|
188
|
+
({ style, className = "", unstyled, ...rest }, ref) => {
|
|
189
|
+
const sheetContext = useSheetContext();
|
|
190
|
+
const clickable = isClickable(rest);
|
|
191
|
+
const Comp = clickable ? motion.button : motion.div;
|
|
192
|
+
const pointerEvents = clickable ? "auto" : "none";
|
|
193
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
194
|
+
const backdropStyle = {
|
|
195
|
+
...applyStyles(styles.backdrop, isUnstyled),
|
|
196
|
+
...style,
|
|
197
|
+
pointerEvents
|
|
198
|
+
};
|
|
199
|
+
return /* @__PURE__ */ React4.createElement(
|
|
200
|
+
Comp,
|
|
201
|
+
{
|
|
202
|
+
...rest,
|
|
203
|
+
ref,
|
|
204
|
+
className: `react-modal-sheet-backdrop ${className}`,
|
|
205
|
+
style: backdropStyle,
|
|
206
|
+
initial: { opacity: 0 },
|
|
207
|
+
animate: { opacity: 1 },
|
|
208
|
+
exit: { opacity: 0 },
|
|
209
|
+
transition: { duration: 1 }
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
SheetBackdrop.displayName = "SheetBackdrop";
|
|
172
215
|
var SheetContainer = forwardRef(
|
|
173
|
-
({ children, style, className = "", ...rest }, ref) => {
|
|
216
|
+
({ children, style, className = "", unstyled, ...rest }, ref) => {
|
|
174
217
|
const sheetContext = useSheetContext();
|
|
218
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
175
219
|
const containerStyle = {
|
|
176
|
-
...styles.container,
|
|
220
|
+
...applyStyles(styles.container, isUnstyled),
|
|
177
221
|
...style,
|
|
178
222
|
y: sheetContext.y
|
|
179
223
|
};
|
|
@@ -271,6 +315,7 @@ var SheetContent = forwardRef(
|
|
|
271
315
|
style: styleProp,
|
|
272
316
|
className = "",
|
|
273
317
|
scrollRef: scrollRefProp = null,
|
|
318
|
+
unstyled,
|
|
274
319
|
...rest
|
|
275
320
|
}, ref) => {
|
|
276
321
|
const sheetContext = useSheetContext();
|
|
@@ -287,13 +332,12 @@ var SheetContent = forwardRef(
|
|
|
287
332
|
}) : Boolean(disableDragProp);
|
|
288
333
|
const disableDrag = disableDragDueToProp || disableDragDueToScroll || sheetContext.disableDrag;
|
|
289
334
|
const dragProps = disableDrag || sheetContext.disableDrag ? void 0 : sheetContext.dragProps;
|
|
335
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
290
336
|
const contentStyle = {
|
|
291
|
-
...styles.content,
|
|
337
|
+
...applyStyles(styles.content, isUnstyled),
|
|
292
338
|
...styleProp
|
|
293
339
|
};
|
|
294
|
-
const scrollStyle =
|
|
295
|
-
...styles.scroller
|
|
296
|
-
};
|
|
340
|
+
const scrollStyle = applyStyles(styles.scroller, isUnstyled);
|
|
297
341
|
if (sheetContext.avoidKeyboard) {
|
|
298
342
|
scrollStyle.paddingBottom = "env(keyboard-inset-height, var(--keyboard-inset-height, 0px))";
|
|
299
343
|
}
|
|
@@ -324,42 +368,73 @@ var SheetContent = forwardRef(
|
|
|
324
368
|
}
|
|
325
369
|
);
|
|
326
370
|
SheetContent.displayName = "SheetContent";
|
|
371
|
+
function SheetDragIndicator({
|
|
372
|
+
style,
|
|
373
|
+
className = "",
|
|
374
|
+
unstyled,
|
|
375
|
+
...rest
|
|
376
|
+
}) {
|
|
377
|
+
const sheetContext = useSheetContext();
|
|
378
|
+
const indicator1Transform = useTransform(
|
|
379
|
+
sheetContext.indicatorRotation,
|
|
380
|
+
(r) => `translateX(2px) rotate(${r}deg)`
|
|
381
|
+
);
|
|
382
|
+
const indicator2Transform = useTransform(
|
|
383
|
+
sheetContext.indicatorRotation,
|
|
384
|
+
(r) => `translateX(-2px) rotate(${ -1 * r}deg)`
|
|
385
|
+
);
|
|
386
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
387
|
+
const indicatorWrapperStyle = {
|
|
388
|
+
...applyStyles(styles.indicatorWrapper, isUnstyled),
|
|
389
|
+
...style
|
|
390
|
+
};
|
|
391
|
+
const indicatorStyle = applyStyles(styles.indicator, isUnstyled);
|
|
392
|
+
return /* @__PURE__ */ React4.createElement(
|
|
393
|
+
"div",
|
|
394
|
+
{
|
|
395
|
+
className: `react-modal-sheet-drag-indicator-container ${className}`,
|
|
396
|
+
style: indicatorWrapperStyle,
|
|
397
|
+
...rest
|
|
398
|
+
},
|
|
399
|
+
/* @__PURE__ */ React4.createElement(
|
|
400
|
+
motion.span,
|
|
401
|
+
{
|
|
402
|
+
className: "react-modal-sheet-drag-indicator",
|
|
403
|
+
style: { ...indicatorStyle, transform: indicator1Transform }
|
|
404
|
+
}
|
|
405
|
+
),
|
|
406
|
+
/* @__PURE__ */ React4.createElement(
|
|
407
|
+
motion.span,
|
|
408
|
+
{
|
|
409
|
+
className: "react-modal-sheet-drag-indicator",
|
|
410
|
+
style: { ...indicatorStyle, transform: indicator2Transform }
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
);
|
|
414
|
+
}
|
|
327
415
|
var SheetHeader = forwardRef(
|
|
328
|
-
({ children, style, disableDrag, ...rest }, ref) => {
|
|
416
|
+
({ children, style, disableDrag, unstyled, className = "", ...rest }, ref) => {
|
|
329
417
|
const sheetContext = useSheetContext();
|
|
330
418
|
const dragConstraints = useDragConstraints();
|
|
331
419
|
const dragProps = disableDrag || sheetContext.disableDrag ? void 0 : sheetContext.dragProps;
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
(
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
(r) => `translateX(-2px) rotate(${ -1 * r}deg)`
|
|
339
|
-
);
|
|
420
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
421
|
+
const headerWrapperStyle = {
|
|
422
|
+
...applyStyles(styles.headerWrapper, isUnstyled),
|
|
423
|
+
...style
|
|
424
|
+
};
|
|
425
|
+
const headerStyle = applyStyles(styles.header, isUnstyled);
|
|
340
426
|
return /* @__PURE__ */ React4.createElement(
|
|
341
427
|
motion.div,
|
|
342
428
|
{
|
|
343
429
|
...rest,
|
|
344
430
|
ref: mergeRefs([ref, dragConstraints.ref]),
|
|
345
|
-
style:
|
|
431
|
+
style: headerWrapperStyle,
|
|
432
|
+
className: `react-modal-sheet-header-container ${className}`,
|
|
346
433
|
...dragProps,
|
|
347
434
|
dragConstraints: dragConstraints.ref,
|
|
348
435
|
onMeasureDragConstraints: dragConstraints.onMeasure
|
|
349
436
|
},
|
|
350
|
-
children || /* @__PURE__ */ React4.createElement("div", { className: "react-modal-sheet-header", style:
|
|
351
|
-
motion.span,
|
|
352
|
-
{
|
|
353
|
-
className: "react-modal-sheet-drag-indicator",
|
|
354
|
-
style: { ...styles.indicator, transform: indicator1Transform }
|
|
355
|
-
}
|
|
356
|
-
), /* @__PURE__ */ React4.createElement(
|
|
357
|
-
motion.span,
|
|
358
|
-
{
|
|
359
|
-
className: "react-modal-sheet-drag-indicator",
|
|
360
|
-
style: { ...styles.indicator, transform: indicator2Transform }
|
|
361
|
-
}
|
|
362
|
-
))
|
|
437
|
+
children || /* @__PURE__ */ React4.createElement("div", { className: "react-modal-sheet-header", style: headerStyle }, /* @__PURE__ */ React4.createElement(SheetDragIndicator, null))
|
|
363
438
|
);
|
|
364
439
|
}
|
|
365
440
|
);
|
|
@@ -1000,20 +1075,21 @@ var Sheet = forwardRef(
|
|
|
1000
1075
|
children,
|
|
1001
1076
|
className = "",
|
|
1002
1077
|
detent = "default",
|
|
1078
|
+
disableDismiss = false,
|
|
1003
1079
|
disableDrag: disableDragProp = false,
|
|
1004
1080
|
disableScrollLocking = false,
|
|
1005
|
-
disableDismiss = false,
|
|
1006
1081
|
dragCloseThreshold = DEFAULT_DRAG_CLOSE_THRESHOLD,
|
|
1007
1082
|
dragVelocityThreshold = DEFAULT_DRAG_VELOCITY_THRESHOLD,
|
|
1083
|
+
initialSnap,
|
|
1008
1084
|
isOpen,
|
|
1009
1085
|
modalEffectRootId,
|
|
1010
1086
|
modalEffectThreshold,
|
|
1011
1087
|
mountPoint,
|
|
1012
1088
|
prefersReducedMotion = false,
|
|
1013
1089
|
snapPoints: snapPointsProp,
|
|
1014
|
-
initialSnap,
|
|
1015
1090
|
style,
|
|
1016
1091
|
tweenConfig = DEFAULT_TWEEN_CONFIG,
|
|
1092
|
+
unstyled = false,
|
|
1017
1093
|
onOpenStart,
|
|
1018
1094
|
onOpenEnd,
|
|
1019
1095
|
onClose,
|
|
@@ -1212,6 +1288,7 @@ var Sheet = forwardRef(
|
|
|
1212
1288
|
avoidKeyboard,
|
|
1213
1289
|
sheetBoundsRef,
|
|
1214
1290
|
sheetRef,
|
|
1291
|
+
unstyled,
|
|
1215
1292
|
y
|
|
1216
1293
|
};
|
|
1217
1294
|
const sheet = /* @__PURE__ */ React4.createElement(SheetContext.Provider, { value: context }, /* @__PURE__ */ React4.createElement(
|
|
@@ -1221,7 +1298,12 @@ var Sheet = forwardRef(
|
|
|
1221
1298
|
ref,
|
|
1222
1299
|
"data-sheet-state": state,
|
|
1223
1300
|
className: `react-modal-sheet-root ${className}`,
|
|
1224
|
-
style: {
|
|
1301
|
+
style: {
|
|
1302
|
+
...applyStyles(styles.root, unstyled),
|
|
1303
|
+
zIndex,
|
|
1304
|
+
visibility,
|
|
1305
|
+
...style
|
|
1306
|
+
}
|
|
1225
1307
|
},
|
|
1226
1308
|
state !== "closed" ? children : null
|
|
1227
1309
|
));
|
|
@@ -1235,6 +1317,7 @@ Sheet.displayName = "Sheet";
|
|
|
1235
1317
|
var Sheet2 = Object.assign(Sheet, {
|
|
1236
1318
|
Container: SheetContainer,
|
|
1237
1319
|
Header: SheetHeader,
|
|
1320
|
+
DragIndicator: SheetDragIndicator,
|
|
1238
1321
|
Content: SheetContent,
|
|
1239
1322
|
Backdrop: SheetBackdrop
|
|
1240
1323
|
});
|