-
-
Save sergii/ec36621a1e4d1f05ac0e1947cfed185f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from 'stimulus' | |
export default class extends Controller { | |
static targets = ['overlay'] | |
static values = { | |
hidden: Boolean | |
} | |
static classes = ['hidden', 'shown'] | |
toggle () { | |
this.hiddenValue = !this.hiddenValue | |
} | |
show () { | |
this.hiddenValue = false | |
} | |
hide () { | |
this.hiddenValue = true | |
} | |
hiddenValueChanged () { | |
if (this.hiddenValue) { | |
this.shownClass.split(' ').forEach(klass => { | |
this.overlayTarget.classList.remove(klass) | |
}) | |
this.hiddenClass.split(' ').forEach(klass => { | |
this.overlayTarget.classList.add(klass) | |
}) | |
} else { | |
this.hiddenClass.split(' ').forEach(klass => { | |
this.overlayTarget.classList.remove(klass) | |
}) | |
this.shownClass.split(' ').forEach(klass => { | |
this.overlayTarget.classList.add(klass) | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment