mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
63 lines
1.3 KiB
Svelte
63 lines
1.3 KiB
Svelte
<script lang="ts">
|
|
import type { Snippet } from "svelte";
|
|
|
|
import debounce from "lodash/debounce";
|
|
|
|
interface Props {
|
|
popover: Snippet;
|
|
stylePopoverPositionBottom: string | undefined;
|
|
stylePopoverPositionLeft: string | undefined;
|
|
toggle: Snippet;
|
|
}
|
|
|
|
const {
|
|
popover,
|
|
stylePopoverPositionBottom,
|
|
stylePopoverPositionLeft,
|
|
toggle,
|
|
}: Props = $props();
|
|
|
|
let visible: boolean = $state(false);
|
|
|
|
const setVisible = debounce((value: boolean) => {
|
|
visible = value;
|
|
}, 50);
|
|
</script>
|
|
|
|
<style>
|
|
.container {
|
|
position: relative;
|
|
display: inline-block;
|
|
}
|
|
.popover {
|
|
background: var(--color-fill-ghost);
|
|
border-radius: var(--border-radius-regular);
|
|
padding: 0.5rem 1rem;
|
|
box-shadow: var(--elevation-low);
|
|
position: absolute;
|
|
clip-path: var(--2px-corner-fill);
|
|
z-index: 10;
|
|
}
|
|
</style>
|
|
|
|
<div class="container">
|
|
<div
|
|
role="button"
|
|
tabindex="0"
|
|
onmouseenter={() => setVisible(true)}
|
|
onmouseleave={() => setVisible(false)}>
|
|
{@render toggle()}
|
|
|
|
{#if visible}
|
|
<div style:position="absolute">
|
|
<div
|
|
class="popover"
|
|
style:left={stylePopoverPositionLeft}
|
|
style:bottom={stylePopoverPositionBottom}>
|
|
{@render popover()}
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
</div>
|