Ad a user card
This commit is contained in:
parent
10211a51ef
commit
59b41eaa70
4 changed files with 156 additions and 18 deletions
39
app/javascript/controllers/dropdown_controller.js
Normal file
39
app/javascript/controllers/dropdown_controller.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["button", "menu", "chevron"]
|
||||
|
||||
connect() {
|
||||
this.closeOnClickOutside = this.closeOnClickOutside.bind(this)
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this.menuTarget.classList.contains("hidden")) {
|
||||
this.open()
|
||||
} else {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
this.menuTarget.classList.remove("hidden")
|
||||
this.chevronTarget.classList.add("rotate-180")
|
||||
document.addEventListener("click", this.closeOnClickOutside)
|
||||
}
|
||||
|
||||
close() {
|
||||
this.menuTarget.classList.add("hidden")
|
||||
this.chevronTarget.classList.remove("rotate-180")
|
||||
document.removeEventListener("click", this.closeOnClickOutside)
|
||||
}
|
||||
|
||||
closeOnClickOutside(event) {
|
||||
if (!this.element.contains(event.target)) {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
document.removeEventListener("click", this.closeOnClickOutside)
|
||||
}
|
||||
}
|
21
app/javascript/controllers/navigation_controller.js
Normal file
21
app/javascript/controllers/navigation_controller.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["hamburger", "menu"]
|
||||
|
||||
toggle() {
|
||||
if (this.menuTarget.classList.contains("hidden")) {
|
||||
this.open()
|
||||
} else {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
this.menuTarget.classList.remove("hidden")
|
||||
}
|
||||
|
||||
close() {
|
||||
this.menuTarget.classList.add("hidden")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue