# Toaster



import ToasterDefault from "@/components/nexus-ui/examples/toaster/default";
import ToasterWithDescription from "@/components/nexus-ui/examples/toaster/with-description";
import ToasterWithAction from "@/components/nexus-ui/examples/toaster/with-action";
import ToasterVariantsRow from "@/components/nexus-ui/examples/toaster/variants-row";
import ToasterPosition from "@/components/nexus-ui/examples/toaster/position";

Headless toast notifications with variant-aware styling and custom action/cancel controls; Powered by [Sonner](https://sonner.emilkowal.ski/).

<DemoWithCode src="components/nexus-ui/examples/toaster/default.tsx">
  <ToasterDefault />
</DemoWithCode>

Installation [#installation]

<Tabs items={["CLI", "Manual"]} framed={false}>
  <Tab value="CLI">
    <Steps>
      <Step>
        Run the following command:
      </Step>

      ```bash
      npx shadcn@latest add @nexus-ui/toaster
      ```

      <Step>
        Add the 

        `Toaster`

         component
      </Step>

      ```tsx title="app/layout.tsx"
      import { Toaster } from "@/components/nexus-ui/toaster"

      export default function RootLayout({ children }) {
        return (
          <html lang="en">
            <head />
            <body>
              <main>{children}</main>
              <Toaster />
            </body>
          </html>
        )
      }
      ```
    </Steps>
  </Tab>

  <Tab value="Manual">
    <Steps>
      <Step>
        Install the following dependencies:
      </Step>

      ```bash
      npx shadcn@latest add button && npm install @hugeicons/core-free-icons @hugeicons/react next-themes sonner
      ```

      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource src="components/nexus-ui/toaster.tsx" title="components/nexus-ui/toaster.tsx" />

      <Step>
        Add the 

        `Toaster`

         component
      </Step>

      ```tsx title="app/layout.tsx"
      import { Toaster } from "@/components/nexus-ui/toaster"

      export default function RootLayout({ children }) {
        return (
          <html lang="en">
            <head />
            <body>
              <Toaster />
              <main>{children}</main>
            </body>
          </html>
        )
      }
      ```
    </Steps>
  </Tab>
</Tabs>

Usage [#usage]

```tsx keepBackground noLineNumbers
import { toast } from "@/components/nexus-ui/toaster";
```

```tsx keepBackground noLineNumbers
toast.default("Event has been created.");
```

Examples [#examples]

With Description [#with-description]

Add supporting copy with the `description` option.

<DemoWithCode src="components/nexus-ui/examples/toaster/with-description.tsx">
  <ToasterWithDescription />
</DemoWithCode>

With Action [#with-action]

Add an inline CTA using the `action` option.

<DemoWithCode src="components/nexus-ui/examples/toaster/with-action.tsx">
  <ToasterWithAction />
</DemoWithCode>

Variants [#variants]

Change the variant on each toast call to control the feedback type and visual style.

<DemoWithCode src="components/nexus-ui/examples/toaster/variants-row.tsx">
  <ToasterVariantsRow />
</DemoWithCode>

Position [#position]

Show toasts in different corners and center positions using per-toast `position`.

<DemoWithCode src="components/nexus-ui/examples/toaster/position.tsx">
  <ToasterPosition />
</DemoWithCode>

API Reference [#api-reference]

toast [#toast]

Custom headless toast helper built on `sonnerToast.custom`. It renders the `Toast` UI while forwarding supported Sonner toast options for behavior and lifecycle.

<TypeTable
  type={{
  title: {
    type: "React.ReactNode",
    description: "Primary toast title text/content.",
  },
  description: {
    type: "React.ReactNode",
    description: "Optional secondary body content.",
  },
  variant: {
    type: '"default" | "success" | "info" | "warning" | "error" | "loading"',
    default: '"default"',
    description:
      "Controls variant color tokens and leading icon. `default` uses neutral theme colors and no icon.",
  },
  icon: {
    type: "React.ReactNode | null",
    description:
      "Overrides the leading icon for this toast. Use `null` to hide it.",
  },
  action: {
    type: "{ label: React.ReactNode; onClick?: () => void }",
    description:
      "Optional custom action button rendered inside the toast card.",
  },
  cancel: {
    type: "{ label: React.ReactNode; onClick?: () => void }",
    description:
      "Optional secondary cancel button rendered inside the toast card.",
  },
  duration: {
    type: "number",
    default: "4000",
    description:
      "Auto-dismiss duration in milliseconds. Use `Infinity` to keep toast open.",
  },
  id: {
    type: "string | number",
    description: "Custom toast id for updates/deduping.",
  },
  position: {
    type: '"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right"',
    description: "Override destination stack position for this toast.",
  },
  toasterId: {
    type: "string",
    description: "Route toast to a specific mounted toaster.",
  },
  dismissible: {
    type: "boolean",
    default: "true",
    description: "Whether the toast can be dismissed by interaction.",
  },
  onDismiss: {
    type: "() => void",
    description: "Called when toast is dismissed.",
  },
  onAutoClose: {
    type: "() => void",
    description: "Called when toast closes from timeout.",
  },
  invert: {
    type: "boolean",
    default: "false",
    description: "Use Sonner inverted styling mode where applicable.",
  },
  closeButton: {
    type: "boolean",
    default: "true",
    description:
      "Show/hide the custom toast close button for this toast instance.",
  },
  testId: {
    type: "string",
    description: "Testing identifier attached to toast node.",
  },
}}
/>

Toaster [#toaster]

Custom wrapper that mounts Sonner and syncs `theme` from `next-themes`, with `toastOptions={{ unstyled: true }}` by default.

<TypeTable
  type={{
  theme: {
    type: '"light" | "dark" | "system"',
    default: '"system"',
    description:
      "Theme synced from `next-themes`; can be overridden via prop.",
  },
  position: {
    type: '"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right"',
    default: '"bottom-right"',
    description: "Global toast placement.",
  },
  expand: {
    type: "boolean",
    default: "false",
    description: "Expand stacked toasts on hover, or always when true.",
  },
  visibleToasts: {
    type: "number",
    default: "3",
    description: "Maximum visible toasts in stack.",
  },
  closeButton: {
    type: "boolean",
    default: "false",
    description:
      "Show default Sonner close controls globally (custom toast UI already renders its own close button).",
  },
  offset: {
    type: "string | number",
    description: "Desktop viewport offset for toast stack.",
  },
  mobileOffset: {
    type: "string | number",
    description: "Mobile viewport offset for toast stack.",
  },
  toastOptions: {
    type: "object",
    default: "{ unstyled: true }",
    description: "Default options applied to all toasts from this toaster.",
  },
  id: {
    type: "string",
    description: "Toaster id for multi-toaster setups.",
  },
}}
/>

For advanced usage and full configuration options, see the [Sonner docs](https://sonner.emilkowal.ski/).
