UNPKG

@momentum-ui/react-collaboration

Version:

Cisco Momentum UI Framework for React Collaboration Applications

69 lines 2.91 kB
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 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useEffect } from 'react'; import { Dialog as MdcDialog } from '@momentum-design/components/dist/react'; import { DEFAULTS } from './Dialog.constants'; import { setupHideOnPlugin } from '../Popover/tippy-plugins/hideOnEscPlugin'; // create a global stack of dialogs var dialogStack = []; /** * @deprecated Use the equivalent from momentum.design (NPM: `@momentum-design/components/dist/react`) */ var Dialog = function (props) { var children = props.children, _a = props.size, size = _a === void 0 ? DEFAULTS.SIZE : _a, other = __rest(props, ["children", "size"]); var dialogProps = __assign({ visible: true }, other); useEffect(function () { // override the default hideOnEsc plugin to handle Esc key press // for any tooltips and popovers inside the dialog // Remove this once Popover, Tooltip etc are migrated to new momentum-design components setupHideOnPlugin({ hideKeys: ['Escape'], stopEventPropagation: true, hideListenerTarget: 'this', }); // Add the dialog to the global stack if (props.id) { dialogStack.push(props.id); } return function () { // Remove the dialog from the global stack if (props.id) { var index = dialogStack.indexOf(props.id); dialogStack.splice(index, 1); } // cleanup the hideOnEsc plugin only if stack is empty if (dialogStack.length === 0) { // Remove the event listener for Esc key press setupHideOnPlugin({ hideKeys: ['Escape'], stopEventPropagation: false, hideListenerTarget: 'window', }); } }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (React.createElement(MdcDialog, __assign({}, dialogProps, { size: size }), children)); }; export default Dialog; //# sourceMappingURL=Dialog.js.map