# Toast

Sonner, unstyled, wearing the kit's skin. Pops in; warnings use a rain cloud, never red.

Docs: https://cozy-ui.solo.engineer/docs/components/toast/

Install: `npx shadcn@latest add @cozy/sonner`

### Usage

```tsx
import { Toaster } from "@/components/ui/sonner"
import { toast } from "sonner"

// once, near the root
<Toaster />

toast.success("Rice harvested", { description: "+120 coins" })
```

### Example

```tsx
import { toast } from "sonner";
import { Button } from "@/components/ui/button";

// Render <Toaster /> once near the root of your app.
export default function ToastDemo() {
  return (
    <div className="flex flex-wrap justify-center gap-3">
      <Button variant="success" onClick={() => toast.success("Rice harvested", { description: "+120 coins, +8 XP" })}>Success</Button>
      <Button variant="secondary" onClick={() => toast.warning("Rain is coming", { description: "Bring the drying rice in from the yard." })}>Warning</Button>
      <Button variant="outline" onClick={() => toast("A neighbour dropped by", { description: "They left a basket of sweet potatoes." })}>Default</Button>
      <Button variant="destructive" onClick={() => toast.error("Power cut!", { description: "The thresher rests for a while. Light the oil lamp." })}>Error</Button>
    </div>
  );
}
```

### Source (components/ui/sonner.tsx)

```tsx
import { Toaster as Sonner, type ToasterProps } from "sonner";
import { InfoGlyph, RainGlyph, RiceGlyph, CloseGlyph, SpinnerGlyph } from "./glyphs";

/** shadcn Toaster: unstyled sonner wearing the cz-toast skin. Warnings use the rain glyph, never red. */
function Toaster(props: ToasterProps) {
  return (
    <Sonner
      position="top-center"
      gap={10}
      toastOptions={{
        unstyled: true,
        classNames: {
          toast: "cz-toast",
          success: "cz-toast--success",
          info: "cz-toast--info",
          warning: "cz-toast--warning",
          error: "cz-toast--error",
        },
      }}
      icons={{
        success: <RiceGlyph style={{ color: "var(--cz-success)" }} />,
        info: <InfoGlyph style={{ color: "var(--cz-outline)" }} />,
        warning: <RainGlyph style={{ color: "var(--cz-info)" }} />,
        error: <CloseGlyph style={{ color: "var(--cz-danger)" }} />,
        loading: <SpinnerGlyph style={{ color: "var(--cz-outline)" }} />,
      }}
      {...props}
    />
  );
}

export { Toaster };
```

npm: `import { Toaster } from "@0xtrou/cozy-ui"` (after `npm install @0xtrou/cozy-ui` and `import "@0xtrou/cozy-ui/styles.css"`).
