project-nomad/admin/inertia/context/ModalContext.ts
2025-06-30 01:44:42 -07:00

20 lines
599 B
TypeScript

import { createContext, useContext, ReactNode } from 'react'
interface ModalContextProps {
openModal: (content: ReactNode, id: string, preventClose?: boolean) => void
closeModal: (id: string) => void
closeAllModals: () => void
_getCurrentModals: () => Record<string, ReactNode>
preventCloseOnOverlayClick?: boolean
}
export const ModalContext = createContext<ModalContextProps | undefined>(undefined)
export const useModals = () => {
const context = useContext(ModalContext)
if (!context) {
throw new Error('useModal must be used within a ModalProvider')
}
return context
}