Design Systems · 8 min read · Beginner
Reusable Components & Avoiding Dynamic Class Bugs
Build clean variant props in React/Astro components without breaking Tailwind's static scanner.
What you'll learn
- Extract repeated card/button patterns into React or Astro components
- Use static lookup objects (`TONES[tone]`) for variants
- Keep `@apply` minimal and prefer component composition
Overview
Build clean variant props in React/Astro components without breaking Tailwind’s static scanner.
Code Example
const TONES = {
primary: 'bg-blue-600 text-white hover:bg-blue-700',
ghost: 'bg-slate-100 text-slate-900 hover:bg-slate-200',
} as const;
export function Button({ tone = 'primary', children }: { tone?: keyof typeof TONES; children: React.ReactNode }) {
return <button className={`inline-flex min-h-11 items-center rounded-2xl px-5 font-semibold transition ${TONES[tone]}`}>{children}</button>;
}
Key Takeaways
- Extract repeated card/button patterns into React or Astro components
- Use static lookup objects (
TONES[tone]) for variants - Keep
@applyminimal and prefer component composition
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why does ``bg-${status}-500`` fail to render styles in production Tailwind builds?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.