-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement tiles showcase expand script (#49)
* feat: implement tiles showcase expand script * feat: implement aria-live on tiles showcase
- Loading branch information
1 parent
7b5aad0
commit 97ef88a
Showing
6 changed files
with
207 additions
and
273 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import 'bootstrap' | ||
import './darkmode.js' | ||
import './tiles-showcase.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,70 @@ | ||
;(() => { | ||
const breakpoints = { | ||
md: 768, | ||
lg: 992, | ||
} | ||
|
||
const visibleInitially = { | ||
md: 4, | ||
lg: 6, | ||
} | ||
|
||
const getTiles = (section) => | ||
Array.from(section.querySelectorAll('.col:has(.tile)')) | ||
|
||
const getButton = (section) => section.querySelector('button') | ||
|
||
const hideTile = (tile) => { | ||
tile.classList.add('d-none') | ||
} | ||
|
||
const showTile = (tile) => { | ||
tile.classList.remove('d-none') | ||
} | ||
|
||
const resetExpansion = (section) => { | ||
const breakpoint = Object.entries(breakpoints) | ||
.reverse() | ||
.find(([_, value]) => document.documentElement.clientWidth >= value)?.[0] | ||
|
||
const visible = visibleInitially[breakpoint] || 2 | ||
|
||
const button = getButton(section) | ||
button.querySelector('i.bi').classList.replace('bi-dash-lg', 'bi-plus-lg') | ||
button.childNodes[button.childNodes.length - 1].textContent = | ||
'Alle Kategorien anzeigen' | ||
|
||
section.setAttribute('aria-expanded', 'false') | ||
|
||
const tiles = getTiles(section) | ||
tiles.forEach(hideTile) | ||
tiles.slice(0, visible).forEach(showTile) | ||
} | ||
|
||
const handleExpansion = (section) => { | ||
const button = getButton(section) | ||
button.querySelector('i.bi').classList.replace('bi-plus-lg', 'bi-dash-lg') | ||
button.childNodes[button.childNodes.length - 1].textContent = | ||
'Weniger Kategorien anzeigen' | ||
|
||
section.setAttribute('aria-expanded', 'true') | ||
|
||
const tiles = getTiles(section) | ||
tiles.forEach(showTile) | ||
} | ||
|
||
const handleShowMore = (section) => { | ||
const isExpanded = section.getAttribute('aria-expanded') === 'true' | ||
|
||
if (isExpanded) { | ||
resetExpansion(section) | ||
} else { | ||
handleExpansion(section) | ||
} | ||
} | ||
|
||
document.querySelectorAll('.tile-showcase').forEach((section) => { | ||
resetExpansion(section) | ||
getButton(section).addEventListener('click', () => handleShowMore(section)) | ||
}) | ||
})() |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.