UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

34 lines (33 loc) 1.28 kB
"use client"; require("../../_virtual/_rolldown/runtime.cjs"); const require_use_lock_scroll = require("./use-lock-scroll.cjs"); let react = require("react"); let _mantine_hooks = require("@mantine/hooks"); //#region packages/@mantine/core/src/components/ModalBase/use-modal.ts function useModal({ id, transitionProps, opened, trapFocus, closeOnEscape, onClose, returnFocus }) { const _id = (0, _mantine_hooks.useId)(id); const [titleMounted, setTitleMounted] = (0, react.useState)(false); const [bodyMounted, setBodyMounted] = (0, react.useState)(false); const shouldLockScroll = require_use_lock_scroll.useLockScroll({ opened, transitionDuration: typeof transitionProps?.duration === "number" ? transitionProps?.duration : 200 }); (0, _mantine_hooks.useWindowEvent)("keydown", (event) => { if (event.key === "Escape" && closeOnEscape && !event.isComposing && opened) event.target?.getAttribute("data-mantine-stop-propagation") !== "true" && onClose(); }, { capture: true }); (0, _mantine_hooks.useFocusReturn)({ opened, shouldReturnFocus: trapFocus && returnFocus }); return { _id, titleMounted, bodyMounted, shouldLockScroll, setTitleMounted, setBodyMounted }; } //#endregion exports.useModal = useModal; //# sourceMappingURL=use-modal.cjs.map