Last active
May 2, 2016 20:29
-
-
Save jacine/7503092d6a09a5100c6122643d936f20 to your computer and use it in GitHub Desktop.
Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends '/themes/THEME/components/container.twig' %} | |
{% block content %} | |
<div{{ attributes.addClass(classes, add_classes).removeClass(remove_classes) }}> | |
{{ children }} | |
</div> | |
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Core Classes #} | |
{% | |
set classes = [ | |
has_parent ? 'js-form-wrapper', | |
has_parent ? 'form-wrapper', | |
] | |
%} | |
{# Map #type to theme component #} | |
{% | |
set map = { | |
'more_link': 'btn', | |
} | |
%} | |
{% set remove_classes = [] %} | |
{% set add_classes = [] %} | |
{% for key,value in map %} | |
{# Prefer component classes instead of defaults when a match is present, e.g. | |
- Add: .btn btn--more-link | |
- Remove: .more-link | |
#} | |
{% if element['#type'] == key %} | |
{# Add component classes. #} | |
{% set add_classes = [ | |
value, | |
value ~ '--' ~ key|clean_class, | |
] %} | |
{# Remove the original base #type class. #} | |
{% set remove_classes = [ key|clean_class ] %} | |
{% endif %} | |
{% endfor %} | |
{% block content %} | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment