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

69 lines
1.8 KiB
Plaintext
Raw Normal View History

2025-04-22 16:09:56 +08:00
{% macro tabs(
2025-04-25 16:42:10 +08:00
id,
tabsets=[],
2025-04-22 16:09:56 +08:00
main_attrs=None,
2025-04-25 16:42:10 +08:00
tablist_attrs=None,
2025-04-26 11:59:53 +08:00
default_tab_index=1,
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/tabs-script.njk" %}
2025-04-22 16:09:56 +08:00
{% endif %}
2025-04-21 10:37:15 +08:00
2025-04-26 11:59:53 +08:00
{% if include_html %}
2025-04-22 16:09:56 +08:00
<div
2025-04-25 16:42:10 +08:00
class="tabs {{ main_attrs.class }}"
2025-04-25 23:14:05 +08:00
x-data="tabs({{ default_tab_index - 1 }})"
2025-04-22 16:09:56 +08:00
{% if id %}id="{{ id }}"{% endif %}
{% for key, value in main_attrs %}
2025-04-25 16:42:10 +08:00
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
2025-04-22 16:09:56 +08:00
{% endfor %}
>
2025-04-25 16:42:10 +08:00
<div
role="tablist"
aria-orientation="horizontal"
x-bind="$tablist"
{% for key, value in tablist_attrs %}
2025-04-22 16:09:56 +08:00
{{ key }}="{{ value }}"
{% endfor %}
>
2025-04-25 16:42:10 +08:00
{% for tabset in tabsets %}
<button
2025-04-27 23:19:52 +08:00
type="button"
2025-04-25 16:42:10 +08:00
role="tab"
id="{{ tabset.id }}-tab-{{ loop.index }}"
aria-controls="{{ tabset.id }}-panel-{{ loop.index }}"
aria-selected="{{ 'true' if loop.index == default_tab_index else 'false' }}"
tabindex="0"
{% for key, value in tabset.tab_attrs %}
{{ key }}="{{ value }}"
{% endfor %}
>
{{ tabset.tab | safe }}
</button>
2025-04-22 16:09:56 +08:00
{% endfor %}
2025-04-25 16:42:10 +08:00
</div>
2025-04-21 10:37:15 +08:00
2025-04-25 16:42:10 +08:00
{% for tabset in tabsets %}
{% if tabset.panel %}
<div
role="tabpanel"
id="{{ tabset.id }}-panel-{{ loop.index }}"
aria-labelledby="{{ tabset.id }}-tab-{{ loop.index }}"
tabindex="-1"
aria-selected="{{ 'true' if loop.index == default_tab_index else 'false' }}"
{% if loop.index != default_tab_index %}hidden{% endif %}
{% for key, value in tabset.panel_attrs %}
{{ key }}="{{ value }}"
{% endfor %}
>
{{ tabset.panel | safe }}
</div>
{% endif %}
{% endfor %}
</div>
2025-04-26 11:59:53 +08:00
{% endif %}
2025-04-25 16:42:10 +08:00
{% endmacro %}