Files
openfoodnetwork/app/webpacker/controllers/remote_toggle_controller.js
Cillian O'Ruanaidh 05756616dd Add a remote-toggle controller that can toggle elements outside of its scope
This is instead of adding the :data-controller attribute to the div#wrapper because that will wrap pretty much all content on the admin pages.

Co-authored-by: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com>
2022-02-04 12:23:24 +00:00

18 lines
486 B
JavaScript

import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["chevron"];
static values = { selector: String }
toggle(event) {
if (this.hasChevronTarget) {
this.chevronTarget.classList.toggle("icon-chevron-down")
this.chevronTarget.classList.toggle("icon-chevron-up")
}
const element = document.querySelector(this.selectorValue)
element.style.display = element.style.display === "none" ? "block" : "none"
}
}