Notification Center
Notification bell with dropdown list component.
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):
... # write to self.component; the re-render carries it
@event_handler()
def clear_notifications(self, **kwargs):
... # write to self.component; the re-render carries itmy_template.html
django
{{ component }}Events this component sends to the view: toggle_notifications, mark_notification_read, clear_notifications.
Parameters
| Name | Type | Default |
|---|---|---|
| notifications | list | None | None |
| unread_count | int | 0 |
| open_event | str — renames the event; identity is `name` | 'toggle_notifications' |
| mark_read_event | str — renames the event; identity is `name` | 'mark_notification_read' |
| clear_event | str — renames the event; identity is `name` | 'clear_notifications' |
| custom_class | str | '' |
| is_open | bool | False |
| **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
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.notification_center | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 6 of this component's classes at line 806, 807, 809, 811, 815, 823. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |