2025-05-01 12:50:40 +08:00
|
|
|
{#
|
|
|
|
|
Renders a select or combobox component.
|
|
|
|
|
|
|
|
|
|
@param id {string} [optional] - Unique identifier for the select component.
|
|
|
|
|
@param selected {string} [optional] - The initially selected value.
|
|
|
|
|
@param name {string} [optional] - The name attribute for the hidden input storing the selected value.
|
|
|
|
|
@param main_attrs {object} [optional] - Additional HTML attributes for the main container div.
|
|
|
|
|
@param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button.
|
|
|
|
|
@param content_attrs {object} [optional] - Additional HTML attributes for the popover content div.
|
|
|
|
|
@param listbox_attrs {object} [optional] - Additional HTML attributes for the listbox div.
|
|
|
|
|
@param input_attrs {object} [optional] - Additional HTML attributes for the hidden input.
|
|
|
|
|
@param search_placeholder {string} [optional] [default="Search entries..."] - Placeholder text for the search input (combobox only).
|
2025-05-01 20:53:03 +08:00
|
|
|
@param is_combobox {boolean} [optional] [default=False] - Renders a combobox with search functionality if true.
|
2025-05-01 12:50:40 +08:00
|
|
|
#}
|
2025-04-22 16:09:56 +08:00
|
|
|
{% macro select(
|
|
|
|
|
id=None,
|
|
|
|
|
selected=None,
|
2025-04-27 23:19:52 +08:00
|
|
|
name=None,
|
|
|
|
|
main_attrs={},
|
|
|
|
|
trigger_attrs={},
|
|
|
|
|
content_attrs={},
|
|
|
|
|
listbox_attrs={},
|
|
|
|
|
input_attrs={},
|
|
|
|
|
search_placeholder="Search entries...",
|
2025-05-01 20:53:03 +08:00
|
|
|
is_combobox=False
|
2025-04-22 16:09:56 +08:00
|
|
|
) %}
|
|
|
|
|
<div
|
|
|
|
|
class="popover {{ main_attrs.class }}"
|
2025-04-27 23:19:52 +08:00
|
|
|
x-data="select('{{ name }}', '{{ selected or '' }}')"
|
2025-04-22 16:09:56 +08:00
|
|
|
@click.away="open = false"
|
|
|
|
|
{% if id %}id="{{ id }}"{% endif %}
|
2025-05-01 20:53:03 +08:00
|
|
|
{% for key, value in main_attrs.items() %}
|
2025-04-22 16:09:56 +08:00
|
|
|
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
|
|
|
{% endfor %}
|
|
|
|
|
>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
aria-haspopup="listbox"
|
|
|
|
|
aria-expanded="false"
|
|
|
|
|
x-bind="$trigger"
|
|
|
|
|
{% if id %}
|
|
|
|
|
id="{{ id }}-trigger"
|
|
|
|
|
aria-controls="{{ id }}-content"
|
|
|
|
|
{% endif %}
|
|
|
|
|
class="btn-outline justify-between font-normal {{ trigger_attrs.class }}"
|
2025-05-01 20:53:03 +08:00
|
|
|
{% for key, value in trigger_attrs.items() %}
|
2025-04-22 16:09:56 +08:00
|
|
|
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
|
|
|
{% endfor %}
|
|
|
|
|
>
|
|
|
|
|
<div x-html="selectedLabel" class="flex items-center gap-x-2"
|
|
|
|
|
></div>
|
2025-04-25 16:42:10 +08:00
|
|
|
{% if is_combobox %}
|
2025-05-01 12:50:40 +08:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevrons-up-down-icon lucide-chevrons-up-down text-muted-foreground opacity-50 shrink-0"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>
|
2025-04-25 16:42:10 +08:00
|
|
|
{% else %}
|
2025-05-01 12:50:40 +08:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down-icon lucide-chevron-down text-muted-foreground opacity-50 shrink-0"><path d="m6 9 6 6 6-6"/></svg>
|
2025-04-25 16:42:10 +08:00
|
|
|
{% endif %}
|
2025-04-22 16:09:56 +08:00
|
|
|
</button>
|
|
|
|
|
<div
|
|
|
|
|
data-popover
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
x-bind="$content"
|
|
|
|
|
{% if id %}id="{{ id }}-content"{% endif %}
|
2025-05-01 20:53:03 +08:00
|
|
|
{% for key, value in content_attrs.items() %}
|
2025-04-22 16:09:56 +08:00
|
|
|
{{ key }}="{{ value }}"
|
|
|
|
|
{% endfor %}
|
|
|
|
|
>
|
|
|
|
|
{% if is_combobox %}
|
|
|
|
|
<header>
|
2025-05-01 12:50:40 +08:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-search-icon lucide-search"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
|
2025-04-22 16:09:56 +08:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value=""
|
2025-04-27 23:19:52 +08:00
|
|
|
placeholder="{{ search_placeholder }}"
|
2025-04-22 16:09:56 +08:00
|
|
|
autocomplete="off"
|
|
|
|
|
autocorrect="off"
|
|
|
|
|
spellcheck="false"
|
|
|
|
|
aria-autocomplete="list"
|
|
|
|
|
role="combobox"
|
|
|
|
|
aria-expanded="true"
|
|
|
|
|
aria-controls="{{ id }}-content"
|
|
|
|
|
aria-labelledby="{{ id }}-trigger"
|
|
|
|
|
x-model="query"
|
|
|
|
|
x-bind="$filter"
|
|
|
|
|
>
|
|
|
|
|
</header>
|
|
|
|
|
{% endif %}
|
|
|
|
|
<div
|
|
|
|
|
role="listbox"
|
|
|
|
|
aria-orientation="vertical"
|
2025-05-01 20:53:03 +08:00
|
|
|
{% for key, value in listbox_attrs.items() %}
|
2025-04-22 16:09:56 +08:00
|
|
|
{{ key }}="{{ value }}"
|
|
|
|
|
{% endfor %}
|
|
|
|
|
>
|
2025-05-02 18:27:45 +08:00
|
|
|
{{ caller() if caller }}
|
2025-04-22 16:09:56 +08:00
|
|
|
</div>
|
2025-04-18 12:58:28 +08:00
|
|
|
</div>
|
2025-04-27 23:19:52 +08:00
|
|
|
{% if name is defined %}
|
|
|
|
|
<input
|
|
|
|
|
type="hidden"
|
|
|
|
|
name="{{ name }}"
|
|
|
|
|
x-model="selectedValue"
|
2025-05-01 20:53:03 +08:00
|
|
|
{% for key, value in input_attrs.items() %}
|
2025-04-27 23:19:52 +08:00
|
|
|
{% if key != 'name' %}{{ key }}="{{ value }}"{% endif %}
|
|
|
|
|
{% endfor %}
|
|
|
|
|
>
|
2025-04-22 16:09:56 +08:00
|
|
|
{% endif %}
|
|
|
|
|
</div>
|
|
|
|
|
{% endmacro %}
|