Files
basecoat/docs/_includes/components/popover.njk
T

56 lines
1.2 KiB
Plaintext
Raw Normal View History

2025-04-22 16:09:56 +08:00
{% macro popover(
id=None,
trigger=None,
main_attrs=None,
trigger_attrs=None,
2025-04-26 11:59:53 +08:00
content_attrs=None,
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-22 16:09:56 +08:00
) %}
2025-04-26 11:59:53 +08:00
{% if include_script %}
2025-04-27 23:19:52 +08:00
{% include "components/popover-script.njk" %}
2025-04-22 16:09:56 +08:00
{% endif %}
2025-04-26 11:59:53 +08:00
{% if include_html %}
2025-04-22 16:09:56 +08:00
<div
2025-04-26 11:59:53 +08:00
class="popover {{ main_attrs.class }}"
2025-04-22 16:09:56 +08:00
x-data="popover"
@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-22 16:09:56 +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 %}
>
2025-04-22 17:43:19 +08:00
{% if caller %}{{ caller() }}{% endif %}
2025-04-21 10:37:15 +08:00
</div>
2025-04-22 16:09:56 +08:00
</div>
2025-04-26 11:59:53 +08:00
{% endif %}
2025-04-22 16:09:56 +08:00
{% endmacro %}