NotificationList renders a bell-style inbox. Pass static data and/or a read() loader that runs when the menu opens.
Setup
<script lang="ts">
import { NotificationList } from '.';
</script>
With static data
<script lang="ts">
import { NotificationList, Button } from '.';
let open = $state(false);
const data = [
{
id: 1,
sender: 'Alex',
content: 'Approved your request',
time: '2m ago',
isRead: false,
icon: 'mdi:bell'
},
{
id: 2,
sender: 'Sam',
content: 'Commented on a ticket',
time: '1h ago',
isRead: true
}
];
</script>
<Button onclick={() => (open = !open)}>Notifications</Button>
<NotificationList bind:open {data} onclick={(item) => console.log(item)} />
Async read
<script lang="ts">
import { NotificationList } from '.';
async function read() {
const res = await fetch('/api/notifications');
return res.json();
}
</script>
<NotificationList {read} onClearNotifications={() => {}} />
Notification item shape
| Field | Type | Description |
id | string | number | Stable id |
sender | string | Title / sender |
content | string | Body text |
time | string | Relative time label |
isRead | boolean | Read state styling |
icon | string | Optional iconify id |
Props
| Prop | Type | Default | Description |
open | boolean | false | Bindable open state |
data | NotificationItem[] | [] | Initial / static items |
read | () => Promise<T[]> \| T[] | — | Loader when opened |
busy | boolean | false | Loading indicator |
onclick | (item: T) => void | — | Item click |
onClearNotifications | () => void | — | Clear action |
header | snippet | — | Custom header |
footer | snippet | — | Custom footer |