Skip to content

Instantly share code, notes, and snippets.

@ManickYoj
Created January 22, 2022 02:34
Show Gist options
  • Save ManickYoj/f4a710c1d831040747967500e1d35bd2 to your computer and use it in GitHub Desktop.
Save ManickYoj/f4a710c1d831040747967500e1d35bd2 to your computer and use it in GitHub Desktop.
// app/javascript/controllers/visibility_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "hideable" ]
showTargets() {
this.hideableTargets.forEach(el => {
el.hidden = false
});
}
hideTargets() {
this.hideableTargets.forEach(el => {
el.hidden = true
});
}
toggleTargets() {
this.hideableTargets.forEach((el) => {
el.hidden = !el.hidden
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment