Skip to Content
Neshel-UI
Typography

@neshel-ui/typography

Semantic, metrics-aware text components with a shared prop vocabulary.

pnpm add @neshel-ui/config @neshel-ui/typography
src/index.css
@import "@neshel-ui/config/tokens.css";
@import "@neshel-ui/typography/styles.css";
ComponentDefault elementasDefaults
Headingh2h1–h6size by level, semibold, display font, trimmed
Paragraphpp, divsize base, body font, trimmed
Captionpp, span, div, small, figcaptionsize sm, tone muted, trimmed
Textspanphrasing elementsinherits everything; never trimmed

Shared props

PropValuesResponsive
sizexs sm base lg xl 2xl 3xl 4xl 5xl 6xlyes
weightlight regular medium semibold boldyes
alignstart center end justifyyes
leadingnone tight snug normal relaxed loose (unitless)yes
tonedefault muted primary destructive (contrast-paired)no
familybody display monono
trackingtight normal wideno
measurenarrow 45ch, comfortable 65ch, wide 80ch, noneno
wrapwrap nowrap balance prettyno
truncateone line with an ellipsisno
trimCapsize 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.

Preview: typography-responsive
Preview theme

Rooted in faith. Built with hope.

Size, weight, alignment and leading accept a value per breakpoint.

typography-responsive.tsx
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).

TypographyProps
PropTypeDefaultDescription
alignResponsive<TextAlign>—Text alignment (logical: start/end).
familyFontRole—Font role (Heading "display", Paragraph and Caption "body"; Text inherits).
leadingResponsive<TextLeading>—Unitless line height; defaults to the size's leading. Drives Capsize trimming.
measureTextMeasure—Maximum line length: narrow 45ch, comfortable 65ch, wide 80ch.
refRef<HTMLElement>——
sizeResponsive<TextSize>—Size token; font-size = token × the font role's cap-height scale.
toneTextTone—Colour role paired with the background for contrast (Caption defaults to "muted").
trackingTextTracking—Letter spacing.
truncateboolean—One line with an ellipsis (clips overflow, so trimming is removed).
weightResponsive<TextWeight>—Font weight; Heading defaults to "semibold".
wrapTextWrap—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" | BreakpointName

Semantics 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.

detect-error.tsx
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.

Edit on GitHub

On this page