feat(operator): notification drawer behind the topbar bell

Right-anchored slide-in inbox triggered by the bell button. Backend is a
follow-up — for now this is a visual + behavior shell with mock fixtures,
same pattern as INCIDENT / FLAGS / OP_AUDIT.

- data/fixtures.ts: new NotificationItem type + 6 seed rows from the
  design (DMARC, invitation, invoice, SAML, ticket reply, failed sign-in)
- useNotifications composable: isOpen + items + unreadCount + markRead +
  markAllRead. Items deep-clone the fixture on first import so toggling
  unread doesn't mutate the shared seed.
- NotificationDrawer component: Teleport + scrim + slide animation,
  header/list/footer. Each row shows tone-tinted icon tile + title +
  description + timestamp + left-rail unread dot. Click a row to mark
  read; click Mark all read or Preferences in the footer.
- OpTopbar: bell now opens the drawer and only shows .icon-btn-dot when
  unreadCount > 0.
- Layout mounts <NotificationDrawer /> alongside the other floating
  components.

Dismissal: backdrop click, Escape, X, and route-change watcher (so
Preferences → /settings closes the drawer cleanly).
This commit is contained in:
Ronni Baslund
2026-05-24 17:08:14 +02:00
parent 455717ac67
commit 9fac11e668
5 changed files with 300 additions and 2 deletions
@@ -0,0 +1,236 @@
<script setup lang="ts">
// Right-anchored notification inbox. Slides in when the bell is clicked.
// Same dismissal pattern as the other floating mounts (CommandPalette /
// IncidentModal): backdrop click, Escape, X, plus auto-close on route
// change so navigating from "Preferences" doesn't leave the drawer hanging.
const { isOpen, items, close, markRead, markAllRead } = useNotifications()
const route = useRoute()
watch(() => route.path, () => {
if (isOpen.value) close()
})
onMounted(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape' && isOpen.value) close()
}
document.addEventListener('keydown', onKey)
onBeforeUnmount(() => document.removeEventListener('keydown', onKey))
})
</script>
<template>
<Teleport to="body">
<Transition name="drawer-fade">
<div v-if="isOpen" class="backdrop" @click="close" />
</Transition>
<Transition name="drawer-slide">
<aside v-if="isOpen" class="drawer" role="dialog" aria-label="Notifications" @click.stop>
<header>
<div>
<Eyebrow>Notifications</Eyebrow>
<h2>Inbox</h2>
</div>
<button class="x" type="button" aria-label="Close" @click="close">
<UiIcon name="x" :size="13" />
</button>
</header>
<ul class="list">
<li
v-for="n in items"
:key="n.id"
:class="['row', { unread: n.unread }]"
tabindex="0"
@click="markRead(n.id)"
@keydown.enter="markRead(n.id)"
>
<span class="rail">
<span v-if="n.unread" class="dot" :data-tone="n.tone" />
</span>
<span class="icon-tile" :data-tone="n.tone">
<UiIcon :name="n.icon" :size="14" />
</span>
<div class="body">
<div class="line">
<span class="title">{{ n.title }}</span>
<Mono dim class="when">{{ n.when }}</Mono>
</div>
<div class="desc">{{ n.body }}</div>
</div>
</li>
<li v-if="!items.length" class="empty">
<Mono dim>// no notifications</Mono>
</li>
</ul>
<footer>
<button type="button" class="link" @click="markAllRead">Mark all read</button>
<NuxtLink to="/settings" class="link prefs" @click="close">
Preferences
<UiIcon name="chevRight" :size="11" />
</NuxtLink>
</footer>
</aside>
</Transition>
</Teleport>
</template>
<style scoped>
.backdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.45);
z-index: 190;
}
.drawer {
position: fixed;
top: 0;
right: 0;
bottom: 0;
width: min(480px, 100vw);
background: var(--elevated);
border-left: 1px solid var(--border);
box-shadow: -16px 0 48px rgba(0, 0, 0, 0.35);
z-index: 200;
display: flex;
flex-direction: column;
overflow: hidden;
}
header {
padding: 18px 22px 14px 22px;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: flex-start;
}
h2 {
margin: 4px 0 0 0;
font-family: var(--font-display);
font-weight: 600;
font-size: 22px;
letter-spacing: -0.02em;
}
.x {
width: 28px;
height: 28px;
border: 0;
border-radius: 6px;
background: transparent;
color: var(--text-mute);
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
}
.x:hover { background: var(--surface); color: var(--text); }
.list {
list-style: none;
margin: 0;
padding: 8px 8px 0 8px;
overflow-y: auto;
flex: 1;
display: flex;
flex-direction: column;
gap: 2px;
}
.row {
display: grid;
grid-template-columns: 10px 36px 1fr;
gap: 12px;
padding: 12px 12px 12px 6px;
border-radius: 8px;
cursor: pointer;
background: transparent;
transition: background 0.1s;
}
.row:hover, .row:focus { background: var(--surface); outline: none; }
.row.unread { background: var(--surface); }
.row.unread:hover { background: var(--bg); }
.rail { display: flex; align-items: flex-start; justify-content: center; padding-top: 14px; }
.dot {
width: 6px;
height: 6px;
border-radius: 999px;
background: var(--warn);
}
.dot[data-tone='info'] { background: var(--info); }
.dot[data-tone='ok'] { background: var(--ok); }
.dot[data-tone='bad'] { background: var(--bad); }
.dot[data-tone='neutral'] { background: var(--text-mute); }
.icon-tile {
width: 36px;
height: 36px;
border-radius: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
background: var(--surface);
color: var(--text-dim);
border: 1px solid var(--border);
}
.icon-tile[data-tone='warn'] { background: rgba(232, 154, 31, 0.12); color: var(--warn); border-color: rgba(232, 154, 31, 0.24); }
.icon-tile[data-tone='info'] { background: rgba(42, 111, 219, 0.10); color: var(--info); border-color: rgba(42, 111, 219, 0.22); }
.icon-tile[data-tone='ok'] { background: rgba(31, 138, 91, 0.10); color: var(--ok); border-color: rgba(31, 138, 91, 0.20); }
.icon-tile[data-tone='bad'] { background: rgba(226, 48, 48, 0.10); color: var(--bad); border-color: rgba(226, 48, 48, 0.22); }
.body { min-width: 0; }
.line {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
}
.title { font-size: 13px; font-weight: 600; line-height: 1.35; }
.when { flex-shrink: 0; white-space: nowrap; }
.desc {
margin-top: 3px;
font-size: 12px;
color: var(--text-mute);
line-height: 1.45;
}
.empty { padding: 40px 12px; text-align: center; }
footer {
border-top: 1px solid var(--border);
background: var(--bg);
padding: 12px 18px;
display: flex;
justify-content: space-between;
align-items: center;
}
.link {
appearance: none;
background: transparent;
border: 0;
color: var(--text);
font-family: inherit;
font-size: 13px;
cursor: pointer;
padding: 6px 10px;
border-radius: 6px;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 6px;
}
.link:hover { background: var(--surface); }
.prefs { color: var(--text-dim); }
/* Animations */
.drawer-fade-enter-active, .drawer-fade-leave-active { transition: opacity 0.18s ease; }
.drawer-fade-enter-from, .drawer-fade-leave-to { opacity: 0; }
.drawer-slide-enter-active, .drawer-slide-leave-active { transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1); }
.drawer-slide-enter-from, .drawer-slide-leave-to { transform: translateX(100%); }
</style>
+3 -2
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
const { open: openPalette } = useCommandPalette()
const { open: openNotifications, unreadCount } = useNotifications()
const { env } = useEnv()
const ENVS = {
@@ -23,9 +24,9 @@ const ENVS = {
</button>
<div class="right">
<button class="icon-btn" title="Notifications">
<button class="icon-btn" title="Notifications" @click="openNotifications">
<UiIcon name="bell" :size="14" />
<span class="icon-btn-dot" />
<span v-if="unreadCount > 0" class="icon-btn-dot" />
</button>
<UserMenu />
@@ -0,0 +1,33 @@
// Shared notification-drawer state. The bell in the topbar opens the drawer
// via `open()`; the drawer reads from `items` and toggles `unread` via
// `markRead` / `markAllRead`. `unreadCount` powers the red dot on the bell.
//
// All state is in-memory and re-seeds from the NOTIFICATIONS fixture on each
// full reload — there's no backend yet. When the real notifications source
// lands (see follow-ups in NEXT-STEPS.md), swap `items` for a useFetch.
import { NOTIFICATIONS, type NotificationItem } from '~/data/fixtures'
const isOpen = ref(false)
const items = ref<NotificationItem[]>(NOTIFICATIONS.map((n) => ({ ...n })))
const unreadCount = computed(() => items.value.filter((n) => n.unread).length)
export const useNotifications = () => ({
isOpen,
items,
unreadCount,
open: () => {
isOpen.value = true
},
close: () => {
isOpen.value = false
},
markRead: (id: string) => {
const i = items.value.find((n) => n.id === id)
if (i) i.unread = false
},
markAllRead: () => {
for (const n of items.value) n.unread = false
},
})
+27
View File
@@ -4,6 +4,8 @@
// derivable from those should NOT live here. See OPERATOR-PLAN.md follow-ups
// for the path from each fixture to a real implementation.
import type { IconName } from '~/components/UiIcon.vue'
export type ServiceStatus = 'ok' | 'warn' | 'bad'
export interface PlatformService {
id: string
@@ -105,3 +107,28 @@ export const OP_AUDIT: AuditEntry[] = [
{ id: 'op_8812', when: '10:12:08', actor: 'Mikkel Nørgaard', role: 'engineer', action: 'feature_flag.created', target: 'beta_ai_summaries', tenant: '—', ip: '10.0.4.21', tone: 'info' },
{ id: 'op_8811', when: '09:30:00', actor: 'Anne Baslund', role: 'platform admin', action: 'tos.published', target: 'v2026.05 · all tenants', tenant: '—', ip: '10.0.4.18', tone: 'info' },
]
export type NotificationKind = 'security' | 'user' | 'billing' | 'integration' | 'support' | 'signin'
export type NotificationTone = 'warn' | 'info' | 'neutral' | 'ok' | 'bad'
export interface NotificationItem {
id: string
kind: NotificationKind
title: string
body: string
when: string
icon: IconName
tone: NotificationTone
unread: boolean
}
// Seed list mirrors the design screenshot. The real source will be an event
// stream / Mongo collection later; for now this is the shell other features
// can plug into. See the "notifications backend" follow-up in NEXT-STEPS.md.
export const NOTIFICATIONS: NotificationItem[] = [
{ id: 'n_2821', kind: 'security', icon: 'shield', tone: 'warn', when: '2 min ago', unread: true, title: 'DMARC policy weak on baslund.dk', body: 'Set the policy to at least quarantine to reduce spoofing.' },
{ id: 'n_2820', kind: 'user', icon: 'users', tone: 'info', when: '14 min ago', unread: true, title: 'Mikkel accepted your invitation', body: 'mikkel@dezky.com joined as Admin.' },
{ id: 'n_2819', kind: 'billing', icon: 'card', tone: 'neutral', when: '1 h ago', unread: false, title: 'Invoice INV-2026-005 paid', body: '1.940,00 DKK · Visa •••• 4242' },
{ id: 'n_2818', kind: 'integration', icon: 'plug', tone: 'neutral', when: '3 h ago', unread: false, title: 'Notion SAML connection live', body: 'Connected via Authentik. 11 users provisioned.' },
{ id: 'n_2817', kind: 'support', icon: 'help', tone: 'neutral', when: 'Yesterday', unread: false, title: 'Sofie replied to your ticket TKT-2832', body: 'Update on missing mobile recordings.' },
{ id: 'n_2816', kind: 'signin', icon: 'bell', tone: 'bad', when: '2 d ago', unread: false, title: 'Failed sign-in attempts on oliver@', body: '3 attempts from 203.0.113.4 — IP added to watchlist.' },
]
+1
View File
@@ -59,6 +59,7 @@ onMounted(() => {
<CommandPalette />
<ImpersonationModal />
<IncidentModal />
<NotificationDrawer />
<TweaksPanel />
</div>
</template>