Skip to content

Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.

TypeScript
599 B
Raw Blame
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
}