import { createContext, useContext, type ComponentType, type ReactNode } from "react"; export interface ToastAction { label: string; onClick(): void; } export interface ToastOptions { title?: string; subtitle?: string; duration?: number; action?: ToastAction; /** Rendered next to `action`. Use for a dismissing counterpart such as snooze. */ secondaryAction?: ToastAction; } export interface ToastHost { Viewport: ComponentType<{ position?: string }>; success(body: string, options?: ToastOptions): string | number | undefined; error(body: string, options?: ToastOptions): string | number | undefined; info(body: string, options?: ToastOptions): string | number | undefined; dismiss(id: string | number): void; /** Runs the newest visible toast's action, for the keyboard. False when no toast has one. */ activateNewest?(): boolean; /** Dismisses the newest visible toast, for the keyboard. False when none is showing. */ dismissNewest?(): boolean; } const ToastContext = createContext(null); export function ToastHostProvider({ host, children, }: { host: ToastHost; children: ReactNode; }) { return {children}; } export function useToastHost(): ToastHost { const host = useContext(ToastContext); if (!host) throw new Error("useToastHost must be used inside ToastHostProvider"); return host; } export function ToastViewport(props: { position?: string }) { const { Viewport } = useToastHost(); return ; }