Notification list

The rows of a notification centre, grouped under "Today" and "Earlier", with an unread dot, a Mark as read button and room for inline actions. Put it in a popover or a drawer behind a bell button.

Notification list

Needs Alpine and the package's script for Mark as read and Dismiss. See getting started. Everything else is plain Blade: each row is a link, and its actions are your own buttons.

Use it

<x-ds::popover label="Notifications" width="lg" placement="bottom-end">
    <x-slot:trigger>
        <x-ds::button variant="ghost" icon="bell" iconOnly :badge="$unread ?: null"
                      :aria-label="$unread ? 'Notifications, '.$unread.' unread' : 'Notifications'" />
    </x-slot:trigger>

    <x-ds::notification-list :unread="$unread" footerHref="/notifications" class="-m-4">
        <x-slot:actions>
            <x-ds::button variant="ghost" size="sm" wire:click="markAllRead">Mark all as read</x-ds::button>
        </x-slot:actions>

        <x-ds::notification-group label="Today">
            @foreach ($today as $n)
                <x-ds::notification-item :id="$n->id" :title="$n->title" :href="$n->url" :time="$n->created_at"
                                         :unread="! $n->read_at" icon="chat-bubble-left" wire:key="n-{{ $n->id }}">
                    {{ $n->body }}
                </x-ds::notification-item>
            @endforeach
        </x-ds::notification-group>
        <x-ds::notification-group label="Earlier">…</x-ds::notification-group>
    </x-ds::notification-list>
</x-ds::popover>

Items can sit straight in the list too, without groups. An empty list shows an empty state.

Props: notification-list

PropTypeDefaultWhat it does
titlestringNotificationsThe heading, and the region's name.
unreadint—A count beside the heading.
emptyTitlestringYou are all caught upShown when there are no items.
emptyDescriptionstring—
footerHrefstring—A link under the list. The footer slot takes markup instead.
footerLabelstringView all notifications

Slots: actions (in the header: "Mark all as read", settings), the default slot (items, or groups), footer.

Props: notification-group

PropTypeDefaultWhat it does
labelstringrequiredThe group's heading: "Today", "Earlier".

Props: notification-item

PropTypeDefaultWhat it does
titlestringrequired
idstring or int—Sent back with read and dismiss.
timedate, ISO 8601 string, or words—A date is shown relative ("3 hours ago") with the full date as its title.
datetimestring—The machine time, when time is words.
unreadboolfalseA dot, "Unread:" for screen readers, and a Mark as read button.
hrefstring—The whole row goes here.
iconstringbellAn icon in a tinted circle, when there is no avatar slot.
toneneutral accent success warning dangerneutralThe circle's tint.
dismissibleboolfalseA ✕ that dispatches dismiss.
readLabelstringMark as read
dismissLabelstringDismiss
unreadLabelstringUnread

Slots: the default slot (the body), avatar (an avatar in place of the icon), actions (inline buttons: Accept, Decline).

Events

The row's own buttons dispatch, bubbling, from the button:

EventWhendetail
readMark as read{ id }
dismiss✕{ id }

The list draws nothing itself: you save the change and re-render. With Livewire:

<div x-on:read="$wire.markRead($event.detail.id)" x-on:dismiss="$wire.dismiss($event.detail.id)">
    <x-ds::notification-list>…</x-ds::notification-list>
</div>

New notifications arrive the same way: wire:poll, or a broadcast event that re-renders the component. The package fetches nothing.

Accessibility

  • A region named by its heading, an h2; each group's label is an h3 over its own list.
  • A row with href is one link, its title, stretched across the row by a pseudo-element so a press anywhere on the row follows it. The actions and the row's buttons sit above that layer, outside the link: nothing interactive is nested in it. The row draws the link's focus ring.
  • Unread is a dot and words: the link's name starts "Unread:". Mark as read and Dismiss are named with the row's title ("Mark as read: Maya commented").

Don't

  • Don't make the whole row a button. It is a link to the thing; the actions are separate.
  • Don't announce every new notification. A count on the bell, and the list when opened, is enough; a live region per row reads the whole list.
  • Don't put more than two actions on a row. Past that, link to the thing.

More in specs/notification-list.md.


From the package repo: edit this page on GitHub.

Was this page helpful?