generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from hlxsites/feature-navigation
[wip] Navigation
- Loading branch information
Showing
9 changed files
with
242 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
raqn-accordion { | ||
--scope-icon-size: 1em; | ||
--accordion-background-color: var(--scope-background, black); | ||
--accordion-color: var(--scope-color, white); | ||
|
||
background-color: var(--accordion-background-color); | ||
color: var(--accordion-color); | ||
margin: var(--scope-margin, 0); | ||
display: grid; | ||
|
||
& .accordion-control { | ||
border-block-start: var(--scope-border-block-start, none); | ||
border-inline-start: var(--scope-border-inline-start, none); | ||
border-inline-end: var(--scope-border-inline-end, none); | ||
|
||
&:first-child { | ||
border-block-start: none | ||
} | ||
|
||
& > * { | ||
--scope-headings-color: var(--scope-color, black); | ||
--scope-hover-color: var(--scope-accent-color, gray); | ||
|
||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
min-width: 100%; | ||
} | ||
|
||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
justify-content: start; | ||
width: 100%; | ||
|
||
&:hover { | ||
--scope-color: var(--scope-headings-color); | ||
} | ||
} | ||
|
||
& raqn-icon { | ||
align-self: end; | ||
transform: rotate(90deg); | ||
transition: transform 0.2s ease-in-out; | ||
} | ||
|
||
& accordion-control.active raqn-icon { | ||
transform: rotate(270deg); | ||
} | ||
|
||
& .accordion-content { | ||
display: grid; | ||
max-height: 0; | ||
overflow: hidden; | ||
opacity: 0; | ||
border-block-end: var(--scope-border-block-end, none); | ||
border-block-start: var(--scope-border-block-start, none); | ||
margin-block-end: -1px; | ||
transition: max-height 0.5s ease-in-out, | ||
opacity 0.5s ease-in-out; | ||
|
||
|
||
&:last-child { | ||
border-block-end: none | ||
} | ||
|
||
&.active { | ||
opacity: 1; | ||
grid-template-rows: 1fr; | ||
max-height: 100vw; | ||
|
||
} | ||
} | ||
|
||
& .accordion-content-wrapper { | ||
margin-block: 1em; | ||
display: grid; | ||
} | ||
} |
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,70 @@ | ||
import Column from '../column/column.js'; | ||
|
||
export default class Accordion extends Column { | ||
ready() { | ||
this.setAttribute('role', 'navigation'); | ||
let children = Array.from(this.children); | ||
children = children.map((child) => { | ||
if (child.tagName !== 'DIV') { | ||
const div = document.createElement('div'); | ||
div.append(child); | ||
this.append(div); | ||
return div; | ||
} | ||
return child; | ||
}); | ||
// console.log(children) | ||
this.setupControls(children.filter((_, ind) => ind % 2 === 0)); | ||
this.setupContent(children.filter((_, ind) => ind % 2 === 1)); | ||
} | ||
|
||
setupControls(controls) { | ||
controls.forEach((control,index) => { | ||
const icon = document.createElement('raqn-icon'); | ||
icon.setAttribute('icon', 'chevron-right'); | ||
const children = Array.from(control.children); | ||
if (children.length === 0) { | ||
const child = document.createElement('span'); | ||
child.textContent = control.textContent; | ||
control.innerHTML = ''; | ||
control.append(child); | ||
} | ||
control.children[0].append(icon); | ||
control.setAttribute('role', 'button'); | ||
control.setAttribute('aria-expanded', 'false'); | ||
control.setAttribute('tabindex', '0'); | ||
control.classList.add('accordion-control'); | ||
control.id = `accordion-${this.id}-${index}`; | ||
control.addEventListener('click', () => this.toggleControl(control)); | ||
control.addEventListener('keypress', (e) => { | ||
if (e.key === 'Enter' || e.key === ' ') { | ||
this.toggleControl(control); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
toggleControl(control) { | ||
const content = control.nextElementSibling; | ||
if (content) { | ||
content.classList.toggle('active'); | ||
control.classList.toggle('active'); | ||
control.setAttribute('aria-expanded', content.classList.contains('active')); | ||
content.setAttribute('aria-hidden', !content.classList.contains('active')); | ||
} | ||
} | ||
|
||
setupContent(contents) { | ||
contents.forEach((content) => { | ||
const internal = content.children; | ||
const wrapper = document.createElement('div'); | ||
wrapper.classList.add('accordion-content-wrapper'); | ||
wrapper.append(...internal); | ||
content.append(wrapper); | ||
content.setAttribute('role', 'region'); | ||
content.setAttribute('aria-hidden',true); | ||
content.classList.add('accordion-content'); | ||
content.setAttribute('aria-labelledby', content.previousElementSibling.id); | ||
}); | ||
} | ||
} |
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
Empty file.
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