Toast
An opinionated toast component.
The Toast component wraps solid-sonner, a SolidJS port of Sonner, and themes it to match your app.
import { toast } from "solid-sonner";import { Button } from "~/components/ui/button";import { Toaster } from "~/components/ui/toast";
export default function ToastDemo() { const showToast = () => toast("Event created", { description: "Sunday, December 3 at 9:00 AM", action: { label: "Undo", onClick: () => {}, }, });
return ( <> <Toaster /> <Button variant="outline" onClick={showToast}> Show Toast </Button> </> );}Installation
Usage
Import toast from solid-sonner directly — the registry's toast.tsx only exports the themed Toaster, it does not re-export toast itself.
import { toast } from "solid-sonner";toast("Event created", { description: "Sunday, December 3 at 9:00 AM",});Types
Call toast.success, toast.info, toast.warning, or toast.error to render the matching status icon. toast.loading renders a spinner.
import { toast } from "solid-sonner";import { Button } from "~/components/ui/button";import { Toaster } from "~/components/ui/toast";
export default function ToastTypes() { return ( <> <Toaster /> <div class="flex flex-wrap gap-2"> <Button variant="outline" onClick={() => toast("Event has been created.")}> Default </Button> <Button variant="outline" onClick={() => toast.success("Event has been created.")}> Success </Button> <Button variant="outline" onClick={() => toast.info("Arrive 10 minutes before the event.")}> Info </Button> <Button variant="outline" onClick={() => toast.warning("The event cannot start before 8:00 AM.")} > Warning </Button> <Button variant="outline" onClick={() => toast.error("The event could not be created.")}> Error </Button> </div> </> );}Action
Pass an action with a label and onClick to render a button on the toast.
toast("Event created", { action: { label: "Undo", onClick: () => {}, },});Promise
Use toast.promise to update one toast as an asynchronous task moves through loading, success, and error states.
import { toast } from "solid-sonner";import { Button } from "~/components/ui/button";import { Toaster } from "~/components/ui/toast";
export default function ToastPromise() { const showToast = () => toast.promise( new Promise<{ name: string }>((resolve) => { window.setTimeout(() => resolve({ name: "Event" }), 2000); }), { loading: "Creating event…", success: (data) => `${data.name} created.`, error: "Could not create event.", }, );
return ( <> <Toaster /> <Button variant="outline" onClick={showToast}> Create Event </Button> </> );}API Reference
Toaster
The only export from toast.tsx. It forwards every prop to solid-sonner's Toaster and additionally wires up the app's color mode, status icons, and CSS variables so toasts match your theme.
See the solid-sonner README for Toaster props (position, richColors, duration, gap, visibleToasts, closeButton, dir, and more) and the full toast() API (toast(), toast.success(), toast.info(), toast.warning(), toast.error(), toast.loading(), toast.custom(), toast.message(), toast.promise(), toast.dismiss()).