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.js
CHANGED
|
@@ -12,100 +12,119 @@ var React4__default = /*#__PURE__*/_interopDefault(React4);
|
|
|
12
12
|
var useMeasure__default = /*#__PURE__*/_interopDefault(useMeasure);
|
|
13
13
|
|
|
14
14
|
// src/SheetBackdrop.tsx
|
|
15
|
+
var SheetContext = React4.createContext(
|
|
16
|
+
void 0
|
|
17
|
+
);
|
|
18
|
+
function useSheetContext() {
|
|
19
|
+
const context = React4.useContext(SheetContext);
|
|
20
|
+
if (!context) throw new Error("Sheet context error");
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
15
23
|
|
|
16
24
|
// src/styles.ts
|
|
17
25
|
var styles = {
|
|
18
26
|
root: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
base: {
|
|
28
|
+
position: "fixed",
|
|
29
|
+
top: 0,
|
|
30
|
+
bottom: 0,
|
|
31
|
+
left: 0,
|
|
32
|
+
right: 0,
|
|
33
|
+
overflow: "hidden",
|
|
34
|
+
pointerEvents: "none"
|
|
35
|
+
},
|
|
36
|
+
decorative: {}
|
|
26
37
|
},
|
|
27
38
|
backdrop: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
base: {
|
|
40
|
+
zIndex: 1,
|
|
41
|
+
position: "fixed",
|
|
42
|
+
top: 0,
|
|
43
|
+
left: 0,
|
|
44
|
+
width: "100%",
|
|
45
|
+
height: "100%",
|
|
46
|
+
touchAction: "none",
|
|
47
|
+
userSelect: "none"
|
|
48
|
+
},
|
|
49
|
+
decorative: {
|
|
50
|
+
backgroundColor: "rgba(0, 0, 0, 0.2)",
|
|
51
|
+
border: "none",
|
|
52
|
+
WebkitTapHighlightColor: "transparent"
|
|
53
|
+
}
|
|
39
54
|
},
|
|
40
55
|
container: {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
base: {
|
|
57
|
+
zIndex: 2,
|
|
58
|
+
position: "absolute",
|
|
59
|
+
left: 0,
|
|
60
|
+
bottom: 0,
|
|
61
|
+
width: "100%",
|
|
62
|
+
pointerEvents: "auto",
|
|
63
|
+
display: "flex",
|
|
64
|
+
flexDirection: "column"
|
|
65
|
+
},
|
|
66
|
+
decorative: {
|
|
67
|
+
backgroundColor: "#fff",
|
|
68
|
+
borderTopRightRadius: "8px",
|
|
69
|
+
borderTopLeftRadius: "8px",
|
|
70
|
+
boxShadow: "0px -2px 16px rgba(0, 0, 0, 0.3)"
|
|
71
|
+
}
|
|
53
72
|
},
|
|
54
73
|
headerWrapper: {
|
|
55
|
-
|
|
74
|
+
base: {
|
|
75
|
+
width: "100%"
|
|
76
|
+
},
|
|
77
|
+
decorative: {}
|
|
56
78
|
},
|
|
57
79
|
header: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
base: {
|
|
81
|
+
width: "100%",
|
|
82
|
+
position: "relative"
|
|
83
|
+
},
|
|
84
|
+
decorative: {
|
|
85
|
+
height: "40px",
|
|
86
|
+
display: "flex",
|
|
87
|
+
alignItems: "center",
|
|
88
|
+
justifyContent: "center"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
indicatorWrapper: {
|
|
92
|
+
base: {
|
|
93
|
+
display: "flex"
|
|
94
|
+
},
|
|
95
|
+
decorative: {}
|
|
64
96
|
},
|
|
65
97
|
indicator: {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
98
|
+
base: {
|
|
99
|
+
display: "inline-block"
|
|
100
|
+
},
|
|
101
|
+
decorative: {
|
|
102
|
+
width: "18px",
|
|
103
|
+
height: "4px",
|
|
104
|
+
borderRadius: "99px",
|
|
105
|
+
backgroundColor: "#ddd"
|
|
106
|
+
}
|
|
70
107
|
},
|
|
71
108
|
content: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
109
|
+
base: {
|
|
110
|
+
minHeight: "0px",
|
|
111
|
+
position: "relative",
|
|
112
|
+
flexGrow: 1,
|
|
113
|
+
display: "flex",
|
|
114
|
+
flexDirection: "column"
|
|
115
|
+
},
|
|
116
|
+
decorative: {}
|
|
77
117
|
},
|
|
78
118
|
scroller: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
119
|
+
base: {
|
|
120
|
+
height: "100%",
|
|
121
|
+
overflowY: "auto",
|
|
122
|
+
overscrollBehaviorY: "none"
|
|
123
|
+
},
|
|
124
|
+
decorative: {}
|
|
82
125
|
}
|
|
83
126
|
};
|
|
84
127
|
|
|
85
|
-
// src/SheetBackdrop.tsx
|
|
86
|
-
var isClickable = (props) => !!props.onClick || !!props.onTap;
|
|
87
|
-
var SheetBackdrop = React4.forwardRef(
|
|
88
|
-
({ style, className = "", ...rest }, ref) => {
|
|
89
|
-
const clickable = isClickable(rest);
|
|
90
|
-
const Comp = clickable ? react.motion.button : react.motion.div;
|
|
91
|
-
const pointerEvents = clickable ? "auto" : "none";
|
|
92
|
-
return /* @__PURE__ */ React4__default.default.createElement(
|
|
93
|
-
Comp,
|
|
94
|
-
{
|
|
95
|
-
...rest,
|
|
96
|
-
ref,
|
|
97
|
-
className: `react-modal-sheet-backdrop ${className}`,
|
|
98
|
-
style: { ...styles.backdrop, ...style, pointerEvents },
|
|
99
|
-
initial: { opacity: 0 },
|
|
100
|
-
animate: { opacity: 1 },
|
|
101
|
-
exit: { opacity: 0 },
|
|
102
|
-
transition: { duration: 1 }
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
SheetBackdrop.displayName = "SheetBackdrop";
|
|
108
|
-
|
|
109
128
|
// src/constants.ts
|
|
110
129
|
var DEFAULT_HEIGHT = "calc(100% - env(safe-area-inset-top) - 34px)";
|
|
111
130
|
var IS_SSR = typeof window === "undefined";
|
|
@@ -119,16 +138,11 @@ var REDUCED_MOTION_TWEEN_CONFIG = {
|
|
|
119
138
|
};
|
|
120
139
|
var DEFAULT_DRAG_CLOSE_THRESHOLD = 0.6;
|
|
121
140
|
var DEFAULT_DRAG_VELOCITY_THRESHOLD = 500;
|
|
122
|
-
var SheetContext = React4.createContext(
|
|
123
|
-
void 0
|
|
124
|
-
);
|
|
125
|
-
function useSheetContext() {
|
|
126
|
-
const context = React4.useContext(SheetContext);
|
|
127
|
-
if (!context) throw new Error("Sheet context error");
|
|
128
|
-
return context;
|
|
129
|
-
}
|
|
130
141
|
|
|
131
142
|
// src/utils.ts
|
|
143
|
+
function applyStyles(styles2, unstyled) {
|
|
144
|
+
return unstyled ? styles2.base : { ...styles2.base, ...styles2.decorative };
|
|
145
|
+
}
|
|
132
146
|
function isAscendingOrder(arr) {
|
|
133
147
|
for (let i = 0; i < arr.length; i++) {
|
|
134
148
|
if (arr[i + 1] < arr[i]) return false;
|
|
@@ -175,12 +189,42 @@ var isIOS = cached(function() {
|
|
|
175
189
|
return isIPhone() || isIPad();
|
|
176
190
|
});
|
|
177
191
|
|
|
178
|
-
// src/
|
|
192
|
+
// src/SheetBackdrop.tsx
|
|
193
|
+
var isClickable = (props) => !!props.onClick || !!props.onTap;
|
|
194
|
+
var SheetBackdrop = React4.forwardRef(
|
|
195
|
+
({ style, className = "", unstyled, ...rest }, ref) => {
|
|
196
|
+
const sheetContext = useSheetContext();
|
|
197
|
+
const clickable = isClickable(rest);
|
|
198
|
+
const Comp = clickable ? react.motion.button : react.motion.div;
|
|
199
|
+
const pointerEvents = clickable ? "auto" : "none";
|
|
200
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
201
|
+
const backdropStyle = {
|
|
202
|
+
...applyStyles(styles.backdrop, isUnstyled),
|
|
203
|
+
...style,
|
|
204
|
+
pointerEvents
|
|
205
|
+
};
|
|
206
|
+
return /* @__PURE__ */ React4__default.default.createElement(
|
|
207
|
+
Comp,
|
|
208
|
+
{
|
|
209
|
+
...rest,
|
|
210
|
+
ref,
|
|
211
|
+
className: `react-modal-sheet-backdrop ${className}`,
|
|
212
|
+
style: backdropStyle,
|
|
213
|
+
initial: { opacity: 0 },
|
|
214
|
+
animate: { opacity: 1 },
|
|
215
|
+
exit: { opacity: 0 },
|
|
216
|
+
transition: { duration: 1 }
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
SheetBackdrop.displayName = "SheetBackdrop";
|
|
179
222
|
var SheetContainer = React4.forwardRef(
|
|
180
|
-
({ children, style, className = "", ...rest }, ref) => {
|
|
223
|
+
({ children, style, className = "", unstyled, ...rest }, ref) => {
|
|
181
224
|
const sheetContext = useSheetContext();
|
|
225
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
182
226
|
const containerStyle = {
|
|
183
|
-
...styles.container,
|
|
227
|
+
...applyStyles(styles.container, isUnstyled),
|
|
184
228
|
...style,
|
|
185
229
|
y: sheetContext.y
|
|
186
230
|
};
|
|
@@ -278,6 +322,7 @@ var SheetContent = React4.forwardRef(
|
|
|
278
322
|
style: styleProp,
|
|
279
323
|
className = "",
|
|
280
324
|
scrollRef: scrollRefProp = null,
|
|
325
|
+
unstyled,
|
|
281
326
|
...rest
|
|
282
327
|
}, ref) => {
|
|
283
328
|
const sheetContext = useSheetContext();
|
|
@@ -294,13 +339,12 @@ var SheetContent = React4.forwardRef(
|
|
|
294
339
|
}) : Boolean(disableDragProp);
|
|
295
340
|
const disableDrag = disableDragDueToProp || disableDragDueToScroll || sheetContext.disableDrag;
|
|
296
341
|
const dragProps = disableDrag || sheetContext.disableDrag ? void 0 : sheetContext.dragProps;
|
|
342
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
297
343
|
const contentStyle = {
|
|
298
|
-
...styles.content,
|
|
344
|
+
...applyStyles(styles.content, isUnstyled),
|
|
299
345
|
...styleProp
|
|
300
346
|
};
|
|
301
|
-
const scrollStyle =
|
|
302
|
-
...styles.scroller
|
|
303
|
-
};
|
|
347
|
+
const scrollStyle = applyStyles(styles.scroller, isUnstyled);
|
|
304
348
|
if (sheetContext.avoidKeyboard) {
|
|
305
349
|
scrollStyle.paddingBottom = "env(keyboard-inset-height, var(--keyboard-inset-height, 0px))";
|
|
306
350
|
}
|
|
@@ -331,42 +375,73 @@ var SheetContent = React4.forwardRef(
|
|
|
331
375
|
}
|
|
332
376
|
);
|
|
333
377
|
SheetContent.displayName = "SheetContent";
|
|
378
|
+
function SheetDragIndicator({
|
|
379
|
+
style,
|
|
380
|
+
className = "",
|
|
381
|
+
unstyled,
|
|
382
|
+
...rest
|
|
383
|
+
}) {
|
|
384
|
+
const sheetContext = useSheetContext();
|
|
385
|
+
const indicator1Transform = react.useTransform(
|
|
386
|
+
sheetContext.indicatorRotation,
|
|
387
|
+
(r) => `translateX(2px) rotate(${r}deg)`
|
|
388
|
+
);
|
|
389
|
+
const indicator2Transform = react.useTransform(
|
|
390
|
+
sheetContext.indicatorRotation,
|
|
391
|
+
(r) => `translateX(-2px) rotate(${ -1 * r}deg)`
|
|
392
|
+
);
|
|
393
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
394
|
+
const indicatorWrapperStyle = {
|
|
395
|
+
...applyStyles(styles.indicatorWrapper, isUnstyled),
|
|
396
|
+
...style
|
|
397
|
+
};
|
|
398
|
+
const indicatorStyle = applyStyles(styles.indicator, isUnstyled);
|
|
399
|
+
return /* @__PURE__ */ React4__default.default.createElement(
|
|
400
|
+
"div",
|
|
401
|
+
{
|
|
402
|
+
className: `react-modal-sheet-drag-indicator-container ${className}`,
|
|
403
|
+
style: indicatorWrapperStyle,
|
|
404
|
+
...rest
|
|
405
|
+
},
|
|
406
|
+
/* @__PURE__ */ React4__default.default.createElement(
|
|
407
|
+
react.motion.span,
|
|
408
|
+
{
|
|
409
|
+
className: "react-modal-sheet-drag-indicator",
|
|
410
|
+
style: { ...indicatorStyle, transform: indicator1Transform }
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
/* @__PURE__ */ React4__default.default.createElement(
|
|
414
|
+
react.motion.span,
|
|
415
|
+
{
|
|
416
|
+
className: "react-modal-sheet-drag-indicator",
|
|
417
|
+
style: { ...indicatorStyle, transform: indicator2Transform }
|
|
418
|
+
}
|
|
419
|
+
)
|
|
420
|
+
);
|
|
421
|
+
}
|
|
334
422
|
var SheetHeader = React4.forwardRef(
|
|
335
|
-
({ children, style, disableDrag, ...rest }, ref) => {
|
|
423
|
+
({ children, style, disableDrag, unstyled, className = "", ...rest }, ref) => {
|
|
336
424
|
const sheetContext = useSheetContext();
|
|
337
425
|
const dragConstraints = useDragConstraints();
|
|
338
426
|
const dragProps = disableDrag || sheetContext.disableDrag ? void 0 : sheetContext.dragProps;
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
(r) => `translateX(-2px) rotate(${ -1 * r}deg)`
|
|
346
|
-
);
|
|
427
|
+
const isUnstyled = unstyled ?? sheetContext.unstyled;
|
|
428
|
+
const headerWrapperStyle = {
|
|
429
|
+
...applyStyles(styles.headerWrapper, isUnstyled),
|
|
430
|
+
...style
|
|
431
|
+
};
|
|
432
|
+
const headerStyle = applyStyles(styles.header, isUnstyled);
|
|
347
433
|
return /* @__PURE__ */ React4__default.default.createElement(
|
|
348
434
|
react.motion.div,
|
|
349
435
|
{
|
|
350
436
|
...rest,
|
|
351
437
|
ref: mergeRefs([ref, dragConstraints.ref]),
|
|
352
|
-
style:
|
|
438
|
+
style: headerWrapperStyle,
|
|
439
|
+
className: `react-modal-sheet-header-container ${className}`,
|
|
353
440
|
...dragProps,
|
|
354
441
|
dragConstraints: dragConstraints.ref,
|
|
355
442
|
onMeasureDragConstraints: dragConstraints.onMeasure
|
|
356
443
|
},
|
|
357
|
-
children || /* @__PURE__ */ React4__default.default.createElement("div", { className: "react-modal-sheet-header", style:
|
|
358
|
-
react.motion.span,
|
|
359
|
-
{
|
|
360
|
-
className: "react-modal-sheet-drag-indicator",
|
|
361
|
-
style: { ...styles.indicator, transform: indicator1Transform }
|
|
362
|
-
}
|
|
363
|
-
), /* @__PURE__ */ React4__default.default.createElement(
|
|
364
|
-
react.motion.span,
|
|
365
|
-
{
|
|
366
|
-
className: "react-modal-sheet-drag-indicator",
|
|
367
|
-
style: { ...styles.indicator, transform: indicator2Transform }
|
|
368
|
-
}
|
|
369
|
-
))
|
|
444
|
+
children || /* @__PURE__ */ React4__default.default.createElement("div", { className: "react-modal-sheet-header", style: headerStyle }, /* @__PURE__ */ React4__default.default.createElement(SheetDragIndicator, null))
|
|
370
445
|
);
|
|
371
446
|
}
|
|
372
447
|
);
|
|
@@ -1007,20 +1082,21 @@ var Sheet = React4.forwardRef(
|
|
|
1007
1082
|
children,
|
|
1008
1083
|
className = "",
|
|
1009
1084
|
detent = "default",
|
|
1085
|
+
disableDismiss = false,
|
|
1010
1086
|
disableDrag: disableDragProp = false,
|
|
1011
1087
|
disableScrollLocking = false,
|
|
1012
|
-
disableDismiss = false,
|
|
1013
1088
|
dragCloseThreshold = DEFAULT_DRAG_CLOSE_THRESHOLD,
|
|
1014
1089
|
dragVelocityThreshold = DEFAULT_DRAG_VELOCITY_THRESHOLD,
|
|
1090
|
+
initialSnap,
|
|
1015
1091
|
isOpen,
|
|
1016
1092
|
modalEffectRootId,
|
|
1017
1093
|
modalEffectThreshold,
|
|
1018
1094
|
mountPoint,
|
|
1019
1095
|
prefersReducedMotion = false,
|
|
1020
1096
|
snapPoints: snapPointsProp,
|
|
1021
|
-
initialSnap,
|
|
1022
1097
|
style,
|
|
1023
1098
|
tweenConfig = DEFAULT_TWEEN_CONFIG,
|
|
1099
|
+
unstyled = false,
|
|
1024
1100
|
onOpenStart,
|
|
1025
1101
|
onOpenEnd,
|
|
1026
1102
|
onClose,
|
|
@@ -1219,6 +1295,7 @@ var Sheet = React4.forwardRef(
|
|
|
1219
1295
|
avoidKeyboard,
|
|
1220
1296
|
sheetBoundsRef,
|
|
1221
1297
|
sheetRef,
|
|
1298
|
+
unstyled,
|
|
1222
1299
|
y
|
|
1223
1300
|
};
|
|
1224
1301
|
const sheet = /* @__PURE__ */ React4__default.default.createElement(SheetContext.Provider, { value: context }, /* @__PURE__ */ React4__default.default.createElement(
|
|
@@ -1228,7 +1305,12 @@ var Sheet = React4.forwardRef(
|
|
|
1228
1305
|
ref,
|
|
1229
1306
|
"data-sheet-state": state,
|
|
1230
1307
|
className: `react-modal-sheet-root ${className}`,
|
|
1231
|
-
style: {
|
|
1308
|
+
style: {
|
|
1309
|
+
...applyStyles(styles.root, unstyled),
|
|
1310
|
+
zIndex,
|
|
1311
|
+
visibility,
|
|
1312
|
+
...style
|
|
1313
|
+
}
|
|
1232
1314
|
},
|
|
1233
1315
|
state !== "closed" ? children : null
|
|
1234
1316
|
));
|
|
@@ -1242,6 +1324,7 @@ Sheet.displayName = "Sheet";
|
|
|
1242
1324
|
var Sheet2 = Object.assign(Sheet, {
|
|
1243
1325
|
Container: SheetContainer,
|
|
1244
1326
|
Header: SheetHeader,
|
|
1327
|
+
DragIndicator: SheetDragIndicator,
|
|
1245
1328
|
Content: SheetContent,
|
|
1246
1329
|
Backdrop: SheetBackdrop
|
|
1247
1330
|
});
|