Command Palette
Command palette/search overlay component.
Preview
New component
Open settings
python
command_palette(is_open=True, content='<div class="palette-item">New component</div><div class="palette-item">Open settings</div>')Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import CommandPalette
from django.utils.safestring import mark_safe
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = CommandPalette(is_open=True, content=mark_safe('<div class="palette-item">New component</div><div class="palette-item">Open settings</div>'))
@event_handler()
def close_palette(self, value=None, **kwargs):
... # write to self.component; the re-render carries it
@event_handler()
def palette_search(self, value=None, **kwargs):
... # write to self.component; the re-render carries itmy_template.html
django
{{ component }}Events this component sends to the view: close_palette, palette_search.
Parameters
| Name | Type | Default |
|---|---|---|
| content | str | '' |
| is_open | bool | False |
| search_event | str — renames the event; identity is `name` | 'palette_search' |
| close_event | str — renames the event; identity is `name` | 'close_palette' |
| placeholder | str | 'Search commands...' |
| custom_class | str | '' |
| **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.command_palette | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 7 of this component's classes at line 730, 732, 734, 736, 738, 740, 741. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/catalogue.css | Defines 1 of this component's classes at line 159. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |