Sha256: 6d916fcd2a35a0dd5bc598cd821cc3d06cafd1dcd6378be05bb804b9e7714ca5
Contents?: true
Size: 759 Bytes
Versions: 117
Compression:
Stored size: 759 Bytes
Contents
import { Controller } from '@hotwired/stimulus' // Connects to data-controller="switcher" export default class extends Controller { connect () { if (this.element.checked) { this.show() } this.element.setAttribute('data-action', `${this.element.getAttribute('data-action') || ''} switcher#show`) } show () { const elemToShow = document.querySelector(this.element.dataset.target) this.getSiblings(elemToShow).forEach((el) => { el.classList.add('d-none') el.classList.remove('d-block') }) elemToShow.classList.remove('d-none') elemToShow.classList.add('d-block') } getSiblings (el) { const childrenArray = [...el.parentNode.children] return childrenArray.filter(child => child !== el) } }
Version data entries
117 entries across 117 versions & 1 rubygems