# Truncate

Text that clips with an ellipsis and shows its full value in a quick tooltip on hover, only while it's actually clipped. It's the rule across the system: every truncated value goes through Truncate, and lint rejects a bare truncate or line-clamp class.

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

```tsx
import { Truncate } from "@leap-crm/design-system";
```

## Best practices

- Do: Wrap every value that can be cut off, like a matter name in a table cell or an email in a header, so the whole value shows in a tooltip while it is clipped.
- Do: Give the parent a width or `min-w-0` in a flex row, so the value has an edge to truncate against.
- Do: Use `lines` for a description that may wrap, so it keeps two or three lines before the ellipsis.
- Don't: Use a bare `truncate`, `line-clamp-*` or `text-ellipsis` class. The reader loses the rest of the value, and lint rejects it.
- Don't: Truncate a value the reader must act on in full, like an amount or a matter number. Give it the room instead.

## Related

- [Tooltip](./tooltip.md)
- [Scroll Area](./scroll-area.md)
- [Empty Value](./empty-value.md)

## Examples

What the examples import:

```tsx
import { Truncate } from "@leap-crm/design-system";
```

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

```tsx
const longName =
  "Hartley Okafor Moreau Family Trust (Superannuation Fund No. 2)";

const longNote =
  "Settlement booked for 14 December. The vendor's solicitor has asked for the deposit release authority before the cooling-off period ends, and the bank wants the signed loan documents by Friday.";
```

### One line

Hover the clipped name: its full value opens at once. The short one fits, so it has no tooltip.

```tsx
<div className="text-body flex w-64 flex-col gap-3">
  <Truncate>{longName}</Truncate>
  <Truncate>Ada Hartley</Truncate>
</div>
```

### Several lines

lines={2} or {3} clamps a longer note and still shows the whole of it on hover.

```tsx
<div className="text-body text-neutral-text-secondary w-80">
  <Truncate lines={2}>{longNote}</Truncate>
</div>
```

### In a row

Inside a flex row, Truncate takes the room that's left and clips there, so the value beside it never gets pushed out.

```tsx
<div className="border-neutral-border text-body flex w-72 items-baseline gap-3 rounded-lg border px-3 py-2">
  <Truncate className="flex-1">{longName}</Truncate>
  <span className="text-small text-neutral-text-muted shrink-0">
    $48,000
  </span>
</div>
```

### Inline

inline renders a span for use inside a sentence, clipped at a width you give it.

```tsx
<p className="text-body">
  Assigned to{" "}
  <Truncate inline className="font-book max-w-32">
    {longName}
  </Truncate>{" "}
  yesterday.
</p>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` (required) | `ReactNode` |  | The text. It clips with an ellipsis when it doesn't fit. |
| `value` | `ReactNode` |  | The full value for the tooltip, when children isn't plain text. Defaults to children. |
| `lines` | `1 \| 2 \| 3` | `1` | How many lines before it clips. |
| `inline` | `boolean` | `false` | A span for inside a line of text; a div otherwise. |
| `side` | `"top" \| "right" \| "bottom" \| "left"` | `"top"` | Which side it opens on. It flips to the other when there isn't room. |
| `align` | `"start" \| "center" \| "end"` | `"start"` | How it lines up along that side: start, center or end. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
