Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.6 kB · 51 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// Thin wrapper around sonner's `toast()` that mirrors the shape of// the app's `useToast` from @streamplace/components. Just enough to// power useBlueskyNotifications on web; a fuller toast system (queue,// theming, variants) can be added in Phase 7 polish.//// The shadcn-style <Toaster /> lives at// js/web/src/components/ui/sonner.tsx; it must be mounted once at// the root of the app for any toast() call to render.import { createElement } from "react";import { toast as sonnerToast } from "sonner";
interface ToastOptions { variant?: "error" | "success" | "info"; duration?: number; actionLabel?: string; onAction?: () => void; iconLeft?: React.ComponentType<{ className?: string }>; // sonner accepts additional options (description, etc.) that // callers can pass through. Keep the surface loose here. [key: string]: any;}
export function useToast() { return { show: (message: string, description?: string, options?: ToastOptions) => { const { actionLabel, onAction, iconLeft: IconLeft, variant, ...rest } = options ?? {}; const toastFn = variant === "error" ? sonnerToast.error : variant === "success" ? sonnerToast.success : sonnerToast; toastFn(message, { ...(description !== undefined ? { description } : {}), ...(IconLeft ? { icon: createElement(IconLeft, { className: "size-4" }) } : {}), ...(actionLabel && onAction ? { action: { label: actionLabel, onClick: onAction } } : {}), ...rest, }); }, };}