dsfr4drupal-1.x-dev/components/button/button.twig
components/button/button.twig
{% set attributes = attributes|default(create_attribute()) %}
{% set button_type = button_type|default('button') %}
{% if variant and variant != 'primary' %}
{% set attributes = attributes.addClass('fr-btn--' ~ variant) %}
{% endif %}
{% if icon %}
{% set attributes = attributes.addClass('fr-icon-' ~ icon) %}
{% if icon_position %}
{% set attributes = attributes.addClass('fr-btn--icon-' ~ icon_position) %}
{% endif %}
{% endif %}
{% if title %}
{% set attributes = attributes.setAttribute('title', title) %}
{% endif %}
{% if disabled %}
{% set attributes = attributes.setAttribute('disabled', true) %}
{% endif %}
{% if url or attributes.href %}
{% set url = url|default(attributes.href) %}
{% if target %}
{% set attributes = attributes.setAttribute('target', '_' ~ target) %}
{% endif %}
{{ link(label, url, attributes.addClass('fr-btn').removeAttribute('href')) }}
{% else %}
<button{{ attributes.setAttribute('type', button_type).addClass('fr-btn') }}>
{{ label }}
</button>
{% endif %}
