# Infotip

> An information icon that opens a short explanation on hover, click or touch.

```tsx title="hero.tsx"
import { Infotip, InfotipContent, InfotipTrigger } from '@langgenius/dify-ui/infotip'
import * as React from 'react'

export function InfotipHeroDemo() {
  const labelId = React.useId()

  return (
    <div className="flex items-center gap-1">
      <span id={labelId} className="system-sm-medium text-text-secondary">
        Chunk overlap
      </span>
      <Infotip>
        <InfotipTrigger aria-labelledby={labelId} className="data-popup-open:text-text-secondary" />
        <InfotipContent aria-labelledby={labelId} className="w-60">
          Repeats the end of each chunk at the start of the next one, so sentences that cross a
          boundary keep their context.
        </InfotipContent>
      </Infotip>
    </div>
  )
}
```

## Usage guidelines

- Use `Infotip` when an information icon's primary action is opening an explanation. Use `Tooltip` when the trigger already has another primary action and only needs a visual hint.
- `Infotip` is a popover: it opens on hover, click, touch and keyboard activation, so its content reaches every user and can hold links.
- Name the trigger with `aria-labelledby` when a visible topic exists, otherwise with a short `aria-label`. The trigger needs its name while the popup is closed, so it never comes from the popup content.
- Name the popup with the same short topic, through `aria-labelledby`, `aria-label` or an `InfotipTitle`. Do not copy the explanation into either name, and keep the body as normal children rather than turning it into the dialog's description.
- `InfotipTrigger` stops click propagation, so an infotip inside a clickable row or card does not trigger the enclosing action.
- `Infotip` owns its surface, spacing, typography, radius and shadow. Callers may constrain the width or keep intentional line breaks, and may place and color the trigger, but do not resize it; use `size`.

## Anatomy

```tsx
import { Infotip, InfotipContent, InfotipTitle, InfotipTrigger } from '@langgenius/dify-ui/infotip'
```

```tsx
<Infotip>
  <InfotipTrigger aria-label="Topic" />
  <InfotipContent>
    <InfotipTitle />
  </InfotipContent>
</Infotip>
```

`InfotipTrigger` renders the icon button itself and takes no children; `iconVariant` picks its glyph: `question` (the default), `information` or `warning`. `InfotipContent` bundles the portal, positioner and popup, and opens on the `top` side by default.

## Examples

### Named by a title

When adjacent text states a value rather than the topic, `InfotipTitle` gives the dialog its name while the trigger carries a matching `aria-label`.

```tsx title="title.tsx"
import { Infotip, InfotipContent, InfotipTitle, InfotipTrigger } from '@langgenius/dify-ui/infotip'

export function InfotipTitleDemo() {
  return (
    <div className="flex items-center gap-1.5 system-sm-medium text-text-secondary">
      <span>High priority</span>
      <Infotip>
        <InfotipTrigger
          aria-label="Processing priority"
          iconVariant="information"
          className="data-popup-open:text-text-secondary"
        />
        <InfotipContent className="w-60">
          <InfotipTitle className="system-xs-semibold text-text-primary">
            Processing priority
          </InfotipTitle>
          <p className="mt-1">
            Documents with a higher priority are indexed first when several are waiting.
          </p>
        </InfotipContent>
      </Infotip>
    </div>
  )
}
```

### Links in the explanation

The popup can hold interactive content. Opening it from the keyboard moves focus to the first link.

```tsx title="link.tsx"
import { Infotip, InfotipContent, InfotipTrigger } from '@langgenius/dify-ui/infotip'
import * as React from 'react'

export function InfotipLinkDemo() {
  const labelId = React.useId()

  return (
    <div className="flex items-center gap-1">
      <span id={labelId} className="system-sm-medium text-text-secondary">
        System prompt
      </span>
      <Infotip>
        <InfotipTrigger
          aria-labelledby={labelId}
          iconVariant="information"
          className="data-popup-open:text-text-secondary"
        />
        <InfotipContent aria-labelledby={labelId} className="w-60">
          Describe the agent’s task and the rules it follows.{' '}
          <a
            href="https://docs.dify.ai"
            className="rounded-xs font-medium text-text-accent underline decoration-text-accent/70 decoration-1 underline-offset-[0.2em] outline-offset-2 outline-state-accent-solid transition-colors hover:decoration-current hover:decoration-2 focus-visible:outline-2 focus-visible:outline-solid active:opacity-80"
            target="_blank"
            rel="noreferrer"
          >
            Read the documentation
          </a>
        </InfotipContent>
      </Infotip>
    </div>
  )
}
```

### Icon variants

`iconVariant` selects the trigger glyph: `question` for general help, `information` for factual details and `warning` for caveats.

```tsx title="icon-variants.tsx"
import { Infotip, InfotipContent, InfotipTrigger } from '@langgenius/dify-ui/infotip'
import * as React from 'react'

const variants = [
  {
    iconVariant: 'question',
    topic: 'Top K',
    explanation: 'The number of chunks returned for each query.',
  },
  {
    iconVariant: 'information',
    topic: 'Model context',
    explanation: 'Includes retrieved chunks, system instructions and recent conversation turns.',
  },
  {
    iconVariant: 'warning',
    topic: 'Legacy indexing',
    explanation: 'Keyword-only indexing skips semantic search and reduces recall on long queries.',
  },
] as const

function VariantRow({ iconVariant, topic, explanation }: (typeof variants)[number]) {
  const labelId = React.useId()

  return (
    <li className="flex items-center justify-between gap-3 py-2.5">
      <div className="flex min-w-0 items-center gap-1 system-sm-medium text-text-secondary">
        <span id={labelId} className="truncate">
          {topic}
        </span>
        <Infotip>
          <InfotipTrigger
            aria-labelledby={labelId}
            iconVariant={iconVariant}
            className="data-popup-open:text-text-secondary"
          />
          <InfotipContent aria-labelledby={labelId} className="w-60">
            {explanation}
          </InfotipContent>
        </Infotip>
      </div>
      <span className="shrink-0 font-mono system-xs-regular text-text-tertiary">{iconVariant}</span>
    </li>
  )
}

export function InfotipIconVariantsDemo() {
  return (
    <ul className="flex w-full max-w-72 flex-col divide-y divide-divider-subtle">
      {variants.map((variant) => (
        <VariantRow key={variant.iconVariant} {...variant} />
      ))}
    </ul>
  )
}
```

### Sizes

`size` sets the icon and the trigger's layout box together: `sm` (12px), `md` (16px, the default) and `lg` (16px with a larger icon). Every size keeps a 24px pointer target outside its layout box, so the larger target does not move the surrounding content. An ancestor that clips overflow also clips that target.

```tsx title="sizes.tsx"
import { Infotip, InfotipContent, InfotipTrigger } from '@langgenius/dify-ui/infotip'
import * as React from 'react'

const rows = [
  {
    size: 'sm',
    topic: 'Top K',
    explanation: 'The number of chunks returned for each query.',
    textClassName: 'system-xs-medium',
  },
  {
    size: 'md',
    topic: 'Score threshold',
    explanation: 'Chunks scoring below this similarity are left out of the results.',
    textClassName: 'system-sm-medium',
  },
  {
    size: 'lg',
    topic: 'Rerank model',
    explanation: 'Reorders the retrieved chunks by relevance before they reach the model.',
    textClassName: 'system-md-medium',
  },
] as const

function SizeRow({ size, topic, explanation, textClassName }: (typeof rows)[number]) {
  const labelId = React.useId()

  return (
    <li className="flex items-center justify-between gap-3 py-2.5">
      <div className={`flex min-w-0 items-center gap-1 text-text-secondary ${textClassName}`}>
        <span id={labelId} className="truncate">
          {topic}
        </span>
        <Infotip>
          <InfotipTrigger
            aria-labelledby={labelId}
            size={size}
            className="data-popup-open:text-text-secondary"
          />
          <InfotipContent aria-labelledby={labelId} className="w-60">
            {explanation}
          </InfotipContent>
        </Infotip>
      </div>
      <span className="shrink-0 font-mono system-xs-regular text-text-tertiary">{size}</span>
    </li>
  )
}

export function InfotipSizesDemo() {
  return (
    <ul className="flex w-full max-w-72 flex-col divide-y divide-divider-subtle">
      {rows.map((row) => (
        <SizeRow key={row.size} {...row} />
      ))}
    </ul>
  )
}
```

## Keyboard

| Key              | Action                                                                                                      |
| ---------------- | ----------------------------------------------------------------------------------------------------------- |
| `Enter`, `Space` | Opens the infotip from a focused trigger and moves focus into the popup, to its first link when it has one. |
| `Tab`            | Moves focus past the popup's last link to the next control on the page and closes the popup.                |
| `Escape`         | Closes the infotip and returns focus to the trigger.                                                        |

## API reference

### Infotip

Groups an icon button trigger and an accessible explanation popover. Doesn't render its own HTML element.

Opens on hover, click, touch, or keyboard activation and supports interactive content such as links.

Inherits `defaultOpen`, `open`, `onOpenChange`, `onOpenChangeComplete`, `actionsRef`, `modal`, `triggerId`, `defaultTriggerId`, `children` from [Base UI Popover.Root](https://base-ui.com/react/components/popover#root).

### InfotipContent

A container for the popover contents. Renders a `<div>` element.

**Props**

| Prop          | Type                                                                       | Default | Description                                                                                             |
| ------------- | -------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------- |
| `side?`       | `'bottom' \| 'inline-end' \| 'inline-start' \| 'left' \| 'right' \| 'top'` | `'top'` | Which side of the trigger to place the popup against. May automatically change to avoid collisions.     |
| `sideOffset?` | `number \| OffsetFunction`                                                 | `8`     | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance. |
| `children`    | `React.ReactNode`                                                          | —       | The explanation content.                                                                                |

Inherits `className`, `render`, `style`, `initialFocus`, `finalFocus`, `align`, `alignOffset` from [Base UI Popover.Popup](https://base-ui.com/react/components/popover#popup).

**Data attributes**

| Attribute             | Description                                                           |
| --------------------- | --------------------------------------------------------------------- |
| `data-open`           | Present when the popup is open.                                       |
| `data-closed`         | Present when the popup is closed.                                     |
| `data-starting-style` | Present when the popup begins animating in.                           |
| `data-ending-style`   | Present when the popup is animating out.                              |
| `data-side`           | Indicates which side the popup is positioned relative to the trigger. |
| `data-align`          | Indicates how the popup is aligned relative to specified side.        |
| `data-instant`        | Present if animations should be instant.                              |

**CSS variables**

| Variable              | Type     | Description                                                                                                                   |
| --------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `--popup-width`       | —        | The width of the popup.                                                                                                       |
| `--popup-height`      | —        | The height of the popup.                                                                                                      |
| `--available-width`   | `number` | The available width between the trigger and the edge of the viewport.                                                         |
| `--available-height`  | `number` | The available height between the trigger and the edge of the viewport.                                                        |
| `--anchor-width`      | `number` | The anchor's width.                                                                                                           |
| `--anchor-height`     | `number` | The anchor's height.                                                                                                          |
| `--transform-origin`  | `string` | The coordinates that this element is anchored to. Used for animations and transitions.                                        |
| `--positioner-width`  | `number` | The width of the popover's positioner. It is important to set `width` to this value when using CSS to animate size changes.   |
| `--positioner-height` | `number` | The height of the popover's positioner. It is important to set `height` to this value when using CSS to animate size changes. |

### InfotipTitle

A heading that labels the popover. Renders an `<h2>` element.

Inherits `className`, `render`, `style` from [Base UI Popover.Title](https://base-ui.com/react/components/popover#title).

### InfotipTrigger

An icon button that opens the infotip on hover or click and stops click propagation; requires `aria-label` or `aria-labelledby`. Renders a `<button>` element.

**Props**

| Prop               | Type                                       | Default      | Description                                                                           |
| ------------------ | ------------------------------------------ | ------------ | ------------------------------------------------------------------------------------- |
| `aria-label?`      | `string`                                   | —            | Names the element for assistive technology. Pass either this or `aria-labelledby`.    |
| `aria-labelledby?` | `string`                                   | —            | Identifies the element that names this one. Pass either this or `aria-label`.         |
| `iconVariant?`     | `'information' \| 'question' \| 'warning'` | `'question'` | The icon shown in the trigger.                                                        |
| `size?`            | `'lg' \| 'md' \| 'sm'`                     | `'md'`       | The size of the trigger and its icon.                                                 |
| `openOnHover?`     | `boolean`                                  | `true`       | Whether the infotip also opens when the trigger is hovered.                           |
| `closeDelay?`      | `number`                                   | `200`        | How long to wait before closing an infotip that was opened on hover, in milliseconds. |

Valid prop combinations:

- `aria-label: string`, `aria-labelledby?: undefined`
- `aria-label?: undefined`, `aria-labelledby: string`

Inherits `id`, `className`, `style`, `payload`, `delay` from [Base UI Popover.Trigger](https://base-ui.com/react/components/popover#trigger).

**Data attributes**

| Attribute         | Description                                     |
| ----------------- | ----------------------------------------------- |
| `data-popup-open` | Present when the corresponding popover is open. |
| `data-pressed`    | Present when the trigger is pressed.            |
| `data-disabled`   | Present when the trigger is disabled.           |
