generated from adobe/aem-boilerplate
-
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.
Merge branch 'main' into 33-two-column-layouts
- Loading branch information
Showing
7 changed files
with
254 additions
and
6 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
cigars-for-beginners/blocks/terms-accordion/terms-accordion.css
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,39 @@ | ||
/* stylelint-disable-next-line no-descending-specificity */ | ||
.terms-accordion details + details { | ||
margin-top: 16px; | ||
} | ||
|
||
.terms-accordion details summary { | ||
position: relative; | ||
padding: 0 16px; | ||
padding-right: 48px; | ||
cursor: pointer; | ||
list-style: none; | ||
overflow: auto; | ||
} | ||
|
||
.terms-accordion details summary::-webkit-details-marker { | ||
display: none; | ||
} | ||
|
||
.terms-accordion details summary::before { | ||
content: "+"; | ||
margin-right: 10px; | ||
} | ||
|
||
.terms-accordion details[open] summary::before { | ||
content: "-" | ||
} | ||
|
||
.terms-accordion details .accordion-item-body { | ||
padding: 0 40px; | ||
color: white; | ||
} | ||
|
||
.terms-accordion details[open] .accordion-item-body { | ||
background-color: transparent; | ||
} | ||
|
||
.terms-accordion .accordion-item-label { | ||
color: white; | ||
} |
33 changes: 33 additions & 0 deletions
33
cigars-for-beginners/blocks/terms-accordion/terms-accordion.js
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,33 @@ | ||
/* | ||
* Accordion Block | ||
* Recreate an accordion | ||
* https://www.hlx.live/developer/block-collection/accordion | ||
*/ | ||
|
||
function hasWrapper(el) { | ||
return !!el.firstElementChild && window.getComputedStyle(el.firstElementChild).display === 'block'; | ||
} | ||
|
||
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); | ||
if (!hasWrapper(summary)) { | ||
summary.innerHTML = `${summary.textContent}`; | ||
} | ||
// decorate accordion item body | ||
const body = row.children[1]; | ||
body.className = 'accordion-item-body'; | ||
if (!hasWrapper(body)) { | ||
body.innerHTML = `<p>${body.innerHTML}</p>`; | ||
} | ||
// decorate accordion item | ||
const details = document.createElement('details'); | ||
details.className = 'accordion-item'; | ||
details.append(summary, body); | ||
row.replaceWith(details); | ||
}); | ||
} |
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,47 @@ | ||
.terms-tabs .tabs-list { | ||
gap: 8px; | ||
max-width: 100%; | ||
overflow-x: auto; | ||
text-align: center; | ||
margin-bottom: 10px; | ||
border-radius: 0; | ||
} | ||
|
||
.terms-tabs .tabs-list button { | ||
margin: 0; | ||
border-radius: 0; | ||
background-color: var(--light-color); | ||
color: white; | ||
font-size: unset; | ||
font-weight: bold; | ||
line-height: unset; | ||
text-align: initial; | ||
text-overflow: unset; | ||
overflow: unset; | ||
white-space: unset; | ||
transition: background-color 0.2s; | ||
} | ||
|
||
.terms-tabs .tabs-list button[aria-selected="false"] { | ||
background-color: #745e44; | ||
} | ||
|
||
.terms-tabs .tabs-list button[aria-selected="true"] { | ||
background-color: #1d1d1d; | ||
cursor: initial; | ||
} | ||
|
||
.terms-tabs .tabs-list button[aria-selected="false"]:hover, | ||
.terms-tabs .tabs-list button[aria-selected="false"]:focus { | ||
background-color: #745e44; | ||
} | ||
|
||
.terms-tabs .tabs-panel { | ||
margin-top: -1px; | ||
padding: 0 16px; | ||
overflow: auto; | ||
} | ||
|
||
.terms-tabs .tabs-panel[aria-hidden="true"] { | ||
display: none; | ||
} |
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 @@ | ||
// eslint-disable-next-line import/no-unresolved | ||
import { toClassName } from '../../scripts/aem.js'; | ||
import { loadFragment } from '../fragment/fragment.js'; | ||
|
||
function hasWrapper(el) { | ||
return !!el.firstElementChild && window.getComputedStyle(el.firstElementChild).display === 'block'; | ||
} | ||
|
||
async function loadTerms(letter) { | ||
if (!letter) { | ||
return null; | ||
} | ||
|
||
const url = `/cigars-for-beginners/fragments/terms/${letter}`; | ||
|
||
let path = url; | ||
if (!(path.charAt(0) === '/')) { | ||
path = new URL(url).pathname; | ||
} | ||
|
||
const fragment = await loadFragment(path); | ||
const tabcontent = document.createElement('p'); | ||
tabcontent.appendChild(fragment); | ||
return tabcontent ? tabcontent.querySelector('main > .section .block') : null; | ||
} | ||
|
||
export default async function decorate(block) { | ||
// build tablist | ||
const tablist = document.createElement('div'); | ||
tablist.className = 'tabs-list'; | ||
tablist.setAttribute('role', 'tablist'); | ||
|
||
// decorate tabs and tabpanels | ||
const tabs = [...block.children].map((child) => child.firstElementChild); | ||
|
||
tabs.forEach((tab, i) => { | ||
const id = toClassName(tab.textContent); | ||
|
||
// decorate tabpanel | ||
const tabpanel = block.children[i]; | ||
tabpanel.className = 'tabs-panel'; | ||
tabpanel.id = `tabpanel-${id}`; | ||
tabpanel.setAttribute('aria-hidden', !!i); | ||
tabpanel.setAttribute('aria-labelledby', `tab-${id}`); | ||
tabpanel.setAttribute('role', 'tabpanel'); | ||
|
||
const terms = loadTerms(id); | ||
|
||
if (!hasWrapper(tabpanel.lastElementChild)) { | ||
terms.then((content) => { | ||
if (content) tabpanel.lastElementChild.replaceWith(content); | ||
}); | ||
} | ||
|
||
// build tab button | ||
const button = document.createElement('button'); | ||
button.className = 'tabs-tab'; | ||
button.id = `tab-${id}`; | ||
button.innerHTML = tab.textContent; | ||
button.setAttribute('aria-controls', `tabpanel-${id}`); | ||
button.setAttribute('aria-selected', !i); | ||
button.setAttribute('role', 'tab'); | ||
button.setAttribute('type', 'button'); | ||
button.addEventListener('click', () => { | ||
block.querySelectorAll('[role=tabpanel]').forEach((panel) => { | ||
panel.setAttribute('aria-hidden', true); | ||
}); | ||
tablist.querySelectorAll('button').forEach((btn) => { | ||
btn.setAttribute('aria-selected', false); | ||
}); | ||
tabpanel.setAttribute('aria-hidden', false); | ||
button.setAttribute('aria-selected', true); | ||
}); | ||
tablist.append(button); | ||
tab.remove(); | ||
}); | ||
|
||
block.prepend(tablist); | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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