Glass Notification
einui/glass-notificationFreeComponent
A customizable notification system with glass morphism styling, allowing for different types of messages and actions.
Live preview
live · rendered by the registry
Rendered by einui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.eindev.ir/r/glass-notification.jsonSource
1"use client"23import * as React from "react"4import { X, CheckCircle, AlertCircle, AlertTriangle, Info } from "lucide-react"5import { cn } from "@/lib/utils"67type NotificationType = "success" | "error" | "warning" | "info"8type NotificationPosition = "top-right" | "top-left" | "bottom-right" | "bottom-left" | "top-center" | "bottom-center"910interface Notification {11 id: string12 type: NotificationType13 title: string14 description?: string15 duration?: number16}1718interface NotificationContextType {19 notifications: Notification[]20 addNotification: (notification: Omit<Notification, "id">) => void21 removeNotification: (id: string) => void22}2324const NotificationContext = React.createContext<NotificationContextType | null>(null)2526export function useNotification() {27 const context = React.useContext(NotificationContext)28 if (!context) {29 throw new Error("useNotification must be used within a GlassNotificationProvider")30 }31 return context32}3334export function GlassNotificationProvider({35 children,36 position = "bottom-right",37}: {38 children: React.ReactNode39 position?: NotificationPosition40}) {41 const [notifications, setNotifications] = React.useState<Notification[]>([])4243 const addNotification = React.useCallback((notification: Omit<Notification, "id">) => {44 const id = Math.random().toString(36).substring(2, 9)45 setNotifications((prev) => [...prev, { ...notification, id }])4647 if (notification.duration !== 0) {48 setTimeout(() => {49 setNotifications((prev) => prev.filter((n) => n.id !== id))50 }, notification.duration || 5000)51 }52 }, [])5354 const removeNotification = React.useCallback((id: string) => {55 setNotifications((prev) => prev.filter((n) => n.id !== id))56 }, [])5758 return (59 <NotificationContext.Provider value={{ notifications, addNotification, removeNotification }}>60 {children}61 <GlassNotificationContainer position={position} />62 </NotificationContext.Provider>63 )64}6566const typeConfig = {67 success: {68 icon: CheckCircle,69 gradient: "from-emerald-500/30 to-green-500/30",70 border: "border-emerald-400/30",71 iconColor: "text-emerald-400",72 },73 error: {74 icon: AlertCircle,75 gradient: "from-red-500/30 to-rose-500/30",76 border: "border-red-400/30",77 iconColor: "text-red-400",78 },79 warning: {80 icon: AlertTriangle,81 gradient: "from-amber-500/30 to-yellow-500/30",82 border: "border-amber-400/30",83 iconColor: "text-amber-400",84 },85 info: {86 icon: Info,87// … truncated
What it pulls in
npm packages
Files it writes
More from einui
All 42 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Base Widgetbase-widget | einui | Components | Free | 1 dep | |
| Calendar Widgetscalendar-widget | einui | Components | Free | 1 dep | |
| Clock Widgetsclock-widget | einui | Components | Free | 1 dep | |
| Glass Alert Dialogglass-alert-dialog | einui | Components | Free | 1 dep | |
| Glass Avatarglass-avatar | einui | Components | Free | 1 dep | |
| Glass Badgeglass-badge | einui | Components | Free | 1 dep | |
| Glass Breadcrumbglass-breadcrumb | einui | Components | Free | 1 dep | |
| Glass Buttonglass-button | einui | Components | Free | 2 deps |
