-
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.
- Loading branch information
1 parent
5e4e984
commit d675e4c
Showing
2 changed files
with
84 additions
and
0 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,61 @@ | ||
.accordion details { | ||
border: 1px solid #dadada; | ||
} | ||
|
||
/* stylelint-disable-next-line no-descending-specificity */ | ||
.accordion details + details { | ||
margin-top: 24px; | ||
} | ||
|
||
.accordion details p { | ||
margin-bottom: 0.8em; | ||
} | ||
|
||
.accordion details summary { | ||
position: relative; | ||
padding: 0 16px; | ||
padding-right: 46px; | ||
cursor: pointer; | ||
list-style: none; | ||
overflow: auto; | ||
transition: background-color 0.2s; | ||
} | ||
|
||
.accordion details[open] summary { | ||
background-color: var(--light-color); | ||
} | ||
|
||
.accordion details summary:focus, | ||
.accordion details summary:hover { | ||
background-color: var(--light-color); | ||
} | ||
|
||
.accordion details summary::-webkit-details-marker { | ||
display: none; | ||
} | ||
|
||
.accordion details summary::after { | ||
content: ''; | ||
position: absolute; | ||
top: 50%; | ||
right: 18px; | ||
transform: translateY(-50%) rotate(135deg); | ||
width: 6px; | ||
height: 6px; | ||
border: 2px solid; | ||
border-width: 2px 2px 0 0; | ||
transition: transform 0.2s; | ||
} | ||
|
||
.accordion details[open] summary::after { | ||
transform: translateY(-50%) rotate(-45deg); | ||
} | ||
|
||
.accordion details .accordion-item-body { | ||
padding: 0 16px; | ||
} | ||
|
||
.accordion details[open] .accordion-item-body { | ||
border-top: 1px solid #dadada; | ||
background-color: var(--background-color); | ||
} |
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,23 @@ | ||
/* | ||
* Accordion Block | ||
* Recreate an accordion | ||
* https://www.hlx.live/developer/block-collection/accordion | ||
*/ | ||
|
||
export default function decorate(block) { | ||
[...block.children].forEach((row) => { | ||
// decorate accordion item label | ||
const label = row.children[0]; | ||
const summary = document.createElement('summary'); | ||
summary.className = 'accordion-item-label'; | ||
summary.append(...label.childNodes); | ||
// decorate accordion item body | ||
const body = row.children[1]; | ||
body.className = 'accordion-item-body'; | ||
// decorate accordion item | ||
const details = document.createElement('details'); | ||
details.className = 'accordion-item'; | ||
details.append(summary, body); | ||
row.replaceWith(details); | ||
}); | ||
} |