@neshel-ui/typography
Semantic, metrics-aware text components with a shared prop vocabulary.
pnpm add @neshel-ui/config @neshel-ui/typography@import "@neshel-ui/config/tokens.css";
@import "@neshel-ui/typography/styles.css";| Component | Default element | as | Defaults |
|---|---|---|---|
| Heading | h2 | h1–h6 | size by level, semibold, display font, trimmed |
| Paragraph | p | p, div | size base, body font, trimmed |
| Caption | p | p, span, div, small, figcaption | size sm, tone muted, trimmed |
| Text | span | phrasing elements | inherits everything; never trimmed |
Shared props
| Prop | Values | Responsive |
|---|---|---|
size | xs sm base lg xl 2xl 3xl 4xl 5xl 6xl | yes |
weight | light regular medium semibold bold | yes |
align | start center end justify | yes |
leading | none tight snug normal relaxed loose (unitless) | yes |
tone | default muted primary destructive (contrast-paired) | no |
family | body display mono | no |
tracking | tight normal wide | no |
measure | narrow 45ch, comfortable 65ch, wide 80ch, none | no |
wrap | wrap nowrap balance pretty | no |
truncate | one line with an ellipsis | no |
trim | Capsize trimming, default true (not on Text) | no |
Size scale (rem / default leading): xs 0.75/1.5 · sm 0.875/1.5 · base 1/1.5 · lg 1.125/1.5 · xl 1.25/1.4 · 2xl 1.5/1.3 · 3xl 1.875/1.25 · 4xl 2.25/1.2 · 5xl 3/1.1 · 6xl 3.75/1.1.
Rooted in faith. Built with hope.
Size, weight, alignment and leading accept a value per breakpoint.
import { Stack } from "@neshel-ui/layout";
import { Heading, Paragraph } from "@neshel-ui/typography";
/** Values cascade upwards (mobile first); resize the window to see the changes. */
export default function TypographyResponsive() {
return (
<Stack space="4">
<Heading
as="h2"
size={{ base: "xl", md: "3xl", lg: "5xl" }}
weight={{ base: "medium", md: "bold" }}
align={{ base: "center", lg: "start" }}
>
Rooted in faith. Built with hope.
</Heading>
<Paragraph
size={{ base: "sm", md: "base", lg: "lg" }}
align={{ base: "center", lg: "start" }}
>
Size, weight, alignment and leading accept a value per breakpoint.
</Paragraph>
</Stack>
);
}TypographyProps
Visual props shared by every typography component (contracts/typography-api.md).
| Prop | Type | Default | Description |
|---|---|---|---|
| align | Responsive<TextAlign> | — | Text alignment (logical: start/end). |
| family | FontRole | — | Font role (Heading "display", Paragraph and Caption "body"; Text inherits). |
| leading | Responsive<TextLeading> | — | Unitless line height; defaults to the size's leading. Drives Capsize trimming. |
| measure | TextMeasure | — | Maximum line length: narrow 45ch, comfortable 65ch, wide 80ch. |
| ref | Ref<HTMLElement> | — | — |
| size | Responsive<TextSize> | — | Size token; font-size = token × the font role's cap-height scale. |
| tone | TextTone | — | Colour role paired with the background for contrast (Caption defaults to "muted"). |
| tracking | TextTracking | — | Letter spacing. |
| truncate | boolean | — | One line with an ellipsis (clips overflow, so trimming is removed). |
| weight | Responsive<TextWeight> | — | Font weight; Heading defaults to "semibold". |
| wrap | TextWrap | — | Line wrapping strategy (balance suits headings, pretty paragraphs). |
Also accepts the props of: React DOM attributes.
TextSize
type TextSize = "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl"TextWeight
type TextWeight = "light" | "regular" | "medium" | "semibold" | "bold"TextAlign
type TextAlign = "start" | "center" | "end" | "justify"TextLeading
type TextLeading = "none" | "tight" | "snug" | "normal" | "relaxed" | "loose"TextTone
type TextTone = "default" | "muted" | "primary" | "destructive"TextTracking
type TextTracking = "tight" | "normal" | "wide"TextMeasure
type TextMeasure = "narrow" | "comfortable" | "wide" | "none"TextWrap
type TextWrap = "wrap" | "nowrap" | "balance" | "pretty"FontRole
type FontRole = "body" | "display" | "mono"Responsive
A value, or values per breakpoint that cascade upwards (mobile first).
type Responsive = T | { readonly [K in Breakpoint]?: T; }Breakpoint
Responsive keys: base (no media query) plus the application's breakpoint names — the defaults
sm md lg xl 2xl, or the names configured in neshel.config.ts once the declarations generated
by neshel generate are part of the program (ADR 0010).
type Breakpoint = "base" | BreakpointNameSemantics first
as sets the element, size the scale: <Heading as="h2" size="5xl"> is an h2. Levels are never
changed automatically. There is no Title, Subtitle or Code component: use Heading/Paragraph
sizes and <Text as="code" family="mono">.
Errors
Invalid usage throws NeshelTypographyError ([@neshel-ui/typography] <Component>: …) on the
server and the client — invalid values, malformed breakpoint keys, as + asChild, an invalid as,
invalid asChild children, trim on Text.
import { NeshelTypographyError } from "@neshel-ui/typography";
export function isTypographyError(error: unknown): boolean {
return error instanceof NeshelTypographyError;
}Layout composition
Typography sets margin: 0 and nothing else; spacing comes from layout gaps. With trimming, a
Stack space="4" between a heading and a paragraph is exactly 1rem from baseline to cap height.
See Typography and Capsize.