Notification Center

Notification bell with dropdown list component.

python 8 params

Preview

No notifications

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import NotificationCenter


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = NotificationCenter()

    @event_handler()
    def toggle_notifications(self, **kwargs):
        self.component.is_open = not self.component.is_open

    @event_handler()
    def mark_notification_read(self, **kwargs):
        pass  # your app acts on 'mark_notification_read'; no component state moves

    @event_handler()
    def clear_notifications(self, **kwargs):
        pass  # your app acts on 'clear_notifications'; no component state moves
my_template.html
django
{{ component }}

Events this component sends to the view: toggle_notifications, mark_notification_read, clear_notifications.

Parameters

NameTypeDefaultDescription
notificationslist | NoneNonelist of dicts with keys: id, message, time, unread
unread_countint0number of unread notifications open_event, mark_read_event, clear_event: dj-click events
open_eventstr — renames the event; identity is `name`'toggle_notifications'—
mark_read_eventstr — renames the event; identity is `name`'mark_notification_read'—
clear_eventstr — renames the event; identity is `name`'clear_notifications'—
custom_classstr''—
is_openboolFalsewhether the dropdown is shown; flip it in your ``open_event`` handler (``self.bell.is_open = not self.bell.is_open``)
**kwargs— passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state——
Source & styles
FilePathNotes
moduledjust.components.components.notification_centerSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 6 of this component's classes at line 832, 833, 835, 837, 841, 849. Override those rules, or the custom properties they read, in a stylesheet loaded after it.