Lewati ke konten

Notifikasi

Unduh .md

Setiap produk Sosialoka mengabarkan perubahan di dua tempat yang sama: panel di bawah lonceng di header, dan halaman notifikasi yang berisi semuanya. Keduanya memakai baris yang sama, jadi sebuah notifikasi terlihat sama di mana pun ia muncul.

  • Pakai panel untuk melihat sekilas: notifikasi terbaru dan cara menghapus badge.
  • Pakai halaman untuk menelusuri semuanya, per kategori atau yang belum dibaca saja.
  • Untuk pesan tentang halaman yang sedang dibuka, pakai Alert atau toast, bukan notifikasi.
  1. Header: judul “Notifikasi”, satu baris keterangan, dan “Tandai semua dibaca”.
  2. Chip kategori: chip Toggle Group, “Semua” paling depan, masing-masing dengan jumlah yang belum dibaca.
  3. Kartu: saklar Semua / Belum dibaca dan menu halaman di atas, lalu baris yang dikelompokkan jadi “Hari ini” dan “Sebelumnya”, lalu “Muat lagi”.
  1. Ikon: ikon kategori di dalam lingkaran netral.
  2. Judul: tebal selama belum dibaca.
  3. Isi: satu atau dua baris.
  4. Waktu dan kategori: “5 menit lalu · Pembayaran”. Tanggal dan jam lengkap muncul sebagai tooltip.
  5. Titik belum dibaca di ujung, lalu menu baris di sebelahnya.
  1. Lonceng: DashboardIconButton dari header Dasbor, dengan jumlah yang belum dibaca sebagai badge.
  2. Popover: lebar 360px, dengan “Notifikasi”, “Tandai semua dibaca”, dan saklar Semua / Belum dibaca di atas.
  3. Baris: maksimal 8, dikelompokkan per waktu, sama dengan baris di halaman.
  4. Footer: “Lihat semua notifikasi” membuka halamannya.
  • Tandai semua dibaca berlaku untuk kategori yang sedang aktif. Nonaktifkan tombolnya kalau tidak ada yang belum dibaca di situ.
  • Chip kategori selalu punya satu kategori aktif: “Semua” sebagai bawaan, dan klik pada chip yang aktif tetap membuatnya aktif. Jumlahnya dibacakan sebagai kata, misalnya “Pembayaran (1 belum dibaca)”. Di HP, chip tetap satu baris yang bisa digulir ke samping; mulai sm, chip turun ke baris baru. Kategori dan saklarnya disimpan di URL, sama seperti filter list.
  • Badge: jumlah yang belum dibaca, “99+” kalau lebih dari 99, dan tidak tampil saat nol. Nama tombol lonceng ikut membawa jumlahnya, misalnya “Notifikasi (3)”.
  • Panel: maksimal 8 baris. Di HP, lonceng membuka halaman, bukan popover.
  • Klik menandai notifikasi sebagai dibaca dan membuka halaman yang dibahasnya. Notifikasi tanpa tujuan hanya ditandai dibaca.
  • Menu baris: beri tombolnya nama sesuai barisnya (“Aksi untuk Royalti Oktober sudah masuk”). “Tandai dibaca” atau “Tandai belum dibaca” di depan, lalu “Hapus” paling akhir, setelah pemisah. Hapus bersifat opsional: hilangkan kalau produknya belum bisa menghapus notifikasi. Setelah dihapus, fokus pindah ke baris berikutnya.
  • Hapus yang sudah dibaca bertanya dulu lewat Alert Dialog, karena notifikasi yang dihapus tidak bisa kembali. Item ini nonaktif kalau tidak ada lagi yang sudah dibaca.
  • Ikon menandai kategori dengan warna netral, jangan warna brand, supaya hanya yang belum dibaca yang menonjol.
  • Waktu: relatif (“5 menit lalu”, “Kemarin”). Tanggal dan jam lengkapnya muncul saat kursor diarahkan dan dibacakan oleh pembaca layar.
  • Lainnya: “Muat lagi” di bawah baris, bukan nomor halaman; notifikasi dibaca dari yang terbaru.
  • State: kategori kosong menampilkan “Belum ada notifikasi di kategori ini.” dan tampilan belum dibaca yang kosong menampilkan “Semua notifikasi sudah kamu baca.”. Memuat dan error mengikuti Kosong, memuat, dan error.
import { useEffect, useRef, useState } from "react"
import {
CheckCheckIcon,
DiscIcon,
FileCheckIcon,
FileTextIcon,
InfoIcon,
MoreHorizontalIcon,
WalletIcon,
type LucideIcon,
} from "lucide-react"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
type Category = "Pembayaran" | "Clearance" | "Laporan" | "Rilis" | "Umum"
interface Notification {
id: number
category: Category
title: string
body: string
/** Relative time shown in the row. */
time: string
/** Full date and time, shown as the tooltip of the relative time. */
at: string
/** ISO date for the <time> element. */
iso: string
group: "Hari ini" | "Sebelumnya"
read: boolean
/** The page the notification is about. Without one, a click only marks it read. */
href?: string
}
const ICONS: Record<Category, LucideIcon> = {
Pembayaran: WalletIcon,
Clearance: FileCheckIcon,
Laporan: FileTextIcon,
Rilis: DiscIcon,
Umum: InfoIcon,
}
const CATEGORIES: Category[] = ["Pembayaran", "Clearance", "Laporan", "Rilis", "Umum"]
const NOTIFICATIONS: Notification[] = [
{ id: 1, category: "Pembayaran", title: "Royalti Oktober sudah masuk", body: "Rp1.250.000,00 masuk ke saldomu.", time: "5 menit lalu", at: "17 Nov 2026, 14.20", iso: "2026-11-17T14:20", group: "Hari ini", read: false, href: "#saldo" },
{ id: 2, category: "Clearance", title: 'Clearance "Langit Jingga" disetujui', body: "Videomu siap tayang.", time: "1 jam lalu", at: "17 Nov 2026, 13.25", iso: "2026-11-17T13:25", group: "Hari ini", read: false, href: "#clearance" },
{ id: 3, category: "Laporan", title: "Laporan royalti Oktober siap", body: "Cek pendapatan tiap platform.", time: "3 jam lalu", at: "17 Nov 2026, 11.05", iso: "2026-11-17T11:05", group: "Hari ini", read: false, href: "#laporan" },
{ id: 4, category: "Rilis", title: '"Senja di Kota" tayang di Spotify', body: "Rilismu sudah bisa diputar.", time: "Kemarin", at: "16 Nov 2026, 19.40", iso: "2026-11-16T19:40", group: "Sebelumnya", read: true, href: "#rilis" },
{ id: 5, category: "Pembayaran", title: "Tagihan langganan November", body: "Bayar sebelum 30 Nov 2026 supaya layananmu tetap jalan.", time: "Kemarin", at: "16 Nov 2026, 09.00", iso: "2026-11-16T09:00", group: "Sebelumnya", read: true, href: "#tagihan" },
{ id: 6, category: "Clearance", title: 'Clearance "Kaset Pertama" perlu diperbaiki', body: "Cek catatan dari tim kami, lalu kirim ulang.", time: "2 hari lalu", at: "15 Nov 2026, 10.15", iso: "2026-11-15T10:15", group: "Sebelumnya", read: true, href: "#clearance" },
{ id: 7, category: "Umum", title: "Kata sandimu baru saja diganti", body: "Bukan kamu? Segera hubungi kami.", time: "3 hari lalu", at: "14 Nov 2026, 08.30", iso: "2026-11-14T08:30", group: "Sebelumnya", read: true },
{ id: 8, category: "Rilis", title: '"Pulang Sore" dijadwalkan 28 Nov 2026', body: "Kami kirim ke semua platform di tanggal itu.", time: "4 hari lalu", at: "13 Nov 2026, 16.45", iso: "2026-11-13T16:45", group: "Sebelumnya", read: true, href: "#rilis" },
{ id: 9, category: "Laporan", title: "Laporan royalti September siap", body: "Cek pendapatan tiap platform.", time: "14 Okt 2026", at: "14 Okt 2026, 10.00", iso: "2026-10-14T10:00", group: "Sebelumnya", read: true, href: "#laporan" },
{ id: 10, category: "Pembayaran", title: "Royalti September sudah masuk", body: "Rp980.000,00 masuk ke saldomu.", time: "13 Okt 2026", at: "13 Okt 2026, 15.10", iso: "2026-10-13T15:10", group: "Sebelumnya", read: true, href: "#saldo" },
]
/** Rows shown before "Muat lagi". */
const FIRST_PAGE = 8
/**
* One notification: category icon, title (bold while unread), body, time and category, an unread dot, and a menu
* beside the row. The row is a link when it has a target, otherwise a button that only marks it read.
*/
function NotificationRow({
notification: n,
onOpen,
onToggleRead,
onRemove,
}: {
notification: Notification
onOpen: () => void
onToggleRead: () => void
onRemove: () => void
}) {
const Icon = ICONS[n.category]
const content = (
<>
<span className="flex size-9 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground">
<Icon className="size-4" />
</span>
<span className="min-w-0 flex-1">
<span className={n.read ? "block text-sm" : "block text-sm font-semibold"}>{n.title}</span>
<span className="mt-0.5 line-clamp-2 block text-sm text-muted-foreground">{n.body}</span>
<span className="mt-1 block text-xs text-muted-foreground">
<time dateTime={n.iso} title={n.at}>
{n.time}
</time>
<span className="sr-only">, {n.at}</span>
{" · "}
{n.category}
</span>
</span>
{n.read ? null : (
<>
<span aria-hidden="true" className="mt-1.5 size-2 shrink-0 rounded-full bg-primary" />
<span className="sr-only">Belum dibaca</span>
</>
)}
</>
)
const rowClass = "flex min-w-0 flex-1 items-start gap-3 rounded-lg px-2 py-2 text-left outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
return (
<li className={n.read ? "flex items-start gap-1 px-2 py-1" : "flex items-start gap-1 bg-muted/50 px-2 py-1"}>
{n.href ? (
<a href={n.href} data-notification={n.id} className={rowClass} onClick={onOpen}>
{content}
</a>
) : (
<button type="button" data-notification={n.id} className={rowClass} onClick={onOpen}>
{content}
</button>
)}
<DropdownMenu>
<DropdownMenuTrigger
render={<Button variant="ghost" size="icon-sm" className="mt-1.5" aria-label={`Aksi untuk ${n.title}`} />}
>
<MoreHorizontalIcon />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={onToggleRead}>{n.read ? "Tandai belum dibaca" : "Tandai dibaca"}</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" onClick={onRemove}>
Hapus
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</li>
)
}
/**
* The notifications page: the title and "Tandai semua dibaca" for the selected category, category chips with unread
* counts, then a card with the Semua / Belum dibaca switch, the page menu, rows grouped by time and "Muat lagi".
* Keep the category and the switch in the URL in a real product, as list filters do.
*/
export default function NotificationsPageDemo() {
const [items, setItems] = useState(NOTIFICATIONS)
const [visible, setVisible] = useState(FIRST_PAGE)
const [category, setCategory] = useState<"semua" | Category>("semua")
const [show, setShow] = useState<"semua" | "belum">("semua")
const [confirmRemoveRead, setConfirmRemoveRead] = useState(false)
/** After a delete, focus moves to the next row (or the previous one, or the empty text) instead of the page. */
const [focusAfterRemove, setFocusAfterRemove] = useState<number | "empty" | null>(null)
const emptyRef = useRef<HTMLParagraphElement>(null)
/** A new filter starts again from the first page. */
const pickCategory = (value: "semua" | Category) => {
setCategory(value)
setVisible(FIRST_PAGE)
}
const pickShow = (value: "semua" | "belum") => {
setShow(value)
setVisible(FIRST_PAGE)
}
const inCategory = (n: Notification) => category === "semua" || n.category === category
const unread = (c: "semua" | Category) => items.filter((n) => !n.read && (c === "semua" || n.category === c)).length
const update = (id: number, read: boolean) => setItems((all) => all.map((n) => (n.id === id ? { ...n, read } : n)))
const markAllRead = () => setItems((all) => all.map((n) => (inCategory(n) ? { ...n, read: true } : n)))
const readCount = items.filter((n) => n.read && inCategory(n)).length
const removeRead = () => setItems((all) => all.filter((n) => !(n.read && inCategory(n))))
// Filter first, then page: "Muat lagi" shows only while more of the filtered rows exist.
const filtered = items.filter((n) => inCategory(n) && (show === "semua" || !n.read))
const shown = filtered.slice(0, visible)
const groups = (["Hari ini", "Sebelumnya"] as const)
.map((label) => ({ label, rows: shown.filter((n) => n.group === label) }))
.filter((g) => g.rows.length > 0)
const empty = show === "belum" ? "Semua notifikasi sudah kamu baca." : "Belum ada notifikasi di kategori ini."
const remove = (id: number) => {
const at = shown.findIndex((n) => n.id === id)
const next = shown[at + 1] ?? shown[at - 1]
setFocusAfterRemove(next ? next.id : "empty")
setItems((all) => all.filter((n) => n.id !== id))
}
useEffect(() => {
if (focusAfterRemove === null) return
// Wait a frame: the closing menu returns focus to its trigger first, and that trigger is gone.
const frame = requestAnimationFrame(() => {
const target =
focusAfterRemove === "empty"
? emptyRef.current
: document.querySelector<HTMLElement>(`[data-notification="${focusAfterRemove}"]`)
target?.focus()
setFocusAfterRemove(null)
})
return () => cancelAnimationFrame(frame)
}, [focusAfterRemove])
return (
<div className="min-h-svh bg-background p-6 text-foreground">
<div className="mx-auto grid max-w-3xl gap-6">
<div className="flex flex-wrap items-start justify-between gap-4">
<div>
<h1 className="text-2xl font-semibold">Notifikasi</h1>
<p className="mt-1 text-sm text-muted-foreground">Kabar terbaru soal akunmu.</p>
</div>
<Button variant="outline" disabled={unread(category) === 0} onClick={markAllRead}>
<CheckCheckIcon />
Tandai semua dibaca
</Button>
</div>
<ToggleGroup
variant="outline"
spacing={2}
aria-label="Filter kategori"
// One line that scrolls sideways on phones; from sm the chips wrap.
className="-mx-1 w-full min-w-0 flex-nowrap overflow-x-auto px-1 pb-1 sm:w-fit sm:flex-wrap sm:overflow-visible"
value={[category]}
// A category filter always has one value: clicking the active chip keeps it on.
onValueChange={(value) => value.length > 0 && pickCategory(value[value.length - 1] as "semua" | Category)}
>
{(["semua", ...CATEGORIES] as const).map((c) => (
<ToggleGroupItem
key={c}
value={c}
// The count reads as words: "Pembayaran (1 belum dibaca)".
aria-label={unread(c) > 0 ? `${c === "semua" ? "Semua" : c} (${unread(c)} belum dibaca)` : undefined}
>
{c === "semua" ? "Semua" : c}
{unread(c) > 0 ? <span className="tabular-nums text-muted-foreground">{unread(c)}</span> : null}
</ToggleGroupItem>
))}
</ToggleGroup>
<div className="rounded-xl border border-border bg-card">
<div className="flex items-center justify-between gap-2 border-b border-border px-4 py-2">
<ToggleGroup
size="sm"
aria-label="Tampilkan"
value={[show]}
onValueChange={(value) => value.length > 0 && pickShow(value[value.length - 1] as "semua" | "belum")}
>
<ToggleGroupItem value="semua">Semua</ToggleGroupItem>
<ToggleGroupItem value="belum">Belum dibaca</ToggleGroupItem>
</ToggleGroup>
<DropdownMenu>
<DropdownMenuTrigger render={<Button variant="ghost" size="icon-sm" aria-label="Opsi notifikasi" />}>
<MoreHorizontalIcon />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem render={<a href="#pengaturan-notifikasi" />}>Pengaturan notifikasi</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" disabled={readCount === 0} onClick={() => setConfirmRemoveRead(true)}>
Hapus yang sudah dibaca
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<AlertDialog open={confirmRemoveRead} onOpenChange={setConfirmRemoveRead}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Hapus {readCount} notifikasi yang sudah dibaca?</AlertDialogTitle>
<AlertDialogDescription>Notifikasi yang dihapus tidak bisa dikembalikan.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel autoFocus>Batal</AlertDialogCancel>
<AlertDialogAction
variant="destructive"
onClick={() => {
removeRead()
setConfirmRemoveRead(false)
}}
>
Hapus
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
{groups.length === 0 ? (
<p ref={emptyRef} tabIndex={-1} className="px-4 py-12 text-center text-sm text-muted-foreground outline-none">
{empty}
</p>
) : (
groups.map((g) => (
<section key={g.label} aria-label={g.label} className="py-2">
<h2 className="px-4 py-1 text-xs font-medium text-muted-foreground">{g.label}</h2>
<ul>
{g.rows.map((n) => (
<NotificationRow
key={n.id}
notification={n}
onOpen={() => update(n.id, true)}
onToggleRead={() => update(n.id, !n.read)}
onRemove={() => remove(n.id)}
/>
))}
</ul>
</section>
))
)}
{filtered.length > visible ? (
<div className="border-t border-border p-2 text-center">
<Button variant="ghost" onClick={() => setVisible((v) => v + FIRST_PAGE)}>
Muat lagi
</Button>
</div>
) : null}
</div>
</div>
</div>
)
}
React
Vue
import { useState } from "react"
import {
BellIcon,
DiscIcon,
FileCheckIcon,
FileTextIcon,
InfoIcon,
MoreHorizontalIcon,
WalletIcon,
type LucideIcon,
} from "lucide-react"
import { DashboardIconButton } from "@/components/blocks/dashboard-shell"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from "@/components/ui/popover"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
type Category = "Pembayaran" | "Clearance" | "Laporan" | "Rilis" | "Umum"
interface Notification {
id: number
category: Category
title: string
body: string
/** Relative time shown in the row. */
time: string
/** Full date and time, shown as the tooltip of the relative time. */
at: string
/** ISO date for the <time> element. */
iso: string
group: "Hari ini" | "Sebelumnya"
read: boolean
/** The page the notification is about. Without one, a click only marks it read. */
href?: string
}
const ICONS: Record<Category, LucideIcon> = {
Pembayaran: WalletIcon,
Clearance: FileCheckIcon,
Laporan: FileTextIcon,
Rilis: DiscIcon,
Umum: InfoIcon,
}
/** The newest notifications; the panel shows at most 8, the page shows the rest. */
const NOTIFICATIONS: Notification[] = [
{ id: 1, category: "Pembayaran", title: "Royalti Oktober sudah masuk", body: "Rp1.250.000,00 masuk ke saldomu.", time: "5 menit lalu", at: "17 Nov 2026, 14.20", iso: "2026-11-17T14:20", group: "Hari ini", read: false, href: "#saldo" },
{ id: 2, category: "Clearance", title: 'Clearance "Langit Jingga" disetujui', body: "Videomu siap tayang.", time: "1 jam lalu", at: "17 Nov 2026, 13.25", iso: "2026-11-17T13:25", group: "Hari ini", read: false, href: "#clearance" },
{ id: 3, category: "Laporan", title: "Laporan royalti Oktober siap", body: "Cek pendapatan tiap platform.", time: "3 jam lalu", at: "17 Nov 2026, 11.05", iso: "2026-11-17T11:05", group: "Hari ini", read: false, href: "#laporan" },
{ id: 4, category: "Rilis", title: '"Senja di Kota" tayang di Spotify', body: "Rilismu sudah bisa diputar.", time: "Kemarin", at: "16 Nov 2026, 19.40", iso: "2026-11-16T19:40", group: "Sebelumnya", read: true, href: "#rilis" },
{ id: 5, category: "Pembayaran", title: "Tagihan langganan November", body: "Bayar sebelum 30 Nov 2026 supaya layananmu tetap jalan.", time: "Kemarin", at: "16 Nov 2026, 09.00", iso: "2026-11-16T09:00", group: "Sebelumnya", read: true, href: "#tagihan" },
{ id: 6, category: "Clearance", title: 'Clearance "Kaset Pertama" perlu diperbaiki', body: "Cek catatan dari tim kami, lalu kirim ulang.", time: "2 hari lalu", at: "15 Nov 2026, 10.15", iso: "2026-11-15T10:15", group: "Sebelumnya", read: true, href: "#clearance" },
{ id: 7, category: "Umum", title: "Kata sandimu baru saja diganti", body: "Bukan kamu? Segera hubungi kami.", time: "3 hari lalu", at: "14 Nov 2026, 08.30", iso: "2026-11-14T08:30", group: "Sebelumnya", read: true },
{ id: 8, category: "Rilis", title: '"Pulang Sore" dijadwalkan 28 Nov 2026', body: "Kami kirim ke semua platform di tanggal itu.", time: "4 hari lalu", at: "13 Nov 2026, 16.45", iso: "2026-11-13T16:45", group: "Sebelumnya", read: true, href: "#rilis" },
]
/** The most rows the panel shows; "Lihat semua notifikasi" opens the page for the rest. */
const PANEL_ROWS = 8
/**
* One notification: category icon, title (bold while unread), body, time and category, an unread dot, and a menu
* beside the row. The row is a link when it has a target, otherwise a button that only marks it read.
*/
function NotificationRow({
notification: n,
onOpen,
onToggleRead,
onRemove,
}: {
notification: Notification
onOpen: () => void
onToggleRead: () => void
onRemove: () => void
}) {
const Icon = ICONS[n.category]
const content = (
<>
<span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground">
<Icon className="size-4" />
</span>
<span className="min-w-0 flex-1">
<span className={n.read ? "block text-sm" : "block text-sm font-semibold"}>{n.title}</span>
<span className="mt-0.5 line-clamp-2 block text-xs text-muted-foreground">{n.body}</span>
<span className="mt-1 block text-xs text-muted-foreground">
<time dateTime={n.iso} title={n.at}>
{n.time}
</time>
<span className="sr-only">, {n.at}</span>
{" · "}
{n.category}
</span>
</span>
{n.read ? null : (
<>
<span aria-hidden="true" className="mt-1.5 size-2 shrink-0 rounded-full bg-primary" />
<span className="sr-only">Belum dibaca</span>
</>
)}
</>
)
const rowClass = "flex min-w-0 flex-1 items-start gap-3 rounded-lg px-2 py-2 text-left outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
return (
<li className={n.read ? "flex items-start gap-1 px-2 py-0.5" : "flex items-start gap-1 bg-muted/50 px-2 py-0.5"}>
{n.href ? (
<a href={n.href} className={rowClass} onClick={onOpen}>
{content}
</a>
) : (
<button type="button" className={rowClass} onClick={onOpen}>
{content}
</button>
)}
<DropdownMenu>
<DropdownMenuTrigger
render={<Button variant="ghost" size="icon-sm" className="mt-1.5" aria-label={`Aksi untuk ${n.title}`} />}
>
<MoreHorizontalIcon />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={onToggleRead}>{n.read ? "Tandai belum dibaca" : "Tandai dibaca"}</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" onClick={onRemove}>
Hapus
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</li>
)
}
/**
* The bell panel: the Dashboard header's bell with the unread count opens a 360px popover with "Tandai semua
* dibaca", the Semua / Belum dibaca switch, at most 8 rows grouped by time, and a link to the notifications page.
* On phones, let the bell open the page instead.
*/
export default function NotificationPanelDemo() {
const [items, setItems] = useState(NOTIFICATIONS)
const [show, setShow] = useState<"semua" | "belum">("semua")
const unread = items.filter((n) => !n.read).length
const update = (id: number, read: boolean) => setItems((all) => all.map((n) => (n.id === id ? { ...n, read } : n)))
// Filter first, then cap at 8 rows.
const shown = items.filter((n) => show === "semua" || !n.read).slice(0, PANEL_ROWS)
const groups = (["Hari ini", "Sebelumnya"] as const)
.map((label) => ({ label, rows: shown.filter((n) => n.group === label) }))
.filter((g) => g.rows.length > 0)
return (
<div className="flex justify-end p-4">
<Popover>
<PopoverTrigger
render={
<DashboardIconButton label="Notifikasi" badge={unread}>
<BellIcon />
</DashboardIconButton>
}
/>
<PopoverContent align="end" className="w-[360px] max-w-[calc(100vw-2rem)] gap-0 p-0">
<div className="flex items-center justify-between gap-2 border-b border-border px-4 py-3">
<PopoverTitle className="text-sm font-semibold">Notifikasi</PopoverTitle>
<Button
variant="link"
size="xs"
disabled={unread === 0}
onClick={() => setItems((all) => all.map((n) => ({ ...n, read: true })))}
>
Tandai semua dibaca
</Button>
</div>
<div className="border-b border-border px-4 py-2">
<ToggleGroup
size="sm"
aria-label="Tampilkan"
value={[show]}
onValueChange={(value) => value.length > 0 && setShow(value[value.length - 1] as "semua" | "belum")}
>
<ToggleGroupItem value="semua">Semua</ToggleGroupItem>
<ToggleGroupItem value="belum" aria-label={unread > 0 ? `Belum dibaca (${unread})` : undefined}>
Belum dibaca
{unread > 0 ? <span className="tabular-nums text-muted-foreground">{unread}</span> : null}
</ToggleGroupItem>
</ToggleGroup>
</div>
<div className="max-h-[420px] overflow-y-auto">
{groups.length === 0 ? (
<p className="px-4 py-10 text-center text-sm text-muted-foreground">Semua notifikasi sudah kamu baca.</p>
) : (
groups.map((g) => (
<section key={g.label} aria-label={g.label} className="py-1.5">
<h3 className="px-4 py-1 text-xs font-medium text-muted-foreground">{g.label}</h3>
<ul>
{g.rows.map((n) => (
<NotificationRow
key={n.id}
notification={n}
onOpen={() => update(n.id, true)}
onToggleRead={() => update(n.id, !n.read)}
onRemove={() => setItems((all) => all.filter((x) => x.id !== n.id))}
/>
))}
</ul>
</section>
))
)}
</div>
<a
href="#notifikasi"
className="block border-t border-border px-4 py-3 text-center text-sm font-medium text-primary-text hover:underline"
>
Lihat semua notifikasi
</a>
</PopoverContent>
</Popover>
</div>
)
}

Toggle Group, Dropdown Menu, Alert Dialog, Popover, Button, Tooltip, dan DashboardIconButton dari blok Dasbor.

Chip kategori berupa ShadToggleGroup dengan allowDeselection: false, di dalam scroll horizontal supaya muat di HP. Di HP, lonceng membuka halaman; di tablet dan desktop, lonceng membuka ShadPopover. Buka aksi baris lewat ShadContextMenu, dan beri tombolnya label semantik.