vendor/easycorp/easyadmin-bundle/templates/components/Button.html.twig line 1

Open in your IDE?
  1. {% props
  2. variant = 'default', # primary|default|danger|success|warning (default: 'default')
  3. isInvisible = false, # true|false (default: false) if true, button has transparent background and no border
  4. isBlock = false, # true|false (default: false) if true, button takes full width of container
  5. size = 'md', # sm|md|lg (default: 'md')
  6. icon = null, # icon name string (e.g., 'tabler:user' or 'fa fas fa-user')
  7. withTrailingIcon = false, # boolean to show icon after label (default: false)
  8. inactive = false, # boolean to disable the button (default: false)
  9. htmlElement = 'button', # button|a|form (default: 'button')
  10. htmlAttributes = {}, # additional HTML attributes as key-value pairs
  11. href = '#', # URL for link buttons (default: '#')
  12. action = null, # form action URL (for htmlElement='form')
  13. method = 'POST', # HTTP method for forms (default: 'POST')
  14. type = null, # button|submit (default: 'submit') button type attribute
  15. name = null, # form button name attribute
  16. value = null, # form button value attribute
  17. %}
  18. {# handle both string and enum values #}
  19. {% set html_element_value = htmlElement.value is defined ? htmlElement.value : htmlElement %}
  20. {% set variant_value = variant.value is defined ? variant.value : variant %}
  21. {% set variant_class = variant_value == 'default' ? 'btn-secondary' : 'btn-' ~ variant_value %}
  22. {% set size_class = size == 'md' ? '' : 'btn-' ~ size %}
  23. {% set css_class = html_classes('btn', variant_class, size_class, {
  24. 'btn-invisible': isInvisible,
  25. 'btn-block': isBlock,
  26. disabled: inactive,
  27. }) %}
  28. {% if html_element_value == 'a' %}
  29. <a {{ attributes.only('class').defaults({class: css_class}) }}
  30. href="{{ inactive ? '#' : href }}"
  31. role="button"
  32. {% if inactive %}aria-disabled="true" tabindex="-1"{% endif %}
  33. {% for attrName, attrValue in htmlAttributes %}{{ attrName }}="{{ (attrValue.trans is defined ? attrValue|trans : attrValue)|e('html') }}" {% endfor %}
  34. {{ attributes.without('class', 'href', 'role', 'aria-disabled', 'tabindex')|raw }}>
  35. {% if icon and not withTrailingIcon %}
  36. <twig:ea:Icon name="{{ icon }}" class="btn-icon" />
  37. {% endif %}
  38. {% if block('content') is defined %}
  39. <span {{ attributes.nested('label').defaults({class: 'btn-label'}) }}>{{ block('content') }}</span>
  40. {% endif %}
  41. {% if icon and withTrailingIcon %}
  42. <twig:ea:Icon name="{{ icon }}" class="btn-icon btn-icon-trailing" />
  43. {% endif %}
  44. </a>
  45. {% elseif html_element_value == 'form' %}
  46. <form action="{{ action }}" method="{{ method }}" {{ attributes.only('id', 'class', 'data-*') }}>
  47. {% if method|upper not in ['GET', 'POST'] %}
  48. <input type="hidden" name="_method" value="{{ method|upper }}">
  49. {% endif %}
  50. <button {{ attributes.only('class').defaults({class: css_class}) }}
  51. type="{{ type ?? 'submit' }}"
  52. {% if name %}name="{{ name }}"{% endif %}
  53. {% if value %}value="{{ value }}"{% endif %}
  54. {% if inactive %}disabled="disabled"{% endif %}
  55. {% for attrName, attrValue in htmlAttributes %}{{ attrName }}="{{ (attrValue.trans is defined ? attrValue|trans : attrValue)|e('html') }}" {% endfor %}
  56. {{ attributes.without('class', 'form', 'type', 'name', 'value', 'disabled')|raw }}
  57. >
  58. {% if icon and not withTrailingIcon %}
  59. <twig:ea:Icon name="{{ icon }}" class="btn-icon" />
  60. {% endif %}
  61. {% if block('content') is defined %}
  62. <span {{ attributes.nested('label').defaults({class: 'btn-label'}) }}>{{ block('content') }}</span>
  63. {% endif %}
  64. {% if icon and withTrailingIcon %}
  65. <twig:ea:Icon name="{{ icon }}" class="btn-icon btn-icon-trailing" />
  66. {% endif %}
  67. </button>
  68. </form>
  69. {% else %}
  70. <button {{ attributes.only('class').defaults({class: css_class}) }}
  71. type="{{ type ?? 'submit' }}"
  72. {% if inactive %}disabled="disabled"{% endif %}
  73. {% for attrName, attrValue in htmlAttributes %}{{ attrName }}="{{ (attrValue.trans is defined ? attrValue|trans : attrValue)|e('html') }}" {% endfor %}
  74. {{ attributes.without('class', 'type', 'disabled')|raw }}>
  75. {% if icon and not withTrailingIcon %}
  76. <twig:ea:Icon name="{{ icon }}" class="btn-icon" />
  77. {% endif %}
  78. {% if block('content') is defined %}
  79. <span {{ attributes.nested('label').defaults({class: 'btn-label'}) }}>{{ block('content') }}</span>
  80. {% endif %}
  81. {% if icon and withTrailingIcon %}
  82. <twig:ea:Icon name="{{ icon }}" class="btn-icon btn-icon-trailing" />
  83. {% endif %}
  84. </button>
  85. {% endif %}