forked from hackorum-dev/hackorum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhover_popover_controller.js
More file actions
41 lines (34 loc) · 1003 Bytes
/
hover_popover_controller.js
File metadata and controls
41 lines (34 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Controller } from "@hotwired/stimulus"
// Adds a small delay before hiding popovers so users can move the cursor into them.
export default class extends Controller {
static targets = ["popover"]
static values = { delay: Number }
connect() {
this.hideTimeout = null
this.delay = this.delayValue || 150
}
show() {
this._clearTimeout()
this.element.classList.add("is-open")
this._updateRowOpenState()
}
scheduleHide() {
this._clearTimeout()
this.hideTimeout = setTimeout(() => {
this.element.classList.remove("is-open")
this._updateRowOpenState()
}, this.delay)
}
_clearTimeout() {
if (this.hideTimeout) {
clearTimeout(this.hideTimeout)
this.hideTimeout = null
}
}
_updateRowOpenState() {
const row = this.element.closest(".topic-row")
if (!row) return
const hasOpenPopover = row.querySelector(".topic-icon.is-open")
row.classList.toggle("is-popover-open", Boolean(hasOpenPopover))
}
}