-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTR-400: Build accordion dwds component (#800)
Co-authored-by: Suresh Manga <[email protected]> Co-authored-by: Cameron Lamb <[email protected]>
- Loading branch information
1 parent
ea06c85
commit 9757df9
Showing
11 changed files
with
239 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% load static %} | ||
<div class="dwds-accordions content-stack"> | ||
<div class="show-all-header"> | ||
<button class="dwds-button dwds-button--clear"> | ||
<span class="show-all-chevron"></span> | ||
<span class="show-all-text">Show all sections</span> | ||
</button> | ||
</div> | ||
|
||
{% for item in items %} | ||
<div class="dwds-accordion-section content-stack"> | ||
<div class="section-header"> | ||
<button class="dwds-button dwds-button--clear"> | ||
<span class="text-large">{{ item.heading }}</span> | ||
<p class="text-small">{{ item.summary }}</p> | ||
<span class="section-toggle"> | ||
<span class="section-chevron"></span> | ||
<span class="section-text">Show</span> | ||
</span> | ||
</button> | ||
</div> | ||
|
||
<div class="section-content content-stack"> | ||
<p>{{ item.content }}</p> | ||
</div> | ||
|
||
</div> | ||
{% endfor %} | ||
|
||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function showSection(accordion) { | ||
const [content, text, sectionChevron] = getCommonElements(accordion); | ||
content.style.display = "block"; | ||
text.innerText = "Hide"; | ||
sectionChevron.classList.add("section-chevron-up"); | ||
} | ||
|
||
function hideSection(accordion) { | ||
const [content, text, sectionChevron] = getCommonElements(accordion); | ||
content.style.display = "none"; | ||
text.innerText = "Show"; | ||
sectionChevron.classList.remove("section-chevron-up"); | ||
} | ||
|
||
function getCommonElements(accordion) { | ||
const content = accordion.getElementsByClassName("section-content")[0]; | ||
const text = accordion.getElementsByClassName("section-text")[0]; | ||
const sectionChevron = accordion.getElementsByClassName("section-chevron")[0]; | ||
return [content, text, sectionChevron]; | ||
} | ||
|
||
function toggleSpecificSection(accordion) { | ||
const sectionText = accordion.getElementsByClassName("section-text")[0]; | ||
if (sectionText.innerText === "Show") { | ||
showSection(accordion); | ||
} else { | ||
hideSection(accordion); | ||
} | ||
} | ||
|
||
function toggleAll(accordions, accordionsInGroup) { | ||
const allText = accordions.getElementsByClassName("show-all-text")[0]; | ||
const allChevron = accordions.querySelector(".show-all-chevron"); | ||
if (allText.innerText === "Hide all sections") { | ||
accordionsInGroup.forEach(function (accordion) { | ||
hideSection(accordion); | ||
}); | ||
allText.innerText = "Show all sections"; | ||
allChevron.classList.remove("show-all-chevron-up"); | ||
} else { | ||
accordionsInGroup.forEach(function (accordion) { | ||
showSection(accordion); | ||
}); | ||
allText.innerText = "Hide all sections"; | ||
allChevron.classList.add("show-all-chevron-up"); | ||
} | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
|
||
document.querySelectorAll('.dwds-accordions').forEach(function (accordions) { | ||
|
||
const accordionsInGroup = accordions.querySelectorAll('.dwds-accordion-section'); | ||
accordionsInGroup.forEach(function (accordion) { | ||
const accordionHeader = accordion.getElementsByClassName("section-header")[0]; | ||
accordionHeader.addEventListener("click", function (e) { | ||
toggleSpecificSection(accordion); | ||
}); | ||
}); | ||
|
||
const allHeader = accordions.getElementsByClassName("show-all-header")[0]; | ||
allHeader.addEventListener("click", function (e) { | ||
toggleAll(accordions, accordionsInGroup); | ||
}); | ||
|
||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
.dwds-accordions { | ||
background-color: var(--color-background); | ||
|
||
.show-all-header { | ||
border-bottom: var(--border-bottom-width) solid var(--color-border); | ||
} | ||
|
||
.dwds-accordion-section { | ||
border-bottom: var(--border-bottom-width) solid var(--color-border); | ||
|
||
.section-header { | ||
|
||
&:hover { | ||
background-color: var(--color-accordion-hover); | ||
|
||
.section-chevron { | ||
color: var(--color-text); | ||
background: var(--color-text); | ||
|
||
&::after { | ||
color: var(--color-background-highlight); | ||
} | ||
} | ||
} | ||
} | ||
|
||
.section-toggle { | ||
font-size: var(--text-small); | ||
font-weight: var(--font-weight-normal); | ||
color: var(--color-button-primary); | ||
margin-bottom: var(--s-1); | ||
} | ||
|
||
.section-content { | ||
display: none; | ||
padding-bottom: var(--s1); | ||
} | ||
|
||
} | ||
|
||
.section-chevron, | ||
.show-all-chevron { | ||
box-sizing: border-box; | ||
display: inline-block; | ||
position: relative; | ||
width: var(--s1); | ||
height: var(--s1); | ||
border: .0625rem solid; | ||
border-radius: 50%; | ||
vertical-align: middle; | ||
|
||
&::after { | ||
content: ""; | ||
box-sizing: border-box; | ||
display: block; | ||
position: absolute; | ||
top: .3125rem; | ||
left: .375rem; | ||
width: .375rem; | ||
height: .375rem; | ||
transform: rotate(135deg); | ||
border-top: .125rem solid; | ||
border-right: .125rem solid; | ||
} | ||
} | ||
|
||
.section-chevron-up, | ||
.show-all-chevron-up { | ||
transform: rotate(180deg); | ||
} | ||
|
||
.show-all-text { | ||
margin-left: var(--s-5); | ||
vertical-align: middle; | ||
} | ||
} |
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
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
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
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
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
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
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