Files
svelte/TooltipContent.svelte
T
zeekayandHanzo Dev 1008926ef7 @hanzo/svelte 1.0.0 — the Svelte backend, on its own
Extracted from @hanzo/ui pkg/ui/src/backends/svelte with its history. It lived
inside a React component library, which meant every consumer of @hanzo/ui
resolved svelte whether they rendered a single Svelte component or not, and the
package declared peer svelte>=5 against a dev svelte ^4.2.20 — two answers to
one question.

Three runtime dependencies, all load-bearing: class-variance-authority for the
variants the components already used, and clsx + tailwind-merge behind cn. The
cn helper is vendored (17 lines) rather than imported back from @hanzo/ui,
because depending on the package this was extracted from would undo the split.
No design-system runtime, no icon pack, no CSS-in-JS.

svelte-check: 50 files, 0 errors.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 12:28:39 -07:00

39 lines
1.1 KiB
Svelte

<!--
TooltipContent — the tip surface (role=tooltip, non-interactive). Standard
popover tokens; positioned relative to the trigger via `side` (default top).
-->
<script lang="ts">
import { getDisclosure, TOOLTIP } from './internal/context'
import { cn } from './core/cn'
let className: string | undefined = undefined
export { className as class }
export let side: 'top' | 'bottom' | 'left' | 'right' = 'top'
const { open, contentId } = getDisclosure(TOOLTIP, 'TooltipContent')
const sideClass: Record<typeof side, string> = {
top: 'bottom-full left-1/2 -translate-x-1/2 mb-1',
bottom: 'top-full left-1/2 -translate-x-1/2 mt-1',
left: 'right-full top-1/2 -translate-y-1/2 mr-1',
right: 'left-full top-1/2 -translate-y-1/2 ml-1',
}
</script>
{#if $open}
<div
role="tooltip"
id={contentId}
data-slot="tooltip-content"
data-state="open"
data-side={side}
class={cn(
'absolute z-50 w-fit whitespace-nowrap rounded-md border bg-popover px-3 py-1.5 text-xs text-popover-foreground shadow-md',
sideClass[side],
className,
)}
>
<slot />
</div>
{/if}