Skip to content

The open alternative to Salesforce, designed for AI.

3.4 KB
Raw Blame
---
title: Text
description: Compose theme typography with single-line truncation or a limited number of lines.
---

import { PageBanner } from "/snippets/page-banner.mdx"

import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';

import TextReference from '/snippets/ui/generated/typography/text.mdx';

## Overview

`Text` provides typography and overflow handling. It renders a `div` by default. Omit `size`, `weight` and `color` to keep inheriting typography from its surroundings.

<StoryEmbed
  storyId="ui-typography-text--display"
  title="Text example"
  height={90}
/>

## Usage

Give the text a constrained width, then set `truncate` to show an ellipsis when it overflows:

```tsx
import { Text } from 'twenty-ui/primitives/typography';

export const ContactName = () => (
  <Text truncate style={{ maxWidth: 160 }}>
    Alexandra Montgomery
  </Text>
);
```

## Choose typography

`size` uses the existing theme scale. It changes font size, with no height, font-family or line-height default:

| Size  | Theme value |
| ----- | ----------- |
| `xxs` | `0.625rem`  |
| `xs`  | `0.85rem`   |
| `sm`  | `0.92rem`   |
| `md`  | `1rem`      |
| `lg`  | `1.23rem`   |
| `xl`  | `1.54rem`   |
| `xxl` | `1.85rem`   |

`weight` accepts `regular` (400), `medium` (500) or `semibold` (600). `color` accepts `primary`, `secondary`, `tertiary` or `light`. Each omitted prop inherits independently. The visual size does not change the semantic element.

<StoryEmbed
  storyId="ui-typography-text--typography-catalog"
  title="Text typography scale"
  height={410}
/>

For captions, compose the small size, semibold weight and light color:

```tsx
import { Text } from 'twenty-ui/primitives/typography';

export const Caption = () => (
  <Text size="xs" weight="semibold" color="light">
    Workspace
  </Text>
);
```

Use native `style` for runtime colors and parent-layout constraints. Caller classes and render composition target the same text element. Text adds no typography defaults when these props are omitted.

## Limit the number of lines

<StoryEmbed
  storyId="ui-typography-text--catalog"
  title="Text overflow options"
  height={210}
/>

Use `lineClamp` with a positive integer. Choose either `truncate` or `lineClamp`; their props are mutually exclusive.

```tsx
import { Text } from 'twenty-ui/primitives/typography';

export const Summary = () => (
  <Text lineClamp={2} style={{ maxWidth: 240 }}>
    Follow up with the customer about their onboarding milestones and upcoming
    renewal.
  </Text>
);
```

## Choose an element

Use `render` when the text needs another semantic element:

```tsx
import { Text } from 'twenty-ui/primitives/typography';

export const Description = () => (
  <Text render={<p />}>Account description</Text>
);
```

Truncation affects the visual presentation; it does not shorten the text in the DOM. Provide a way to read the full content when the visible portion is insufficient.

## Props

Native attributes, children, refs, class names, and styles target the rendered text element. `TextProps` is exported from `twenty-ui/primitives/typography`. Text content is rendered unchanged, including caller-provided links.

<TextReference />

## Migration

`color` now selects a semantic theme color. Move arbitrary CSS color values from a native `color` attribute to `style={{ color: customColor }}`. Existing styles, classes and render composition continue to target the text element.

<PageBanner illustration="section-document-generator" />