{#
/**
 * @file
 * Icon component
 *
 * @param string  $name           The file name of the icon.
 * @param boolean $ignore_missing Avoid empty <span> printing
 * @param array   $attr           Custom attributes.
 */
#}

{% set attributes = merge_html_attributes(
  attr ?? null,
  {
    class: 'inline-block',
  },
  {
    class: [
      'icon',
      'icon--%s'|format(name)
    ],
  }
) %}

{%- set icon -%}
  {% if ':' in name %}
    {{ meta_icon(name) }}
  {% else %}
    {{ source('@svg/%s.svg'|format(name), true) }}
  {% endif %}
{%- endset -%}

{% if icon is not empty or not (ignore_missing ?? true)  %}
  <span {{ html_attributes(attributes) }}>
    {{ icon }}
  </span>
{% endif %}
