UNPKG

react-simple-modal-controller

Version:
32 lines (31 loc) 1.44 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); }; import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect } from "react"; import { modal } from "../context/event"; import { useSyncModalStore } from "../context/useSyncModalStore"; import Portal from "./Portal"; export var ModalProvider = function (_a) { var children = _a.children; var modalInfos = useSyncModalStore(); useEffect(function () { return function () { modal.clear(); }; }, []); if (!modalInfos.length) return _jsx(_Fragment, { children: children }); return (_jsxs(_Fragment, { children: [children, _jsx(Portal, { children: modalInfos.map(function (topComponentInfo) { var _a; return (_jsx(topComponentInfo.Component, __assign({}, (topComponentInfo.resolve && { resolve: topComponentInfo.resolve }), ((_a = topComponentInfo === null || topComponentInfo === void 0 ? void 0 : topComponentInfo.props) !== null && _a !== void 0 ? _a : {})), topComponentInfo.id)); }) })] })); };