{# Renders a standalone command menu component with search and keyboard navigation. @param id {string} [optional] - Unique identifier for the command component. @param items {array} [optional] - Array of items to render (alternative to using caller). @param placeholder {string} [optional] [default="Type a command or search..."] - Placeholder text for the search input. @param empty_text {string} [optional] [default="No results found."] - Text displayed when no results match the search. @param main_attrs {object} [optional] - Additional HTML attributes for the main container div. @param input_attrs {object} [optional] - Additional HTML attributes for the search input. @param listbox_attrs {object} [optional] - Additional HTML attributes for the listbox div. #} {% macro command( id=None, items=None, placeholder="Type a command or search...", empty_text="No results found.", main_attrs={}, input_attrs={}, listbox_attrs={} ) %} {% set id = id or ("command-" ~ range(100000, 999999) | random | string) %}
{% if items and items|length > 0 %} {{ render_command_items(items, id ~ "-items" if id else "items") }} {% else %} {{ caller() if caller }} {% endif %}
{% endmacro %} {# Renders a command dialog (modal command palette). @param id {string} [optional] - Unique identifier for the command dialog. @param items {array} [optional] - Array of items to render (alternative to using caller). @param placeholder {string} [optional] [default="Type a command or search..."] - Placeholder text for the search input. @param empty_text {string} [optional] [default="No results found."] - Text displayed when no results match the search. @param dialog_attrs {object} [optional] - Additional HTML attributes for the dialog element. @param input_attrs {object} [optional] - Additional HTML attributes for the search input. @param listbox_attrs {object} [optional] - Additional HTML attributes for the listbox div. @param open {boolean} [optional] [default=False] - Whether the command dialog should be open initially. #} {% macro command_dialog( id=None, items=None, placeholder="Type a command or search...", empty_text="No results found.", dialog_attrs={}, input_attrs={}, listbox_attrs={}, open=False ) %} {% set id = id or ("command-dialog-" ~ range(100000, 999999) | random | string) %}
{% if items and items|length > 0 %} {{ render_command_items(items, id ~ "-items" if id else "items") }} {% else %} {{ caller() if caller }} {% endif %}
{% endmacro %} {# Renders a list of items for the command component. @param items {array} - The array of items to render. @param parent_id_prefix {string} [optional] - The prefix for the item id. #} {% macro render_command_items(items, parent_id_prefix="items") %} {% for item in items %} {% set item_id = parent_id_prefix ~ "-" ~ loop.index %} {% if item.type == "group" %} {% set group_label_id = item.id if item.id else "group-label-" + item_id %}
{{ item.label }} {{ render_command_items(item.items, item_id) if item.items }}
{% elif item.type == "separator" %}
{% elif item.type == "item" or not item.type %}
{{ item.content | safe if item.content else item.label }}
{% endif %} {% endfor %} {% endmacro %}