Notification
100xui/notificationFreeBlock
A reusable notification component that displays animated messages with smooth slide and scale transitions, perfect for in-app alerts, toasts, and contextual updates.
Live preview
live · rendered by the registry
Rendered by 100xui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://100xui.com/r/notification.jsonSource
1"use client";23import * as React from "react";4import {5 motion,6 useAnimate,7 type Transition,8 type HTMLMotionProps,9 type MotionStyle,10} from "motion/react";11import { XIcon } from "lucide-react";1213import { cn } from "@/lib/utils";1415interface NotificationContextType {16 dismissNotification: () => void;17 showNotification: () => Promise<void>;18 hideNotification: () => Promise<void>;19 scope: React.RefObject<HTMLDivElement>;20 expandedGap: React.CSSProperties["gap"];21 minVisibleContentHeight: React.CSSProperties["height"];22 initialContentScale: React.CSSProperties["scale"];23 slideFromTop: boolean;24}2526const NotificationContext = React.createContext<NotificationContextType | null>(27 null,28);2930function useNotification() {31 const ctx = React.useContext(NotificationContext);32 if (!ctx)33 throw new Error(34 "useNotification must be used within Notification Provider",35 );36 return ctx;37}3839interface NotificationProps extends React.ComponentProps<"div"> {40 transition?: Partial<Record<"scale" | "translateY", Transition>>;41 initialContentScale?: React.CSSProperties["scale"];42 expandedGap?: React.CSSProperties["gap"];43 minVisibleContentHeight?: React.CSSProperties["height"];44 slideContentFrom?: "bottom" | "top";45}4647export function Notification({48 transition: { scale: scaleTransition, translateY: translateYTransition } = {49 scale: { ease: "easeOut" },50 translateY: { ease: "easeOut" },51 },52 initialContentScale = 0.95,53 expandedGap = "calc(var(--spacing) * 2)",54 minVisibleContentHeight = "calc(var(--spacing) * 2)",55 onMouseLeave,56 className,57 children,58 slideContentFrom = "top",59 ...rest60}: NotificationProps) {61 const [isRendered, setIsRendered] = React.useState(true);62 const [scope, animate] = useAnimate();63 const slideFromTop = slideContentFrom === "top";6465 const showNotification = async () => {66 await animate(scope.current, { y: "0px" }, translateYTransition);67 await animate(scope.current, { scale: 1 }, scaleTransition);68 };6970 const hideNotification = async () => {71 await animate(72 scope.current,73 { scale: initialContentScale },74 scaleTransition,75 );76 await animate(77 scope.current,78 {79 y: `calc(${slideFromTop ? "1" : "-1"} * (-100% - ${expandedGap} + ${minVisibleContentHeight}))`,80 },81 translateYTransition,82 );83 };8485 const dismissNotification = () => setIsRendered(false);8687 return (88 <>89 {isRendered && (90 <NotificationContext.Provider91// … truncated
What it pulls in
npm packages
Files it writes
More from 100xui
All 14 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Apple galleryapple-gallery | 100xui | Blocks | Free | 1 dep | |
| Chat bento cardchat-bento-card | 100xui | Blocks | Free | 1 dep | |
| demosdemos | 100xui | Blocks | Free | no deps · 12 files | |
| In-page navbarin-page-navbar | 100xui | Blocks | Free | 1 dep · 2 files | |
| internalsinternals | 100xui | Blocks | Free | no deps · 4 files | |
| iPhone 3D mockupiphone-3d-mockup | 100xui | Blocks | Free | no deps | |
| Menu wheelmenu-wheel | 100xui | Blocks | Free | 1 dep | |
| Morph modalmorph-modal | 100xui | Blocks | Free | 1 dep |
