@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
74 lines (73 loc) • 3.01 kB
JavaScript
"use client";
import { getDefaultZIndex } from "../../core/utils/get-default-z-index/get-default-z-index.mjs";
import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs";
import { factory } from "../../core/factory/factory.mjs";
import Drawer_module_default from "./Drawer.module.mjs";
import { DrawerBody } from "./DrawerBody.mjs";
import { DrawerCloseButton } from "./DrawerCloseButton.mjs";
import { DrawerContent } from "./DrawerContent.mjs";
import { DrawerHeader } from "./DrawerHeader.mjs";
import { DrawerOverlay } from "./DrawerOverlay.mjs";
import { DrawerRoot } from "./DrawerRoot.mjs";
import { DrawerStack, DrawerStackContext } from "./DrawerStack.mjs";
import { DrawerTitle } from "./DrawerTitle.mjs";
import { use, useEffect } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region packages/@mantine/core/src/components/Drawer/Drawer.tsx
const defaultProps = {
closeOnClickOutside: true,
withinPortal: true,
lockScroll: true,
trapFocus: true,
returnFocus: true,
closeOnEscape: true,
keepMounted: false,
zIndex: getDefaultZIndex("modal"),
withOverlay: true,
withCloseButton: true
};
const Drawer = factory((_props) => {
const { title, withOverlay, overlayProps, withCloseButton, closeButtonProps, children, opened, stackId, zIndex, ...others } = useProps("Drawer", defaultProps, _props);
const ctx = use(DrawerStackContext);
const hasHeader = !!title || withCloseButton;
const stackProps = ctx && stackId ? {
closeOnEscape: ctx.currentId === stackId,
trapFocus: ctx.currentId === stackId,
zIndex: ctx.getZIndex(stackId)
} : {};
const overlayVisible = withOverlay === false ? false : stackId && ctx ? ctx.currentId === stackId : opened;
useEffect(() => {
if (ctx && stackId) opened ? ctx.addModal(stackId, zIndex || getDefaultZIndex("modal")) : ctx.removeModal(stackId);
}, [
opened,
stackId,
zIndex
]);
return /* @__PURE__ */ jsxs(DrawerRoot, {
opened,
zIndex: ctx && stackId ? ctx.getZIndex(stackId) : zIndex,
...others,
...stackProps,
children: [withOverlay && /* @__PURE__ */ jsx(DrawerOverlay, {
visible: overlayVisible,
transitionProps: ctx && stackId ? { duration: 0 } : void 0,
...overlayProps
}), /* @__PURE__ */ jsxs(DrawerContent, {
__hidden: ctx && stackId && opened ? stackId !== ctx.currentId : false,
children: [hasHeader && /* @__PURE__ */ jsxs(DrawerHeader, { children: [title && /* @__PURE__ */ jsx(DrawerTitle, { children: title }), withCloseButton && /* @__PURE__ */ jsx(DrawerCloseButton, { ...closeButtonProps })] }), /* @__PURE__ */ jsx(DrawerBody, { children })]
})]
});
});
Drawer.classes = Drawer_module_default;
Drawer.displayName = "@mantine/core/Drawer";
Drawer.Root = DrawerRoot;
Drawer.Overlay = DrawerOverlay;
Drawer.Content = DrawerContent;
Drawer.Body = DrawerBody;
Drawer.Header = DrawerHeader;
Drawer.Title = DrawerTitle;
Drawer.CloseButton = DrawerCloseButton;
Drawer.Stack = DrawerStack;
//#endregion
export { Drawer };
//# sourceMappingURL=Drawer.mjs.map