diff --git a/admin/src/common/contexts/Dialog/DialogContext.jsx b/admin/src/common/contexts/Dialog/DialogContext.jsx new file mode 100644 index 0000000..ca4671d --- /dev/null +++ b/admin/src/common/contexts/Dialog/DialogContext.jsx @@ -0,0 +1,38 @@ +import React, {createContext, useEffect, useRef} from "react"; +import "./styles.sass"; + +export const DialogContext = createContext({}); + +export const DialogProvider = (props) => { + const ref = useRef(); + + const close = () => { + ref.current?.classList.add("dialog-hidden"); + } + + const onClose = (e) => { + if (e.animationName === "fadeOut") props?.close(); + } + + const handleKeyDown = (event) => { + if (event.code === "Enter" && props.submit) props.submit(); + } + + useEffect(() => { + const handleClick = (event) => { + if (!ref.current?.contains(event.target)) close(); + } + + document.addEventListener("mousedown", handleClick); + }, [ref]); + + return ( + +
+
+ {props.children} +
+
+
+ ) +} \ No newline at end of file