import type { JSX } from "@solidjs/web"; import { type MaybeAccessor, readOption } from "../../internals/maybe-accessor"; import { createToast } from "../create-toast"; import type { ToastManager } from "../create-toast-manager"; import { ToastProviderContext } from "./toast-provider-context"; export interface ToastProviderProps { children?: JSX.Element; /** * Default auto-dismiss duration (ms). `0` disables auto-dismiss. * @default 5000 */ timeout?: MaybeAccessor; /** * Maximum number of toasts visible at once. Oldest toasts beyond the * limit are marked `limited` so consumers can animate them out. * @default 3 */ limit?: MaybeAccessor; /** * Optional standalone manager created via {@link createToastManager}. * Events emitted by the manager are forwarded into this provider's * store, letting code outside the component tree add / close / update * toasts. */ toastManager?: ToastManager | undefined; } /** * Root of the toast system — composes {@link createToast} and exposes the * store via context so descendants can call `useToastManager()` or render the * viewport. * * All queue logic lives in `createToast`; this component is a thin JSX wrapper * that binds the headless primitive to the existing `ToastProviderContext` * surface consumed by `Toast.Viewport`, `Toast.Root`, `Toast.Close`, etc. */ export function ToastProvider(props: ToastProviderProps): JSX.Element { const toast = createToast({ get timeout() { return readOption(props.timeout); }, get limit() { return readOption(props.limit); }, get toastManager() { return props.toastManager; }, }); return ( {props.children} ); }