Notification stack
Notifications stacked in depth that fan out on hover or focus, with dismiss and clear all.
Svelte 5 · Version 1.0.0 · Zero extra packages
Live preview
-
Deploy succeeded
Production is now running build 2.4.1.
-
New comment
Maya replied to your pricing page review.
-
Usage at 80%
You have used 800k of 1M events this month.
Design decision
Stacking keeps many alerts in the space of one, and expanding on focus keeps every alert reachable by keyboard. Original Svelte 5 implementation. No code was copied from the inspiring component.
Inspired by Dismissible Alert Stack by @olewandowski1 on 21st.dev ↗
Source and integration
Pass notices with id, title, description, time and an optional tone (success, info or warning).
You may copy and adapt this original SaaSCrisp implementation in personal and commercial websites.
NotificationStack.svelte
<script lang="ts">
type Tone = 'success' | 'info' | 'warning';
type Notice = { id: string; title: string; description: string; time: string; tone?: Tone };
let { notices, label = 'Notifications' }: { notices: Notice[]; label?: string } = $props();
const icons: Record<Tone, string> = {
success: 'M6 12.5l4 4 8-9',
info: 'M12 16v-5M12 8h.01',
warning: 'M12 8v5M12 16.5h.01'
};
const CARD = 78;
const GAP = 8;
const PEEK = 14;
let dismissed = $state<string[]>([]);
let expanded = $state(false);
const visible = $derived(notices.filter((notice) => !dismissed.includes(notice.id)));
const height = $derived(
visible.length === 0 ? 0 : expanded ? visible.length * (CARD + GAP) - GAP : CARD + Math.min(visible.length - 1, 2) * PEEK
);
function dismiss(id: string) {
dismissed = [...dismissed, id];
}
</script>
<section
class="ns"
aria-label={label}
onpointerenter={() => (expanded = true)}
onpointerleave={() => (expanded = false)}
onfocusin={() => (expanded = true)}
onfocusout={(event) => {
if (!event.currentTarget.contains(event.relatedTarget as Node | null)) expanded = false;
}}
>
<header>
<span>{label} <b>{visible.length}</b></span>
{#if visible.length}
<button type="button" class="ns-clear" onclick={() => (dismissed = notices.map((notice) => notice.id))}>Clear all</button>
{/if}
</header>
{#if visible.length}
<ol style:height="{height}px">
{#each visible as notice, index (notice.id)}
<li
class:hidden={!expanded && index > 2}
style:z-index={visible.length - index}
style:transform={expanded
? `translateY(${index * (CARD + GAP)}px)`
: `translateY(${index * PEEK}px) scale(${1 - index * 0.06})`}
style:opacity={!expanded && index > 0 ? 1 - index * 0.25 : 1}
>
<span class="ns-icon {notice.tone ?? 'info'}" aria-hidden="true">
<svg viewBox="0 0 24 24"><path d={icons[notice.tone ?? 'info']} /></svg>
</span>
<div class="ns-text">
<p class="ns-title">{notice.title} <time>{notice.time}</time></p>
<p class="ns-desc">{notice.description}</p>
</div>
<button type="button" class="ns-close" aria-label="Dismiss {notice.title}" onclick={() => dismiss(notice.id)}>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18" /></svg>
</button>
</li>
{/each}
</ol>
{:else}
<p class="ns-empty" role="status">You’re all caught up.</p>
{/if}
</section>
<style>
.ns {
--_bg: var(--ui-bg, #ffffff);
--_border: var(--ui-border, rgb(15 23 42 / 0.1));
--_text: var(--ui-text, #0f172a);
--_muted: var(--ui-muted, #64748b);
--_accent: var(--ui-accent, #4f46e5);
display: grid;
gap: 12px;
width: 100%;
max-width: 380px;
margin-inline: auto;
color: var(--_text);
font-family: var(--ui-font, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif);
text-align: left;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 4px;
color: var(--_muted);
font-size: 13px;
}
header b {
margin-left: 4px;
padding: 1px 7px;
border-radius: 999px;
background: rgb(15 23 42 / 0.07);
color: var(--_text);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
button {
border: 0;
background: none;
color: inherit;
font: inherit;
cursor: pointer;
}
button:focus-visible {
outline: 2px solid var(--_accent);
outline-offset: 2px;
}
.ns-clear {
padding: 2px 6px;
border-radius: 6px;
color: var(--_muted);
font-size: 13px;
}
.ns-clear:hover {
color: var(--_text);
}
ol {
position: relative;
margin: 0;
padding: 0;
list-style: none;
transition: height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
li {
position: absolute;
inset: 0 0 auto;
display: flex;
align-items: center;
gap: 12px;
height: 78px;
padding: 0 12px 0 14px;
border: 1px solid var(--_border);
border-radius: 16px;
background: var(--_bg);
box-shadow:
inset 0 1px 0 rgb(255 255 255 / 0.05),
0 12px 30px -12px rgb(15 23 42 / 0.12);
transform-origin: bottom center;
transition:
transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
opacity 0.3s;
}
li.hidden {
visibility: hidden;
}
.ns-icon {
display: grid;
flex-shrink: 0;
place-items: center;
width: 32px;
height: 32px;
border-radius: 10px;
background: rgb(15 23 42 / 0.06);
color: var(--_text);
}
.ns-icon.success {
background: color-mix(in srgb, var(--_accent) 14%, transparent);
color: var(--_accent);
}
.ns-icon.warning {
background: rgb(217 119 6 / 0.12);
color: #b45309;
}
.ns-icon svg {
width: 16px;
height: 16px;
fill: none;
stroke: currentColor;
stroke-width: 2.4;
stroke-linecap: round;
stroke-linejoin: round;
}
.ns-text {
flex: 1;
min-width: 0;
}
.ns-text p {
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.ns-title {
font-size: 14px;
font-weight: 600;
}
time {
margin-left: 4px;
color: var(--_muted);
font-size: 12px;
font-weight: 400;
}
.ns-desc {
margin-top: 3px !important;
color: var(--_muted);
font-size: 13px;
}
.ns-close {
display: grid;
flex-shrink: 0;
place-items: center;
width: 26px;
height: 26px;
border-radius: 7px;
color: var(--_muted);
opacity: 0.6;
transition:
opacity 0.15s,
background-color 0.15s;
}
li:hover .ns-close,
.ns-close:focus-visible {
opacity: 1;
}
.ns-close:hover {
background: rgb(15 23 42 / 0.07);
color: var(--_text);
}
.ns-close svg {
width: 13px;
height: 13px;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
}
.ns-empty {
margin: 0;
padding: 26px;
border: 1px dashed var(--_border);
border-radius: 16px;
color: var(--_muted);
font-size: 14px;
text-align: center;
}
@media (prefers-reduced-motion: reduce) {
ol,
li {
transition: none;
}
}
</style>
Agent prompt
Use the SaaSCrisp UI Library MCP at https://www.saascrisp.com/api/library/mcp. Retrieve notification-stack version 1.0.0 for svelte with get_ui_asset. Preview: https://www.saascrisp.com/library/notification-stack. Confirm the project's stack, reuse local primitives and map CSS variables to existing design tokens. Integrate the files and run the project's checks. Report changed files and additional dependencies.