Text
πDark Mode Compatible
A flexible, polymorphic typography component that provides consistent text styling across the Lufa Design System.
Overviewβ
Use Text when you needβ¦
- Consistent typography using semantic type scales (h1-h6, body, caption, label)
- Semantic text colors that adapt to light and dark themes
- Font weight control (normal, medium, semibold, bold)
- Text alignment (left, center, right, justify)
- Text transformations (uppercase, lowercase, capitalize)
- Semantic HTML elements via the polymorphic
asprop - Token-based design values that automatically adapt to themes
Live demoInteractive
Default text
Anatomyβ
The Text component is a single typography element with customizable font properties.
ββββββββββββββββββββββββββββββββββββββββββββ
β Text Component β
β ββββββββββββββββββββββββββββββββββββββ β
β β variant: h1-h6, body, caption β β
β β color: primary, secondary, etc. β β
β β weight: normal, medium, bold β β
β β align: left, center, right β β
β β transform: uppercase, etc. β β
β β β β
β β The quick brown fox jumps... β β
β ββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββ
Component Structure:
- Container: Single text element (default
p, customizable viaasprop) - Variant: Typography scale from design tokens (h1-h6, body variants, caption, label)
- Color: Semantic text color tokens
- Weight: Font weight values (normal, medium, semibold, bold)
- Align: Text alignment property
- Transform: Text transformation setting
Usageβ
Import the component:
import { Text } from '@grasdouble/lufa_design-system';
Basic usageβ
src/App.tsx
import { Text } from '@grasdouble/lufa_design-system';
function App() {
return (
<>
<Text as="h1" variant="h1" weight="bold">
Page Title
</Text>
<Text variant="body" color="secondary">
This is a paragraph of body text with secondary color.
</Text>
<Text as="label" variant="label" transform="uppercase" weight="semibold">
Section Label
</Text>
<Text variant="caption" color="tertiary" align="center">
Image caption text
</Text>
</>
);
}
Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'p' | 'span' | 'div' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'label' | 'legend' | 'figcaption' | 'p' | HTML element to render |
variant | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'body-large' | 'body' | 'body-small' | 'caption' | 'label' | 'body' | Typography variant (semantic scale) |
color | 'primary' | 'secondary' | 'tertiary' | 'success' | 'error' | 'warning' | 'info' | 'inverse' | 'primary' | Text color using semantic tokens |
weight | 'normal' | 'medium' | 'semibold' | 'bold' | 'normal' | Font weight |
align | 'left' | 'center' | 'right' | 'justify' | 'left' | Text alignment |
transform | 'none' | 'uppercase' | 'lowercase' | 'capitalize' | 'none' | Text transformation |
className | string | undefined | Additional CSS classes |
children | ReactNode | undefined | Text content to render inside the Text |
Also supports all standard HTML attributes for the underlying element (for example id, role, aria-*, data-*, style, and event handlers).
Accessibilityβ
Use semantic elements and matching variants for headings and labels to ensure correct screen reader output.
import { Text } from '@grasdouble/lufa_design-system';
export function HeadingBlock() {
return (
<>
<Text as="h1" variant="h1">
Main Title
</Text>
<Text as="h2" variant="h2">
Section Title
</Text>
<Text as="h3" variant="h3">
Subsection Title
</Text>
</>
);
}
import { Text } from '@grasdouble/lufa_design-system';
export function LabeledField() {
return (
<>
<Text as="label" variant="label" htmlFor="email">
Email Address
</Text>
<input type="email" id="email" />
</>
);
}
- Match heading variants to heading elements (
as="h2"withvariant="h2"). - Associate labels with inputs using
htmlForandid. - Avoid making Text focusable unless it is intentionally interactive.
- Ensure color contrast remains at WCAG AA levels.
Theming & Tokensβ
Typography variants map to semantic typography tokens:
h1(~40px),h2(~32px),h3(~28px),h4(~24px),h5(~20px),h6(~18px)body-large(~18px),body(~16px),body-small(~14px)caption(~12px),label(~14px)
Semantic colors adapt across themes: primary, secondary, tertiary, success, error, warning, info, inverse.
import { Text } from '@grasdouble/lufa_design-system';
export function TokenColorExample() {
return <Text color="secondary">Token-based color adapts to theme</Text>;
}
Do / Donβtβ
Do
- Use semantic HTML via the
asprop for headings, labels, and captions - Use semantic colors for status and emphasis
- Use weight and variant together to communicate hierarchy
- Use transform sparingly for labels and metadata
- Combine Text with layout components for spacing
Don't
- Use heading variants without matching heading elements
- Skip heading levels in a content hierarchy
- Hard-code colors in
stylewhen tokens suffice - Use uppercase for long passages of text
- Mix too many weights in tight groups
Related Componentsβ
- Box - Layout primitive for spacing and backgrounds
- Stack - Layout primitive for stacking text elements
- Badge - Small UI element for labels and counts
- Button - Interactive element that includes text styling
- Heading - Specialized component for page and section titles
- Paragraph - Specialized component for body text blocks