flotilla/src/app/components/RoomItemMenuButton.svelte

43 lines
1.2 KiB
Svelte
Raw Normal View History

2024-10-16 18:27:27 +00:00
<script lang="ts">
import {between} from "@welshman/lib"
2026-08-29 17:20:39 +00:00
import type {Maybe} from "@welshman/lib"
2025-09-10 22:26:39 +00:00
import MenuDots from "@assets/icons/menu-dots.svg?dataurl"
2024-10-16 18:27:27 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import Tippy from "@lib/components/Tippy.svelte"
2026-08-29 17:20:39 +00:00
import type {TippyController} from "@lib/components/Tippy.svelte"
2025-10-30 22:36:14 +00:00
import RoomItemMenu from "@app/components/RoomItemMenu.svelte"
2024-10-16 18:27:27 +00:00
const {url, event} = $props()
2024-10-16 18:27:27 +00:00
2026-08-29 17:20:39 +00:00
const open = () => tippy?.show()
2024-10-16 18:27:27 +00:00
2026-08-29 17:20:39 +00:00
const onClick = () => tippy?.hide()
2026-07-28 00:13:14 +00:00
2026-08-29 17:20:39 +00:00
const onMouseMove = ({clientX, clientY}: MouseEvent) => {
const rect = tippy?.rect()
2026-07-28 00:13:14 +00:00
2026-08-29 17:20:39 +00:00
if (rect) {
const {x, y, width, height} = rect
2024-10-16 18:27:27 +00:00
if (!between([x, x + width], clientX) || !between([y - 50, y + height + 50], clientY)) {
2026-08-29 17:20:39 +00:00
tippy!.hide()
2025-02-04 00:37:14 +00:00
}
2024-10-16 18:27:27 +00:00
}
}
2026-08-29 17:20:39 +00:00
let tippy: Maybe<TippyController> = $state()
2024-10-16 18:27:27 +00:00
</script>
2026-08-29 17:20:39 +00:00
<svelte:document onmousemove={tippy?.visible ? onMouseMove : undefined} />
2024-10-16 18:27:27 +00:00
<Button onclick={open} class="button button-xs button-neutral join-item">
<Tippy
2026-08-29 17:20:39 +00:00
bind:controller={tippy}
component={RoomItemMenu}
props={{url, event, onClick}}
2026-08-29 17:20:39 +00:00
params={{trigger: "manual", interactive: true}}>
2025-09-10 22:26:39 +00:00
<Icon icon={MenuDots} size={4} />
</Tippy>
</Button>