Typography
Standardized typographic scale and text styling component. Supports HTML heading hierarchy (h1–h6), body text, leads, muted captions, code snippets, and color themes.
Core implementation of the Typography component with variant mapping and polymorphic element support.
import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react";
import { cn } from "@/lib/utils";
type TypographyVariant =
| "h1"
| "h2"
| "h3"
| "h4"
| "h5"
| "h6"
| "p"
| "lead"
| "large"
| "small"
| "muted"
| "code";
type TypographyColor =
| "default"
| "muted"
| "primary"
| "secondary"
| "accent"
| "success"
| "warning"
| "danger";
export interface TypographyProps extends React.HTMLAttributes<HTMLElement> {
variant?: TypographyVariant;
color?: TypographyColor;
as?: React.ElementType;
children?: React.ReactNode;
}
const variantStyles: Record<TypographyVariant, string> = {
h1: "scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl",
h2: "scroll-m-20 text-3xl font-semibold tracking-tight first:mt-0",
h3: "scroll-m-20 text-2xl font-semibold tracking-tight",
h4: "scroll-m-20 text-xl font-semibold tracking-tight",
h5: "scroll-m-20 text-lg font-semibold tracking-tight",
h6: "scroll-m-20 text-base font-semibold tracking-tight",
p: "leading-7 [&:not(:first-child)]:mt-4",
lead: "text-xl text-muted-foreground",
large: "text-lg font-semibold",
small: "text-sm font-medium leading-none",
muted: "text-sm text-muted-foreground",
code: "relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold",
};
const defaultElementMap: Record<TypographyVariant, React.ElementType> = {
h1: "h1",
h2: "h2",
h3: "h3",
h4: "h4",
h5: "h5",
h6: "h6",
p: "p",
lead: "p",
large: "div",
small: "small",
muted: "p",
code: "code",
};
const colorStyles: Record<TypographyColor, string> = {
default: "text-foreground",
muted: "text-muted-foreground",
primary: "text-primary",
secondary: "text-secondary",
accent: "text-accent",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const Typography = React.forwardRef<HTMLElement, TypographyProps>(
(
{
variant = "p",
color = "default",
as,
className,
children,
...props
},
ref
) => {
const Component = as || defaultElementMap[variant] || "p";
return (
<Component
ref={ref as any}
className={cn(
variantStyles[variant],
color !== "default" && colorStyles[color],
className
)}
{...props}
>
{children}
</Component>
);
}
);
Typography.displayName = "Typography";
export { Typography };Headings
Use variant h1 through h6 for semantic section headers.
h1 | h2 | h3 | h4 | h5 | h6Heading 1 (h1)
Heading 2 (h2)
Heading 3 (h3)
Heading 4 (h4)
Heading 5 (h5)
Heading 6 (h6)
Text Variants
Paragraphs, lead copy, large text, small text, muted text, and inline code.
p | lead | large | small | muted | codeA prominent lead paragraph for introducing key sections or articles.
Standard body text for long-form narrative content. Bloom UI provides responsive design tokens, accessible contrast, and harmonized typography.
Muted text style for subtle secondary information.
Execute pnpm test:unit to run component test suites.
Colors
Semantic colors applied directly to text.
default | muted | primary | secondary | accent | success | warning | dangerDefault
Muted
Primary
Secondary
Accent
Success
Warning
Danger
Props — Typography
Properties to configure the Typography component.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'lead' | 'large' | 'small' | 'muted' | 'code' | 'p' | Visual typographic style and default HTML tag. |
| color | 'default' | 'muted' | 'primary' | 'secondary' | 'accent' | 'success' | 'warning' | 'danger' | 'default' | Semantic color theme of the text. |
| as | ElementType | — | Override the rendered underlying HTML element tag while preserving typography styles. |