โจ Typography Component
The Typography component provides a consistent way to apply text styles across your application using a combination of TailwindCSS utility classes and variant-driven props. It supports responsive font sizing and weight control with a simple API.
- Supports all Tailwind typography sizes (
xsto7xl) - Font weight variants (
normaltoextrabold) - Responsive scaling built in
(sm, md, etc.) - Flexible
asprop to render any HTML element - Built using
class-variance-authorityandcn()
๐งฉ Usage
<Typography variant="2xl/semibold" as="h1">
Elegant Headings
</Typography>
<Typography variant="base/normal">
This is body text using the base font size and normal weight.
</Typography>
<Typography variant="sm/extrabold" as="span">
Small but bold!
</Typography>๐งช Variants
You can control the text size and weight using the variant prop. It uses a string format: <fontSize>/<fontWeight> (e.g. "xl/bold","sm/medium").
| Font Size | Variant Example |
|---|---|
| xs | variant="xs/bold"โ text-xs font-bold |
| base | variant="base/medium"โ text-sm font-medium |
| 4xl | variant="4xl/semibold"โ text-2xl font-semibold |
| 7xl | variant="7xl/extrabold"โ text-5xl sm:text-6xl md:text-7xl font-extrabold |
๐งฑ Props
| Prop | Type | Description |
|---|---|---|
| variant | "xs/normal" | "2xl/bold" | Controls font size and weight |
| as | React.ElementType | Element to render (e.g. p, h2, span) |
| className | string | Additional classes to merge |
| ...props | HTMLAttributes | All valid HTML props |
๐ Example Showcase
Typography: xl/bold
<Typography variant="xl/bold" />Typography: 4xl/normal
<Typography variant="4xl/normal" />Typography: sm/extrabold
<Typography variant="sm/extrabold" />Typography: 2xl/medium as h2
<Typography variant="2xl/medium" as="h2" />๐ก Design Tip
Use Typography as your default text component to ensure your site has consistent spacing, font sizes, and responsive behavior. No need to replicate the same classes over and over again.