-
Notifications
You must be signed in to change notification settings - Fork 3
/
DrawerOverlay.js
88 lines (83 loc) · 2.06 KB
/
DrawerOverlay.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
/* eslint jsx-a11y/click-events-have-key-events: 0 */
import React from "react";
import PropTypes from "prop-types";
const transform = ({ position, swiping, open }) => {
switch (position) {
case "top":
return {
top: 0,
left: 0,
right: 0,
height: swiping || open ? "100%" : "20px",
};
case "right":
return {
right: 0,
top: 0,
bottom: 0,
width: swiping || open ? "100%" : "20px",
};
case "bottom":
return {
bottom: 0,
left: 0,
right: 0,
height: swiping || open ? "100%" : "20px",
};
case "left":
default:
return {
left: 0,
top: 0,
bottom: 0,
width: swiping || open ? "100%" : "20px",
};
}
};
const transition = ({ swiping, open }) => {
if (swiping) {
return "";
} else if (open) {
return "background-color .2s ease-in-out, width 0s 0s, height 0s 0s";
}
return "background-color .2s ease-in-out, width 0s .2s, height 0s 0s";
};
const DrawerOverlay = ({
position,
open,
swiping,
translation,
toggleDrawer,
handleTouchStart,
handleTouchMove,
handleTouchEnd,
style,
}) => (
<div
className="DrawerOverlay"
onClick={open ? toggleDrawer : null}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove(100)}
onTouchEnd={handleTouchEnd}
style={{
position: "fixed",
zIndex: 1,
backgroundColor: `rgba(0,0,0,${0.6 * translation / 100})`,
transition: transition({ swiping, open }),
...transform({ position, swiping, open }),
...style,
}}
/>
);
export default DrawerOverlay;
DrawerOverlay.propTypes = {
position: PropTypes.oneOf(["left", "right", "top", "bottom"]).isRequired,
open: PropTypes.bool.isRequired,
swiping: PropTypes.bool.isRequired,
translation: PropTypes.number.isRequired,
toggleDrawer: PropTypes.func.isRequired,
handleTouchStart: PropTypes.func.isRequired,
handleTouchMove: PropTypes.func.isRequired,
handleTouchEnd: PropTypes.func.isRequired,
style: PropTypes.object.isRequired,
};