notification deck.
A lock-screen notification stack that collapses into a tidy deck and fans out on tap, even when the cards are different heights.
live component, try it
what to expect.
how it works.
Cards in a notification deck are not the same height, and that is what breaks the obvious version. Collapsed, each card peeks a fixed distance below the one in front, and every card behind the front is clamped to the front card's height, so a notification that wraps to two lines can neither hang out below the deck nor hide the card behind it. Expanded, each offset comes from the measured height of the card above plus a gap, so the fan never overlaps. Heights are read by a resize observer and handed to a pure function as numbers, which keeps the stacking maths testable without a layout engine. The second card runs to two lines on purpose.
take it with you.
Three steps, and the stage above runs in your own project.
Install
Nothing to add. It runs on React alone, 18 or newer.
Copy the files
3 files, kept together in one folder,
notifications/. The styles travel with them."use client"; import { useEffect, useRef, useState, type CSSProperties } from "react"; import { stackOffsets, type Pose } from "./stack"; import "./notifications.css"; export interface Note { id: string; app: string; title: string; body: string; } export interface DeckProps { notes: Note[]; // px of each card left showing below the one in front peek?: number; // how much smaller each card behind gets scaleStep?: number; } const GAP = 8; export default function NotificationDeck({ notes, peek = 10, scaleStep = 0.04 }: DeckProps) { const [expanded, setExpanded] = useState(false); const [heights, setHeights] = useState<number[]>([]); const cardsRef = useRef<(HTMLElement | null)[]>([]); useEffect(() => { const nodes = cardsRef.current.slice(0, notes.length).filter(Boolean) as HTMLElement[]; if (nodes.length === 0) return; const read = () => setHeights(nodes.map((n) => Math.max(n.scrollHeight, n.offsetHeight))); read(); const ro = new ResizeObserver(read); for (const n of nodes) ro.observe(n); return () => ro.disconnect(); }, [notes.length]); const poses: Pose[] = stackOffsets( heights.length === notes.length ? heights : notes.map(() => 0), { peek, scaleStep, expanded, gap: GAP }, ); const frontHeight = heights[0]; return ( <button type="button" className="deck" data-expanded={String(expanded)} aria-expanded={expanded} aria-label={expanded ? "collapse notifications" : "expand notifications"} onClick={() => setExpanded((e) => !e)} > {notes.map((note, i) => { const isBackground = !expanded && i > 0; return ( <article key={note.id} className="deck-card" data-background={String(isBackground)} ref={(el) => { cardsRef.current[i] = el; }} style={ { zIndex: notes.length - i, transform: `translateY(${poses[i]?.y ?? 0}px) scale(${poses[i]?.scale ?? 1})`, ...(isBackground && frontHeight ? { maxHeight: `${frontHeight}px` } : {}), } as CSSProperties } > <span className="deck-app">{note.app}</span> <strong>{note.title}</strong> <p>{note.body}</p> </article> ); })} </button> ); }Use it
The stage above, exactly as it runs here. The comments mark what to change.
"use client"; import NotificationDeck, { type Note } from "./notifications/NotificationDeck"; // the second note wraps, so the stack has uneven heights to fit const NOTES: Note[] = [ { id: "a", app: "messages", title: "sam", body: "did the reel land?" }, { id: "b", app: "calendar", title: "in 15 minutes", body: "design review, and then the thing about the capture rig that nobody wants to talk about", }, { id: "c", app: "mail", title: "vercel", body: "your deployment is ready" }, ]; export default function NotificationsExample() { return ( <div className="deck-lab"> <p className="deck-lab-time" aria-hidden="true"> Sunday 31 August </p> {/* tap the stack to fan it out, tap again to fold it */} <NotificationDeck notes={NOTES} peek={10} scaleStep={0.04} /> </div> ); }