Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Created March 1, 2021 09:59
Show Gist options
  • Save julianrubisch/d964ac47e403fe0fdac1cbc580518459 to your computer and use it in GitHub Desktop.
Save julianrubisch/d964ac47e403fe0fdac1cbc580518459 to your computer and use it in GitHub Desktop.
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