Text
The typography primitive. Extends Box with font, text, truncation, and line clamp props.
Text extends Box, so it accepts every Box prop, and adds styled-system typography plus a few text utilities. Use it for headings, paragraphs, labels, links, and any element that needs font styling.
Version 2.1 is here
Faster builds, a new upload block and dark mode for every chart.
Import#
import { Text } from "@reactberry/system/elements";
Usage#
import { Box, Text } from "@reactberry/system/elements";
export default function SectionHeader() {
return (
<Box display="flex" flexDirection="column" gap="xxs">
<Text as="h2" fontSize="xl" fontWeight="600" color="primary">
Billing
</Text>
<Text as="p" fontSize={["s", "m"]} color="secondary">
Manage your plan and payment methods.
</Text>
</Box>
);
}
Examples#
Font sizes#
fontSize maps to theme.fontSizes. Use the short aliases from xxs to xxl.
Truncate and clamp#
truncate cuts a single line with an ellipsis. lineClamp limits text to a number of lines.
The quarterly review covers revenue, churn and hiring across all regions, with a detailed breakdown of each product line and the plans for next quarter.
Icons with as#
Pass an icon component to as and use size for its width and height. The icons fill with currentColor, so color applies.
API#
Text#
| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | "span" | Element or component to render, for example |
truncate | boolean | — | Single-line ellipsis. Sets |
lineClamp | number | — | Clamps to the given number of lines with an ellipsis, using |
textTransform | string | — | CSS |
textDecoration | string | — | CSS |
textOverflow | string | — | CSS |
whiteSpace | string | — | CSS |
overflowWrap | string | — | CSS |
disabled | boolean | — | Sets |
Text also accepts every Box prop and the styled-system typography group:
fontSize— maps totheme.fontSizesfontWeight,lineHeight,letterSpacing,fontFamily,fontStyle,textAlign— raw CSS values (for examplefontWeight="600",lineHeight="1.5")
The default themes do not define fonts, fontWeights, lineHeights or letterSpacings scales, so those props pass through unchanged. Named values such as "medium" or "relaxed" are not valid CSS for fontWeight or lineHeight.
Font size reference#
Aliases from theme.fontSizes:
xxs0.625rem,xs0.75rem,s0.875rem,m1rem,l1.25rem,xl1.5rem,xxl2rem,xxxl3rem,huge5rem
Long names (xxsmall, xsmall, small, medium, large, xlarge, xxlarge, xxxlarge) match the short aliases. Numeric indices 0 to 13 are also available.
Accessibility#
Textrenders aspanby default. Passasfor headings, paragraphs and labels so the document structure is correct.- Text cut off by
truncateorlineClampis still in the DOM and read in full by screen readers.
Notes#
- Use
fontSizefor text size.sizesets width and height (inherited from Box), which is useful for icons rendered withas. - Use
Textrather thanBoxwhenever typography props are needed.