tailwind-components
БесплатноБез исполняемых скриптовНе проверенUse when building reusable component patterns with Tailwind CSS. Covers component extraction, @apply directive, and composable design patterns.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
Tailwind CSS - Component Patterns
While Tailwind is utility-first, you'll often want to extract common patterns into reusable components. This skill covers strategies for building maintainable component architectures with Tailwind.
Key Concepts
Component Extraction Strategies
There are several approaches to creating reusable components with Tailwind:
- Template/Component Abstraction (Recommended)
- CSS
@applyDirective (Use sparingly) - JavaScript/TypeScript Component Classes
- Tailwind Plugins
Template Component Abstraction
The most maintainable approach is to extract components at the template level:
// Button.tsx
interface ButtonProps {
variant?: 'primary' | 'secondary' | 'outline'
size?: 'sm' | 'md' | 'lg'
children: React.ReactNode
onClick?: () => void
}
export function Button({
variant = 'primary',
size = 'md',
children,
onClick
}: ButtonProps) {
const baseClasses = 'font-semibold rounded transition-colors focus:ring-2 focus:ring-offset-2'
const variantClasses = {
primary: 'bg-blue-500 hover:bg-blue-600 text-white focus:ring-blue-300',
secondary: 'bg-gray-500 hover:bg-gray-600 text-white focus:ring-gray-300',
outline: 'border-2 border-blue-500 text-blue-500 hover:bg-blue-50 focus:ring-blue-300',
}
const sizeClasses = {
sm: 'px-3 py-1.5 text-sm',
md: 'px-4 py-2 text-base',
lg: 'px-6 py-3 text-lg',
}
return (
<button
className={`${baseClasses} ${variantClasses[variant]} ${sizeClasses[size]}`}
onClick={onClick}
>
{children}
</button>
)
}
Best Practices
1. Use Class Variance Authority (CVA)
For complex component variants, use cva for better type safety:
import { cva, type VariantProps } from 'class-variance-authority'
const button = cva(
// Base classes
'font-semibold rounded transition-colors focus:ring-2',
{
variants: {
intent: {
primary: 'bg-blue-500 hover:bg-blue-600 text-white',
secondary: 'bg-gray-500 hover:bg-gray-600 text-white',
danger: 'bg-red-500 hover:bg-red-600 text-white',
},
size: {
small: 'text-sm px-3 py-1.5',
medium: 'text-base px-4 py-2',
large: 'text-lg px-6 py-3',
},
disabled: {
true: 'opacity-50 cursor-not-allowed',
},
},
compoundVariants: [
{
intent: 'primary',
size: 'medium',
className: 'uppercase',
},
],
defaultVariants: {
intent: 'primary',
size: 'medium',
},
}
)
interface ButtonProps extends VariantProps<typeof button> {
children: React.ReactNode
}
export function Button({ intent, size, disabled, children }: ButtonProps) {
return (
<button className={button({ intent, size, disabled })}>
{children}
</button>
)
}
2. Use clsx/cn for Conditional Classes
Combine multiple class strings efficiently:
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
// Usage
<div className={cn(
'base-classes',
isActive && 'active-classes',
isDisabled && 'disabled-classes',
className // Allow props override
)} />
3. Create Compound Components
Build flexible component APIs:
// Card.tsx
interface CardProps {
children: React.ReactNode
className?: string
}
export function Card({ children, className }: CardProps) {
return (
<div className={cn(
'bg-white rounded-lg shadow-md overflow-hidden',
className
)}>
{children}
</div>
)
}
Card.Header = function CardHeader({ children, className }: CardProps) {
return (
<div className={cn('px-6 py-4 border-b border-gray-200', className)}>
{children}
</div>
)
}
Card.Body = function CardBody({ children, className }: CardProps) {
return (
<div className={cn('px-6 py-4', className)}>
{children}
</div>
)
}
Card.Footer = function CardFooter({ children, className }: CardProps) {
return (
<div className={cn('px-6 py-4 bg-gray-50 border-t border-gray-200', className)}>
{children}
</div>
)
}
// Usage
<Card>
<Card.Header>
<h2 className="text-xl font-bold">Title</h2>
</Card.Header>
<Card.Body>
<p>Content goes here</p>
</Card.Body>
<Card.Footer>
<button>Action</button>
</Card.Footer>
</Card>
4. Use @apply Sparingly
Only use @apply for truly reusable base styles:
/* globals.css */
@layer components {
.btn {
@apply px-4 py-2 rounded font-semibold transition-colors;
}
.btn-primary {
@apply bg-blue-500 hover:bg-blue-600 text-white;
}
.btn-secondary {
@apply bg-gray-500 hover:bg-gray-600 text-white;
}
}
Note: Prefer component abstraction over @apply to maintain Tailwind's utility-first benefits.
5. Design System Integration
Create a centralized design system:
// design-syste
Установить tailwind-components в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGrepGlobFAQ
Что делает скилл tailwind-components?
Use when building reusable component patterns with Tailwind CSS. Covers component extraction, @apply directive, and composable design patterns.
Как установить скилл tailwind-components?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tailwind-components запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic