Skip to content

Text

The Text component is a versatile typographic component that supports various styling options through variants, colors, and text alignment. It picks a sensible default HTML element based on the selected variant, which you can override with as.

Use variant to set the typographic style (headings, body, and caption scales) and color to tint it — leave color unset to inherit the variant’s own default. align controls horizontal alignment, while wrap tunes how lines break. For overflow, truncate cuts a single line with an ellipsis and lineClamp limits the text to a set number of lines (it takes precedence over truncate). Try them in the playground below.

Highlight text

HighlightText renders a string with the characters matching match wrapped in <mark>. Matching is fuzzy (the same fuzzysort matching used by file search), so match="rdm" highlights the letters of “README”. With no match, or no match found, it renders plain text.

import { HighlightText } from "@harnessio/ui/components";
<HighlightText text={file.name} match={searchQuery} />;

Installation

import { Text } from "@harnessio/ui/components";
// Basic
<Text>Default text with the body-normal variant</Text>
// Variant + color
<Text variant="heading-section" color="foreground-1">Section heading</Text>
// Override the element for correct semantics
<Text variant="heading-hero" as="h1">Hero heading as a real h1</Text>
// Truncation
<Text truncate>Truncated with an ellipsis if it overflows</Text>