-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDrawerContentContainer.js
82 lines (78 loc) · 1.9 KB
/
DrawerContentContainer.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
import React from "react";
import PropTypes from "prop-types";
const transform = ({ position, size, translation }) => {
switch (position) {
case "top":
return {
left: 0,
right: 0,
top: `-${size}%`,
height: `${size}%`,
transform: `translateY(${translation}%)`,
};
case "right":
return {
top: 0,
bottom: 0,
right: `-${size}%`,
width: `${size}%`,
transform: `translateX(${-translation}%)`,
};
case "bottom":
return {
left: 0,
right: 0,
bottom: `-${size}%`,
height: `${size}%`,
transform: `translateY(${-translation}%)`,
};
case "left":
default:
return {
top: 0,
bottom: 0,
left: `-${size}%`,
width: `${size}%`,
transform: `translateX(${translation}%)`,
};
}
};
const DrawerContentContainer = ({
position,
size,
swiping,
translation,
handleTouchStart,
handleTouchMove,
handleTouchEnd,
drawerContent,
style,
}) => (
<div
className="DrawerContentContainer"
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove(size)}
onTouchEnd={handleTouchEnd}
style={{
position: "fixed",
zIndex: 1,
transition: swiping ? "" : "transform .2s ease-in-out",
...transform({ position, size, translation }),
...style,
}}
>
{drawerContent}
</div>
);
export default DrawerContentContainer;
DrawerContentContainer.propTypes = {
position: PropTypes.oneOf(["left", "right", "top", "bottom"]).isRequired,
size: PropTypes.number.isRequired,
swiping: PropTypes.bool.isRequired,
translation: PropTypes.number.isRequired,
handleTouchStart: PropTypes.func.isRequired,
handleTouchMove: PropTypes.func.isRequired,
handleTouchEnd: PropTypes.func.isRequired,
drawerContent: PropTypes.element.isRequired,
style: PropTypes.object.isRequired,
};