# Highlight

Marks an existing item someone was taken to, from a notification, a link, search or Firm Pilot. It never shows for an item they just created. Every item that can be linked to has this state. It is a ring that flows round the edge: a blue-to-navy comet turning once every 3 seconds. A record (a note, task, interaction, document or fact) also breathes a very light navy tint under it, until the reader presses anywhere. A control on an opportunity, like the field Firm Pilot points at, gets the ring alone for 4 seconds. useHighlight scrolls the target to the middle first. Both are hidden from screen readers; with reduced motion the ring is a still focus-blue edge and the tint holds steady.

- Beta: ready to use; its API can still change in a minor release.
- Category: Status & indicators

```tsx
import { Highlight, useHighlight } from "@leap-crm/design-system";
```

## Best practices

- Do: Show it on an existing item someone was taken to, from a notification, a link, search or Firm Pilot. Drive it with `useHighlight`, which scrolls the item to the middle first.
- Do: Pass the `radius` of what it covers: `none` for a table row, `md` for a workspace card, `lg` for a `Card`, so the ring follows the edge.
- Do: Use `kind="control"` for the one field Firm Pilot points at on an opportunity, with `frame="inside"` when the control sits in a box that clips.
- Do: Move focus to the target when it should be announced. The highlight is hidden from screen readers.
- Don't: Highlight an item the user just created. Pass null to `useHighlight` for it: they already know where it is.
- Don't: Use it for a selected row, a hover or an error. It means only that someone was taken here; those states belong to the component itself.

## Related

- [Search Match](./search-match.md)
- [Skeleton](./skeleton.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { Badge, Button, Highlight, useHighlight } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const notes = [
  {
    title: "Vendor wants a 60-day settlement",
    body: "Agent called: the vendor prefers 60 days and will take 45 with a 10% deposit.",
  },
  {
    title: "Finance pre-approval received",
    body: "Rose sent the pre-approval letter from her broker, valid to 15 Jan.",
  },
  {
    title: "Building and pest booked",
    body: "Inspector booked for Thursday at 9am. Rose will meet them on site.",
  },
];

function NoteCard({
  title,
  body,
  target,
}: {
  title: string;
  body: string;
  target: number | null;
}) {
  const { ref, active } = useHighlight<HTMLElement>(target, {
    duration: null,
  });
  return (
    <article
      ref={ref}
      className="border-neutral-border bg-neutral-surface relative flex flex-col gap-1 rounded-md border p-4"
    >
      <h3 className="text-body font-book text-neutral-text">{title}</h3>
      <p className="text-small text-neutral-text-muted">{body}</p>
      <Highlight active={active} />
    </article>
  );
}

function LinkedNote() {
  const [nonce, setNonce] = useState<number | null>(null);
  return (
    <div className="flex w-96 flex-col items-start gap-4">
      <Button
        intent="outline"
        size="sm"
        onClick={() => setNonce(value => (value ?? 0) + 1)}
      >
        Open “Finance pre-approval” from a link
      </Button>
      <div className="flex w-full flex-col gap-2">
        {notes.map((note, index) => (
          <NoteCard
            key={note.title}
            title={note.title}
            body={note.body}
            target={index === 1 ? nonce : null}
          />
        ))}
      </div>
    </div>
  );
}

function PointedControl() {
  const [nonce, setNonce] = useState<number | null>(null);
  const { ref, active } = useHighlight(nonce);
  return (
    <div className="flex flex-col items-start gap-4">
      <Button
        intent="outline"
        size="sm"
        onClick={() => setNonce(value => (value ?? 0) + 1)}
      >
        Point at the lead source
      </Button>
      <div className="text-small text-neutral-text-muted flex items-center gap-4">
        <Badge tone="warning" size="sm">
          Agreement
        </Badge>
        <span>CRM/1042</span>
        <div ref={ref} className="relative">
          <span className="text-neutral-text">Lead source: Google Ads</span>
          <Highlight active={active} kind="control" />
        </div>
        <span>Est. value $3,300</span>
      </div>
    </div>
  );
}
```

### A note opened from a link

The record kind. Each press directs you to the note again: the note scrolls into view, the ring flows round it over a light pulse, and both stay until you press anywhere.

```tsx
<LinkedNote />
```

### A control Firm Pilot points at

The control kind. The flowing ring alone, 4 px outside the control; it fades after 4 seconds or at the next press.

```tsx
<PointedControl />
```

### Frames

Around for a control with room outside it. Inside for one in a box that clips, like a table cell.

```tsx
<div className="flex items-center gap-8">
  {(["around", "inside"] as const).map(frame => (
    <div
      key={frame}
      className="border-neutral-border text-small text-neutral-text relative rounded-md border px-3 py-2"
    >
      {frame === "around" ? "Around" : "Inside"}
      <Highlight active kind="control" frame={frame} />
    </div>
  ))}
</div>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `active` (required) | `boolean` |  | Shows the highlight. It fades in and out. |
| `kind` | `"record" \| "control"` | `"record"` | Record: a row or card someone was directed to, like a note, task, interaction, document or fact; the ring flows round it over a very light navy pulse. Control: one control on a record, like the field Firm Pilot points at on an opportunity; the ring alone. |
| `frame` | `"around" \| "inside"` | `"around"` | Control only. Around draws the ring 4 px outside the control; inside draws it on the control's edge, for a control in a box that clips. |
| `radius` | `"none" \| "md" \| "lg"` | `"md"` | Record only: the radius of the row or card it covers. None for a table row, md (4 px) for a workspace card, lg (8 px) for a Card. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
