templates/component/button.html.twig line 1

Open in your IDE?
  1. {% import 'macros/utils.macro.twig' as utils %}
  2. {# Options #}
  3. {% set tag = tag|default('a') %}
  4. {% set text = text|default(null) %}
  5. {% set icon_before = icon_before|default(null) %}
  6. {% set icon_after = icon_after|default(null) %}
  7. {% set attr = attr|deep_merge({ class: 'btn' }) %}
  8. {% set type = type|default("primary") %}
  9. {% set types = {
  10.   primary: "btn-primary",
  11.   secondary: "btn-secondary",
  12.   neutral: "btn-neutral",
  13. } %}
  14. {% set attr = attr|deep_merge({
  15.   class: types[type]
  16. }) %}
  17. {% set size = size|default("base") %}
  18. {% set sizes = {
  19.   small: "btn-sm",
  20.   base: "",
  21. } %}
  22. {% set attr = attr|deep_merge({
  23.   class: sizes[size]
  24. }) %}
  25. <{{tag}} {{- utils.attributes(attr) -}}>
  26.   {% if icon_before %}
  27.     {% include "icons/" ~ icon_before ~ ".svg.twig" with { class: "w-4 h-4 text-white" } only %}
  28.   {% endif %}
  29.   <span class="flex-1">{{- text|raw -}}</span>
  30.   {% if icon_after %}
  31.     {% include "icons/" ~ icon_after ~ ".svg.twig" with { class: "w-4 h-4 text-white" } only %}
  32.   {% endif %}
  33. </{{tag}}>