# Tooltip (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-tooltip` · version 1.0.0 · component · free
- category: Overlays
- build: Base UI (this item also ships a Radix build)
- install (this build): `npx shadcn@latest add https://beautiful-ui.dev/r/lumen-tooltip.json`
- npm dependencies: @base-ui/react@^1
- registry dependencies: utils, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-tooltip
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Names every icon, and never makes anyone wait twice: 380ms for the first, then instant along the toolbar, with the shortcut in a key cap. shadcn's Tooltip, cut from Lumen glass.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: `@base-ui/react@^1` (Base UI build); `radix-ui@^1` (Radix build).
- Files: `components/ui/lumen/tooltip.tsx`; shared code: `lib/beautiful-ui/lumen/portal.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-foundation`.
- Builds: separate Base UI and Radix files. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `TooltipProvider`, `Tooltip`, `TooltipTrigger`, `TooltipContent`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { Button } from "@/components/ui/lumen/button";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `TooltipProvider` | `tooltip-provider` | Shared timing: 380ms, then none while moving along a toolbar. |
| `Tooltip` | `tooltip` | One tooltip's state. |
| `TooltipTrigger` | `tooltip-trigger` | What it describes, usually a Lumen icon button. |
| `TooltipContent` | `tooltip-content` | The glass pill, with a key cap for a nested kbd. |

Style a part with `[data-slot="<slot>"]` selectors or its `className`; keep the attributes when editing.

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/tooltip.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- tooltip, icon button, toolbar, shortcut hint, keyboard shortcut, hover label, shadcn tooltip, Lumen, glass
- Naming an icon-only action: a Lumen Button with size="icon" in a TooltipTrigger
- Showing the shortcut next to the name: put a <Kbd> (or any [data-slot="kbd"]) in the content
- Toolbars: after the first tooltip, the next ones open at once as you move along
- A drop-in for shadcn's Tooltip: same exports, parts and data-slots

### Not when
- Anything people must read or click: use a popover
- The only place information lives: tooltips don't show on touch, so the action must make sense without it

## Mistakes
- Wrap the app in TooltipProvider once: Radix requires it, and it carries Lumen's 380ms / 500ms timing
- A tooltip doesn't name the button for screen readers: always set aria-label on icon-only triggers
- The shortcut in the key cap is display only: bind the key yourself
- Import from @/components/ui/lumen/tooltip: it never replaces your own components/ui/tooltip.tsx

## Usage

```tsx
import { Button } from "@/components/ui/lumen/button";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/lumen/tooltip";

// Once, near the root:
<TooltipProvider>{children}</TooltipProvider>

<Tooltip>
  <TooltipTrigger render={<Button variant="secondary" size="icon" icon="plus" aria-label="New chart" />} />
  <TooltipContent>
    New chart <kbd data-slot="kbd">N</kbd>
  </TooltipContent>
</Tooltip>
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `TooltipProvider delay / timeout (Base UI) · delayDuration / skipDelayDuration (Radix)` | `number` | `380 / 500` | Lumen's timing: wait 380ms, then no wait while another tooltip closed under 500ms ago. One provider near the root, as with shadcn. |
| `Tooltip open / defaultOpen / onOpenChange` | `boolean / boolean / (open) => void` |  | Control a tooltip, e.g. keep one open on a docs page. |
| `TooltipTrigger render (Base UI) / asChild (Radix)` | `ReactElement / boolean` |  | Render as your own element, usually a Lumen Button with size="icon" and an aria-label. |
| `TooltipContent side / align / sideOffset` | `"top" \| "bottom" \| "left" \| "right" / "start" \| "center" \| "end" / number` | `"top" / "center" / 10` | Where it opens; it rises 4px from that side. |
| `TooltipContent container` | `HTMLElement \| ref` | `document.body` | Where it portals to, e.g. inside a scope that sets the Lumen tokens. |
| `className / …` | `as shadcn` |  | Everything shadcn's parts take passes through; className merges last with cn. |

Full docs: https://beautiful-ui.dev/components/lumen-tooltip

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Tab | Focus the trigger and show its tooltip |
| Escape | Hide the tooltip |

## Motion inventory

| Interaction | What moves |
|---|---|
| Open | After 380ms (or at once within 500ms of another closing, or on focus): rises 4px from its side and scales .96 → 1 (.4s, cubic-bezier(.22,1,.36,1)) while fading in (.2s) |
| Close | Fades out in .2s |
| Reduced motion | 150ms fades, nothing moves |

## Accessibility contract (preserve when editing)
- A tooltip is a visual hint, as in shadcn: screen readers don't announce it, so every icon-only trigger needs its own aria-label (the tooltip repeats it)
- Opens on keyboard focus at once and closes on Escape
- Hidden from touch, as tooltips are: never put the only copy of something in one
- prefers-reduced-motion: it fades in without rising

## Install

Base UI project (a base-* style in components.json):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/lumen-tooltip.json
```

Radix project (a radix-*, new-york or default style):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/radix-nova/lumen-tooltip.json
```

Or add the `@beautiful-ui` registry to components.json and run `npx shadcn@latest add @beautiful-ui/lumen-tooltip`: the CLI picks the build from your style.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

## Source (Base UI build)

### components/ui/lumen/tooltip.tsx

```tsx
"use client";

/**
 * Tooltip (Lumen Halo) v1.0.0 · Beautiful UI
 * Docs: https://beautiful-ui.dev/components/lumen-tooltip · Agent prompt: https://beautiful-ui.dev/md/lumen-tooltip.md
 * Licensed to the purchaser under the Beautiful UI license: https://beautiful-ui.dev/license
 */

import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";
import { cn } from "@/lib/utils";
import { useLumenPortal } from "@/lib/beautiful-ui/lumen/portal";

/*
 * Lumen Tooltip (Base UI build). shadcn's Tooltip in Lumen Halo: a 28px glass pill that rises 4px
 * into place, with a key cap for a nested <Kbd> (or any [data-slot="kbd"]). Same exports, parts and
 * data-slots as shadcn. Lumen's timing lives on the provider: 380ms before the first tooltip, then
 * none while you move along a toolbar (a tooltip closed under 500ms ago); keyboard focus opens at once.
 * Put one TooltipProvider near the root, as with shadcn.
 */

function TooltipProvider({ delay = 380, timeout = 500, ...props }: TooltipPrimitive.Provider.Props) {
  return <TooltipPrimitive.Provider data-slot="tooltip-provider" delay={delay} timeout={timeout} {...props} />;
}

function Tooltip({ ...props }: TooltipPrimitive.Root.Props) {
  return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;
}

function TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) {
  return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
}

function TooltipContent({
  className,
  side = "top",
  sideOffset = 10,
  align = "center",
  alignOffset = 0,
  container,
  children,
  ...props
}: TooltipPrimitive.Popup.Props &
  Pick<TooltipPrimitive.Positioner.Props, "align" | "alignOffset" | "side" | "sideOffset"> & {
    /** Where the tooltip portals to (default document.body), e.g. inside a themed scope. */
    container?: TooltipPrimitive.Portal.Props["container"];
  }) {
  const portal = useLumenPortal();
  return (
    <TooltipPrimitive.Portal container={container ?? portal}>
      <TooltipPrimitive.Positioner align={align} alignOffset={alignOffset} side={side} sideOffset={sideOffset} className="isolate z-50">
        <TooltipPrimitive.Popup data-slot="tooltip-content" className={cn(`lumen-tooltip lumen-control`, className)} {...props}>
          {children}
        </TooltipPrimitive.Popup>
      </TooltipPrimitive.Positioner>
    </TooltipPrimitive.Portal>
  );
}

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
```

### lib/beautiful-ui/lumen/portal.ts

```tsx
"use client";

import * as React from "react";

/*
 * Where Lumen overlays (dialogs, sheets, menus, popovers, select) portal to. Unset, they portal to
 * document.body, as shadcn's do. Provide an element to keep them inside a themed or scoped part of
 * the page: a preview, a shadow root, an embedded widget.
 *
 *   <LumenPortalContext value={element}>…</LumenPortalContext>
 */
export const LumenPortalContext = React.createContext<HTMLElement | null>(null);

/** The container for an overlay's Portal: the provided element, else undefined (document.body). */
export function useLumenPortal(): HTMLElement | undefined {
  return React.useContext(LumenPortalContext) ?? undefined;
}
```

### CSS (the registry `css` / `cssVars`, merged into the global stylesheet by the shadcn CLI)

```css
@layer components {
  @keyframes lumen-tip-in {
    from {
      opacity: 0;
      transform: translate(var(--lt-x,0),var(--lt-y,4px)) scale(.96);
    }
  }
  @keyframes lumen-tip-out {
    to {
      opacity: 0;
      transform: scale(.98);
    }
  }
  .lumen-tooltip {
    display: flex;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    min-height: 28px;
    max-width: min(20rem,calc(100vw - 16px));
    padding: 5px 10px;
    border-radius: calc(10px * var(--lumen-radius-k, 1));
    background: var(--gc-tipBg);
    box-shadow: var(--gc-tipSh);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    color: var(--gc-ink);
    font: 500 12px/18px var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    letter-spacing: normal;
    text-transform: none;
    transform-origin: var(--transform-origin,var(--radix-tooltip-content-transform-origin,50% 100%));
  }
  .lumen-tooltip:has([data-slot="kbd"]) {
    padding-inline-end: 5px;
  }
  .lumen-tooltip [data-slot="kbd"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 18px;
    height: 18px;
    margin-inline-start: auto;
    padding: 0 5px;
    border-radius: calc(5px * var(--lumen-radius-k, 1));
    background: var(--gc-kbd);
    box-shadow: none;
    font: 500 10.5px/1 var(--lumen-font-mono, var(--font-mono, var(--font-geist-mono, 'Geist Mono'))), ui-monospace, monospace;
    color: var(--gc-m70);
  }
  .lumen-tooltip[data-side="bottom"] {
    --lt-y: -4px;
  }
  .lumen-tooltip[data-side="left"],.lumen-tooltip[data-side="inline-start"] {
    --lt-x: 4px;
    --lt-y: 0;
  }
  .lumen-tooltip[data-side="right"],.lumen-tooltip[data-side="inline-end"] {
    --lt-x: -4px;
    --lt-y: 0;
  }
  .lumen-tooltip[data-open],.lumen-tooltip[data-state="delayed-open"],.lumen-tooltip[data-state="instant-open"] {
    animation: lumen-tip-in var(--gc-t-tip) cubic-bezier(.22,1,.36,1) both,lumen-fade-in var(--gc-t-fade) ease both;
  }
  .lumen-tooltip[data-closed],.lumen-tooltip[data-state="closed"] {
    animation: lumen-tip-out var(--gc-t-fade) ease both;
  }
  @keyframes lumen-fade-in {
    from {
      opacity: 0;
    }
  }
}
```

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
