stack/src/components/button/button.twig line 1

Open in your IDE?
  1. {%- set class_name = [
  2.   "btn",
  3.   "u-posr u-cursor-pointer d-inline-flex gap-1 align-items-center justify-content-center flex-nowrap flex-shrink-0",
  4.   props.variant in ["outline", "primary", "ghost", "facebook", "twitter", "instagram", "linkedin", "youtube"] ? "--" ~ props.variant : "--primary",
  5.   props.size in ["xs", "sm"] ? "--" ~ props.size : null,
  6.   props.animation in ["right", "zoom", "left", "down"] ? "--animation-" ~ props.animation : null,
  7.   props.icon_before ? "--icon-before" : null,
  8.   props.icon_only ? "--icon-only" : null,
  9.   props.full_width_mobile ? "--full-width-mobile" : null,
  10.   props.full_width ? "--full-width w-100" : null,
  11.   props.extra_class ? props.extra_class : null
  12. ]|join(' ')|trim -%}
  13. {%- set tag = props.tag in ['button', 'a', 'span'] ? props.tag : "a" -%}
  14. {%- set href_value = props.url is defined ? props.url : '#' -%}
  15. {%- set href = tag == 'a' ? "href='" ~ href_value ~ "'" : null -%}
  16. {%- set attrs = [
  17.   'class="' ~ class_name ~ '"',
  18. ] -%}
  19. {%- if href -%}
  20.   {%- set attrs = attrs|merge([href]) -%}
  21. {%- endif -%}
  22. {%- if props.id %}
  23.   {%- set attrs = attrs|merge(['id="' ~ props.id ~ '"']) -%}
  24. {%- endif -%}
  25. {%- if props.type and tag == "button" %}
  26.   {%- set attrs = attrs|merge(['type="' ~ props.type ~ '"']) -%}
  27. {%- endif -%}
  28. {%- if props.onclick is defined %}
  29.   {%- set attrs = attrs|merge(['onclick="' ~ props.onclick ~ '"']) -%}
  30. {%- endif -%}
  31. {%- if props.blank == true and tag == "a" %}
  32.   {%- set attrs = attrs|merge(['target="_blank"']) -%}
  33. {%- endif -%}
  34. {%- if tag == "button" and props.title %}
  35.   {%- set attrs = attrs|merge(['aria-label="' ~ props.title ~ '"']) -%}
  36. {%- endif -%}
  37. {%- if props.name and tag == "button" %}
  38.   {% set attrs = attrs|merge(['name=' ~ props.name ~ '']) %}
  39. {%- endif -%}
  40. {%- if props.value and tag == "button" %}
  41.   {%- set attrs = attrs|merge(['value="' ~ props.value ~ '"']) -%}
  42. {%- endif -%}
  43. {% if props.icon_only and tag == 'a' and props.title %}
  44.   {%- set attrs = attrs|merge(['title="' ~ props.title ~ '"']) -%}
  45. {% endif %}
  46. {%- if props.data is defined -%}
  47.   {%- set data_attrs = [] -%}
  48.   {%- for key, attribute in props.data -%}
  49.     {%- set data_attrs = data_attrs|merge(['data-' ~ key ~ '="' ~ attribute ~ '"']) -%}
  50.   {%- endfor -%}
  51.   {%- set data_attrs = data_attrs|join(' ')|trim -%}
  52.   {%- set attrs = attrs|merge([data_attrs]) -%}
  53. {%- endif -%}
  54. {%- set attrs = attrs|join(' ')|trim -%}
  55. <{{tag}} {{ attrs|raw }}>
  56.   {% if not props.icon_only %}
  57.     <span class="btn__title">
  58.       {{ props.title }}
  59.     </span>
  60.   {% endif %}
  61.   {% if props.icon %}
  62.     <span class="btn__icon d-flex align-items-center justify-content-center">
  63.       {% include "@Components/icon/icon.twig" with {props: {
  64.         src: props.icon.src,
  65.         color: props.icon.color,
  66.         size: props.icon.size,
  67.         stroke_off: props.stroke_off
  68.       }} %}
  69.     </span>
  70.   {% endif %}
  71. </{{tag}}>