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 floatingnotificationImport
Component.tsx
1import { FloatingNotification } from "@components/customComponents/FloatingNotification";Props
| Name | Type | Default | Description |
|---|---|---|---|
| message | string | This is a notification message | The notification message to display |
| type | 'success' | 'error' | 'warning' | 'info' | info | The type of notification (affects color and icon) |
| duration | number | 3000 | Duration in milliseconds before auto-close |
| position | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center' | top-right | Position of the notification on screen |
| onClose | () => void | - | Callback function called when notification closes |
| autoClose | boolean | true | Whether the notification should auto-close |
| className | string | - | 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}