// In app/layout.tsx or src/App.tsx
import { Toaster } from "@/components/ui/toast";
function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="es">
<body>
{children}
<Toaster
defaultPosition="bottom-right"
defaultDuration={4000}
defaultShowProgressBar={true}
gap={12}
/>
</body>
</html>
);
}
Simple Toast
Displays ephemeral notifications (toasts) to inform users about events or actions of the application.
Playground
Customize the Simple Toast properties to see different variations.
Customize
Installation
pnpm dlx shadcn@latest add https://shadcn-ui-variants.vercel.app/r/simple-toast.json
Overview
This component provides a highly customizable and lightweight toast system, built with React and Tailwind CSS. It integrates directly into your project through a simple copy and paste, giving you full control over the code and appearance.
Usage
- Render the
<Toaster />
: Import and render theToaster
component once in your application, preferably in your root layout. You can set default values here. - Call
toast()
: Import thetoast
function and use it to display notifications from anywhere.import { toast } from "@/components/ui/toast"; import { Button } from "@/components/ui/button"; function MyPage() { return ( <Button onClick={() => { toast({ title: "Event Scheduled", description: "Friday, April 25 at 10:00 AM", type: "success", duration: 5000, }); }} > Agendar Evento </Button> ); }
Examples
Toast with Actions
Permanent Toast with Manual Closing
Toast with Custom Animation and Positioning
Toast with Icon and Custom Content
Nested toasts with combined animations and styles
Click to start a toast sequence.
Features
- Ultra Lightweight: No external runtime dependencies (React only).
- Customizable: Modify styles with Tailwind, use your own icons, define enter/exit animations, render complex React content, add action buttons and more.
- Copy & Paste: Easy integration by copying a single file into your project.
- Total Control: You own the source code, modify it according to your needs.
- Intuitive API: Use
toast()
function to show notifications and<Toaster />
to configure and render. - Configurable Animations: Define separate enter and exit animations, or let the exit animation be inferred automatically.
- Dual Actions: Support for primary and secondary action buttons with callbacks.
- Progress Bar: Optionally show the time remaining for automatic closing.
- Typed with TypeScript: Fully written in TypeScript.
Customization
Being a copied component in your project, you have total freedom:
- Styles: Modify directly
ToastPrimitive
insidesimple-toast.tsx
. Use Tailwind to change colors, spacing, fonts, borders, shadows, etc. Use theclassName
prop for quick overrides. - Colors and Icons: Edit
colorVariants
andiconVariants
objects to change the base colors of the default fonts or icons. Use thecustomIcon
prop for unique icons per toast. - Animations:
- Modify the
keyframes
andanimation
intailwind.config.js
to change the appearance or duration of animations. - Adjust the
EXIT_ANIMATION_DURATION
constant insimple-toast.tsx
if you change the duration of exit animations in CSS.
- Modify the
- HTML/JSX structure: Change the structure inside
ToastPrimitive
if you need a different layout. - State Logic: Modify the
toast
,dismiss
functions or theuseToast
hook if you require different state handling behavior.
API Reference
<Toaster />
Component
Renders the toasts and allows you to set global defaults.
Prop | Type | Default |
---|---|---|
defaultDuration |
| 5000 |
defaultPosition |
| "bottom-right" |
defaultEnterAnimationType |
| "fade-in" |
defaultExitAnimationType |
| "fade-out" |
defaultShowCloseButton |
| false |
defaultShowProgressBar |
| false |
gap |
| 16 |
className |
| - |
...rest |
| N/A |
toast()
Function
Displays a toast notification. Accepts a ToastOptions
object.
ToastOptions
(inherits from ToastProps
excluding id
and isExiting
):
Prop | Type | Default |
---|---|---|
type |
| "info" |
title |
| Required |
description |
| - |
duration |
| Global `defaultDuration` |
position |
| Global `defaultPosition` |
enterAnimationType |
| Global `defaultEnterAnimationType` |
exitAnimationType |
| Inferred from `enterAnimationType` / Global `defaultExitAnimationType` |
customIcon |
| - |
primaryAction |
| - |
secondaryAction |
| - |
showCloseButton |
| Global `defaultShowCloseButton` |
showProgressBar |
| Global `defaultShowProgressBar` |
onDismiss |
| - |
onAutoClose |
| - |
className |
| - |
style |
| - |
...rest |
| N/A |
Other Exports
dismiss(id: string)
: Function to dismiss a toast manually using its ID (returned bytoast()
).useToast()
: Hook that returns the current state ({ toasts: ToastProps[], toast, dismiss }
). Useful for advanced cases.ToastPrimitive
: The React component that renders the UI of a single toast. You can import it if you need even more granular control.- Types:
ToastType
,ToastPosition
,ToastEnterAnimationType
,ToastExitAnimationType
,ToastProps
,ToasterProps
,ToastOptions
,ToastAction
.