This commit is contained in:
Pete Matsyburka committed 2026-09-23 19:57:08 +03:00
1 parent 92bfedd01d
commit e004ac2d40
6 files changed
+31 -18

No files matched your search

+14 -10
View File
@@ -1,19 +1,23 @@
export default class extends HTMLElement {
connectedCallback () {
this.addEventListener('click', this.onClick)
}
onClick = (event) => {
const button = this.querySelector('a, button, label')
if (!button?.contains(event.target)) return
const target = this.dataset.targetId ? document.getElementById(this.dataset.targetId) : button
button.addEventListener('click', () => {
this.dataset.classes.split(' ').forEach((cls) => {
if (this.dataset.action === 'remove') {
target.classList.remove(cls)
} else if (this.dataset.action === 'add') {
target.classList.add(cls)
} else {
target.classList.toggle(cls)
}
})
this.dataset.classes.split(' ').forEach((cls) => {
if (this.dataset.action === 'remove') {
target.classList.remove(cls)
} else if (this.dataset.action === 'add') {
target.classList.add(cls)
} else {
target.classList.toggle(cls)
}
})
}
}