Notifications
An inbox where agent updates and mentions arrive live. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.
Need this designed into your product? Book a call
Install
Add it to your project with the CLI.
HTML, CSS and JS
npx designme add notificationsReact
npx designme add notifications --reactAstro
npx designme add notifications --astroshadcn, React
npx shadcn@latest add https://designme.dev/r/shadcn/notifications.json shadcn, Astro
npx shadcn@latest add https://designme.dev/r/shadcn/astro/notifications.json The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.
About
What it is for and what it does.
Notifications is an inbox panel where updates from the agent and mentions from people arrive in one list. New items drop in at the top and bump the unread count, and underline tabs under the head split the list into All, Agent and Mentions. A person clicks an item to open it, which marks it read; a read item has Mark as unread on its row, and Mark all read clears everything at once.
- When background agent runs finish, pause or need review while the person is elsewhere
- When agent updates and teammates' mentions should share one inbox but stay easy to separate
- When a header bell or side panel needs a list with a live unread count
- When an agent stops at a limit and the person has to hear about it
- Agent items show an
iconon a tile in the tint of itstone(ok,warn,bad,accentorneutral), with the icon in that status's text colour; people's items show anavatarwith initials.colorsets a colour of your own instead. - A new id at the top of
itemsdrops in on its own and makes the unread count bump. - The panel keeps no room for items to come: it eases taller as one arrives or a filter shows more, and shorter as it shows fewer.
- The filter is a row of underline tabs under the head, on a hairline that runs edge to edge, with the picked tab's line sliding to it. It shows all items or only those whose
kindmatches, and you can supply your ownfilters. Mark all read stays at the head's top right. - Clicking an item opens it: it is marked read and
onOpenis called with it, so you can show what it is about. A read item keeps its colours; only its unread dot goes. The change comes back throughonItemsChange. - On a read item, Mark as unread (
markUnreadLabel) shows where the unread dot was, as a hollow dot button, when the pointer is on the row or the keyboard focus is in it. It brings the dot back. - Mark all read marks every item read, and the unread dots in view clear one row after another.
- An empty filter shows a small sketch of a list,
emptyLabel("Nothing here yet" by default) andemptyDetail, a muted line under it.
- The unread count has an
aria-labellike "3 unread". - Each item is a button that opens it; an unread one says "Unread" to screen readers. Mark as unread is a separate, labelled button in the row, reached with Tab once the focus is on its item.
- The filter is a
tablistlabelled Filter: each tab reportsaria-selected, Left and Right move between them, and the list is itstabpanel.
Usage
Import it in React and drive it from your own state, or place it in an Astro page.
React
import { Notifications } from '@/components/designme/notifications/Notifications';React example
The demo above as a React component, 34 lines you can copy.
'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useRef, useState } from 'react';
import { Notifications, type NotificationsItem } from './Notifications';
import { useStory } from '../lib/useScript';
/* ---------- Notifications: an inbox where two new items arrive while you watch ---------- */
const START: NotificationsItem[] = [
{ id: 'audit', kind: 'agent', icon: 'ok', tone: 'ok', text: <><b>Pricing audit</b> finished. 2 fixes ready to review</>, time: '4 min ago' },
{ id: 'maya', kind: 'mention', avatar: { initials: 'MK', color: 'var(--dm-av-l)' }, text: <><b>Maya</b> mentioned you in Checkout flow</>, time: '20 min ago' },
{ id: 'export', kind: 'agent', icon: 'alert', tone: 'warn', text: <><b>Token export</b> paused at the $5 cap</>, time: '1 hour ago' },
{ id: 'jon', kind: 'mention', avatar: { initials: 'JO', color: 'var(--dm-av-m)' }, text: <><b>Jon</b> asked for your review on PR #284</>, time: '2 hours ago', read: true }
];
const INCOMING: NotificationsItem[] = [
{ id: 'qa', kind: 'agent', icon: 'spark', tone: 'accent', text: <><b>Weekly design QA</b> started on 12 frames</>, time: 'Just now' },
{ id: 'ari', kind: 'mention', avatar: { initials: 'AR', color: 'var(--dm-av-p)' }, text: <><b>Ari</b> replied: “Looks great, ship it”</>, time: 'Just now' }
];
export default function NotificationsDemo() {
const ref = useRef<HTMLDivElement>(null);
const [items, setItems] = useState(START);
// two items arrive while you watch; your first click or key in the inbox stops them, so a filter you picked or a
// Mark all read stays as you left it
useStory(ref, async ({ wait }) => {
await wait(2200);
for (const x of INCOMING) { setItems(xs => [x, ...xs]); await wait(2600); }
});
return (
<div ref={ref} style={{ width: '100%' }}>
<Notifications items={items} onItemsChange={setItems} />
</div>
);
}
Astro
In a page in src/pages. It plays the demo above; change its notifications.js to show your own data. Attributes like class go on its root element.
---
import Notifications from '../components/designme/notifications/Notifications.astro';
---
<Notifications />
<Notifications data-style="soft" class="my-class" />Props
Everything Notifications takes.
| Prop | Type | What it does |
|---|---|---|
items | NotificationsItem[] | Newest first. A new id at the top drops in and bumps the count |
defaultItems | NotificationsItem[] | |
onItemsChange | (items: NotificationsItem[]) => void | Called when items are read or unread, one at a time or all at once |
onOpen | (item: NotificationsItem) => void | Called when an item is clicked, after it is marked read: open what it is about here |
filters | NotificationsFilter[] | |
filter | string | The open filter. Leave it out to let the tabs change it |
defaultFilter | string | |
onFilterChange | (filter: string) => void | |
title | string | |
markAllLabel | string | |
emptyLabel | string | |
emptyDetail | string | The muted line under emptyLabel |
markUnreadLabel | string | The row action on a read item, "Mark as unread" by default |
className | string |
Code
The full source, as the CLI installs it.
Notifications.tsxReact · 139 lines
'use client';
import { useEffect, useId, useRef, useState, type ReactNode } from 'react';
import { cx } from '../lib/cx';
import { useControllable } from '../lib/hooks';
import { Icon, type IconName } from '../lib/icons';
import { Avatar, enter, Tip, UTabs, useGrow } from '../lib/motion';
import { useHoverGlide } from '../lib/glide';
import '../designme.css';
import './notifications.css';
export interface NotificationsItem {
id: string;
/** Which filter it belongs to, like 'agent' or 'mention' */
kind: string;
/** What happened. Wrap the subject in <b>, like <><b>Pricing audit</b> finished</> */
text: ReactNode;
/** Like "4 min ago" */
time: string;
/** An icon on a tinted tile, for things the agent did */
icon?: IconName;
/** What the icon's tile says: 'ok' (green), 'warn' (amber), 'bad' (red), 'accent' or 'neutral' (grey), each its status's
tint with its icon in the status's text colour. neutral by default */
tone?: 'ok' | 'warn' | 'bad' | 'accent' | 'neutral';
/** A colour of your own for the icon instead of a tone, like 'var(--dm-pl)', on a tint of itself */
color?: string;
/** An avatar instead of an icon, for people */
avatar?: { initials: string; color: string };
read?: boolean;
}
export interface NotificationsFilter {
/** 'all' shows everything; anything else shows the items of that kind */
value: string;
label: string;
}
export interface NotificationsProps {
/** Newest first. A new id at the top drops in and bumps the count */
items?: NotificationsItem[];
defaultItems?: NotificationsItem[];
/** Called when items are read or unread, one at a time or all at once */
onItemsChange?: (items: NotificationsItem[]) => void;
/** Called when an item is clicked, after it is marked read: open what it is about here */
onOpen?: (item: NotificationsItem) => void;
filters?: NotificationsFilter[];
/** The open filter. Leave it out to let the tabs change it */
filter?: string;
defaultFilter?: string;
onFilterChange?: (filter: string) => void;
title?: string;
markAllLabel?: string;
emptyLabel?: string;
/** The muted line under emptyLabel */
emptyDetail?: string;
/** The row action on a read item, "Mark as unread" by default */
markUnreadLabel?: string;
className?: string;
}
const FILTERS: NotificationsFilter[] = [{ value: 'all', label: 'All' }, { value: 'agent', label: 'Agent' }, { value: 'mention', label: 'Mentions' }];
/** An inbox where agent updates and mentions arrive live, under filter tabs. Click one to open it and mark it read; Mark as unread is on the row. */
export function Notifications({ items, defaultItems = [], onItemsChange, onOpen, filters = FILTERS, filter, defaultFilter = 'all', onFilterChange, title = 'Inbox', markAllLabel = 'Mark all read', emptyLabel = 'Nothing here yet', emptyDetail = 'New updates and mentions show up here', markUnreadLabel = 'Mark as unread', className }: NotificationsProps) {
const [list, setList] = useControllable(items, defaultItems, onItemsChange);
const [cur, setCur] = useControllable(filter, defaultFilter, onFilterChange);
const shown = list.filter(x => cur === 'all' || x.kind === cur);
const unread = list.filter(x => !x.read).length;
// the rows painted together (on first show and on each filter) stagger in; ones that arrive later drop in on their own
const [paint, setPaint] = useState(() => ({ filter: cur, ids: shown.map(x => x.id) }));
if (paint.filter !== cur) setPaint({ filter: cur, ids: shown.map(x => x.id) });
// a new item bumps the count
const [known, setKnown] = useState(() => new Set(list.map(x => x.id)));
const [bump, setBump] = useState(0);
const fresh = list.filter(x => !known.has(x.id));
if (fresh.length) { setKnown(new Set([...known, ...fresh.map(x => x.id)])); setBump(b => b + 1); }
// Mark all read clears the dots one row after another
const [pending, setPending] = useState<string[]>([]);
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
useEffect(() => () => timers.current.forEach(clearTimeout), []);
const markAll = () => {
const rows = shown.filter(x => !x.read).map(x => x.id);
setPending(rows);
rows.forEach((id, i) => timers.current.push(setTimeout(() => setPending(p => p.filter(x => x !== id)), i * 50)));
setList(list.map(x => (x.read ? x : { ...x, read: true })));
};
const setRead = (id: string, read: boolean) => { if (list.some(x => x.id === id && !!x.read !== read)) setList(list.map(x => (x.id === id ? { ...x, read } : x))); };
const open = (x: NotificationsItem) => { setRead(x.id, true); onOpen?.({ ...x, read: true }); };
const uid = useId();
// the card keeps no room for items to come: it eases taller as one arrives or a filter shows more, and shorter as it shows fewer
const [root, inner] = useGrow();
// Studio's one hover: a highlight that glides from item to item
useHoverGlide(root, '.dm-ntx-n');
return (
<div data-dm="" ref={root} className={cx('dm-ntx dm-panel dm-growing', className)}>
<div ref={inner} className="dm-grow">
<div className="dm-ntx-h">
{/* the inbox's mark, in the column the items' icons and avatars sit in */}
<span className="dm-ntx-hi" aria-hidden="true"><Icon name="bell" /></span>
<b>{title}</b>
<span key={bump} className={cx('dm-ntx-ct dm-num', !unread && 'dm-z', bump > 0 && 'dm-bump')} aria-label={`${unread} unread`}>{unread}</span>
<span className="dm-ntx-sp" />
<button type="button" className="dm-pill dm-ghost dm-sm dm-ntx-all" onClick={markAll}>{markAllLabel}</button>
</div>
{/* the filter: underline tabs under the head, on a hairline that runs edge to edge */}
<UTabs className="dm-ntx-ut" label="Filter" value={cur} onChange={setCur} options={filters} idBase={uid} />
<div key={paint.filter} className="dm-ntx-list" role="tabpanel" aria-labelledby={`${uid}-${cur}`}>
{shown.length ? shown.map(x => {
const at = paint.ids.indexOf(x.id), e = at >= 0 ? enter(at * 40) : null;
return (
// an item is the item itself (a click opens it and marks it read) and, where its unread dot sits, Mark as unread, a hollow
// dot that shows on a read item under the pointer or with the focus in the row
<div key={x.id} className={cx('dm-ntx-n', x.read && !pending.includes(x.id) && 'dm-read', e ? e.className : 'dm-new')} style={e?.style}>
<button type="button" className="dm-ntx-o" onClick={() => open(x)}>
<span className="dm-ic" data-tone={x.avatar || x.color ? undefined : x.tone ?? 'neutral'}
style={x.avatar || !x.color ? undefined : { color: x.color, background: `color-mix(in srgb,${x.color} 13%,transparent)` }}>
{x.avatar ? <Avatar initials={x.avatar.initials} color={x.avatar.color} /> : <Icon name={x.icon ?? 'bell'} size="xs" />}
</span>
<span className="dm-t">{x.text}<span>{x.time}</span></span>
{!x.read && <span className="dm-ntx-sr">Unread</span>}
</button>
<span className="dm-ntx-m">
<span className="dm-u" aria-hidden="true" />
{x.read && <Tip label={markUnreadLabel}><button type="button" className="dm-ib dm-ntx-u" aria-label={markUnreadLabel} onClick={ev => { setRead(x.id, false); (ev.currentTarget.closest('.dm-ntx-n')?.querySelector('.dm-ntx-o') as HTMLElement | null)?.focus(); }}><i /></button></Tip>}
</span>
</div>
);
}) : (
// an empty filter: a small sketch of a list, a title and one muted line
<div className="dm-ntx-em"><span className="dm-ntx-em-art" aria-hidden="true" /><b>{emptyLabel}</b>{emptyDetail && <span>{emptyDetail}</span>}</div>
)}
</div>
</div>
</div>
);
}
notifications.cssReact · 86 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Notifications ---------- */
/* an inbox: a head with its name, the unread count and Mark all read, a filter, then the items, newest first. The rules
straight under this line are the inbox's parts as the Sales CRM's notifications menu uses them (a bare .ntx in its own
popover); the component's own card (.ntx.panel, below) sets its own measures over them */
.dm-ntx{padding:var(--dm-s-3);display:flex;flex-direction:column;gap:var(--dm-s-2)}
.dm-ntx-h{display:flex;align-items:center;gap:var(--dm-s-2);margin:0 -12px 2px;padding:2px var(--dm-s-3) 10px var(--dm-s-4);font-size:14px;border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.dm-ntx-h b{font-weight:500}
.dm-ntx-ct{min-width:20px;height:20px;padding:0 6px;border-radius:var(--dm-r-pill);background:var(--dm-accent);color:var(--dm-on-accent);font-size:11px;font-weight:500;display:grid;place-items:center;transition:transform .35s var(--dm-ease),opacity .3s}
.dm-ntx-ct.dm-z{opacity:0;transform:scale(.5)}
.dm-ntx-ct.dm-bump{animation:dm-ntb .45s var(--dm-ease)}
@keyframes dm-ntb{40%{transform:scale(1.3)}}
.dm-ntx-sp{flex:1}
.dm-ntx-tabs .dm-seg2 button{font-size:12px;height:26px;padding:0 9px}
.dm-ntx-list{display:flex;flex-direction:column}
.dm-ntx-n{display:flex;gap:10px;padding:9px var(--dm-s-2);border-radius:var(--dm-r-in);text-align:left;width:100%;position:relative;transition:background .2s}
@media (hover:hover) and (pointer:fine){.dm-ntx-n:hover{background:var(--dm-row)}}
/* what an agent did: its icon on its status's tint (a finished run green, one that paused amber, a run that started the
accent), in the status colours (owner, 3 Nov: saturated), never a washed-out mix; a tile given its own colour inline keeps it */
.dm-ntx-n .dm-ic{width:30px;height:30px;border-radius:calc(10px * var(--dm-rk-m,var(--dm-rk)));display:grid;place-items:center;flex:none;background:var(--dm-ntx-tb,transparent);color:var(--dm-ntx-tc,var(--dm-fg2))}
.dm-ntx-n .dm-ic[data-tone="ok"]{--dm-ntx-tb:var(--dm-ok-bg);--dm-ntx-tc:var(--dm-ok)}
.dm-ntx-n .dm-ic[data-tone="warn"]{--dm-ntx-tb:var(--dm-warn-bg);--dm-ntx-tc:var(--dm-warn)}
.dm-ntx-n .dm-ic[data-tone="bad"]{--dm-ntx-tb:var(--dm-bad-bg);--dm-ntx-tc:var(--dm-bad)}
.dm-ntx-n .dm-ic[data-tone="accent"]{--dm-ntx-tb:var(--dm-accent-bg);--dm-ntx-tc:var(--dm-accent-fg)}
.dm-ntx-n .dm-ic[data-tone="neutral"]{--dm-ntx-tb:var(--dm-chip);--dm-ntx-tc:var(--dm-fg2)}
.dm-ntx-n .dm-ic .dm-av{width:30px;height:30px;font-size:11px}
.dm-ntx-n .dm-t{flex:1;min-width:0;font-size:13px;line-height:1.45;color:var(--dm-fg2)}
.dm-ntx-n .dm-t b{font-weight:500;color:var(--dm-fg)}
.dm-ntx-n .dm-t span{display:block;font-size:11.5px;color:var(--dm-muted);margin-top:2px}
.dm-ntx-n .dm-u{width:7px;height:7px;border-radius:50%;background:var(--dm-accent-mark,var(--dm-accent));margin-top:6px;flex:none;transition:transform .3s var(--dm-ease),opacity .3s}
.dm-ntx-n.dm-read .dm-u{transform:scale(0);opacity:0}
.dm-ntx-n.dm-read .dm-t{color:var(--dm-muted)}
.dm-ntx-n.dm-new{animation:dm-ntn .6s var(--dm-ease) both}
@keyframes dm-ntn{from{opacity:0;transform:translateY(-10px);filter:blur(4px)}}
.dm-ntx-e{padding:40px 10px;text-align:center;font-size:13px;color:var(--dm-muted)}
/* the component's own card. It sits on two columns (owner, 18 Nov), its content 16px from every edge in every style: the
head's neutral mark (the inbox's bell) in a 30px column with each item's icon or avatar centred under it, and the inbox's
name and each item's words 12px after it; Mark all read's words and the unread dots end on the content's right edge. The
head's hairline runs from edge to edge with 16px under it. An item is a button, so its hover fill reaches 8px out round it,
a quiet fill that shows in light mode too, with the card's corners less 8. A read item keeps its colours (owner, 20 Nov:
nothing fades to say it is past): only its unread dot goes. The card keeps no room for items to come: it grows as they
arrive (grow()), centred in its stage */
.dm-ntx.dm-panel{padding:var(--dm-s-4);--dm-row:color-mix(in srgb,var(--dm-fg) 5%,transparent)}
.dm-ntx.dm-panel .dm-ntx-h{gap:var(--dm-s-3);margin:0 calc(-1 * var(--dm-s-4)) var(--dm-s-2);padding:0 var(--dm-s-4) var(--dm-s-4);line-height:20px}
.dm-ntx-hi{width:30px;height:30px;display:grid;place-items:center;flex:none;border-radius:calc(10px * var(--dm-rk-m,var(--dm-rk)));background:var(--dm-chip);color:var(--dm-fg2)}
.dm-ntx.dm-panel .dm-ntx-ct{margin-left:calc(-1 * var(--dm-s-1))}
/* Mark all read is a text button: its words end on the content's edge and its hover box reaches out round them */
.dm-ntx.dm-panel .dm-ntx-all.dm-pill{padding:0 var(--dm-s-2);margin-right:calc(-1 * var(--dm-s-2))}
/* the filter is a row of underline tabs under the head (owner, 28 Nov): the head keeps Mark all read top right and has no line
of its own; the tabs' row carries the hairline, edge to edge, and the picked tab's 2px line slides along it (the core's
underline tabs, .utabs) */
.dm-ntx.dm-panel:has(.dm-ntx-ut) .dm-ntx-h{border-bottom:0;margin-bottom:0}
.dm-ntx-ut{margin:calc(-1 * var(--dm-s-2)) calc(-1 * var(--dm-s-4)) var(--dm-s-2)}
/* an item is two buttons on one row: the item itself, which opens it and marks it read, and, at the unread dot's place, Mark as
unread, a hollow dot that shows on a read item under the pointer or with the focus in the row */
.dm-ntx-o{flex:1;min-width:0;display:flex;align-items:center;gap:var(--dm-s-3);text-align:left;color:inherit}
.dm-ntx-m{position:relative;flex:none;width:7px;height:7px;display:grid}
.dm-ntx.dm-panel .dm-ntx-n .dm-ntx-m .dm-u{margin:0}
.dm-ntx-u{position:absolute;left:50%;top:50%;width:24px;height:24px;margin:-12px 0 0 -12px;opacity:0;visibility:hidden;transition:opacity var(--dm-t-fast) var(--dm-ease),visibility 0s var(--dm-t-fast),background var(--dm-t-fast)}
.dm-ntx-u i{width:7px;height:7px;border-radius:50%;box-shadow:inset 0 0 0 1.5px var(--dm-muted)}
@media (hover:hover) and (pointer:fine){.dm-ntx-n.dm-read:is(:hover,:focus-within) .dm-ntx-u{opacity:1;visibility:visible;transition-delay:0s}}
.dm-ntx-n:not(.dm-read) .dm-ntx-u{display:none}
.dm-ntx-sr{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.dm-ntx.dm-panel .dm-ntx-list{margin:0 calc(-1 * var(--dm-s-2)) calc(-1 * var(--dm-s-2))}
.dm-ntx.dm-panel .dm-ntx-n{align-items:center;gap:var(--dm-s-3);padding:var(--dm-s-2);border-radius:calc(var(--dm-r-card) - var(--dm-s-2));transition:background-color var(--dm-t-fast)}
.dm-ntx.dm-panel .dm-ntx-n .dm-t span{line-height:15px}
.dm-ntx.dm-panel .dm-ntx-n .dm-u{margin-top:0}
.dm-ntx.dm-panel .dm-ntx-n.dm-read .dm-t{color:var(--dm-fg2)}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov) */
.dm-ntx.dm-panel :is(.dm-pill,.dm-ntx-n):active{transform:none}
/* an empty filter: a small sketch of a list on a white card, a title and one muted line (Studio's empty state, in every style) */
.dm-ntx-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:var(--dm-s-6) var(--dm-s-4) var(--dm-s-4);text-align:center}
.dm-ntx-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.dm-ntx-em>span:not(.dm-ntx-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted)}
.dm-ntx-em-art{position:relative;display:block;width:136px;height:70px;margin:0 0 var(--dm-s-4);border-radius:calc(10px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow)}
.dm-ntx-em-art::before{content:"";position:absolute;left:14px;top:14px;width:10px;height:10px;border-radius:50%;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-row))}
.dm-ntx-em-art::after{content:"";position:absolute;left:32px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-row))}
:root:not([data-style="soft"],[data-style="studio"]) .dm-ntx-em-art:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:inset 0 0 0 1px var(--dm-line)}
/* Studio: the head's mark has a hairline like the other tiles, and a new item rises in without a blur */
:root[data-style="studio"] .dm-ntx-hi,:root [data-style="studio"] .dm-ntx-hi,:root [data-style="studio"].dm-ntx-hi{box-shadow:inset 0 0 0 1px var(--dm-hair)}
/* the head (the inbox, its count and Mark all read) is an off-white head strip, as every Studio card with a head has; its
controls sit 16px from the strip's top and bottom (--dm-strip-y, owner, 23 Nov) and on the content's 16px column */
:root[data-style="studio"] .dm-ntx.dm-panel .dm-ntx-h,:root [data-style="studio"] .dm-ntx.dm-panel .dm-ntx-h,:root [data-style="studio"].dm-ntx.dm-panel .dm-ntx-h{margin:calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4)) var(--dm-s-2);padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .dm-ntx.dm-panel:has(.dm-ntx-ut) .dm-ntx-h,:root [data-style="studio"] .dm-ntx.dm-panel:has(.dm-ntx-ut) .dm-ntx-h,:root [data-style="studio"].dm-ntx.dm-panel:has(.dm-ntx-ut) .dm-ntx-h{margin-bottom:0;border-bottom:0}
:root[data-style="studio"] .dm-ntx.dm-panel .dm-ntx-n.dm-new,:root [data-style="studio"] .dm-ntx.dm-panel .dm-ntx-n.dm-new,:root [data-style="studio"].dm-ntx.dm-panel .dm-ntx-n.dm-new{animation:dm-clpiece var(--dm-t-slow) var(--dm-ease) both}
Notifications.astroAstro · 28 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Notifications: An inbox where agent updates and mentions arrive live.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change notifications.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './notifications.css';
export interface Props extends HTMLAttributes<'div'> {
/** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', className]} data-c="notifications" {...rest}>
<div class="stage-in"><Fragment is:raw>
<div class="ntx panel">
<div class="ntx-h"><span class="ntx-hi" aria-hidden="true"><svg class="i s"><use href="#i-bell"/></svg></span><b>Inbox</b><span class="ntx-ct num">0</span><span class="ntx-sp"></span><button class="pill ghost sm ntx-all">Mark all read</button></div>
<div class="utabs ntx-ut" role="tablist" aria-label="Filter"><span class="utabs-i" aria-hidden="true"></span><button role="tab" aria-selected="true" data-v="all">All</button><button role="tab" aria-selected="false" tabindex="-1" data-v="agent">Agent</button><button role="tab" aria-selected="false" tabindex="-1" data-v="men">Mentions</button></div>
<div class="ntx-list" role="tabpanel"></div>
</div>
</Fragment></div>
</div>
<script>
import './notifications.js';
</script>
notifications.htmlHTML · 10 lines
<div class="card" data-c="notifications">
<div class="stage-in">
<div class="ntx panel">
<div class="ntx-h"><span class="ntx-hi" aria-hidden="true"><svg class="i s"><use href="#i-bell"/></svg></span><b>Inbox</b><span class="ntx-ct num">0</span><span class="ntx-sp"></span><button class="pill ghost sm ntx-all">Mark all read</button></div>
<div class="utabs ntx-ut" role="tablist" aria-label="Filter"><span class="utabs-i" aria-hidden="true"></span><button role="tab" aria-selected="true" data-v="all">All</button><button role="tab" aria-selected="false" tabindex="-1" data-v="agent">Agent</button><button role="tab" aria-selected="false" tabindex="-1" data-v="men">Mentions</button></div>
<div class="ntx-list" role="tabpanel"></div>
</div>
</div>
</div>
notifications.cssHTML · 85 lines
/* ---------- Notifications ---------- */
/* an inbox: a head with its name, the unread count and Mark all read, a filter, then the items, newest first. The rules
straight under this line are the inbox's parts as the Sales CRM's notifications menu uses them (a bare .ntx in its own
popover); the component's own card (.ntx.panel, below) sets its own measures over them */
.ntx{padding:var(--dm-s-3);display:flex;flex-direction:column;gap:var(--dm-s-2)}
.ntx-h{display:flex;align-items:center;gap:var(--dm-s-2);margin:0 -12px 2px;padding:2px var(--dm-s-3) 10px var(--dm-s-4);font-size:14px;border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.ntx-h b{font-weight:500}
.ntx-ct{min-width:20px;height:20px;padding:0 6px;border-radius:var(--dm-r-pill);background:var(--dm-accent);color:var(--dm-on-accent);font-size:11px;font-weight:500;display:grid;place-items:center;transition:transform .35s var(--dm-ease),opacity .3s}
.ntx-ct.z{opacity:0;transform:scale(.5)}
.ntx-ct.bump{animation:ntb .45s var(--dm-ease)}
@keyframes ntb{40%{transform:scale(1.3)}}
.ntx-sp{flex:1}
.ntx-tabs .seg2 button{font-size:12px;height:26px;padding:0 9px}
.ntx-list{display:flex;flex-direction:column}
.ntx-n{display:flex;gap:10px;padding:9px var(--dm-s-2);border-radius:var(--dm-r-in);text-align:left;width:100%;position:relative;transition:background .2s}
@media (hover:hover) and (pointer:fine){.ntx-n:hover{background:var(--dm-row)}}
/* what an agent did: its icon on its status's tint (a finished run green, one that paused amber, a run that started the
accent), in the status colours (owner, 3 Nov: saturated), never a washed-out mix; a tile given its own colour inline keeps it */
.ntx-n .ic{width:30px;height:30px;border-radius:calc(10px * var(--dm-rk-m,var(--dm-rk)));display:grid;place-items:center;flex:none;background:var(--dm-ntx-tb,transparent);color:var(--dm-ntx-tc,var(--dm-fg2))}
.ntx-n .ic[data-tone="ok"]{--dm-ntx-tb:var(--dm-ok-bg);--dm-ntx-tc:var(--dm-ok)}
.ntx-n .ic[data-tone="warn"]{--dm-ntx-tb:var(--dm-warn-bg);--dm-ntx-tc:var(--dm-warn)}
.ntx-n .ic[data-tone="bad"]{--dm-ntx-tb:var(--dm-bad-bg);--dm-ntx-tc:var(--dm-bad)}
.ntx-n .ic[data-tone="accent"]{--dm-ntx-tb:var(--dm-accent-bg);--dm-ntx-tc:var(--dm-accent-fg)}
.ntx-n .ic[data-tone="neutral"]{--dm-ntx-tb:var(--dm-chip);--dm-ntx-tc:var(--dm-fg2)}
.ntx-n .ic .av{width:30px;height:30px;font-size:11px}
.ntx-n .t{flex:1;min-width:0;font-size:13px;line-height:1.45;color:var(--dm-fg2)}
.ntx-n .t b{font-weight:500;color:var(--dm-fg)}
.ntx-n .t span{display:block;font-size:11.5px;color:var(--dm-muted);margin-top:2px}
.ntx-n .u{width:7px;height:7px;border-radius:50%;background:var(--dm-accent-mark,var(--dm-accent));margin-top:6px;flex:none;transition:transform .3s var(--dm-ease),opacity .3s}
.ntx-n.read .u{transform:scale(0);opacity:0}
.ntx-n.read .t{color:var(--dm-muted)}
.ntx-n.new{animation:ntn .6s var(--dm-ease) both}
@keyframes ntn{from{opacity:0;transform:translateY(-10px);filter:blur(4px)}}
.ntx-e{padding:40px 10px;text-align:center;font-size:13px;color:var(--dm-muted)}
/* the component's own card. It sits on two columns (owner, 18 Nov), its content 16px from every edge in every style: the
head's neutral mark (the inbox's bell) in a 30px column with each item's icon or avatar centred under it, and the inbox's
name and each item's words 12px after it; Mark all read's words and the unread dots end on the content's right edge. The
head's hairline runs from edge to edge with 16px under it. An item is a button, so its hover fill reaches 8px out round it,
a quiet fill that shows in light mode too, with the card's corners less 8. A read item keeps its colours (owner, 20 Nov:
nothing fades to say it is past): only its unread dot goes. The card keeps no room for items to come: it grows as they
arrive (grow()), centred in its stage */
.ntx.panel{padding:var(--dm-s-4);--dm-row:color-mix(in srgb,var(--dm-fg) 5%,transparent)}
.ntx.panel .ntx-h{gap:var(--dm-s-3);margin:0 calc(-1 * var(--dm-s-4)) var(--dm-s-2);padding:0 var(--dm-s-4) var(--dm-s-4);line-height:20px}
.ntx-hi{width:30px;height:30px;display:grid;place-items:center;flex:none;border-radius:calc(10px * var(--dm-rk-m,var(--dm-rk)));background:var(--dm-chip);color:var(--dm-fg2)}
.ntx.panel .ntx-ct{margin-left:calc(-1 * var(--dm-s-1))}
/* Mark all read is a text button: its words end on the content's edge and its hover box reaches out round them */
.ntx.panel .ntx-all.pill{padding:0 var(--dm-s-2);margin-right:calc(-1 * var(--dm-s-2))}
/* the filter is a row of underline tabs under the head (owner, 28 Nov): the head keeps Mark all read top right and has no line
of its own; the tabs' row carries the hairline, edge to edge, and the picked tab's 2px line slides along it (the core's
underline tabs, .utabs) */
.ntx.panel:has(.ntx-ut) .ntx-h{border-bottom:0;margin-bottom:0}
.ntx-ut{margin:calc(-1 * var(--dm-s-2)) calc(-1 * var(--dm-s-4)) var(--dm-s-2)}
/* an item is two buttons on one row: the item itself, which opens it and marks it read, and, at the unread dot's place, Mark as
unread, a hollow dot that shows on a read item under the pointer or with the focus in the row */
.ntx-o{flex:1;min-width:0;display:flex;align-items:center;gap:var(--dm-s-3);text-align:left;color:inherit}
.ntx-m{position:relative;flex:none;width:7px;height:7px;display:grid}
.ntx.panel .ntx-n .ntx-m .u{margin:0}
.ntx-u{position:absolute;left:50%;top:50%;width:24px;height:24px;margin:-12px 0 0 -12px;opacity:0;visibility:hidden;transition:opacity var(--dm-t-fast) var(--dm-ease),visibility 0s var(--dm-t-fast),background var(--dm-t-fast)}
.ntx-u i{width:7px;height:7px;border-radius:50%;box-shadow:inset 0 0 0 1.5px var(--dm-muted)}
@media (hover:hover) and (pointer:fine){.ntx-n.read:is(:hover,:focus-within) .ntx-u{opacity:1;visibility:visible;transition-delay:0s}}
.ntx-n:not(.read) .ntx-u{display:none}
.ntx-sr{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.ntx.panel .ntx-list{margin:0 calc(-1 * var(--dm-s-2)) calc(-1 * var(--dm-s-2))}
.ntx.panel .ntx-n{align-items:center;gap:var(--dm-s-3);padding:var(--dm-s-2);border-radius:calc(var(--dm-r-card) - var(--dm-s-2));transition:background-color var(--dm-t-fast)}
.ntx.panel .ntx-n .t span{line-height:15px}
.ntx.panel .ntx-n .u{margin-top:0}
.ntx.panel .ntx-n.read .t{color:var(--dm-fg2)}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov) */
.ntx.panel :is(.pill,.ntx-n):active{transform:none}
/* an empty filter: a small sketch of a list on a white card, a title and one muted line (Studio's empty state, in every style) */
.ntx-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:var(--dm-s-6) var(--dm-s-4) var(--dm-s-4);text-align:center}
.ntx-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.ntx-em>span:not(.ntx-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted)}
.ntx-em-art{position:relative;display:block;width:136px;height:70px;margin:0 0 var(--dm-s-4);border-radius:calc(10px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow)}
.ntx-em-art::before{content:"";position:absolute;left:14px;top:14px;width:10px;height:10px;border-radius:50%;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-row))}
.ntx-em-art::after{content:"";position:absolute;left:32px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-row))}
:root:not([data-style="soft"],[data-style="studio"]) .ntx-em-art:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:inset 0 0 0 1px var(--dm-line)}
/* Studio: the head's mark has a hairline like the other tiles, and a new item rises in without a blur */
:root[data-style="studio"] .ntx-hi,:root [data-style="studio"] .ntx-hi,:root [data-style="studio"].ntx-hi{box-shadow:inset 0 0 0 1px var(--dm-hair)}
/* the head (the inbox, its count and Mark all read) is an off-white head strip, as every Studio card with a head has; its
controls sit 16px from the strip's top and bottom (--dm-strip-y, owner, 23 Nov) and on the content's 16px column */
:root[data-style="studio"] .ntx.panel .ntx-h,:root [data-style="studio"] .ntx.panel .ntx-h,:root [data-style="studio"].ntx.panel .ntx-h{margin:calc(-1 * var(--dm-s-4)) calc(-1 * var(--dm-s-4)) var(--dm-s-2);padding:var(--dm-strip-y) var(--dm-s-4);background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .ntx.panel:has(.ntx-ut) .ntx-h,:root [data-style="studio"] .ntx.panel:has(.ntx-ut) .ntx-h,:root [data-style="studio"].ntx.panel:has(.ntx-ut) .ntx-h{margin-bottom:0;border-bottom:0}
:root[data-style="studio"] .ntx.panel .ntx-n.new,:root [data-style="studio"] .ntx.panel .ntx-n.new,:root [data-style="studio"].ntx.panel .ntx-n.new{animation:clpiece var(--dm-t-slow) var(--dm-ease) both}
notifications.jsHTML · 35 lines
DM.def('notifications', (r, c) => {
r.innerHTML = r.innerHTML.replace('{bell}', I('bell'));
// Studio's one hover: a highlight that glides from row to row (hoverGlide)
c.offs.push(hoverGlide($('.ntx', r), '.ntx-n'));
// what the agent did shows its icon on its status's tint (tone: ok, warn, bad, accent or neutral); people show their avatar
let N = [
{ k:'agent', ic:'ok', tone:'ok', t:'<b>Pricing audit</b> finished. 2 fixes ready to review', w:'4 min ago' },
{ k:'men', av:['MK','var(--dm-av-l)','MK-g03'], t:'<b>Maya</b> mentioned you in Checkout flow', w:'20 min ago' },
{ k:'agent', ic:'alert', tone:'warn', t:'<b>Token export</b> paused at the $5 cap', w:'1 hour ago' },
{ k:'men', av:['JO','var(--dm-av-m)','JO-g01'], t:'<b>Jon</b> asked for your review on PR #284', w:'2 hours ago', read:true }
];
const root = r.classList.contains('ntx') ? r : $('.ntx', r), list = $('.ntx-list', r), ct = $('.ntx-ct', r); let f = 'all';
const count = (bump) => { const n = N.filter(x => !x.read).length; ct.textContent = n; ct.classList.toggle('z', !n); if (bump){ ct.classList.remove('bump'); void ct.offsetWidth; ct.classList.add('bump'); } };
const row = x => `<div class="ntx-n${x.read ? ' read' : ''}"><button class="ntx-o"><span class="ic"${x.ic ? ` data-tone="${x.tone || 'neutral'}"` : ''}>${x.ic ? I(x.ic,'xs') : AV(x.av[0], x.av[1], x.av[2])}</span><span class="t">${x.t}<span>${x.w}</span></span><span class="ntx-sr">${x.read ? '' : 'Unread'}</span></button><span class="ntx-m"><span class="u" aria-hidden="true"></span><button class="ib ntx-u" aria-label="Mark as unread" data-tip="Mark as unread"><i></i></button></span></div>`;
// clicking an item opens it (onOpen in React) and marks it read; Mark as unread, on the row, takes it back
const mark = (b, x, read) => { if (x.read === read) return; x.read = read; b.classList.toggle('read', read); $('.ntx-sr', b).textContent = read ? '' : 'Unread'; count(); };
const wire = (b, x) => { $('.ntx-o', b).onclick = () => mark(b, x, true); $('.ntx-u', b).onclick = () => { hideTip(); mark(b, x, false); $('.ntx-o', b).focus({ preventScroll:true }); }; };
// an empty filter shows Studio's empty state: a small sketch of a list, a title and one muted line
const EMPTY = '<div class="ntx-em"><span class="ntx-em-art" aria-hidden="true"></span><b>Nothing here yet</b><span>New updates and mentions show up here</span></div>';
function paint(anim){ const L = N.filter(x => f === 'all' || x.k === f); list.innerHTML = L.length ? L.map(row).join('') : EMPTY;
$$('.ntx-n', list).forEach((b, i) => wire(b, L[i]));
if (anim) stagger($$('.ntx-n', list), 40); count(); }
// the filter's tabs: a click or Left and Right pick one, and the line under the tabs slides to it (placed at once the first time)
utabs(c, $('.ntx-ut', r), v => { if (f !== v){ f = v; paint(true); } }, list);
$('.ntx-all', r).onclick = () => { N.forEach(x => x.read = true); count(); $$('.ntx-n', list).forEach((b, i) => c.later(i * 50, () => { b.classList.add('read'); $('.ntx-sr', b).textContent = ''; })); };
paint(true);
// the card fits its items at every moment (owner, 17 and 18 Nov: no room kept for the ones to come): it eases taller as one
// arrives or a filter shows more, and shorter as one shows fewer, centred in its stage (grow(), once its entrance has ended)
if (root) Promise.resolve().then(() => Promise.all(root.getAnimations().map(a => a.finished.catch(() => {})))).then(() => { if (!c.dead && root.isConnected) c.offs.push(grow(root)); });
const incoming = [{ k:'agent', ic:'spark', tone:'accent', t:'<b>Weekly design QA</b> started on 12 frames', w:'Just now' }, { k:'men', av:['AR','var(--dm-av-p)','AR-g02'], t:'<b>Ari</b> replied: “Looks great, ship it”', w:'Just now' }];
// two items arrive while you watch; once you click or type in the inbox the preview leaves it to you, so a tab you
// picked or a Mark all read stays as you left it
incoming.forEach((x, i) => c.later(2200 + i * 2600, () => { if (c.mine) return; N.unshift(x); if (f === 'all' || f === x.k){ const el = html(row(x)); el.classList.add('new'); list.prepend(el); $('.ntx-em', list)?.remove(); wire(el, x); } count(true); }));
});
Questions
What people ask about it.
- How do I push a new notification in while the inbox is open?
- Control it with
itemsandonItemsChange, and add the new item to the front of the array with an id it has not seen. It drops in at the top and the count bumps. - Can I add my own filter, like Billing?
- Yes. Pass
filterswith avalueandlabelfor each tab, and give items the matchingkind. The value 'all' always shows everything. - How do I bold the subject of a notification?
texttakes React nodes, so wrap the subject in<b>, like<><b>Pricing audit</b> finished</>.
More in Collaboration
Threads, inboxes and boards for teams working alongside an agent.