Files
basecoat/docs/_includes/components/dropdown-menu.njk
T

58 lines
1.2 KiB
Plaintext
Raw Normal View History

2025-04-25 16:42:10 +08:00
{% macro dropdown_menu(
id=None,
trigger=None,
2025-04-27 23:19:52 +08:00
main_attrs={},
trigger_attrs={},
content_attrs={},
2025-04-26 11:59:53 +08:00
include_html=true,
2025-04-27 23:19:52 +08:00
include_script=false,
2025-04-26 11:59:53 +08:00
register_on=["alpine:init"]
2025-04-25 16:42:10 +08:00
) %}
2025-04-26 11:59:53 +08:00
{% if include_script %}
2025-04-27 23:19:52 +08:00
{% include "components/dropdown-menu-script.njk" %}
2025-04-25 16:42:10 +08:00
{% endif %}
2025-04-26 11:59:53 +08:00
{% if include_html %}
2025-04-25 16:42:10 +08:00
<div
2025-04-26 11:59:53 +08:00
class="popover {{ main_attrs.class }}"
2025-04-25 16:42:10 +08:00
x-data="dropdownMenu"
@click.away="open = false"
{% if id %}id="{{ id }}"{% endif %}
{% for key, value in main_attrs %}
2025-04-26 11:59:53 +08:00
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
2025-04-25 16:42:10 +08:00
{% endfor %}
>
{% if trigger %}
<button
type="button"
aria-haspopup="menu"
aria-expanded="false"
x-bind="$trigger"
{% if id %}
id="{{ id }}-trigger"
aria-controls="{{ id }}-menu"
{% endif %}
{% for key, value in trigger_attrs %}
{{ key }}="{{ value }}"
{% endfor %}
>
{{ trigger | safe }}
</button>
{% endif %}
<div
data-popover
aria-hidden="true"
x-bind="$content"
{% if id %}id="{{ id }}-menu"{% endif %}
{% for key, value in content_attrs %}
{{ key }}="{{ value }}"
{% endfor %}
>
<nav role="menu">
{% if caller %}{{ caller() }}{% endif %}
</nav>
</div>
</div>
2025-04-26 11:59:53 +08:00
{% endif %}
2025-04-25 16:42:10 +08:00
{% endmacro %}