UNPKG

@cimpress/react-components

Version:
33 lines 1.53 kB
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 { CSSTransition } from 'react-transition-group'; import { DisplayModal } from './Modal'; export const Modal = (_a) => { var { show } = _a, rest = __rest(_a, ["show"]); useEffect(() => { if (!show) { document.body.className = document.body.className.replace(/ ?modal-open/, ''); } else { document.body.className += document.body.className.length ? ' modal-open' : 'modal-open'; } // clean up any open modal classes from the body before unmounting the component return () => { document.body.className = document.body.className.replace(/ ?modal-open/, ''); }; }, [show]); const nodeRef = React.useRef(null); return (React.createElement(CSSTransition, { classNames: "modal", nodeRef: nodeRef, in: show, timeout: 300, exit: false, unmountOnExit: true }, React.createElement(DisplayModal, Object.assign({}, rest)))); }; //# sourceMappingURL=ModalTransitionController.js.map