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
5export function Headings() {
6 return (
7 <div className="flex w-full flex-col gap-4">
8 <Typography variant="h1">Heading 1</Typography>
9 <Typography variant="h2">Heading 2</Typography>
10 <Typography variant="h3">Heading 3</Typography>
11 <Typography variant="h4">Heading 4</Typography>
12 <Typography variant="h5">Heading 5</Typography>
13 <Typography variant="h6">Heading 6</Typography>
14 </div>
15 );
16}

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
5export function LeadMuted() {
6 return (
7 <div className="flex w-full flex-col gap-4">
8 <div>
9 <Typography
10 variant="small"
11 className="text-primary mb-1 block font-bold tracking-wider uppercase"
12 >
13 Lead Text
14 </Typography>
15 <Typography variant="lead">
16 A tall paragraph text style designed to introduce an article or section.
17 </Typography>
18 </div>
19
20 <div>
21 <Typography
22 variant="small"
23 className="text-primary mb-1 block font-bold tracking-wider uppercase"
24 >
25 Large Text
26 </Typography>
27 <Typography variant="large">
28 Slightly larger copy designed for subheaders, callouts, or featured content.
29 </Typography>
30 </div>
31
32 <div>
33 <Typography
34 variant="small"
35 className="text-primary mb-1 block font-bold tracking-wider uppercase"
36 >
37 Small & Muted Text
38 </Typography>
39 <Typography variant="muted">
40 De-emphasized descriptive text, perfect for captions or legal copy.
41 </Typography>
42 </div>
43 </div>
44 );
45}

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

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