mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
30 lines
576 B
JavaScript
30 lines
576 B
JavaScript
import { Controller } from "stimulus";
|
|
|
|
export default class extends Controller {
|
|
static targets = ["content"];
|
|
|
|
connect() {
|
|
super.connect();
|
|
window.addEventListener("click", this.#hideIfClickedOutside);
|
|
}
|
|
|
|
disconnect() {
|
|
window.removeEventListener("click", this.#hideIfClickedOutside);
|
|
}
|
|
|
|
toggle() {
|
|
this.contentTarget.classList.toggle("show");
|
|
}
|
|
|
|
#hideIfClickedOutside = (event) => {
|
|
if (this.element.contains(event.target)) {
|
|
return;
|
|
}
|
|
this.#hide();
|
|
};
|
|
|
|
#hide() {
|
|
this.contentTarget.classList.remove("show");
|
|
}
|
|
}
|