@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@import "@neshel-ui/config/tokens.css";
@import "@neshel-ui/typography/styles.css";| Componente | Elemento predeterminado | as | Valores predeterminados |
|---|---|---|---|
| Heading | h2 | h1–h6 | tamaño según nivel, semibold, fuente display, recortado |
| Paragraph | p | p, div | tamaño base, fuente body, recortado |
| Caption | p | p, span, div, small, figcaption | tamaño sm, tono muted, recortado |
| Text | span | elementos de frase | lo hereda todo; nunca se recorta |
Props compartidas
| Prop | Valores | Adaptable |
|---|---|---|
size | xs sm base lg xl 2xl 3xl 4xl 5xl 6xl | sí |
weight | light regular medium semibold bold | sí |
align | start center end justify | sí |
leading | none tight snug normal relaxed loose (sin unidades) | sí |
tone | default muted primary destructive (emparejados por contraste) | 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 | una línea con puntos suspensivos | no |
trim | recorte 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.
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
Props visuales comunes a todos los componentes de tipografía (contracts/typography-api.md).
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| align | Responsive<TextAlign> | — | Alineación del texto (lógica: start/end). |
| family | FontRole | — | Rol de fuente (Heading "display", Paragraph y Caption "body"; Text hereda). |
| leading | Responsive<TextLeading> | — | Interlineado sin unidades; por defecto, el del tamaño. Controla el recorte de Capsize. |
| measure | TextMeasure | — | Longitud máxima de línea: narrow 45ch, comfortable 65ch, wide 80ch. |
| ref | Ref<HTMLElement> | — | — |
| size | Responsive<TextSize> | — | Token de tamaño; font-size = token × la escala de altura de mayúsculas del rol de fuente. |
| tone | TextTone | — | Rol de color emparejado con el fondo por contraste (Caption usa "muted" por defecto). |
| tracking | TextTracking | — | Espaciado entre letras. |
| truncate | boolean | — | Una línea con puntos suspensivos (recorta el desbordamiento, así que se elimina el recorte de Capsize). |
| weight | Responsive<TextWeight> | — | Peso de la fuente; Heading usa "semibold" por defecto. |
| wrap | TextWrap | — | 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" | BreakpointNamePrimero 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.
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.