Created
February 25, 2019 21:55
-
-
Save cameroncowden/c56a48b900150a04639ca7bae12ceb61 to your computer and use it in GitHub Desktop.
A shopify section which builds accordions using
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
<section class="accordion faq"> | |
{% if section.settings.title %} | |
<p style="text-align: center; font-style: italic;">{{ section.settings.title }}</p> | |
{% endif %} | |
{% for block in section.blocks %} | |
{% capture index %}{% increment ind %}{% endcapture %} | |
<input id="tab-{{ index }}" type="checkbox" name="faqs" class="hidden"> | |
<div class="section section-{{ section.id }} {% if forloop.first == true %}opened{% endif %} mar-top-sm" data-block-id="{{ block.id }}" {{ block.shopify_attributes }}> | |
<label for="tab-{{ index }}" class="tab-opener"> | |
<h3 class="faq-question">{{ block.settings.title | escape }}</h3> | |
</label> | |
<div class="faq-answer mar-bot-sm">{{ block.settings.content }}</div> | |
</div> | |
{% endfor %} | |
</section> | |
{% schema %} | |
{ | |
"name": "Accordions", | |
"settings": [ | |
{ | |
"type": "text", | |
"id": "title", | |
"label": "Optional Header", | |
"default": "Accordion Header" | |
} | |
], | |
"blocks": [ | |
{ | |
"type": "accordion", | |
"name": "Accordion", | |
"settings": [ | |
{ | |
"type": "text", | |
"id": "title", | |
"default": "Accordion Header", | |
"label": "Accordion Header" | |
}, | |
{ | |
"type": "richtext", | |
"id": "content", | |
"default": "<p>This section doesn’t currently include any content. <b>Add content to this section using the sidebar in the customizer.</b></p>", | |
"label": "Accordion Content" | |
} | |
] | |
} | |
] | |
} | |
{% endschema %} | |
{% stylesheet 'scss' %} | |
.faq { | |
margin-top: 40px; | |
input { | |
display: none; | |
} | |
label { | |
display: flex; | |
} | |
label:before { | |
content: "+"; | |
display: inline-block; | |
width: 15px; | |
margin-right: 10px; | |
text-align: center; | |
font-size: 20px; | |
line-height: 1.2; | |
font-weight: bold; | |
} | |
p { | |
padding-left: 25px; | |
} | |
label h3 { | |
display: inline-block; | |
font-size: 20px; | |
} | |
input:checked + div > label:before { | |
content: "-"; | |
} | |
input + div > div { | |
display: none; | |
} | |
input:checked + div > div { | |
display: block; | |
} | |
} | |
{% endstylesheet %} | |
{% javascript %} | |
{% endjavascript %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment