14 lines
369 B
JavaScript
14 lines
369 B
JavaScript
document.addEventListener('alpine:init', () => {
|
|
Alpine.data('switchToggle', (initial) => ({
|
|
on: initial,
|
|
toggle() {
|
|
this.on = !this.on;
|
|
this.$el.classList.toggle('active', this.on);
|
|
this.$nextTick(() => {
|
|
const hidden = this.$el.nextElementSibling;
|
|
if (hidden) hidden.value = this.on ? 'on' : '';
|
|
});
|
|
}
|
|
}));
|
|
});
|