Notification Popover

Style-agnostic notification popover using CSS custom properties.

python 8 params

Preview

Arguments
notification_popover(notifications=[{'id': 'n1', 'title': 'New comment', 'body': 'Ada replied to your post.', 'time': '2m', 'read': False}, {'id': 'n2', 'title': 'Deploy finished', 'body': 'build #412 is live.', 'time': '1h', 'read': True}], unread_count=1)

Usage

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


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

    def mount(self, request, **kwargs):
        self.component = NotificationPopover(notifications=[{'id': 'n1', 'title': 'New comment', 'body': 'Ada replied to your post.', 'time': '2m', 'read': False}, {'id': 'n2', 'title': 'Deploy finished', 'body': 'build #412 is live.', 'time': '1h', 'read': True}], unread_count=1)

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

    @event_handler()
    def mark_read(self, **kwargs):
        ...  # write to self.component; the re-render carries it
my_template.html
django
{{ component }}

Events this component sends to the view: toggle_notifications, mark_read.

Parameters

NameTypeDefault
notificationsList[Union[dict, object]] | NoneNone
unread_countint0
mark_read_eventstr — renames the event; identity is `name`'mark_read'
toggle_eventstr — renames the event; identity is `name`'toggle_notifications'
is_openboolFalse
titlestr'Notifications'
custom_classstr''
**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_popoverSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 4 of this component's classes at line 1618, 1619, 1621, 1622. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_components/components-classes.cssDefines 3 of this component's classes at line 660, 661, 662. Override those rules, or the custom properties they read, in a stylesheet loaded after it.