Last active
August 9, 2022 08:30
-
-
Save SofiaSousa/fb0f5c8fa02a02b0173d640acfbc5d6d to your computer and use it in GitHub Desktop.
Controllers
This file contains 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 "@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