# Cursor Tooltip

A popup that appears when an element is hovered or focused, showing a hint for sighted users.

Build a Tooltip in this project that looks and behaves like Cursor's. Measured from the running Cursor app (cursor.com). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or [Base UI](https://base-ui.com/react/components/tooltip) if it has none.

Fidelity: Partly measured from the tooltip in the Cursor desktop app bundle. No reference has been captured yet.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--surface-bg` | `oklch(1 0 0)` | `oklch(0.249 0 0)` |
| `--surface-border` | `color-mix(in srgb, var(--cursor-base) 12%, transparent)` | `color-mix(in srgb, var(--cursor-base) 12%, transparent)` |
| `--surface-text` | `oklch(0.2264 0 0)` | `oklch(0.955 0 0)` |
| `--shadow-menu` | `0 3px 8px 0 var(--cursor-shadow-secondary), 0 2px 5px 0 var(--cursor-shadow-secondary), 0 1px 1px 0 var(--cursor-shadow-secondary)` | `0 3px 8px 0 var(--cursor-shadow-secondary), 0 2px 5px 0 var(--cursor-shadow-secondary), 0 1px 1px 0 var(--cursor-shadow-secondary)` |
| `--font-regular` | `"SF Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif` | `"SF Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif` |
| `--font-size-small` | `0.8125rem` | `0.8125rem` |
| `--font-weight-normal` | `418` | `418` |
| `--radius-control` | `8px` | `8px` |
| `--cursor-duration-fast` | `0.1s` | `0.1s` |
| `--ease-sharp` | `cubic-bezier(0.165, 0.84, 0.44, 1)` | `cubic-bezier(0.165, 0.84, 0.44, 1)` |

## CSS

Scoped under `[data-style="cursor"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="cursor"] {
  .ui-tooltip-popup {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-control);
    background-color: var(--surface-bg);
    box-shadow:
      inset 0 0 0 1px var(--surface-border),
      var(--shadow-menu);
    color: var(--surface-text);
    font-family: var(--font-regular);
    font-size: var(--font-size-small);
    line-height: 18px;
    letter-spacing: -0.08px;
    -webkit-font-smoothing: antialiased;
    --ui-floating-anchor-offset-x: 0px;
    --ui-floating-anchor-offset-y: 0px;
    transform-origin: var(--transform-origin);
    transition:
      opacity var(--cursor-duration-fast) var(--ease-sharp),
      transform var(--cursor-duration-fast) var(--ease-sharp);

    &[data-side="top"] {
      --ui-floating-anchor-offset-y: 2px;
    }

    &[data-side="bottom"] {
      --ui-floating-anchor-offset-y: -2px;
    }

    &[data-side="left"] {
      --ui-floating-anchor-offset-x: 2px;
    }

    &[data-side="right"] {
      --ui-floating-anchor-offset-x: -2px;
    }

    &[data-starting-style],
    &[data-ending-style] {
      opacity: 0;
      transform: translate3d(var(--ui-floating-anchor-offset-x), var(--ui-floating-anchor-offset-y), 0) scale(0.98);
    }

    &[data-instant] {
      transition-duration: 0s;
    }
  }

  .ui-tooltip-label {
    font-weight: var(--font-weight-normal);
  }

  .ui-tooltip-popup > kbd {
    margin-right: -4px;
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Tooltip as BaseTooltip } from "@base-ui/react/tooltip";
import type { ReactElement, ReactNode } from "react";
import { Kbd } from "./kbd";
import { usePortalContainer } from "./portal";

export const TooltipProvider = BaseTooltip.Provider;

type TooltipProps = {
  children: ReactElement;
  content: ReactNode;
  shortcut?: string;
  side?: BaseTooltip.Positioner.Props["side"];
};

export function Tooltip({ children, content, shortcut, side = "bottom" }: TooltipProps) {
  return (
    <BaseTooltip.Root>
      <BaseTooltip.Trigger render={children} />
      <BaseTooltip.Portal container={usePortalContainer()}>
        <BaseTooltip.Positioner side={side} sideOffset={8}>
          <BaseTooltip.Popup className="ui-tooltip-popup">
            <span className="ui-tooltip-label">{content}</span>
            {shortcut ? <Kbd>{shortcut}</Kbd> : null}
          </BaseTooltip.Popup>
        </BaseTooltip.Positioner>
      </BaseTooltip.Portal>
    </BaseTooltip.Root>
  );
}
```

## Example

```tsx
import { Button, Tooltip } from "@replicas/ui";

export default function TooltipDemo() {
  return (
    <>
      <Tooltip content="Search" shortcut="/">
        <Button variant="ghost">Search</Button>
      </Tooltip>
      <Tooltip content="Create new file" shortcut="N">
        <Button variant="ghost">New file</Button>
      </Tooltip>
    </>
  );
}
```

## Foundations

The rest of the Cursor style, as a skill: https://replicas.raphaelsalaja.com/skills/cursor/SKILL.md