0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 01:22:07 +01:00

Add icon support to generic breadcrumbs template tag

This commit is contained in:
Sage Abdullah 2024-02-23 16:55:11 +00:00 committed by Thibaud Colas
parent 2f5565a996
commit 24deedea78
3 changed files with 23 additions and 3 deletions

View File

@ -12,8 +12,15 @@
}
}
.w-breadcrumbs__sublabel {
.w-breadcrumbs__sublabel,
.w-breadcrumbs__icon {
display: inline-block;
}
.w-breadcrumbs__icon {
width: theme('spacing.5');
height: theme('spacing.5');
margin-inline-end: theme('spacing[2.5]');
}
}
}

View File

@ -6,6 +6,7 @@
`items` - A list of {"url": Union[str, None], "label": str, "sublabel": Union[str, None]} dicts
`classname` - Modifier classes
`is_expanded` - Whether the breadcrumbs are always expanded or not, if True the breadcrumbs will not be collapsible
`icon_name` - The name of the icon to display before the final item when the breadcrumbs are collapsed
{% endcomment %}
{% with breadcrumb_link_classes='w-flex w-items-center w-text-text-label w-pr-0.5 w-text-14 w-no-underline w-outline-offset-inside w-border-b w-border-b-2 w-border-transparent w-box-content hover:w-border-current hover:w-text-text-label' breadcrumb_item_classes='w-h-full w-flex w-items-center w-overflow-hidden w-transition w-duration-300 w-whitespace-nowrap w-flex-shrink-0' icon_classes='w-w-4 w-h-4 w-ml-3' %}
{# Breadcrumbs are visible on mobile by default but hidden on desktop #}
@ -48,6 +49,11 @@
data-w-breadcrumbs-target="content"
{% endif %}
>
{% fragment as icon %}
{% if icon_name and forloop.last %}
{% icon name=icon_name classname="w-breadcrumbs__icon w-hidden" %}
{% endif %}
{% endfragment %}
{% fragment as sublabel %}
{% if item.sublabel %}
<span class="w-sr-only">: </span>
@ -58,11 +64,13 @@
{% endfragment %}
{% if item.url is not None %}
<a class="{{ breadcrumb_link_classes }}" href="{{ item.url }}">
{{ icon }}
{{ item.label }}
{{ sublabel }}
</a>
{% else %}
<div class="w-flex w-justify-start w-items-center">
{{ icon }}
{{ item.label }}
{{ sublabel }}
</div>

View File

@ -67,8 +67,13 @@ register.filter("naturaltime", naturaltime)
@register.inclusion_tag("wagtailadmin/shared/breadcrumbs.html")
def breadcrumbs(items, is_expanded=False, classname=None):
return {"items": items, "is_expanded": is_expanded, "classname": classname}
def breadcrumbs(items, is_expanded=False, classname=None, icon_name=None):
return {
"items": items,
"is_expanded": is_expanded,
"classname": classname,
"icon_name": icon_name,
}
@register.inclusion_tag("wagtailadmin/shared/page_breadcrumbs.html", takes_context=True)