Saltar al contenido
Neshel-UI
Tipografía

@neshel-ui/typography

Componentes de texto semánticos y basados en métricas, con un vocabulario de props compartido.

pnpm add @neshel-ui/config @neshel-ui/typography
src/index.css
@import "@neshel-ui/config/tokens.css";
@import "@neshel-ui/typography/styles.css";
ComponenteElemento predeterminadoasValores predeterminados
Headingh2h1–h6tamaño según nivel, semibold, fuente display, recortado
Paragraphpp, divtamaño base, fuente body, recortado
Captionpp, span, div, small, figcaptiontamaño sm, tono muted, recortado
Textspanelementos de fraselo hereda todo; nunca se recorta

Props compartidas

PropValoresAdaptable
sizexs sm base lg xl 2xl 3xl 4xl 5xl 6xlsí
weightlight regular medium semibold boldsí
alignstart center end justifysí
leadingnone tight snug normal relaxed loose (sin unidades)sí
tonedefault muted primary destructive (emparejados por contraste)no
familybody display monono
trackingtight normal wideno
measurenarrow 45ch, comfortable 65ch, wide 80ch, noneno
wrapwrap nowrap balance prettyno
truncateuna línea con puntos suspensivosno
trimrecorte de Capsize, true por defecto (no en Text)no

Escala de tamaños (rem / interlineado predeterminado): 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.

Vista previa: typography-responsive
Tema de la vista previa

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

Props visuales comunes a todos los componentes de tipografía (contracts/typography-api.md).

TypographyProps
PropTipoPredeterminadoDescripción
alignResponsive<TextAlign>—Alineación del texto (lógica: start/end).
familyFontRole—Rol de fuente (Heading "display", Paragraph y Caption "body"; Text hereda).
leadingResponsive<TextLeading>—Interlineado sin unidades; por defecto, el del tamaño. Controla el recorte de Capsize.
measureTextMeasure—Longitud máxima de línea: narrow 45ch, comfortable 65ch, wide 80ch.
refRef<HTMLElement>——
sizeResponsive<TextSize>—Token de tamaño; font-size = token × la escala de altura de mayúsculas del rol de fuente.
toneTextTone—Rol de color emparejado con el fondo por contraste (Caption usa "muted" por defecto).
trackingTextTracking—Espaciado entre letras.
truncateboolean—Una línea con puntos suspensivos (recorta el desbordamiento, así que se elimina el recorte de Capsize).
weightResponsive<TextWeight>—Peso de la fuente; Heading usa "semibold" por defecto.
wrapTextWrap—Estrategia de ajuste de línea (balance encaja con encabezados, pretty con párrafos).

También acepta las props de: 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

Un valor, o valores por breakpoint que se heredan hacia arriba (mobile first).

type Responsive = T | { readonly [K in Breakpoint]?: T; }

Breakpoint

Claves adaptables: base (sin media query) más los nombres de breakpoint de la aplicación: los predeterminados sm md lg xl 2xl, o los configurados en neshel.config.ts cuando las declaraciones generadas por neshel generate forman parte del programa (ADR 0010).

type Breakpoint = "base" | BreakpointName

Primero la semántica

as fija el elemento y size la escala: <Heading as="h2" size="5xl"> es un h2. Los niveles nunca cambian automáticamente. No hay componentes Title, Subtitle ni Code: usa tamaños de Heading/Paragraph y <Text as="code" family="mono">.

Errores

Un uso incorrecto lanza NeshelTypographyError ([@neshel-ui/typography] <Componente>: …) en el servidor y en el cliente: valores inválidos, claves de breakpoint mal formadas, as + asChild, un as inválido, hijos inválidos de asChild, trim en Text.

detect-error.tsx
import { NeshelTypographyError } from "@neshel-ui/typography";

export function isTypographyError(error: unknown): boolean {
  return error instanceof NeshelTypographyError;
}

Composición con el layout

La tipografía establece margin: 0 y nada más; el espaciado viene de los espacios del layout. Con el recorte, un Stack space="4" entre un encabezado y un párrafo mide exactamente 1rem desde la línea base hasta la altura de las mayúsculas. Consulta Tipografía y Capsize.

Editar en GitHub

En esta página