Layout & Containers
Tooltip
A small contextual label that appears on hover or keyboard focus. Wrap the trigger in the default slot and pass the text via the content attribute (or the content slot for rich markup). Shows on hover and focus for accessibility, dismisses on Escape, and flips on the main axis when it would overflow the viewport.
Preview
Section titled “Preview”<nana-tooltip content="Saves your changes">
<nana-button>Hover me</nana-button>
</nana-tooltip> <script lang="ts">
import { NanaTooltip } from '$lib/components/ui/tooltip';
import { NanaButton } from '$lib/components/ui/button';
</script>
<NanaTooltip content="Saves your changes" placement="top">
{#snippet children()}
<NanaButton variant="secondary">Hover me</NanaButton>
{/snippet}
</NanaTooltip> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add tooltip --framework web-componentsnpx @nana-tec/ui add tooltip --framework svelteLands in src/lib/components/ui/tooltip/ as NanaTooltip.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/tooltip";
Copied in with npx @nana-tec/ui add tooltip? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<nana-tooltip content="Saves your changes"> <nana-button>Hover me</nana-button></nana-tooltip><script lang="ts"> import { NanaTooltip } from '$lib/components/ui/tooltip'; import { NanaButton } from '$lib/components/ui/button';</script>
<NanaTooltip content="Saves your changes" placement="top"> {#snippet children()} <NanaButton>Hover me</NanaButton> {/snippet}</NanaTooltip>The trigger goes in the children snippet, wrapped in an inline span that
carries the hover, focus and Escape handling plus aria-describedby.
Placements
Section titled “Placements”<nana-tooltip content="Top" placement="top" arrow>
<nana-button variant="secondary" size="sm">Top</nana-button>
</nana-tooltip>
<nana-tooltip content="Right" placement="right" arrow>
<nana-button variant="secondary" size="sm">Right</nana-button>
</nana-tooltip>
<nana-tooltip content="Bottom" placement="bottom" arrow>
<nana-button variant="secondary" size="sm">Bottom</nana-button>
</nana-tooltip>
<nana-tooltip content="Left" placement="left" arrow>
<nana-button variant="secondary" size="sm">Left</nana-button>
</nana-tooltip> Variants
Section titled “Variants”<nana-tooltip content="Dark" variant="dark" arrow>
<nana-button variant="secondary" size="sm">Dark</nana-button>
</nana-tooltip>
<nana-tooltip content="Light" variant="light" arrow>
<nana-button variant="secondary" size="sm">Light</nana-button>
</nana-tooltip>
<nana-tooltip content="Success" variant="success" arrow>
<nana-button variant="secondary" size="sm">Success</nana-button>
</nana-tooltip>
<nana-tooltip content="Danger" variant="danger" arrow>
<nana-button variant="secondary" size="sm">Danger</nana-button>
</nana-tooltip>
<nana-tooltip content="Info" variant="info" arrow>
<nana-button variant="secondary" size="sm">Info</nana-button>
</nana-tooltip>
<nana-tooltip content="Warning" variant="warning" arrow>
<nana-button variant="secondary" size="sm">Warning</nana-button>
</nana-tooltip> Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
arrow | arrow | boolean | false | Show a pointing arrow. |
closeDelay | close-delay | number | 0 | Delay before hiding on leave/blur, in ms. |
content | content | string | '' | Plain-text tooltip content. Ignored when the content slot is used. |
disabled | disabled | boolean | false | Disable the tooltip entirely. |
open | open | boolean | false | Open state (use with trigger="manual" for full control). |
openDelay | open-delay | number | 300 | Delay before showing on hover/focus, in ms. |
placement | placement | TooltipPlacement | 'top' | Where the tooltip sits relative to the trigger. |
size | size | TooltipSize | 'md' | Size scale. |
trigger | trigger | TooltipTrigger | 'hover' | What opens the tooltip. hover also responds to keyboard focus. |
variant | variant | TooltipVariant | 'dark' | Colour theme. |
Methods
| Method | Description |
|---|---|
hide(): void | Close the tooltip immediately. |
show(): void | Open the tooltip immediately. |
toggle(): void | Toggle the tooltip. |
Events
| Event | Description |
|---|---|
nana-show | Fired when the tooltip opens |
nana-hide | Fired when the tooltip closes |
Slots
| Slot | Description |
|---|---|
(default) | The trigger element the tooltip describes |
content | Rich tooltip content (overrides the content attribute) |
CSS parts
| Part | Description |
|---|---|
::part(base) | The positioning container |
::part(body) | The tooltip bubble |
::part(arrow) | The arrow |
::part(trigger) | The wrapper around the slotted trigger content |
CSS custom properties
| Property | Description |
|---|---|
--nana-tooltip-bg | Bubble background |
--nana-tooltip-color | Bubble text colour |
--nana-tooltip-max-width | Max bubble width before wrapping |
--nana-tooltip-border | Border shorthand for the bubble |
--nana-tooltip-ease | Easing curve for both the show and hide transitions |
--nana-tooltip-enter-duration | How long the tooltip takes to appear |
--nana-tooltip-exit-duration | How long the tooltip takes to disappear |
--nana-tooltip-padding | Bubble padding |
--nana-tooltip-radius | Bubble corner radius |
--nana-tooltip-shadow | Bubble shadow |
--nana-tooltip-z | Stacking order for the bubble |
NanaTooltip
| Prop | Type | Default |
|---|---|---|
contentrequired | string | |
placement | TooltipPlacement | 'top' |
disabled | boolean | false |
openDelay | number | |
closeDelay | number | |
openbind: | boolean | false |
onOpenChange | (open: boolean) => void | |
children | Snippet |