generated from boboko/starter
22 lines
595 B
JavaScript
22 lines
595 B
JavaScript
import { Controller } from '@hotwired/stimulus'
|
|
|
|
export default class extends Controller {
|
|
static targets = ['button', 'panel']
|
|
|
|
show(event) {
|
|
this.activate(event.currentTarget.dataset.panel)
|
|
}
|
|
|
|
activate(panelId) {
|
|
this.buttonTargets.forEach(btn => {
|
|
const active = btn.dataset.panel === panelId
|
|
btn.classList.toggle('is-active', active)
|
|
btn.setAttribute('aria-selected', String(active))
|
|
})
|
|
|
|
this.panelTargets.forEach(panel => {
|
|
panel.hidden = panel.id !== `tab-panel-${panelId}`
|
|
})
|
|
}
|
|
}
|