mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-24 21:25:55 +00:00
102 lines
1.6 KiB
Plaintext
102 lines
1.6 KiB
Plaintext
---
|
|
title: Sonner
|
|
description: An opinionated toast component for React.
|
|
component: true
|
|
links:
|
|
doc: https://sonner.emilkowal.ski
|
|
---
|
|
|
|
<ComponentPreview name="sonner-demo" />
|
|
|
|
## About
|
|
|
|
Sonner is built and maintained by [emilkowalski\_](https://twitter.com/emilkowalski_).
|
|
|
|
## Installation
|
|
|
|
<CodeTabs>
|
|
|
|
<TabsList>
|
|
<TabsTrigger value="cli">CLI</TabsTrigger>
|
|
<TabsTrigger value="manual">Manual</TabsTrigger>
|
|
</TabsList>
|
|
<TabsContent value="cli">
|
|
|
|
<Steps>
|
|
|
|
<Step>Run the following command:</Step>
|
|
|
|
```bash
|
|
npx shadcn@latest add sonner
|
|
```
|
|
|
|
<Step>Add the Toaster component</Step>
|
|
|
|
```tsx title="app/layout.tsx" {1,9}
|
|
import { Toaster } from "@/components/ui/sonner"
|
|
|
|
export default function RootLayout({ children }) {
|
|
return (
|
|
<html lang="en">
|
|
<head />
|
|
<body>
|
|
<main>{children}</main>
|
|
<Toaster />
|
|
</body>
|
|
</html>
|
|
)
|
|
}
|
|
```
|
|
|
|
</Steps>
|
|
|
|
</TabsContent>
|
|
|
|
<TabsContent value="manual">
|
|
|
|
<Steps>
|
|
|
|
<Step>Install the following dependencies:</Step>
|
|
|
|
```bash
|
|
npm install sonner next-themes
|
|
```
|
|
|
|
<Step>Copy and paste the following code into your project.</Step>
|
|
|
|
<ComponentSource name="sonner" />
|
|
|
|
<Step>Add the Toaster component</Step>
|
|
|
|
```tsx title="app/layout.tsx" {1,9}
|
|
import { Toaster } from "@/components/ui/sonner"
|
|
|
|
export default function RootLayout({ children }) {
|
|
return (
|
|
<html lang="en">
|
|
<head />
|
|
<body>
|
|
<main>{children}</main>
|
|
<Toaster />
|
|
</body>
|
|
</html>
|
|
)
|
|
}
|
|
```
|
|
|
|
</Steps>
|
|
|
|
</TabsContent>
|
|
|
|
</CodeTabs>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import { toast } from "sonner"
|
|
```
|
|
|
|
```tsx
|
|
toast("Event has been created.")
|
|
```
|