Please use Desktop to view and interact with components
Page Transitions300msspring
Toast Notification
Animated toast notification popup
toastnotificationalertshadcn
Useto navigate between components
Preview
This component requires shadcn/ui
This component uses shadcn/ui components. Make sure you have shadcn/ui set up in your project.
- Install shadcn/ui:
npx shadcn-ui@latest init - Install required components based on the imports in the code (e.g.,
npx shadcn-ui@latest add button) - Ensure your
tailwind.config.tsandglobals.cssare configured as per shadcn/ui documentation
Code
TypeScript + React
'use client'
import { motion, AnimatePresence } from 'framer-motion'
import { useState } from 'react'
import { Button } from '@/components/ui/button'
import { Card } from '@/components/ui/card'
import { CheckCircle2, X } from 'lucide-react'
export function ToastNotification() {
const [isVisible, setIsVisible] = useState(false)
const showToast = () => {
setIsVisible(true)
setTimeout(() => setIsVisible(false), 3000)
}
return (
<>
<Button onClick={showToast}>Show Notification</Button>
<AnimatePresence>
{isVisible && (
<motion.div
initial={{ opacity: 0, y: -50, scale: 0.9 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
exit={{ opacity: 0, scale: 0.9, transition: { duration: 0.2 } }}
className="fixed right-4 top-4 z-50"
>
<Card className="flex w-80 items-start gap-3 p-4 shadow-2xl">
<CheckCircle2 className="h-5 w-5 flex-shrink-0 text-green-500" />
<div className="flex-1">
<h4 className="font-semibold">Success!</h4>
<p className="text-sm text-[var(--foreground)]/70">
Your changes have been saved.
</p>
</div>
<button
onClick={() => setIsVisible(false)}
className="flex-shrink-0 rounded-sm opacity-70 hover:opacity-100"
>
<X className="h-4 w-4" />
</button>
</Card>
</motion.div>
)}
</AnimatePresence>
</>
)
}
How to Use
- 1Install Framer Motion:
npm install framer-motion - 2Set up shadcn/ui: Install shadcn/ui components used in this code. Check the imports in the code above and install the required components (e.g.,
npx shadcn-ui@latest add button card) - 3Copy the code from above
- 4Paste it into your project and customize as needed
- 5Colors are customizable via Tailwind CSS classes. The default theme uses dark mode colors defined in your globals.css file