Skip to content

Instantly share code, notes, and snippets.

@SofiaSousa
Last active August 9, 2022 08:30
Show Gist options
  • Save SofiaSousa/fb0f5c8fa02a02b0173d640acfbc5d6d to your computer and use it in GitHub Desktop.
Save SofiaSousa/fb0f5c8fa02a02b0173d640acfbc5d6d to your computer and use it in GitHub Desktop.
Controllers
import { Controller } from "@hotwired/stimulus"
export default class ResultsToggle extends Controller {
// ---
// Targets
static targets = ["elementToHide"]
// ---
// Values
static values = { visible: Boolean }
// ---
// Classes
static classes = ["hidden"]
// ---
// Actions
toggle() {
// Update the state - Stimulus creates a property <valueName>Value
// for each value that can be used as a getter and as a setter
this.visibleValue = !this.visibleValue
}
visibleValueChanged() {
// Stimulus callback <value name>Changed which is automatically
// called when the value is changed
this.elementToHideTarget.classList.toggle(this.hiddenClass, !this.visibleValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment