File size: 1,363 Bytes
058d10c c1646a5 058d10c c1646a5 058d10c c1646a5 058d10c f77d645 058d10c c1646a5 058d10c |
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 56 57 |
<script lang="ts">
import { type ComponentProps, type Extracted } from "melt";
import { Tooltip, type TooltipProps } from "melt/builders";
import type { Snippet } from "svelte";
type FloatingConfig = NonNullable<Extracted<TooltipProps["floatingConfig"]>>;
interface Props {
children: Snippet;
trigger: Snippet<[Tooltip]>;
placement?: NonNullable<FloatingConfig["computePosition"]>["placement"];
openDelay?: ComponentProps<TooltipProps>["openDelay"];
}
const { children, trigger, placement = "top", openDelay = 500 }: Props = $props();
const tooltip = new Tooltip({
forceVisible: true,
floatingConfig: () => ({
computePosition: { placement },
flip: {
fallbackPlacements: ["bottom"],
padding: 10,
},
}),
openDelay: () => openDelay,
});
</script>
{@render trigger(tooltip)}
<div {...tooltip.content} class="rounded-xl bg-white p-0 shadow-xl dark:bg-gray-700">
<div {...tooltip.arrow} class="rounded-tl"></div>
<p class="px-4 py-1 text-gray-700 dark:text-white">{@render children()}</p>
</div>
<style>
[data-melt-tooltip-content] {
border: 0;
position: absolute;
pointer-events: none;
opacity: 0;
transform: scale(0.9);
transition: 0.3s;
transition-property: opacity, transform;
}
[data-melt-tooltip-content][data-open] {
pointer-events: auto;
opacity: 1;
transform: scale(1);
}
</style>
|