1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | exports.__esModule = true;
|
6 | exports.DrawerCloseButton = exports.DrawerTransition = void 0;
|
7 |
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 |
|
10 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
11 |
|
12 | var _core = require("@emotion/core");
|
13 |
|
14 | var _renderprops = require("react-spring/renderprops.cjs");
|
15 |
|
16 | var _Modal = require("../Modal");
|
17 |
|
18 | exports.DrawerHeader = _Modal.ModalHeader;
|
19 | exports.DrawerFooter = _Modal.ModalFooter;
|
20 | exports.DrawerBody = _Modal.ModalBody;
|
21 | exports.DrawerOverlay = _Modal.ModalOverlay;
|
22 | exports.DrawerContent = _Modal.ModalContent;
|
23 |
|
24 | var _CloseButton = _interopRequireDefault(require("../CloseButton"));
|
25 |
|
26 | var _ColorModeProvider = require("../ColorModeProvider");
|
27 |
|
28 | var _react = require("react");
|
29 |
|
30 |
|
31 | var DrawerTransition = function DrawerTransition(_ref) {
|
32 | var isOpen = _ref.isOpen,
|
33 | children = _ref.children,
|
34 | _ref$duration = _ref.duration,
|
35 | duration = _ref$duration === void 0 ? 200 : _ref$duration,
|
36 | placement = _ref.placement,
|
37 | isFullHeight = _ref.isFullHeight;
|
38 | var placements = {
|
39 | bottom: {
|
40 | maxWidth: "100%",
|
41 | height: isFullHeight ? "100vh" : "auto",
|
42 | bottom: 0,
|
43 | left: 0,
|
44 | right: 0
|
45 | },
|
46 | top: {
|
47 | maxWidth: "100%",
|
48 | height: isFullHeight ? "100vh" : "auto",
|
49 | top: 0,
|
50 | left: 0,
|
51 | right: 0
|
52 | },
|
53 | left: {
|
54 | height: "100vh",
|
55 | left: 0,
|
56 | top: 0
|
57 | },
|
58 | right: {
|
59 | right: 0,
|
60 | top: 0,
|
61 | height: "100vh"
|
62 | }
|
63 | };
|
64 | var transitionOptions = {
|
65 | bottom: {
|
66 | offset: "100%",
|
67 | transform: function transform(y) {
|
68 | return "translateY(" + y + ")";
|
69 | }
|
70 | },
|
71 | top: {
|
72 | offset: "-100%",
|
73 | transform: function transform(y) {
|
74 | return "translateY(" + y + ")";
|
75 | }
|
76 | },
|
77 | left: {
|
78 | offset: "-100%",
|
79 | transform: function transform(x) {
|
80 | return "translateX(" + x + ")";
|
81 | }
|
82 | },
|
83 | right: {
|
84 | offset: "100%",
|
85 | transform: function transform(x) {
|
86 | return "translateX(" + x + ")";
|
87 | }
|
88 | }
|
89 | };
|
90 | var _transitionOptions$pl = transitionOptions[placement],
|
91 | transform = _transitionOptions$pl.transform,
|
92 | offset = _transitionOptions$pl.offset;
|
93 | return (0, _core.jsx)(_renderprops.Transition, {
|
94 | items: isOpen,
|
95 | from: {
|
96 | opacity: 0,
|
97 | offset: offset
|
98 | },
|
99 | enter: {
|
100 | opacity: 1,
|
101 | offset: "0%"
|
102 | },
|
103 | leave: {
|
104 | opacity: 0,
|
105 | offset: offset
|
106 | },
|
107 | config: {
|
108 | duration: duration
|
109 | }
|
110 | }, function (isOpen) {
|
111 | return isOpen && function (styles) {
|
112 | return children({
|
113 | reactSpringStyles: styles,
|
114 | transformStyle: transform(styles.offset),
|
115 | placementStyle: placements[placement]
|
116 | });
|
117 | };
|
118 | });
|
119 | };
|
120 |
|
121 | exports.DrawerTransition = DrawerTransition;
|
122 | var DrawerCloseButton = (0, _react.forwardRef)(function (_ref2, ref) {
|
123 | var onClick = _ref2.onClick,
|
124 | rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, ["onClick"]);
|
125 |
|
126 | var _useColorMode = (0, _ColorModeProvider.useColorMode)(),
|
127 | colorMode = _useColorMode.colorMode;
|
128 |
|
129 | var hoverColor = {
|
130 | light: "blackAlpha.100",
|
131 | dark: "whiteAlpha.100"
|
132 | };
|
133 | var activeColor = {
|
134 | light: "blackAlpha.200",
|
135 | dark: "whiteAlpha.200"
|
136 | };
|
137 | return (0, _core.jsx)(_CloseButton["default"], (0, _extends2["default"])({
|
138 | ref: ref,
|
139 | onClick: onClick,
|
140 | position: "fixed",
|
141 | zIndex: "1",
|
142 | top: "8px",
|
143 | right: "12px",
|
144 | _hover: {
|
145 | bg: hoverColor[colorMode]
|
146 | },
|
147 | _active: {
|
148 | bg: activeColor[colorMode]
|
149 | }
|
150 | }, rest));
|
151 | });
|
152 | exports.DrawerCloseButton = DrawerCloseButton; |
\ | No newline at end of file |