Skip to content

Commit

Permalink
Merge pull request #79 from araise-dev/feature/menu-count
Browse files Browse the repository at this point in the history
feat(menu): add count to menu item
  • Loading branch information
tuxes3 authored Nov 27, 2024
2 parents d14088b + 77829eb commit 70c57c3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Resources/views/extensions/knp_menu_main.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
class: (item.attributes.class|default('') ~ ' ' ~ classes)|trim,
}) %}

{# extract count #}
{% set count = attributes.count|default(false) %}
{% set attributes = attributes|filter((v, k) => k != 'count') %}

{# add attributes for link/button #}
{%- if item.hasChildren() %}
{% set htmlElement = 'button' %}
Expand All @@ -69,7 +73,7 @@
}) %}
{% endif %}

{# extract icon #}
{# extract icon on sub items #}
{% set icon = attributes.icon|default(false) %}
{% set attributes = attributes|filter((v, k) => k != 'icon') %}

Expand Down Expand Up @@ -105,6 +109,10 @@

{{ item.label|trans }}

{% if count %}
<span class="ml-auto inline-flex items-center rounded-full bg-primary-400 px-1.5 py-0.5 text-xs font-medium text-white">{{ count }}</span>
{% endif %}

{# if there are children: add caret icon #}
{% if item.children|length > 0 %}
{% set classes = 'text-neutral-300 ml-auto h-3 w-3 transform group-hover:text-neutral-400 rotate-0 transition-colors ease-in-out duration-150' %}
Expand All @@ -131,4 +139,4 @@
{% endif %}
</div>
{% endif %}
{% endblock %}
{% endblock %}

0 comments on commit 70c57c3

Please sign in to comment.