Command Palette

Command palette/search overlay component.

python 7 params

Preview

is_open
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 it
my_template.html
django
{{ component }}

Events this component sends to the view: close_palette, palette_search.

Parameters

NameTypeDefault
contentstr''
is_openboolFalse
search_eventstr — renames the event; identity is `name`'palette_search'
close_eventstr — renames the event; identity is `name`'close_palette'
placeholderstr'Search commands...'
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.command_paletteSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 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.
cssdjust_theming/catalogue.cssDefines 1 of this component's classes at line 159. Override those rules, or the custom properties they read, in a stylesheet loaded after it.