UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

116 lines 4.01 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; }; var __read = this && this.__read || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = this && this.__spreadArray || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import React, { useRef } from 'react'; import { createPortal } from 'react-dom'; import { cn } from '@bem-react/classname'; import { canUseDOM } from '../../lib/canUseDOM'; import { LayerManager } from '../LayerManager/LayerManager'; import './Modal.css'; export var cnModal = cn('Modal'); // TODO: implement and use focus catcher export var Modal = function (_a) { var _b; var visible = _a.visible, keepMounted = _a.keepMounted, _c = _a.contentVerticalAlign, align = _c === void 0 ? 'middle' : _c, onClose = _a.onClose, _d = _a.essentialRefs, essentialRefs = _d === void 0 ? [] : _d, propsHostRef = _a.hostRef, children = _a.children, innerRef = _a.innerRef, scope = _a.scope, zIndex = _a.zIndex, hideBackdrop = _a.hideBackdrop, props = __rest(_a, ["visible", "keepMounted", "contentVerticalAlign", "onClose", "essentialRefs", "hostRef", "children", "innerRef", "scope", "zIndex", "hideBackdrop"]); var contentRef = useRef(null); var scopeRef = (_b = scope === null || scope === void 0 ? void 0 : scope.current) !== null && _b !== void 0 ? _b : null; // skip render on SSR if (scopeRef !== null && !canUseDOM()) { return null; } // skip render non visible component if (!visible && !keepMounted) { return null; } var renderedComponent = /*#__PURE__*/React.createElement(LayerManager, { visible: visible, onClose: onClose, essentialRefs: __spreadArray([contentRef], __read(essentialRefs), false) }, /*#__PURE__*/React.createElement("div", __assign({ ref: innerRef }, props, { className: cnModal({ visible: visible }, [props.className]), style: __assign({ zIndex: zIndex }, props.style) }), !hideBackdrop && /*#__PURE__*/React.createElement("div", { className: cnModal('Overlay') }), /*#__PURE__*/React.createElement("div", { className: cnModal('Wrapper') }, /*#__PURE__*/React.createElement("div", { className: cnModal('Table') }, /*#__PURE__*/React.createElement("div", { className: cnModal('Cell', { align: align }) }, /*#__PURE__*/React.createElement("div", { ref: contentRef, className: cnModal('Content'), tabIndex: -1, role: "dialog", "aria-modal": true }, children)))))); return scopeRef !== null ? /*#__PURE__*/createPortal(renderedComponent, scopeRef) : renderedComponent; }; Modal.displayName = cnModal();