Created
March 1, 2021 09:59
-
-
Save julianrubisch/d964ac47e403fe0fdac1cbc580518459 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