FloatingNotification

A fully animated notification component that slides in from various positions with auto-close functionality and multiple types (success, error, warning, info).

Installation

Install using our CLI tool (recommended):

Terminal
1npx mixcn-ui add floatingnotification

Import

Component.tsx
1import { FloatingNotification } from "@components/customComponents/FloatingNotification";

Props

NameTypeDefaultDescription
messagestringThis is a notification messageThe notification message to display
type'success' | 'error' | 'warning' | 'info'infoThe type of notification (affects color and icon)
durationnumber3000Duration in milliseconds before auto-close
position'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center'top-rightPosition of the notification on screen
onClose() => void-Callback function called when notification closes
autoClosebooleantrueWhether the notification should auto-close
classNamestring-Additional CSS classes

Examples

Interactive Demo

Interactive Demo.tsx
1import { useState } from "react"; 2import FloatingNotification from "@/components/uiComponents/FloatingNotification"; 3 4export default function Demo() { 5 const [notifications, setNotifications] = useState([]); 6 7 const addNotification = (type, position) => { 8 const newNotification = { 9 id: Date.now(), 10 type, 11 message: "Operation completed!", 12 position, 13 }; 14 setNotifications(prev => [...prev, newNotification]); 15 16 setTimeout(() => { 17 setNotifications(prev => prev.filter(n => n.id !== newNotification.id)); 18 }, 3000); 19 }; 20 21 return ( 22 <div> 23 <button onClick={() => addNotification("success", "top-right")}> 24 Show Success 25 </button> 26 {notifications.map(notification => ( 27 <FloatingNotification key={notification.id} {...notification} /> 28 ))} 29 </div> 30 ); 31}