Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for accordions #126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,26 @@ <h1>Name</h1>

</code>
</pre>
</pre>
<h3 id="accordion-block">Accordion - Block</h3><a class="permalink" href="#accordion-block">permalink</a>

<h4>Expected Contexts</h3>
<ul>
<li><span class="distinct">body.defualt-page > main >article</span></li>
</ul>

<pre>
<code class="lang-html">

<article>
<h1 >Frequently asked Questions</h1>
<button aria-expanded="false" class="accordion-header" aria-controls="answer1">Question you might have?<img src="/src/svg/cc/icons/cc-arrow-up.svg" alt="" class="accordion-chevron"> </button>
<p id="answer1" class="hidden" role="region" aria-labelledby="question1">Answer to the question</p>

</article>

</code>
</pre>

</main>

Expand Down
1 change: 0 additions & 1 deletion specimen/contexts/default-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ <h3>Steps to launch</h3>

<li>Top Level Item</li>
</ul>
</div>

</main>

Expand Down
43 changes: 42 additions & 1 deletion src/css/vocabulary.css
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,42 @@ body > footer .license svg {
.program-index main > article.projects article a {
--underline-background-color: var(--vocabulary-brand-color-soft-turquoise);
}
/* accordion styles */
.accordion-header{
padding:1rem 1rem;
border-bottom: 1px solid gray;
cursor: pointer;
width: 100%;
font-family: 'Roboto Condensed';
font-style: normal;
font-weight: 700;
font-size: 1.75em;
display: flex;
justify-content: space-between;
border: none;


margin:0;
}
.accordion-content{
display: block;
padding:1rem 1rem;
margin: 0;
}
.accordion-chevron{
margin-left:1rem;
height: 1.8rem;
transform: translateY(6px);
}
.hidden{
display: none;
opacity: 0;
}
.accordion-chevron-active{
transition:all 300ms ease-in-out;
transform: rotateX(180deg);
}


/* program-page context */

Expand Down Expand Up @@ -2047,7 +2083,12 @@ body > footer .license svg {
flex-direction: column;
flex-wrap: wrap;
}

.accordion-chevron{
height: 1.5rem;
}
.accordion-header{
font-size: 1.5rem;
}
.team-index main article.persons ul {
display: initial;
}
Expand Down
33 changes: 33 additions & 0 deletions src/js/vocabulary.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,36 @@ if (attributionButton !== null && attributionPanel !== null ) {
});

}

// accordion logic

const accordionHeader = document.querySelectorAll(".accordion-header")

if(typeof accordionHeader !== null){
accordionHeader.forEach(header=>{
header.addEventListener("click",(event)=>{
// updating aria-expanded attr as user clicks on the accordion
const expanded = header.getAttribute('aria-expanded') === "true" || false;
header.setAttribute('aria-expanded', !expanded);
const content = header.nextElementSibling
const chevron = header.querySelector(".accordion-chevron")

if(content.classList.contains("hidden")){
// removing hidden class from accordion-content
content.classList.toggle("hidden")
// adding accordion-content class in accordion-content
content.classList.toggle("accordion-content")
// adding accordion-chevron-active class in accordion chevron
chevron.classList.toggle("accordion-chevron-active")

}else{
// removing hidden class from accordion-content
chevron.classList.toggle("accordion-chevron-active")
// adding hidden class in accordion-content is it is active
content.classList.toggle("hidden")
// removing accordion-content class from accordion-content
content.classList.toggle("accordion-content")
}
})
})
}
1 change: 1 addition & 0 deletions src/svg/cc/icons/cc-arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.