Text Component

January 21, 2026 · View on GitHub

A flexible and customizable text component for rendering text content with various styling options.

Installation

import { Text } from "@docspace/ui-kit";

Basic Usage

<Text as="p" title="Some title">
  Some text
</Text>

Component Properties

PropsTypeRequiredDefaultDescription
asReact.ElementType-pHTML element type to render (p, span, h1, etc.)
tagstring--Alternative to as prop for element type
backgroundColorstring--Background color of the text element
colorstring--Text color
displaystring--CSS display property
fontSizestring-13pxFont size
fontWeightnumber | string-400Font weight
isBoldboolean-falseSets font weight to 700 when true
isInlineboolean-falseSets display to inline-block when true
isItalicboolean-falseSets font style to italic
lineHeightstring--Line height
noSelectboolean-falseDisables text selection when true
textAlignstring-leftText alignment (left, center, right, justify)
titlestring--Tooltip text on hover
truncateboolean-falseEnables text truncation with ellipsis
dir"ltr" | "rtl" | "auto"--Text direction
classNamestring--Additional CSS class names
styleReact.CSSProperties--Additional inline styles
onClick(e: React.MouseEvent) => void--Click event handler
refReact.Ref<HTMLElement>--Ref to the underlying DOM element
viewstring--View mode (e.g., "tile")
dataTestIdstring-textTest ID for testing purposes

Examples

Default Text

<Text>Default text with standard styling</Text>

Heading Text

<Text as="h1" fontSize="24px" fontWeight="700">
  Heading Text
</Text>

Inline Text

<>
  <Text isInline>First inline text</Text>{" "}
  <Text isInline>Second inline text</Text>
</>

Styled Text

<Text
  fontSize="16px"
  fontWeight="600"
  color="white"
  backgroundColor="black"
  textAlign="center"
  isBold
  isItalic
  lineHeight="1.5"
>
  Styled text with custom properties
</Text>

Interactive Text

<Text
  isInline
  onClick={() => console.log("clicked")}
  style={{ cursor: "pointer" }}
>
  Click me!
</Text>

Non-Selectable Text

<Text noSelect>This text cannot be selected</Text>

Truncated Text

<div style={{ width: 200 }}>
  <Text truncate>
    This is a very long text that will be truncated when it exceeds the
    container width
  </Text>
</div>

RTL Direction

<Text dir="rtl" textAlign="right">
  مرحبا بالعالم - Hello World
</Text>

Auto Direction

<Text dir="auto">English text with auto direction</Text>
<Text dir="auto">نص عربي مع اتجاه تلقائي</Text>

Font Sizes

<Text fontSize="10px">Extra small text</Text>
<Text fontSize="13px">Default text</Text>
<Text fontSize="16px">Large text</Text>
<Text fontSize="24px">Display text</Text>

Font Weights

<Text fontWeight="300">Light</Text>
<Text fontWeight="400">Regular</Text>
<Text fontWeight="600">Semibold</Text>
<Text fontWeight="700">Bold</Text>

All Headings

<Text as="h1" fontSize="32px" fontWeight="700">Heading 1</Text>
<Text as="h2" fontSize="28px" fontWeight="700">Heading 2</Text>
<Text as="h3" fontSize="24px" fontWeight="600">Heading 3</Text>
<Text as="h4" fontSize="20px" fontWeight="600">Heading 4</Text>
<Text as="h5" fontSize="16px" fontWeight="600">Heading 5</Text>
<Text as="h6" fontSize="14px" fontWeight="600">Heading 6</Text>

Text Alignment

<Text textAlign="left">Left aligned</Text>
<Text textAlign="center">Center aligned</Text>
<Text textAlign="right">Right aligned</Text>
<Text textAlign="justify">Justified text</Text>

With Tooltip

<Text title="This tooltip appears on hover">Hover over this text</Text>

Accessibility

The Text component supports:

  • Custom HTML elements via as prop for semantic markup
  • Text direction control via dir prop
  • ARIA attributes through props spreading
  • Keyboard interaction for clickable text

Browser Support

The Text component is compatible with all modern browsers and includes:

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Contributing

For bug reports and feature requests, please create an issue in the repository.