About
Stacked notifications from background agents that finish, need your input or report a deploy, with actions and hover to fan out.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Agent Notification to your project and fits it to your theme.
Code
How Agent Notification is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client"
import * as React from "react"
import { AgentNotifications, dismissAgentNotification, notifyAgent } from "@/components/ui/agent-notification"
const reducedMotion = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches
const HOLD = Number.POSITIVE_INFINITY
/** Three background runs report in while you keep working. */
function finished() {
return notifyAgent({
kind: "done",
title: "Agent finished: 4 files changed",
description: "Add CSV export to the runs table. 18 tests pass and the pull request is ready.",
run: "tallyline/web · feat/csv-export",
action: { label: "View diff", onClick: () => {} },
duration: HOLD,
})
}
function needsInput() {
return notifyAgent({
kind: "needs-input",
title: "Needs your input",
description: "Archive old runs wants to run pnpm db:migrate on the preview database.",
run: "tallyline/web · chore/archive-runs",
action: { label: "Review", onClick: () => {} },
secondaryAction: { label: "Allow once", onClick: () => {} },
})
}
function deployed() {
return notifyAgent({
kind: "info",
title: "Preview deployed",
description: "feat/csv-export is live on its preview link.",
duration: HOLD,
})
}
const STEPS: [number, () => void][] = [
[500, finished],
[1900, needsInput],
[3300, deployed],
]
const EXPAND_AT = 5200
const COLLAPSE_AT = 7600
const CLEAR_AT = 9400
/** The tour, in ms from the start of each loop. */
const LOOP_MS = 10_400
const FIT_CSS = "html,body{overflow:hidden}[data-fit-small] [data-fit-hide]{display:none!important}"
/**
* 21st shows a demo in a small frame: about 674 by 421 on a component page, 358 by 224 on a
* phone and 245 by 139 on a profile card. A demo taller than its frame gets scrollbars, which
* render white on dark pages. FitFrame fills the frame exactly instead.
*
* - "scale": the content shrinks until it fits, centered. For visuals such as orbs.
* - "crop": the content stays at full size from the top and fades out at the bottom. For text
* that streams in, where a changing scale would make the page breathe.
*
* `minWidth` lays out a wide demo (a table, a two column panel) at that width and scales it down
* to the frame, instead of letting it collapse to a narrow layout. The frame centers it, so it
* shrinks evenly on both sides.
*
* Anything marked `data-fit-hide` (state buttons, the chatcn.dev line) drops out in frames
* shorter than `hideBelow`, so a profile card shows the visual alone.
*/
function FitFrame({
children,
mode = "scale",
hideBelow = 360,
minWidth,
}: {
children: React.ReactNode
mode?: "scale" | "crop"
hideBelow?: number
minWidth?: string
}) {
const content = React.useRef<HTMLDivElement>(null)
const [cropped, setCropped] = React.useState(false)
React.useLayoutEffect(() => {
const el = content.current
if (!el) return
const measure = () => {
const vw = window.innerWidth
const vh = window.innerHeight
el.toggleAttribute("data-fit-small", vh < hideBelow)
// Layout sizes ignore the transform, so measuring never feeds back.
const w = Math.max(el.offsetWidth, el.scrollWidth)
const h = Math.max(el.offsetHeight, el.scrollHeight)
const scale = mode === "scale" ? Math.min(1, vw / w, vh / h) : 1
el.style.transform = scale < 1 ? `scale(${scale})` : ""
setCropped(mode === "crop" && h > vh + 1)
}
measure()
const observer = new ResizeObserver(measure)
observer.observe(el)
// Content that changes inside a fixed width box (a headline that cycles words) never resizes
// the box itself, so changes below it measure again on the next frame.
let frame = 0
const mutations = new MutationObserver(() => {
cancelAnimationFrame(frame)
frame = requestAnimationFrame(measure)
})
mutations.observe(el, { subtree: true, childList: true, characterData: true })
window.addEventListener("resize", measure)
return () => {
observer.disconnect()
mutations.disconnect()
cancelAnimationFrame(frame)
window.removeEventListener("resize", measure)
}
}, [mode, hideBelow])
const fade = "linear-gradient(to bottom, #000 calc(100% - 40px), transparent)"
return (
<div
className="flex w-full justify-center overflow-hidden"
style={{
height: "100dvh",
alignItems: mode === "crop" ? "flex-start" : "center",
maskImage: cropped ? fade : undefined,
WebkitMaskImage: cropped ? fade : undefined,
}}
>
<style>{FIT_CSS}</style>
<div
ref={content}
className="w-full shrink-0"
style={{ transformOrigin: mode === "crop" ? "top center" : "center", minWidth }}
>
{children}
</div>
</div>
)
}
const CODE = [
["export function", " RunsTable({ runs }: { runs: Run[] }) {"],
[" const", " [sort, setSort] = useState<Sort>(\"started\")"],
[" const", " rows = useMemo(() => sortRuns(runs, sort), [runs, sort])"],
["", ""],
[" return", " ("],
["", " <Table>"],
["", " <TableHeader sort={sort} onSort={setSort} />"],
["", " {rows.map((run) => ("],
["", " <RunRow key={run.id} run={run} />"],
["", " ))}"],
["", " </Table>"],
["", " )"],
["", "}"],
["", ""],
["function", " sortRuns(runs: Run[], sort: Sort) {"],
[" return", " [...runs].sort((a, b) => compare(a[sort], b[sort]))"],
["", "}"],
] as const
/** The line under each 21st demo that points back to the kit. */
function MoreOn({ slug, children }: { slug: string; children: React.ReactNode }) {
return (
<p data-fit-hide className="text-[0.75rem]/[1rem] text-(color:--chatcn-fg-faint) text-center text-balance">
{children}{" "}
<a
href={`https://chatcn.dev/docs/components/${slug}`}
target="_blank"
rel="noopener"
className="text-(color:--chatcn-fg-subtle) hover:text-(color:--chatcn-fg) underline underline-offset-2"
>
chatcn.dev
</a>
</p>
)
}
/**
* Notifications from agents running in the background: a finished run, one that needs your
* input, a deploy. They stack in the corner of your workspace and fan out on hover. The tour
* plays them in, fans the stack out, then clears it and starts again.
*/
export default function AgentNotificationPreview() {
const [expand, setExpand] = React.useState(false)
React.useEffect(() => {
if (reducedMotion()) {
finished()
needsInput()
return () => dismissAgentNotification()
}
let timers: number[] = []
const loop = () => {
timers = [
...STEPS.map(([at, show]) => window.setTimeout(show, at)),
window.setTimeout(() => setExpand(true), EXPAND_AT),
window.setTimeout(() => setExpand(false), COLLAPSE_AT),
window.setTimeout(() => dismissAgentNotification(), CLEAR_AT),
window.setTimeout(loop, LOOP_MS),
]
}
loop()
return () => {
for (const t of timers) window.clearTimeout(t)
dismissAgentNotification()
}
}, [])
return (
<FitFrame minWidth="44rem">
<div className="flex w-full flex-col items-center justify-center gap-4 p-6">
{/* The transform makes this window the stack's frame, so cards sit in its corner. */}
<div className="rounded-(--chatcn-radius-xl) shadow-(--chatcn-shadow-border) bg-(color:--chatcn-bg) relative flex h-[28rem] w-[41rem] shrink-0 flex-col overflow-hidden [transform:translateZ(0)]">
<div className="border-(color:--chatcn-border) text-[0.8125rem]/[1.25rem] text-(color:--chatcn-fg-muted) flex h-10 shrink-0 items-center gap-2 border-b px-4">
<span className="text-(color:--chatcn-fg) font-medium">runs-table.tsx</span>
<span className="text-(color:--chatcn-fg-subtle)">tallyline/web</span>
<span className="text-(color:--chatcn-fg-subtle) ms-auto">3 agents running</span>
</div>
<pre className="text-[0.8125rem]/[1.25rem] text-(color:--chatcn-fg-muted) m-0 flex-1 overflow-hidden px-4 py-3 font-mono leading-[1.4rem]">
{CODE.map(([kw, rest], i) => (
// biome-ignore lint/suspicious/noArrayIndexKey: a fixed listing.
<div key={i} className="flex gap-4">
<span className="text-(color:--chatcn-fg-faint) w-5 shrink-0 text-end tabular-nums">{i + 1}</span>
<span className="whitespace-pre">
<span className="text-(color:--chatcn-fg)">{kw}</span>
{rest}
</span>
</div>
))}
</pre>
<AgentNotifications expand={expand} offset={16} />
</div>
<MoreOn slug="agent-notification">Notifications from agents that finish or need you. On</MoreOn>
</div>
</FitFrame>
)
}
















