UNPKG

10.1 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.isHorizontal = isHorizontal;
11exports.getAnchor = getAnchor;
12exports.default = exports.styles = void 0;
13
14var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
16var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
17
18var React = _interopRequireWildcard(require("react"));
19
20var _propTypes = _interopRequireDefault(require("prop-types"));
21
22var _clsx = _interopRequireDefault(require("clsx"));
23
24var _Modal = _interopRequireDefault(require("../Modal"));
25
26var _Backdrop = _interopRequireDefault(require("../Backdrop"));
27
28var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
29
30var _Slide = _interopRequireDefault(require("../Slide"));
31
32var _Paper = _interopRequireDefault(require("../Paper"));
33
34var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
35
36var _transitions = require("../styles/transitions");
37
38var _useTheme = _interopRequireDefault(require("../styles/useTheme"));
39
40var styles = function styles(theme) {
41 return {
42 /* Styles applied to the root element. */
43 root: {},
44
45 /* Styles applied to the root element if `variant="permanent or persistent"`. */
46 docked: {
47 flex: '0 0 auto'
48 },
49
50 /* Styles applied to the `Paper` component. */
51 paper: {
52 overflowY: 'auto',
53 display: 'flex',
54 flexDirection: 'column',
55 height: '100%',
56 flex: '1 0 auto',
57 zIndex: theme.zIndex.drawer,
58 WebkitOverflowScrolling: 'touch',
59 // Add iOS momentum scrolling.
60 // temporary style
61 position: 'fixed',
62 top: 0,
63 // We disable the focus ring for mouse, touch and keyboard users.
64 // At some point, it would be better to keep it for keyboard users.
65 // :focus-ring CSS pseudo-class will help.
66 outline: 0
67 },
68
69 /* Styles applied to the `Paper` component if `anchor="left"`. */
70 paperAnchorLeft: {
71 left: 0,
72 right: 'auto'
73 },
74
75 /* Styles applied to the `Paper` component if `anchor="right"`. */
76 paperAnchorRight: {
77 left: 'auto',
78 right: 0
79 },
80
81 /* Styles applied to the `Paper` component if `anchor="top"`. */
82 paperAnchorTop: {
83 top: 0,
84 left: 0,
85 bottom: 'auto',
86 right: 0,
87 height: 'auto',
88 maxHeight: '100%'
89 },
90
91 /* Styles applied to the `Paper` component if `anchor="bottom"`. */
92 paperAnchorBottom: {
93 top: 'auto',
94 left: 0,
95 bottom: 0,
96 right: 0,
97 height: 'auto',
98 maxHeight: '100%'
99 },
100
101 /* Styles applied to the `Paper` component if `anchor="left"` and `variant` is not "temporary". */
102 paperAnchorDockedLeft: {
103 borderRight: "1px solid ".concat(theme.palette.divider)
104 },
105
106 /* Styles applied to the `Paper` component if `anchor="top"` and `variant` is not "temporary". */
107 paperAnchorDockedTop: {
108 borderBottom: "1px solid ".concat(theme.palette.divider)
109 },
110
111 /* Styles applied to the `Paper` component if `anchor="right"` and `variant` is not "temporary". */
112 paperAnchorDockedRight: {
113 borderLeft: "1px solid ".concat(theme.palette.divider)
114 },
115
116 /* Styles applied to the `Paper` component if `anchor="bottom"` and `variant` is not "temporary". */
117 paperAnchorDockedBottom: {
118 borderTop: "1px solid ".concat(theme.palette.divider)
119 },
120
121 /* Styles applied to the `Modal` component. */
122 modal: {}
123 };
124};
125
126exports.styles = styles;
127var oppositeDirection = {
128 left: 'right',
129 right: 'left',
130 top: 'down',
131 bottom: 'up'
132};
133
134function isHorizontal(anchor) {
135 return ['left', 'right'].indexOf(anchor) !== -1;
136}
137
138function getAnchor(theme, anchor) {
139 return theme.direction === 'rtl' && isHorizontal(anchor) ? oppositeDirection[anchor] : anchor;
140}
141
142var defaultTransitionDuration = {
143 enter: _transitions.duration.enteringScreen,
144 exit: _transitions.duration.leavingScreen
145};
146/**
147 * The props of the [Modal](/api/modal/) component are available
148 * when `variant="temporary"` is set.
149 */
150
151var Drawer = /*#__PURE__*/React.forwardRef(function Drawer(props, ref) {
152 var _props$anchor = props.anchor,
153 anchorProp = _props$anchor === void 0 ? 'left' : _props$anchor,
154 BackdropProps = props.BackdropProps,
155 children = props.children,
156 classes = props.classes,
157 className = props.className,
158 _props$elevation = props.elevation,
159 elevation = _props$elevation === void 0 ? 16 : _props$elevation,
160 _props$ModalProps = props.ModalProps;
161 _props$ModalProps = _props$ModalProps === void 0 ? {} : _props$ModalProps;
162 var BackdropPropsProp = _props$ModalProps.BackdropProps,
163 ModalProps = (0, _objectWithoutProperties2.default)(_props$ModalProps, ["BackdropProps"]),
164 onClose = props.onClose,
165 _props$open = props.open,
166 open = _props$open === void 0 ? false : _props$open,
167 _props$PaperProps = props.PaperProps,
168 PaperProps = _props$PaperProps === void 0 ? {} : _props$PaperProps,
169 SlideProps = props.SlideProps,
170 _props$TransitionComp = props.TransitionComponent,
171 TransitionComponent = _props$TransitionComp === void 0 ? _Slide.default : _props$TransitionComp,
172 _props$transitionDura = props.transitionDuration,
173 transitionDuration = _props$transitionDura === void 0 ? defaultTransitionDuration : _props$transitionDura,
174 _props$variant = props.variant,
175 variant = _props$variant === void 0 ? 'temporary' : _props$variant,
176 other = (0, _objectWithoutProperties2.default)(props, ["anchor", "BackdropProps", "children", "classes", "className", "elevation", "ModalProps", "onClose", "open", "PaperProps", "SlideProps", "TransitionComponent", "transitionDuration", "variant"]);
177 var theme = (0, _useTheme.default)(); // Let's assume that the Drawer will always be rendered on user space.
178 // We use this state is order to skip the appear transition during the
179 // initial mount of the component.
180
181 var mounted = React.useRef(false);
182 React.useEffect(function () {
183 mounted.current = true;
184 }, []);
185 var anchor = getAnchor(theme, anchorProp);
186 var drawer = /*#__PURE__*/React.createElement(_Paper.default, (0, _extends2.default)({
187 elevation: variant === 'temporary' ? elevation : 0,
188 square: true
189 }, PaperProps, {
190 className: (0, _clsx.default)(classes.paper, classes["paperAnchor".concat((0, _capitalize.default)(anchor))], PaperProps.className, variant !== 'temporary' && classes["paperAnchorDocked".concat((0, _capitalize.default)(anchor))])
191 }), children);
192
193 if (variant === 'permanent') {
194 return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({
195 className: (0, _clsx.default)(classes.root, classes.docked, className),
196 ref: ref
197 }, other), drawer);
198 }
199
200 var slidingDrawer = /*#__PURE__*/React.createElement(TransitionComponent, (0, _extends2.default)({
201 in: open,
202 direction: oppositeDirection[anchor],
203 timeout: transitionDuration,
204 appear: mounted.current
205 }, SlideProps), drawer);
206
207 if (variant === 'persistent') {
208 return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({
209 className: (0, _clsx.default)(classes.root, classes.docked, className),
210 ref: ref
211 }, other), slidingDrawer);
212 } // variant === temporary
213
214
215 return /*#__PURE__*/React.createElement(_Modal.default, (0, _extends2.default)({
216 BackdropProps: (0, _extends2.default)({}, BackdropProps, BackdropPropsProp, {
217 transitionDuration: transitionDuration
218 }),
219 BackdropComponent: _Backdrop.default,
220 className: (0, _clsx.default)(classes.root, classes.modal, className),
221 open: open,
222 onClose: onClose,
223 ref: ref
224 }, other, ModalProps), slidingDrawer);
225});
226process.env.NODE_ENV !== "production" ? Drawer.propTypes = {
227 // ----------------------------- Warning --------------------------------
228 // | These PropTypes are generated from the TypeScript type definitions |
229 // | To update them edit the d.ts file and run "yarn proptypes" |
230 // ----------------------------------------------------------------------
231
232 /**
233 * Side from which the drawer will appear.
234 */
235 anchor: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
236
237 /**
238 * @ignore
239 */
240 BackdropProps: _propTypes.default.object,
241
242 /**
243 * The contents of the drawer.
244 */
245 children: _propTypes.default.node,
246
247 /**
248 * Override or extend the styles applied to the component.
249 * See [CSS API](#css) below for more details.
250 */
251 classes: _propTypes.default.object,
252
253 /**
254 * @ignore
255 */
256 className: _propTypes.default.string,
257
258 /**
259 * The elevation of the drawer.
260 */
261 elevation: _propTypes.default.number,
262
263 /**
264 * Props applied to the [`Modal`](/api/modal/) element.
265 */
266 ModalProps: _propTypes.default.object,
267
268 /**
269 * Callback fired when the component requests to be closed.
270 *
271 * @param {object} event The event source of the callback.
272 */
273 onClose: _propTypes.default.func,
274
275 /**
276 * If `true`, the drawer is open.
277 */
278 open: _propTypes.default.bool,
279
280 /**
281 * Props applied to the [`Paper`](/api/paper/) element.
282 */
283 PaperProps: _propTypes.default.object,
284
285 /**
286 * Props applied to the [`Slide`](/api/slide/) element.
287 */
288 SlideProps: _propTypes.default.object,
289
290 /**
291 * The duration for the transition, in milliseconds.
292 * You may specify a single timeout for all transitions, or individually with an object.
293 */
294 transitionDuration: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
295 appear: _propTypes.default.number,
296 enter: _propTypes.default.number,
297 exit: _propTypes.default.number
298 })]),
299
300 /**
301 * The variant to use.
302 */
303 variant: _propTypes.default.oneOf(['permanent', 'persistent', 'temporary'])
304} : void 0;
305
306var _default = (0, _withStyles.default)(styles, {
307 name: 'MuiDrawer',
308 flip: false
309})(Drawer);
310
311exports.default = _default;
\No newline at end of file