@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
31 lines (30 loc) • 1.33 kB
JavaScript
"use client";
require("../../_virtual/_rolldown/runtime.cjs");
const require_get_default_z_index = require("../../core/utils/get-default-z-index/get-default-z-index.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region packages/@mantine/core/src/components/Modal/ModalStack.tsx
const ModalStackContext = (0, react.createContext)(null);
function ModalStack({ children }) {
const [stack, setStack] = (0, react.useState)([]);
const [maxZIndex, setMaxZIndex] = (0, react.useState)(require_get_default_z_index.getDefaultZIndex("modal"));
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModalStackContext, {
value: {
stack,
addModal: (id, zIndex) => {
setStack((current) => [...new Set([...current, id])]);
setMaxZIndex((current) => typeof zIndex === "number" && typeof current === "number" ? Math.max(current, zIndex) : current);
},
removeModal: (id) => setStack((current) => current.filter((currentId) => currentId !== id)),
getZIndex: (id) => `calc(${maxZIndex} + ${stack.indexOf(id)} + 1)`,
currentId: stack[stack.length - 1],
maxZIndex
},
children
});
}
ModalStack.displayName = "@mantine/core/ModalStack";
//#endregion
exports.ModalStack = ModalStack;
exports.ModalStackContext = ModalStackContext;
//# sourceMappingURL=ModalStack.cjs.map