frontpage/components/Terminal/contexts/ModalFunctions.tsx

18 lines
816 B
TypeScript
Raw Normal View History

2022-06-12 14:22:15 +02:00
import { createContext, useContext } from "react";
import type { PropsWithChildren } from "react";
2022-09-30 19:38:25 +02:00
import type { Project, Diary } from "../../../lib/content/types";
2022-06-12 14:22:15 +02:00
interface ModalFunctions {
setVisible?: CallableFunction;
setContent?: (content: Project| Diary) => void;
2022-06-15 00:35:49 +02:00
setHtml?: (html: any) => void;
2022-06-14 23:18:00 +02:00
onContentReady?: () => void;
2022-06-12 14:22:15 +02:00
}
const modalFunctions: ModalFunctions = {};
const ModalContext = createContext(modalFunctions);
const updateCallbacks = (callbacks: ModalFunctions) => Object.assign(modalFunctions, callbacks);
const useModalFunctions = () => ({modalFunctions: useContext(ModalContext), updateCallbacks});
const ModalFunctionProvider = (props: PropsWithChildren<{}>) => <ModalContext.Provider value={modalFunctions} {...props} />;
export { ModalFunctionProvider, useModalFunctions };