Text
⋯
Text applies Nesra’s typography roles to a chosen HTML element. The visual role does not choose the heading level for the document.
import { Text } from "@nesra/ui/text";
export function Description() { return ( <section> <Text as="h2" variant="heading3"> Account details </Text> <Text>Review the information before saving.</Text> </section> );}Text is also exported from @nesra/ui.
Examples
Section titled “Examples”Typography roles
Section titled “Typography roles”Typography lists the exact metrics.
import { Text } from "@nesra/ui/text";
export function TextRolesExample() { return ( <div className="grid w-full gap-nesra-spacing-md"> <Text as="h2" variant="heading5"> Account details </Text> <Text size="large" weight="semibold"> Lead copy </Text> <Text>Default product copy</Text> <Text size="small" weight="medium"> Compact metadata </Text> </div> );}HTML semantics and truncation
Section titled “HTML semantics and truncation”import { Text } from "@nesra/ui/text";
export function TextSemanticsExample() { return ( <div className="grid w-full max-w-80 gap-nesra-spacing-md"> <Text as="h3" variant="heading5"> Section heading </Text> <Text as="span" className="text-nesra-text-support" size="small" truncate> A long supporting label that stays on one line in this narrow container </Text> </div> );}Light and Dark
Section titled “Light and Dark”Text sets typography only and inherits its color, so it follows whatever text role its container
uses in either mode. Set a color with a text role such as text-nesra-text-body or
text-nesra-text-support. The text-nesra-text-muted alias was removed in 1.0; see Upgrading to 1.0.
Accessibility
Section titled “Accessibility”Choose as from the document structure. For example, a visually smaller section heading can use
as="h2" with variant="heading3". Heading variants require an explicit as value. A default
body Text renders <p>. truncate clips a single line visually, so make essential content
available in full elsewhere on the page.
API reference
Section titled “API reference”| Prop | Type | Default | Description |
|---|---|---|---|
variant |
TextVariant |
body |
Selects the visual role. |
size |
large | medium | small | xsmall |
medium |
Body size. Unavailable for headings. |
weight |
semibold | medium | regular |
regular |
Body weight. Unavailable for headings. |
as |
TextElement |
p for body |
Required for heading variants. |
truncate |
boolean |
false |
Adds single-line ellipsis behavior. |
className |
string |
— | Adds or overrides classes through Nesra’s class merger. |
Native text element attributes and refs are forwarded. See Typography for exact type metrics and font-loading responsibilities.
TextVariant is body, heading1, heading2, heading3, heading4, heading5, or heading6.
TextElement is h1, h2, h3, h4, h5, h6, p, span, label, dt, dd, li,
figcaption, legend, em, strong, small, abbr, or time.