UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

38 lines 1.31 kB
import React, { useEffect } from "react"; export const coordsAreInside = ({ clientX, clientY }, { left, top, right, bottom }) => { if (clientX < left || clientY < top) return false; if (clientX > right || clientY > bottom) return false; return true; }; export function getCloseHandler(modalRef, header, onBeforeClose) { if (header && header.closeButton === false) return undefined; if (onBeforeClose) { return () => { var _a; return onBeforeClose() !== false && ((_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close()); }; } return () => { var _a; return (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.close(); }; } function useIsModalOpen(modalRef) { const [isOpen, setIsOpen] = React.useState(false); useEffect(() => { if (!modalRef) { return; } setIsOpen(modalRef.open); const observer = new MutationObserver(() => { setIsOpen(modalRef.open); }); observer.observe(modalRef, { attributes: true, attributeFilter: ["open"], }); return () => { observer.disconnect(); }; }, [modalRef]); return isOpen; } export { useIsModalOpen }; //# sourceMappingURL=ModalUtils.js.map