x
1
2
3
4
5
6
7
8
9
10
11
<div class="inline-flex" data-controller="popover" data-action="mouseenter->popover#showLater mouseleave->popover#hideLater"> <a href="" class="font-medium underline" data-popover-target="button"> @rails </a> <div popover="hint" class="popover" data-popover-target="menu"> <div class="flex flex-col p-4"> <h2 class="text-lg font-semibold">Ruby on Rails</h2> <p class="text-sm text-subtle">The webframework that changed the world.</p> </div> </div></div>
1
2
3
4
5
6
7
8
9
10
11
12
<div class="inline-flex" data-controller="popover" data-action="mouseenter->popover#showLater mouseleave->popover#hideLater"> <a href="" class="font-medium underline" data-popover-target="button"> @rails </a> <div popover="hint" class="popover" data-popover-target="menu"> <div class="flex flex-col p-4"> <h2 class="text-lg font-semibold">Ruby on Rails</h2> <p class="text-sm text-subtle">The webframework that changed the world.</p> </div> </div></div>
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
.popover { background-color: var(--color-bg); border-radius: var(--rounded-md); border-width: var(--border); box-shadow: var(--shadow-md); color: var(--color-text); inline-size: var(--popover-size, max-content); /* Setup transition */ transition-behavior: allow-discrete; transition-duration: var(--time-150); transition-property: display, overlay, opacity, transform; /* Exit stage to */ opacity: 0; transform: var(--scale-95); /* On stage */ &:popover-open { opacity: 1; transform: var(--scale-100); } /* Enter stage from */ @starting-style { &:popover-open { opacity: 0; transform: var(--scale-95); } }}
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Controller } from "@hotwired/stimulus"import { computePosition, flip, shift, offset, autoUpdate } from "https://esm.sh/@floating-ui/dom@1.6.13?standalone"export default class extends Controller { static targets = [ "button", "menu" ] static values = { placement: { type: String, default: "bottom" } } #showTimer = null #hideTimer = null initialize() { this.orient = this.orient.bind(this) } connect() { this.cleanup = autoUpdate(this.buttonTarget, this.menuTarget, this.orient) } disconnect() { this.cleanup() } show() { this.menuTarget.showPopover() } hide() { this.menuTarget.hidePopover() } toggle() { this.menuTarget.togglePopover() } showLater() { clearTimeout(this.#hideTimer) this.#showTimer = setTimeout(() => this.show(), 700) } hideLater() { clearTimeout(this.#showTimer) this.#hideTimer = setTimeout(() => this.hide(), 300) } orient() { computePosition(this.buttonTarget, this.menuTarget, this.#options).then(({x, y}) => { this.menuTarget.style.insetInlineStart = `${x}px` this.menuTarget.style.insetBlockStart = `${y}px` }) } get #options() { return { placement: this.placementValue, middleware: [offset(4), flip(), shift({padding: 4})] } }}