feat: chart toggles

This commit is contained in:
Cory Dransfeldt 2024-04-05 09:09:43 -07:00
parent daf958c845
commit f5036cbdf3
No known key found for this signature in database
10 changed files with 153 additions and 40 deletions

View file

@ -0,0 +1,30 @@
window.onload = () => {
const initializeButtonSet = (buttonSet) => {
const buttons = buttonSet.querySelectorAll('button')
const buttonIds = Array.from(buttons).map(button => button.getAttribute('data-toggle'))
buttons.forEach(button => {
button.addEventListener('click', function () {
const targetId = this.getAttribute('data-toggle')
const targetContent = document.getElementById(targetId)
buttons.forEach(btn => {
btn.classList.remove('active')
btn.classList.add('secondary')
})
buttonIds.forEach(id => {
document.getElementById(id).classList.add('hidden')
})
this.classList.remove('secondary')
this.classList.add('active')
targetContent.classList.remove('hidden')
})
})
}
const buttonSets = document.querySelectorAll('.now__section--header-buttons')
buttonSets.forEach(initializeButtonSet)
}