-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathSwipeableDrawer.js
758 lines (669 loc) · 24 KB
/
SwipeableDrawer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
'use client';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
import NoSsr from '../NoSsr';
import Drawer, { getAnchor, isHorizontal } from '../Drawer/Drawer';
import useForkRef from '../utils/useForkRef';
import ownerDocument from '../utils/ownerDocument';
import ownerWindow from '../utils/ownerWindow';
import useEventCallback from '../utils/useEventCallback';
import useEnhancedEffect from '../utils/useEnhancedEffect';
import { useTheme } from '../zero-styled';
import { useDefaultProps } from '../DefaultPropsProvider';
import { getTransitionProps } from '../transitions/utils';
import SwipeArea from './SwipeArea';
// This value is closed to what browsers are using internally to
// trigger a native scroll.
const UNCERTAINTY_THRESHOLD = 3; // px
// This is the part of the drawer displayed on touch start.
const DRAG_STARTED_SIGNAL = 20; // px
// We can only have one instance at the time claiming ownership for handling the swipe.
// Otherwise, the UX would be confusing.
// That's why we use a singleton here.
let claimedSwipeInstance = null;
// Exported for test purposes.
export function reset() {
claimedSwipeInstance = null;
}
function calculateCurrentX(anchor, touches, doc) {
return anchor === 'right' ? doc.body.offsetWidth - touches[0].pageX : touches[0].pageX;
}
function calculateCurrentY(anchor, touches, containerWindow) {
return anchor === 'bottom'
? containerWindow.innerHeight - touches[0].clientY
: touches[0].clientY;
}
function getMaxTranslate(horizontalSwipe, paperInstance) {
return horizontalSwipe ? paperInstance.clientWidth : paperInstance.clientHeight;
}
function getTranslate(currentTranslate, startLocation, open, maxTranslate) {
return Math.min(
Math.max(
open ? startLocation - currentTranslate : maxTranslate + startLocation - currentTranslate,
0,
),
maxTranslate,
);
}
/**
* @param {Element | null} element
* @param {Element} rootNode
*/
function getDomTreeShapes(element, rootNode) {
// Adapted from https://github.com/oliviertassinari/react-swipeable-views/blob/7666de1dba253b896911adf2790ce51467670856/packages/react-swipeable-views/src/SwipeableViews.js#L129
const domTreeShapes = [];
while (element && element !== rootNode.parentElement) {
const style = ownerWindow(rootNode).getComputedStyle(element);
if (
// Ignore the scroll children if the element is absolute positioned.
style.getPropertyValue('position') === 'absolute' ||
// Ignore the scroll children if the element has an overflowX hidden
style.getPropertyValue('overflow-x') === 'hidden'
) {
// noop
} else if (
(element.clientWidth > 0 && element.scrollWidth > element.clientWidth) ||
(element.clientHeight > 0 && element.scrollHeight > element.clientHeight)
) {
// Ignore the nodes that have no width.
// Keep elements with a scroll
domTreeShapes.push(element);
}
element = element.parentElement;
}
return domTreeShapes;
}
/**
* @param {object} param0
* @param {ReturnType<getDomTreeShapes>} param0.domTreeShapes
*/
function computeHasNativeHandler({ domTreeShapes, start, current, anchor }) {
// Adapted from https://github.com/oliviertassinari/react-swipeable-views/blob/7666de1dba253b896911adf2790ce51467670856/packages/react-swipeable-views/src/SwipeableViews.js#L175
const axisProperties = {
scrollPosition: {
x: 'scrollLeft',
y: 'scrollTop',
},
scrollLength: {
x: 'scrollWidth',
y: 'scrollHeight',
},
clientLength: {
x: 'clientWidth',
y: 'clientHeight',
},
};
return domTreeShapes.some((shape) => {
// Determine if we are going backward or forward.
let goingForward = current >= start;
if (anchor === 'top' || anchor === 'left') {
goingForward = !goingForward;
}
const axis = anchor === 'left' || anchor === 'right' ? 'x' : 'y';
const scrollPosition = Math.round(shape[axisProperties.scrollPosition[axis]]);
const areNotAtStart = scrollPosition > 0;
const areNotAtEnd =
scrollPosition + shape[axisProperties.clientLength[axis]] <
shape[axisProperties.scrollLength[axis]];
if ((goingForward && areNotAtEnd) || (!goingForward && areNotAtStart)) {
return true;
}
return false;
});
}
const iOS = typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent);
const SwipeableDrawer = React.forwardRef(function SwipeableDrawer(inProps, ref) {
const props = useDefaultProps({ name: 'MuiSwipeableDrawer', props: inProps });
const theme = useTheme();
const transitionDurationDefault = {
enter: theme.transitions.duration.enteringScreen,
exit: theme.transitions.duration.leavingScreen,
};
const {
anchor = 'left',
disableBackdropTransition = false,
disableDiscovery = false,
disableSwipeToOpen = iOS,
hideBackdrop,
hysteresis = 0.52,
allowSwipeInChildren = false,
minFlingVelocity = 450,
ModalProps: { BackdropProps, ...ModalPropsProp } = {},
onClose,
onOpen,
open = false,
PaperProps = {},
SwipeAreaProps,
swipeAreaWidth = 20,
transitionDuration = transitionDurationDefault,
variant = 'temporary', // Mobile first.
...other
} = props;
const [maybeSwiping, setMaybeSwiping] = React.useState(false);
const swipeInstance = React.useRef({
isSwiping: null,
});
const swipeAreaRef = React.useRef();
const backdropRef = React.useRef();
const paperRef = React.useRef();
const handleRef = useForkRef(PaperProps.ref, paperRef);
const touchDetected = React.useRef(false);
// Ref for transition duration based on / to match swipe speed
const calculatedDurationRef = React.useRef();
// Use a ref so the open value used is always up to date inside useCallback.
useEnhancedEffect(() => {
calculatedDurationRef.current = null;
}, [open]);
const setPosition = React.useCallback(
(translate, options = {}) => {
const { mode = null, changeTransition = true } = options;
const anchorRtl = getAnchor(theme, anchor);
const rtlTranslateMultiplier = ['right', 'bottom'].includes(anchorRtl) ? 1 : -1;
const horizontalSwipe = isHorizontal(anchor);
const transform = horizontalSwipe
? `translate(${rtlTranslateMultiplier * translate}px, 0)`
: `translate(0, ${rtlTranslateMultiplier * translate}px)`;
const drawerStyle = paperRef.current.style;
drawerStyle.webkitTransform = transform;
drawerStyle.transform = transform;
let transition = '';
if (mode) {
transition = theme.transitions.create(
'all',
getTransitionProps(
{
easing: undefined,
style: undefined,
timeout: transitionDuration,
},
{
mode,
},
),
);
}
if (changeTransition) {
drawerStyle.webkitTransition = transition;
drawerStyle.transition = transition;
}
if (!disableBackdropTransition && !hideBackdrop) {
const backdropStyle = backdropRef.current.style;
backdropStyle.opacity = 1 - translate / getMaxTranslate(horizontalSwipe, paperRef.current);
if (changeTransition) {
backdropStyle.webkitTransition = transition;
backdropStyle.transition = transition;
}
}
},
[anchor, disableBackdropTransition, hideBackdrop, theme, transitionDuration],
);
const handleBodyTouchEnd = useEventCallback((nativeEvent) => {
if (!touchDetected.current) {
return;
}
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- claimedSwipeInstance is a singleton
claimedSwipeInstance = null;
touchDetected.current = false;
ReactDOM.flushSync(() => {
setMaybeSwiping(false);
});
// The swipe wasn't started.
if (!swipeInstance.current.isSwiping) {
swipeInstance.current.isSwiping = null;
return;
}
swipeInstance.current.isSwiping = null;
const anchorRtl = getAnchor(theme, anchor);
const horizontal = isHorizontal(anchor);
let current;
if (horizontal) {
current = calculateCurrentX(
anchorRtl,
nativeEvent.changedTouches,
ownerDocument(nativeEvent.currentTarget),
);
} else {
current = calculateCurrentY(
anchorRtl,
nativeEvent.changedTouches,
ownerWindow(nativeEvent.currentTarget),
);
}
const startLocation = horizontal ? swipeInstance.current.startX : swipeInstance.current.startY;
const maxTranslate = getMaxTranslate(horizontal, paperRef.current);
const currentTranslate = getTranslate(current, startLocation, open, maxTranslate);
const translateRatio = currentTranslate / maxTranslate;
if (Math.abs(swipeInstance.current.velocity) > minFlingVelocity) {
// Calculate transition duration to match swipe speed
calculatedDurationRef.current =
Math.abs((maxTranslate - currentTranslate) / swipeInstance.current.velocity) * 1000;
}
if (open) {
if (swipeInstance.current.velocity > minFlingVelocity || translateRatio > hysteresis) {
onClose();
} else {
// Reset the position, the swipe was aborted.
setPosition(0, {
mode: 'exit',
});
}
return;
}
if (swipeInstance.current.velocity < -minFlingVelocity || 1 - translateRatio > hysteresis) {
onOpen();
} else {
// Reset the position, the swipe was aborted.
setPosition(getMaxTranslate(horizontal, paperRef.current), {
mode: 'enter',
});
}
});
const startMaybeSwiping = (force = false) => {
if (!maybeSwiping) {
// on Safari Mobile, if you want to be able to have the 'click' event fired on child elements, nothing in the DOM can be changed.
// this is because Safari Mobile will not fire any mouse events (still fires touch though) if the DOM changes during mousemove.
// so do this change on first touchmove instead of touchstart
if (force || !(disableDiscovery && allowSwipeInChildren)) {
ReactDOM.flushSync(() => {
setMaybeSwiping(true);
});
}
const horizontalSwipe = isHorizontal(anchor);
if (!open && paperRef.current) {
// The ref may be null when a parent component updates while swiping.
setPosition(
getMaxTranslate(horizontalSwipe, paperRef.current) +
(disableDiscovery ? 15 : -DRAG_STARTED_SIGNAL),
{
changeTransition: false,
},
);
}
swipeInstance.current.velocity = 0;
swipeInstance.current.lastTime = null;
swipeInstance.current.lastTranslate = null;
swipeInstance.current.paperHit = false;
touchDetected.current = true;
}
};
const handleBodyTouchMove = useEventCallback((nativeEvent) => {
// the ref may be null when a parent component updates while swiping
if (!paperRef.current || !touchDetected.current) {
return;
}
// We are not supposed to handle this touch move because the swipe was started in a scrollable container in the drawer
if (claimedSwipeInstance !== null && claimedSwipeInstance !== swipeInstance.current) {
return;
}
startMaybeSwiping(true);
const anchorRtl = getAnchor(theme, anchor);
const horizontalSwipe = isHorizontal(anchor);
const currentX = calculateCurrentX(
anchorRtl,
nativeEvent.touches,
ownerDocument(nativeEvent.currentTarget),
);
const currentY = calculateCurrentY(
anchorRtl,
nativeEvent.touches,
ownerWindow(nativeEvent.currentTarget),
);
if (open && paperRef.current.contains(nativeEvent.target) && claimedSwipeInstance === null) {
const domTreeShapes = getDomTreeShapes(nativeEvent.target, paperRef.current);
const hasNativeHandler = computeHasNativeHandler({
domTreeShapes,
start: horizontalSwipe ? swipeInstance.current.startX : swipeInstance.current.startY,
current: horizontalSwipe ? currentX : currentY,
anchor,
});
if (hasNativeHandler) {
claimedSwipeInstance = true;
return;
}
claimedSwipeInstance = swipeInstance.current;
}
// We don't know yet.
if (swipeInstance.current.isSwiping == null) {
const dx = Math.abs(currentX - swipeInstance.current.startX);
const dy = Math.abs(currentY - swipeInstance.current.startY);
const definitelySwiping = horizontalSwipe
? dx > dy && dx > UNCERTAINTY_THRESHOLD
: dy > dx && dy > UNCERTAINTY_THRESHOLD;
if (definitelySwiping && nativeEvent.cancelable) {
nativeEvent.preventDefault();
}
if (
definitelySwiping === true ||
(horizontalSwipe ? dy > UNCERTAINTY_THRESHOLD : dx > UNCERTAINTY_THRESHOLD)
) {
swipeInstance.current.isSwiping = definitelySwiping;
if (!definitelySwiping) {
handleBodyTouchEnd(nativeEvent);
return;
}
// Shift the starting point.
swipeInstance.current.startX = currentX;
swipeInstance.current.startY = currentY;
// Compensate for the part of the drawer displayed on touch start.
if (!disableDiscovery && !open) {
if (horizontalSwipe) {
swipeInstance.current.startX -= DRAG_STARTED_SIGNAL;
} else {
swipeInstance.current.startY -= DRAG_STARTED_SIGNAL;
}
}
}
}
if (!swipeInstance.current.isSwiping) {
return;
}
const maxTranslate = getMaxTranslate(horizontalSwipe, paperRef.current);
let startLocation = horizontalSwipe
? swipeInstance.current.startX
: swipeInstance.current.startY;
if (open && !swipeInstance.current.paperHit) {
startLocation = Math.min(startLocation, maxTranslate);
}
const translate = getTranslate(
horizontalSwipe ? currentX : currentY,
startLocation,
open,
maxTranslate,
);
if (open) {
if (!swipeInstance.current.paperHit) {
const paperHit = horizontalSwipe ? currentX < maxTranslate : currentY < maxTranslate;
if (paperHit) {
swipeInstance.current.paperHit = true;
swipeInstance.current.startX = currentX;
swipeInstance.current.startY = currentY;
} else {
return;
}
} else if (translate === 0) {
swipeInstance.current.startX = currentX;
swipeInstance.current.startY = currentY;
}
}
if (swipeInstance.current.lastTranslate === null) {
swipeInstance.current.lastTranslate = translate;
swipeInstance.current.lastTime = performance.now() + 1;
}
const velocity =
((translate - swipeInstance.current.lastTranslate) /
(performance.now() - swipeInstance.current.lastTime)) *
1e3;
// Low Pass filter.
swipeInstance.current.velocity = swipeInstance.current.velocity * 0.4 + velocity * 0.6;
swipeInstance.current.lastTranslate = translate;
swipeInstance.current.lastTime = performance.now();
// We are swiping, let's prevent the scroll event on iOS.
if (nativeEvent.cancelable) {
nativeEvent.preventDefault();
}
setPosition(translate);
});
const handleBodyTouchStart = useEventCallback((nativeEvent) => {
// We are not supposed to handle this touch move.
// Example of use case: ignore the event if there is a Slider.
if (nativeEvent.defaultPrevented) {
return;
}
// We can only have one node at the time claiming ownership for handling the swipe.
if (nativeEvent.defaultMuiPrevented) {
return;
}
// At least one element clogs the drawer interaction zone.
if (
open &&
(hideBackdrop || !backdropRef.current.contains(nativeEvent.target)) &&
!paperRef.current.contains(nativeEvent.target)
) {
return;
}
const anchorRtl = getAnchor(theme, anchor);
const horizontalSwipe = isHorizontal(anchor);
const currentX = calculateCurrentX(
anchorRtl,
nativeEvent.touches,
ownerDocument(nativeEvent.currentTarget),
);
const currentY = calculateCurrentY(
anchorRtl,
nativeEvent.touches,
ownerWindow(nativeEvent.currentTarget),
);
if (!open) {
// logic for if swipe should be ignored:
// if disableSwipeToOpen
// if target != swipeArea, and target is not a child of paper ref
// if is a child of paper ref, and `allowSwipeInChildren` does not allow it
if (
disableSwipeToOpen ||
!(
nativeEvent.target === swipeAreaRef.current ||
(paperRef.current?.contains(nativeEvent.target) &&
(typeof allowSwipeInChildren === 'function'
? allowSwipeInChildren(nativeEvent, swipeAreaRef.current, paperRef.current)
: allowSwipeInChildren))
)
) {
return;
}
if (horizontalSwipe) {
if (currentX > swipeAreaWidth) {
return;
}
} else if (currentY > swipeAreaWidth) {
return;
}
}
nativeEvent.defaultMuiPrevented = true;
claimedSwipeInstance = null;
swipeInstance.current.startX = currentX;
swipeInstance.current.startY = currentY;
startMaybeSwiping();
});
React.useEffect(() => {
if (variant === 'temporary') {
const doc = ownerDocument(paperRef.current);
doc.addEventListener('touchstart', handleBodyTouchStart);
// A blocking listener prevents Firefox's navbar to auto-hide on scroll.
// It only needs to prevent scrolling on the drawer's content when open.
// When closed, the overlay prevents scrolling.
doc.addEventListener('touchmove', handleBodyTouchMove, { passive: !open });
doc.addEventListener('touchend', handleBodyTouchEnd);
return () => {
doc.removeEventListener('touchstart', handleBodyTouchStart);
doc.removeEventListener('touchmove', handleBodyTouchMove, { passive: !open });
doc.removeEventListener('touchend', handleBodyTouchEnd);
};
}
return undefined;
}, [variant, open, handleBodyTouchStart, handleBodyTouchMove, handleBodyTouchEnd]);
React.useEffect(
() => () => {
// We need to release the lock.
if (claimedSwipeInstance === swipeInstance.current) {
claimedSwipeInstance = null;
}
},
[],
);
React.useEffect(() => {
if (!open) {
setMaybeSwiping(false);
}
}, [open]);
return (
<React.Fragment>
<Drawer
open={variant === 'temporary' && maybeSwiping ? true : open}
variant={variant}
ModalProps={{
BackdropProps: {
...BackdropProps,
ref: backdropRef,
},
// Ensures that paperRef.current will be defined inside the touch start event handler
// See https://github.com/mui/material-ui/issues/30414 for more information
...(variant === 'temporary' && {
keepMounted: true,
}),
...ModalPropsProp,
}}
hideBackdrop={hideBackdrop}
PaperProps={{
...PaperProps,
style: {
pointerEvents: variant === 'temporary' && !open && !allowSwipeInChildren ? 'none' : '',
...PaperProps.style,
},
ref: handleRef,
}}
anchor={anchor}
transitionDuration={calculatedDurationRef.current || transitionDuration}
onClose={onClose}
ref={ref}
{...other}
/>
{!disableSwipeToOpen && variant === 'temporary' && (
<NoSsr>
<SwipeArea
anchor={anchor}
ref={swipeAreaRef}
width={swipeAreaWidth}
{...SwipeAreaProps}
/>
</NoSsr>
)}
</React.Fragment>
);
});
SwipeableDrawer.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* If set to true, the swipe event will open the drawer even if the user begins the swipe on one of the drawer's children.
* This can be useful in scenarios where the drawer is partially visible.
* You can customize it further with a callback that determines which children the user can drag over to open the drawer
* (for example, to ignore other elements that handle touch move events, like sliders).
*
* @param {TouchEvent} event The 'touchstart' event
* @param {HTMLDivElement} swipeArea The swipe area element
* @param {HTMLDivElement} paper The drawer's paper element
*
* @default false
*/
allowSwipeInChildren: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
/**
* @ignore
*/
anchor: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Disable the backdrop transition.
* This can improve the FPS on low-end devices.
* @default false
*/
disableBackdropTransition: PropTypes.bool,
/**
* If `true`, touching the screen near the edge of the drawer will not slide in the drawer a bit
* to promote accidental discovery of the swipe gesture.
* @default false
*/
disableDiscovery: PropTypes.bool,
/**
* If `true`, swipe to open is disabled. This is useful in browsers where swiping triggers
* navigation actions. Swipe to open is disabled on iOS browsers by default.
* @default typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent)
*/
disableSwipeToOpen: PropTypes.bool,
/**
* @ignore
*/
hideBackdrop: PropTypes.bool,
/**
* Affects how far the drawer must be opened/closed to change its state.
* Specified as percent (0-1) of the width of the drawer
* @default 0.52
*/
hysteresis: PropTypes.number,
/**
* Defines, from which (average) velocity on, the swipe is
* defined as complete although hysteresis isn't reached.
* Good threshold is between 250 - 1000 px/s
* @default 450
*/
minFlingVelocity: PropTypes.number,
/**
* @ignore
*/
ModalProps: PropTypes /* @typescript-to-proptypes-ignore */.shape({
BackdropProps: PropTypes.shape({
component: elementTypeAcceptingRef,
}),
}),
/**
* Callback fired when the component requests to be closed.
*
* @param {React.SyntheticEvent<{}>} event The event source of the callback.
*/
onClose: PropTypes.func.isRequired,
/**
* Callback fired when the component requests to be opened.
*
* @param {React.SyntheticEvent<{}>} event The event source of the callback.
*/
onOpen: PropTypes.func.isRequired,
/**
* If `true`, the component is shown.
* @default false
*/
open: PropTypes.bool,
/**
* @ignore
*/
PaperProps: PropTypes /* @typescript-to-proptypes-ignore */.shape({
component: elementTypeAcceptingRef,
style: PropTypes.object,
}),
/**
* The element is used to intercept the touch events on the edge.
*/
SwipeAreaProps: PropTypes.object,
/**
* The width of the left most (or right most) area in `px` that
* the drawer can be swiped open from.
* @default 20
*/
swipeAreaWidth: PropTypes.number,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
* @default {
* enter: theme.transitions.duration.enteringScreen,
* exit: theme.transitions.duration.leavingScreen,
* }
*/
transitionDuration: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
appear: PropTypes.number,
enter: PropTypes.number,
exit: PropTypes.number,
}),
]),
/**
* @ignore
*/
variant: PropTypes.oneOf(['permanent', 'persistent', 'temporary']),
};
export default SwipeableDrawer;