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, **kwargs):
        self.component.is_open = False

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

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

Parameters

NameTypeDefaultDescription
contentstr''results content (pre-rendered HTML)
is_openboolFalsewhether palette is open
search_eventstr — renames the event; identity is `name`'palette_search'dj-input event for search
close_eventstr — renames the event; identity is `name`'close_palette'dj-click event to close
placeholderstr'Search commands...'search input placeholder
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 756, 758, 760, 762, 764, 766, 767. 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.