UNPKG

@whatoplay/react-drawer

Version:
624 lines (581 loc) 25.4 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("react"), require("classnames"), require("@material/list/dist/mdc.list.js"), require("@material/drawer/dist/mdc.drawer.js")); else if(typeof define === 'function' && define.amd) define(["react", "classnames", "@material/list/dist/mdc.list.js", "@material/drawer/dist/mdc.drawer.js"], factory); else { var a = typeof exports === 'object' ? factory(require("react"), require("classnames"), require("@material/list/dist/mdc.list.js"), require("@material/drawer/dist/mdc.drawer.js")) : factory(root["react"], root["classnames"], root["@material/list/dist/mdc.list.js"], root["@material/drawer/dist/mdc.drawer.js"]); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 30); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_0__; /***/ }), /***/ 1: /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_1__; /***/ }), /***/ 3: /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_3__; /***/ }), /***/ 30: /***/ (function(module, exports, __webpack_require__) { "use strict"; // The MIT License // // Copyright (c) 2018 Google, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __webpack_require__(0); var classnames = __webpack_require__(1); var mdc_drawer_1 = __webpack_require__(4); // @ts-ignore no .d.ts file var mdc_list_1 = __webpack_require__(3); var Header_1 = __webpack_require__(31); exports.DrawerHeader = Header_1.default; var Content_1 = __webpack_require__(32); exports.DrawerContent = Content_1.default; var Subtitle_1 = __webpack_require__(33); exports.DrawerSubtitle = Subtitle_1.default; var Title_1 = __webpack_require__(34); exports.DrawerTitle = Title_1.default; var AppContent_1 = __webpack_require__(35); exports.DrawerAppContent = AppContent_1.default; var listCssClasses = mdc_list_1.MDCListFoundation.cssClasses; ; ; var Drawer = /** @class */ (function (_super) { __extends(Drawer, _super); function Drawer() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.previousFocus = null; _this.drawerElement = React.createRef(); _this.state = { classList: new Set() }; _this.initFoundation = function () { var _a = _this.props, dismissible = _a.dismissible, modal = _a.modal; if (_this.foundation) { _this.foundation.destroy(); } if (dismissible) { _this.foundation = new mdc_drawer_1.MDCDismissibleDrawerFoundation(_this.adapter); _this.foundation.init(); } else if (modal) { _this.initializeFocusTrap(); _this.foundation = new mdc_drawer_1.MDCModalDrawerFoundation(_this.adapter); _this.foundation.init(); } }; _this.initializeFocusTrap = function () { _this.focusTrap = mdc_drawer_1.util.createFocusTrapInstance(_this.drawerElement.current); }; _this.handleKeyDown = function (evt) { _this.props.onKeyDown(evt); if (!_this.foundation) return; _this.foundation.handleKeydown(evt); }; _this.handleTransitionEnd = function (evt) { _this.props.onTransitionEnd(evt); if (!_this.foundation) return; _this.foundation.handleTransitionEnd(evt); }; return _this; } Drawer.prototype.componentDidMount = function () { var open = this.props.open; this.initFoundation(); if (open && this.foundation) { this.foundation.open(); } }; Drawer.prototype.componentDidUpdate = function (prevProps) { var _a = this.props, dismissible = _a.dismissible, modal = _a.modal, open = _a.open; var changedToModal = prevProps.modal !== this.props.modal; var changedToDismissible = prevProps.dismissible !== this.props.dismissible; if (!dismissible && !modal) return; if (changedToModal || changedToDismissible) { this.initFoundation(); } if (open !== prevProps.open) { open ? this.foundation.open() : this.foundation.close(); } }; Drawer.prototype.componentWillUnmount = function () { if (!this.foundation) return; this.foundation.destroy(); }; Object.defineProperty(Drawer.prototype, "classes", { get: function () { var classList = this.state.classList; var _a = this.props, className = _a.className, dismissible = _a.dismissible, modal = _a.modal; return classnames('mdc-drawer', Array.from(classList), className, { 'mdc-drawer--dismissible': dismissible, 'mdc-drawer--modal': modal, }); }, enumerable: true, configurable: true }); Object.defineProperty(Drawer.prototype, "adapter", { get: function () { var _this = this; return { addClass: function (className) { var classList = _this.state.classList; classList.add(className); _this.setState({ classList: classList }); }, removeClass: function (className) { var classList = _this.state.classList; classList.delete(className); _this.setState({ classList: classList }); }, hasClass: function (className) { return _this.classes.split(' ').includes(className); }, elementHasClass: function (element, className) { return element.classList.contains(className); }, saveFocus: function () { _this.previousFocus = document.activeElement; }, restoreFocus: function () { var drawerElement = _this.drawerElement && _this.drawerElement.current; if (drawerElement && _this.previousFocus && _this.previousFocus.focus && drawerElement.contains(document.activeElement)) { _this.previousFocus.focus(); } }, focusActiveNavigationItem: function () { var drawerElement = _this.drawerElement && _this.drawerElement.current; if (!drawerElement) return; var activeNavItemEl = drawerElement.querySelector("." + listCssClasses.LIST_ITEM_ACTIVATED_CLASS); if (activeNavItemEl) { activeNavItemEl.focus(); } }, notifyClose: this.props.onClose, notifyOpen: this.props.onOpen, trapFocus: function () { if (_this.focusTrap) { _this.focusTrap.activate(); } }, releaseFocus: function () { if (_this.focusTrap) { _this.focusTrap.deactivate(); } }, }; }, enumerable: true, configurable: true }); Drawer.prototype.render = function () { var _a = this.props, /* eslint-disable no-unused-vars */ onClose = _a.onClose, onOpen = _a.onOpen, onKeyDown = _a.onKeyDown, onTransitionEnd = _a.onTransitionEnd, dismissible = _a.dismissible, children = _a.children, className = _a.className, /* eslint-enable no-unused-vars */ Tag = _a.tag, modal = _a.modal, otherProps = __rest(_a, ["onClose", "onOpen", "onKeyDown", "onTransitionEnd", "dismissible", "children", "className", "tag", "modal"]); return (React.createElement(React.Fragment, null, React.createElement(Tag, __assign({ className: this.classes, ref: this.drawerElement, onKeyDown: this.handleKeyDown, onTransitionEnd: this.handleTransitionEnd }, otherProps), children), modal ? this.renderScrim() : null)); }; Drawer.prototype.renderScrim = function () { var _this = this; return (React.createElement("div", { className: 'mdc-drawer-scrim', onClick: function () { return _this.foundation.handleScrimClick(); } })); }; Drawer.defaultProps = { className: '', children: null, open: false, onOpen: function () { }, onClose: function () { }, onTransitionEnd: function () { }, onKeyDown: function () { }, tag: 'aside', dismissible: false, modal: false, }; return Drawer; }(React.Component)); exports.default = Drawer; /***/ }), /***/ 31: /***/ (function(module, exports, __webpack_require__) { "use strict"; // The MIT License // // Copyright (c) 2018 Google, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __webpack_require__(0); var classnames = __webpack_require__(1); ; var DrawerHeader = function (_a) { var _b = _a.tag, Tag = _b === void 0 ? 'div' : _b, children = _a.children, _c = _a.className, className = _c === void 0 ? '' : _c, otherProps = __rest(_a, ["tag", "children", "className"]) // eslint-disable-line react/prop-types ; return ( // https://github.com/Microsoft/TypeScript/issues/28892 // @ts-ignore React.createElement(Tag, __assign({ className: classnames('mdc-drawer__header', className) }, otherProps), children)); }; exports.default = DrawerHeader; /***/ }), /***/ 32: /***/ (function(module, exports, __webpack_require__) { "use strict"; // The MIT License // // Copyright (c) 2018 Google, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __webpack_require__(0); var classnames = __webpack_require__(1); ; var DrawerContent = function (_a) { var _b = _a.tag, Tag = _b === void 0 ? 'div' : _b, children = _a.children, _c = _a.className, className = _c === void 0 ? '' : _c, otherProps = __rest(_a, ["tag", "children", "className"]) // eslint-disable-line react/prop-types ; return ( // https://github.com/Microsoft/TypeScript/issues/28892 // @ts-ignore React.createElement(Tag, __assign({ className: classnames('mdc-drawer__content', className) }, otherProps), children)); }; exports.default = DrawerContent; /***/ }), /***/ 33: /***/ (function(module, exports, __webpack_require__) { "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __webpack_require__(0); var classnames = __webpack_require__(1); ; var DrawerSubTitle = function (_a) { var _b = _a.tag, Tag = _b === void 0 ? 'h6' : _b, children = _a.children, _c = _a.className, className = _c === void 0 ? '' : _c, otherProps = __rest(_a, ["tag", "children", "className"]) // eslint-disable-line react/prop-types ; return ( // https://github.com/Microsoft/TypeScript/issues/28892 // @ts-ignore React.createElement(Tag, __assign({ className: classnames('mdc-drawer__subtitle', className) }, otherProps), children)); }; exports.default = DrawerSubTitle; /***/ }), /***/ 34: /***/ (function(module, exports, __webpack_require__) { "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __webpack_require__(0); var classnames = __webpack_require__(1); ; var DrawerTitle = function (_a) { var _b = _a.tag, Tag = _b === void 0 ? 'h3' : _b, children = _a.children, _c = _a.className, className = _c === void 0 ? '' : _c, otherProps = __rest(_a, ["tag", "children", "className"]) // eslint-disable-line react/prop-types ; return ( // https://github.com/Microsoft/TypeScript/issues/28892 // @ts-ignore React.createElement(Tag, __assign({ className: classnames('mdc-drawer__title', className) }, otherProps), children)); }; exports.default = DrawerTitle; /***/ }), /***/ 35: /***/ (function(module, exports, __webpack_require__) { "use strict"; // The MIT License // // Copyright (c) 2018 Google, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __webpack_require__(0); var classnames = __webpack_require__(1); ; var DrawerAppContent = function (_a) { var _b = _a.tag, Tag = _b === void 0 ? 'div' : _b, children = _a.children, _c = _a.className, className = _c === void 0 ? '' : _c, otherProps = __rest(_a, ["tag", "children", "className"]) // eslint-disable-line react/prop-types ; return ( // https://github.com/Microsoft/TypeScript/issues/28892 // @ts-ignore React.createElement(Tag, __assign({ className: classnames('mdc-drawer-app-content', className) }, otherProps), children)); }; exports.default = DrawerAppContent; /***/ }), /***/ 4: /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_4__; /***/ }) /******/ }); }); //# sourceMappingURL=drawer-wtp.js.map