mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
* Implement inline category selection * Add turbo frame to refresh updated transaction * Improve styles * Fix category assignment * Reorganize code * Revert event propagation * Remove unused frames * Make only the transaction name clickable * Add custom scrollbar class
35 lines
873 B
JavaScript
35 lines
873 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
// Connects to data-controller="dropdown"
|
|
export default class extends Controller {
|
|
static targets = ["menu"]
|
|
|
|
toggleMenu = (e) => {
|
|
e.stopPropagation(); // Prevent event from closing the menu immediately
|
|
this.menuTarget.classList.contains("hidden") ? this.showMenu() : this.hideMenu();
|
|
}
|
|
|
|
showMenu = () => {
|
|
document.addEventListener("click", this.onDocumentClick);
|
|
this.menuTarget.classList.remove("hidden");
|
|
}
|
|
|
|
hideMenu = () => {
|
|
document.removeEventListener("click", this.onDocumentClick);
|
|
this.menuTarget.classList.add("hidden");
|
|
}
|
|
|
|
disconnect = () => {
|
|
this.hideMenu();
|
|
}
|
|
|
|
onDocumentClick = (e) => {
|
|
if (this.menuTarget.contains(e.target)) {
|
|
// user has clicked inside of the dropdown
|
|
e.stopPropagation();
|
|
return;
|
|
}
|
|
|
|
this.hideMenu();
|
|
}
|
|
}
|