{#
/**
 * Icon
 *
 * A vector-based icon. Icons are svg data embedded in an inline `svg` element via the `use` element and svg fragment identifiers.
 *
 * Currently available icons:
 *
 * - check-circle
 * - cornell-seal
 * - facebook
 * - handshake
 * - ilr-nickname
 * - instagram
 * - linkedin
 * - mortarboard
 * - news-phone
 * - newsletter
 * - speech-bubble
 * - student
 * - profile
 * - tower
 * - twitter
 * - x
 * - play
 * - pause
 * - youtube
 *
 * @var string $icon The name if the desired icon.
 * @var string $title A title for the icon. Generally used for tooltips and accessibility.
 * @var string $size The size of the icon in CSS units (e.g. 18px, 2em). (optional; default: 2em)
 * @var string $label A visible text label to be displayed alongside the icon. (optional)
 * @var string $label_element The HTML element for the icon label. (default: `div`)
 * @var string $link A URL/URI that will be added to an `a` element around the icon and label.
 * @var Drupal\Core\Template\Attribute|array $attributes Attributes (class, data, etc.) for the icon. Useful for passing in variant classes. (optional)
 * @var Drupal\Core\Template\Attribute|array $attributes_label Attributes (class, data, etc.) for the icon label. (optional)
 *
 * @union-variation cu-icon--inline Places the icon, label, and wrapper inline.
 * @union-variation cu-icon--inline-centered Places the label inline and centers the wrapper.
 * @union-variation cu-icon--color-light Deprecated. All icons should now follow the current color scheme.
 * @union-variation cu-icon--color-brand Deprecated. All icons should now follow the current color scheme.
 *
 */
#}
{% set size = size|default('2em') %}
{% set label_element = label_element|default('div') %}
{% set attributes = union_attributes(attributes|default([])) %}
{% set attributes = attributes.addClass(['cu-icon cu-icon--' ~ icon]) %}
{% set attributes_svg = union_attributes({
  class: 'cu-icon__image',
  width: size
}) %}
{% set attributes_label = union_attributes(attributes_label|default([])) %}
{% if label_element starts with 'h' %}
{% set attributes_label = attributes_label.addClass(['cu-heading']) %}
{% endif %}
{% if link %}
  {% set icon_wrapper_element = 'a' %}
  {% set attributes = attributes.addClass(['cu-icon--link']) %}
  {% set attributes = attributes.setAttribute('href', link) %}
{% else %}
  {% set icon_wrapper_element = 'div' %}
{% endif %}

<{{icon_wrapper_element}}{{attributes}}>
  <svg{{ attributes_svg }} viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
    <title>{{ title }} Icon</title>
    <use href="{{ union_file('/images/icons.svg') }}#{{ icon }}" />
  </svg>
  {% if label %}<{{ label_element }}{{ attributes_label.addClass('cu-icon__label') }}>{{ label }}</{{ label_element }}>{% endif %}
</{{icon_wrapper_element}}>
