import type { Component } from "vue"; import ConfirmationModal from "../components/ConfirmationModal.vue"; import NotificationModal from "../components/NotificationModal.vue"; import TextInputModal from "../components/TextInputModal.vue"; export type ModalCallbackType = ( event: ModalEvents[T], close: () => void, ...args: any[] ) => Promise | void; export interface ModalStackElement { component: Component; type: T; callback: ModalCallbackType; loading: Ref; data: ModalDatas[T]; } export enum ModalType { Confirmation, Notification, TextInput } export type ModalEvents = { [ModalType.Confirmation]: "confirm" | "cancel"; [ModalType.Notification]: "close"; [ModalType.TextInput]: "cancel" | "submit" }; export type ModalDatas = { [ModalType.Confirmation]: { title: string; description: string; buttonText?: string; }; [ModalType.Notification]: { title: string; description: string; buttonText?: string; }; [ModalType.TextInput]: { title: string, description: string, buttonText?: string, dft?: string, placeholder?: string, } }; const modalComponents: { [key in ModalType]: Component } = { [ModalType.Confirmation]: ConfirmationModal, [ModalType.Notification]: NotificationModal, [ModalType.TextInput]: TextInputModal, }; export function createModal( type: T, data: ModalDatas[T], callback: ModalCallbackType ) { const modalStack = useModalStack(); modalStack.value.push({ type, component: modalComponents[type], data, callback, loading: ref(false), }); } export const useModalStack = () => useState>>("modal-stack", () => []);