toolbar-button.twig

Same filename and directory in other branches
  1. 10 core/modules/navigation/components/toolbar-button/toolbar-button.twig
{# Extra classes variable added to be sure that modifiers will
appear after main classes #}
{%
  set classes = [
    'toolbar-button',
    icon.icon_id ? 'toolbar-button--icon--' ~ icon.icon_id : '',
  ]
%}

{% if modifiers is iterable %}
  {% set classes = classes|merge(modifiers|map(modifier => "toolbar-button--#{modifier}")) %}
{% endif %}

{% if extra_classes is iterable %}
  {% set classes = classes|merge(extra_classes) %}
{% endif %}

{% if text and text|length > 1 %}
  {# We take the first two letters of the button text to use as a fallback when
  the toolbar button does not have a pre-assigned icon. #}
  {% set icon_text = text|slice(0, 2)|join('') %}
  {% set attributes = attributes.setAttribute('data-index-text', text|first|lower).setAttribute('data-icon-text', icon_text) %}
{% endif %}

<{{ html_tag|default('button') }} {{ attributes.addClass(classes) }}>

  {% if icon.icon_id %}
    {{ icon(icon.pack_id|default('navigation'), icon.icon_id, icon.settings|default({ class: 'toolbar-button__icon', size: 20 })) }}
  {% endif %}

  {% if action %}
    <span data-toolbar-action class="visually-hidden">{{ action }}</span>
  {% endif %}
  {% block content %}
    {% if text %}
      <span class="toolbar-button__label" data-toolbar-text>{{~ text ~}}</span>
    {% endif %}
  {% endblock %}

  {% if modifiers is iterable and ('expand--side' in modifiers or 'expand--down' in modifiers) %}
    {{ icon('navigation', 'chevron', { class: 'toolbar-button__chevron', size: 16 }) }}
  {% endif %}

</{{ html_tag|default('button') }}>

File

core/modules/navigation/components/toolbar-button/toolbar-button.twig

View source
  1. {# Extra classes variable added to be sure that modifiers will
  2. appear after main classes #}
  3. {%
  4. set classes = [
  5. 'toolbar-button',
  6. icon.icon_id ? 'toolbar-button--icon--' ~ icon.icon_id : '',
  7. ]
  8. %}
  9. {% if modifiers is iterable %}
  10. {% set classes = classes|merge(modifiers|map(modifier => "toolbar-button--#{modifier}")) %}
  11. {% endif %}
  12. {% if extra_classes is iterable %}
  13. {% set classes = classes|merge(extra_classes) %}
  14. {% endif %}
  15. {% if text and text|length > 1 %}
  16. {# We take the first two letters of the button text to use as a fallback when
  17. the toolbar button does not have a pre-assigned icon. #}
  18. {% set icon_text = text|slice(0, 2)|join('') %}
  19. {% set attributes = attributes.setAttribute('data-index-text', text|first|lower).setAttribute('data-icon-text', icon_text) %}
  20. {% endif %}
  21. <{{ html_tag|default('button') }} {{ attributes.addClass(classes) }}>
  22. {% if icon.icon_id %}
  23. {{ icon(icon.pack_id|default('navigation'), icon.icon_id, icon.settings|default({ class: 'toolbar-button__icon', size: 20 })) }}
  24. {% endif %}
  25. {% if action %}
  26. <span data-toolbar-action class="visually-hidden">{{ action }}</span>
  27. {% endif %}
  28. {% block content %}
  29. {% if text %}
  30. <span class="toolbar-button__label" data-toolbar-text>{{~ text ~}}</span>
  31. {% endif %}
  32. {% endblock %}
  33. {% if modifiers is iterable and ('expand--side' in modifiers or 'expand--down' in modifiers) %}
  34. {{ icon('navigation', 'chevron', { class: 'toolbar-button__chevron', size: 16 }) }}
  35. {% endif %}
  36. </{{ html_tag|default('button') }}>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.