Skip to content

Instantly share code, notes, and snippets.

@paulmsmith
Created October 5, 2016 20:49
Show Gist options
  • Save paulmsmith/6ab46cb932ececc46e1b29d28f31a6a6 to your computer and use it in GitHub Desktop.
Save paulmsmith/6ab46cb932ececc46e1b29d28f31a6a6 to your computer and use it in GitHub Desktop.
massively over-engineered button macro
{# global anchor ui element #}
{% macro abstractButton(options) %}
{% if not(ctx.ua.isMobile) and options.link.metaData.visibility != "mobile" or ctx.ua.isMobile and options.link.metaData.visibility != "desktop" %}
{%- set elm = options.elm | d('a') %}
<{{ elm }}
{{ (options.link.mobileAlt if ctx.ua.isMobile) | d(options.link.url) | d('#') | attr('href') if elm == 'a' }}
{{ options.baseClass | d("link") | componentClasses(options.metaData) | attr('class') }}
{{ options.link.properties.id | attr('id') }}
{{ options.metaData.data | pairs | attrs('data-') | join(' ') if options.metaData.data }}
{{ options.link.title | attr('title') }}
{{ options.link.properties.target | attr('target') }}
{{ "submit" | attr('type') if options.elm == "button" and options.submit }}
{{ options.buttonType | attr('type') if options.elm == "button" }}
{{'data-view="' + (options.metaData.viewOverrides | join(',')) + '"' if options.metaData.viewOverrides}}>
{# inner wraps both the link "label" text and the icon if that is rendered #}
{# if you want just use class and only have the containing element and non of the below stuff then pass containerOnly #}
{%- if caller and options.containerOnly %}
{{ caller(options) }}
{%- else %}
<span class="link__inner">
{# link label wraps just the link text or the contents of a call #}
{%- if options.iconfirst %}
{{ _icon(options) }}
{%- endif %}
<span class="link__label{%- if options.labelClasses %} {{ options.labelClasses | join(' ') }}{%- endif %}">
{%- if caller %}
{{ caller(options.link.properties.text) }}
{% elif options.link.properties.multimedia %}
{{ mm.image(options.link.properties.multimedia) }}
{%- else %}
{{ options.link.properties.text }}
{%- endif %}
</span>
{# if passed an ic on or the link is modified as a "cta" which always has an icon #}
{%- if options.iconfirst == undefined %}
{{ _icon(options) }}
{%- endif %}
</span>
{%- endif %}
</{{ elm }}>
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment