Search for a command to run...
An opinionated toast component for SolidJS.
npx shadcn@latest add @zaidan/sonnerpnpx shadcn add @zaidan/sonneryarn dlx shadcn@latest add @zaidan/sonnerbunx shadcn@latest add @zaidan/sonnerInstall the following dependencies:
npm i solid-sonnerpnpm add solid-sonneryarn add solid-sonnerbun add solid-sonnerCopy and paste the following code into your project.
1import { CircleCheck, Info, LoaderCircle, OctagonX, TriangleAlert } from "lucide-solid";2import type { Component, ComponentProps, JSX } from "solid-js";3import { Toaster as Sonner } from "solid-sonner";4import { useColorMode } from "~/lib/hooks/use-color-mode";5
6type ToasterProps = ComponentProps<typeof Sonner>;7
8const Toaster: Component<ToasterProps> = (props) => {9 const { colorMode } = useColorMode();10 return (11 <Sonner12 theme={colorMode()}13 class="toaster group"14 position="top-center"15 icons={{16 success: <CircleCheck class="size-4" />,17 info: <Info class="size-4" />,18 warning: <TriangleAlert class="size-4" />,19 error: <OctagonX class="size-4" />,20 loading: <LoaderCircle class="size-4 animate-spin" />,21 }}22 style={23 {24 "--normal-bg": "var(--popover)",25 "--normal-text": "var(--popover-foreground)",26 "--normal-border": "var(--border)",27 "--border-radius": "var(--radius)",28 } as JSX.CSSProperties29 }30 {...props}31 />32 );33};34
35export { Toaster };Here are the source code of all the examples from the preview page:
import { toast } from "solid-sonner";import { Button } from "~/components/ui/button";function BasicExample() { return ( <Example title="Basic" class="items-center justify-center"> <Button variant="outline" onClick={() => toast("Event has been created")}> Show Toast </Button> </Example> );import { toast } from "solid-sonner";import { Button } from "~/components/ui/button";function WithDescriptionExample() { return ( <Example title="With Description" class="items-center justify-center"> <Button variant="outline" onClick={() => toast("Event has been created", { description: "Monday, January 3rd at 6:00pm", }) } > Show Toast </Button> </Example> );