Saltar al contenido principal

Typography

Un componente de texto polimórfico para encabezados, párrafos, texto destacado y estilos en línea consistentes.

This is a default paragraph typography rendering. It uses the default font size, line height, and paragraph spacing.

default.tsx
1'use client';
2
3import { Typography } from '@/components/ui/typography';
4
5export function Default() {
6 return (
7 <Typography variant="p">
8 This is a default paragraph typography rendering. It uses the default font size, line height,
9 and paragraph spacing.
10 </Typography>
11 );
12}

Instalación

pnpm dlx nachui add typography

Anatomía

1import { Typography } from '@/components/ui/typography';
1<Typography variant="h1">Hola Mundo</Typography>
2<Typography variant="p">El texto del cuerpo va aquí.</Typography>
3<Typography variant="muted">Texto de menor énfasis.</Typography>

Ejemplos

Default

This is a default paragraph typography rendering. It uses the default font size, line height, and paragraph spacing.

default.tsx
1'use client';
2
3import { Typography } from '@/components/ui/typography';
4
5export function Default() {
6 return (
7 <Typography variant="p">
8 This is a default paragraph typography rendering. It uses the default font size, line height,
9 and paragraph spacing.
10 </Typography>
11 );
12}

Encabezados

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6
headings.tsx
1'use client';
2
3import { Typography } from '@/components/ui/typography';
4
5const headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
6
7export function Headings() {
8 return (
9 <div className="flex w-full flex-col gap-4">
10 {headings.map((heading) => (
11 <Typography key={heading} variant={heading}>
12 Heading {heading.replace('h', '')}
13 </Typography>
14 ))}
15 </div>
16 );
17}

Lead, Large y Muted

Lead Text

A tall paragraph text style designed to introduce an article or section.

Large Text

Slightly larger copy designed for subheaders, callouts, or featured content.

Small & Muted Text

De-emphasized descriptive text, perfect for captions or legal copy.

lead-muted.tsx
1'use client';
2
3import { Typography } from '@/components/ui/typography';
4
5const items = [
6 {
7 label: 'Lead Text',
8 variant: 'lead' as const,
9 content: 'A tall paragraph text style designed to introduce an article or section.',
10 },
11 {
12 label: 'Large Text',
13 variant: 'large' as const,
14 content: 'Slightly larger copy designed for subheaders, callouts, or featured content.',
15 },
16 {
17 label: 'Small & Muted Text',
18 variant: 'muted' as const,
19 content: 'De-emphasized descriptive text, perfect for captions or legal copy.',
20 },
21];
22
23export function LeadMuted() {
24 return (
25 <div className="flex w-full flex-col gap-4">
26 {items.map(({ label, variant, content }) => (
27 <div key={variant}>
28 <Typography
29 variant="small"
30 className="text-primary mb-1 block font-bold tracking-wider uppercase"
31 >
32 {label}
33 </Typography>
34 <Typography variant={variant}>{content}</Typography>
35 </div>
36 ))}
37 </div>
38 );
39}

Polimórfico (prop as)

Paragraph rendered as Span

This uses paragraph styling but is rendered as a inline `span` tag in the DOM.

Heading rendered as Div

This looks like an H3, but it's actually a `div` element.

Code block rendering

console.log("This automatically renders as a code tag by variant inference");
custom-tag.tsx
1'use client';
2
3import { Typography } from '@/components/ui/typography';
4
5const examples = [
6 {
7 label: 'Paragraph rendered as Span',
8 element: (
9 <Typography as="span" variant="p" className="bg-secondary/20 rounded p-2">
10 This uses paragraph styling but is rendered as a inline `span` tag in the DOM.
11 </Typography>
12 ),
13 },
14 {
15 label: 'Heading rendered as Div',
16 element: (
17 <Typography as="div" variant="h3">
18 This looks like an H3, but it&apos;s actually a `div` element.
19 </Typography>
20 ),
21 },
22 {
23 label: 'Code block rendering',
24 element: (
25 <Typography variant="code">
26 console.log(&quot;This automatically renders as a code tag by variant inference&quot;);
27 </Typography>
28 ),
29 },
30];
31
32export function CustomTag() {
33 return (
34 <div className="flex w-full flex-col gap-6">
35 {examples.map(({ label, element }) => (
36 <div key={label}>
37 <Typography
38 variant="small"
39 className="text-primary mb-1 block font-bold tracking-wider uppercase"
40 >
41 {label}
42 </Typography>
43 {element}
44 </div>
45 ))}
46 </div>
47 );
48}

Referencia de API

Typography

PropTipoPor defectoDescripción
variant'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'blockquote' | 'lead' | 'large' | 'small' | 'muted' | 'code''p'Variante de estilo de texto
asReact.ElementType-Sobrescribe el elemento HTML renderizado
align'left' | 'center' | 'right' | 'justify'-Alineación del texto
weight'light' | 'normal' | 'medium' | 'semibold' | 'bold' | 'extrabold'-Peso de fuente personalizado
classNamestring-Clases CSS adicionales
¿Encontraste algo que mejorar?

¿Notaste un error, tipografía o detalle faltante en esta página? Ayúdanos a mejorar la documentación abriendo un issue en GitHub.

Crear un Issue