class-variance-authority
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "class-variance-authority" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-56e3ece3bae225004f21300d0d10015a42d05e8844cf4283d66d2c1be11c428b. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Use Class Variance Authority (CVA) to define component variants. Suitable for creating variant-based components with Tailwind, building design system tokens, or managing complex conditional class names in React.
Introduction source: third_party · TerminalSkills · 1.0.0 Reference
SkillPi interpretation
- Testing
- Not tested
Browse files
Frontmatter
name: class-variance-authority
description: >-
Define component variants with CVA. Use when creating variant-based
components with Tailwind, building design system tokens, or managing
complex conditional class names in React.
license: Apache-2.0
compatibility: 'Any framework with Tailwind CSS'
metadata:
author: terminal-skills
version: 1.0.0
category: development
tags: [cva, tailwind, variants, design-system, components]Class Variance Authority (CVA)
Overview
CVA creates type-safe component variants with Tailwind. Define base styles, variants (size, color, state), compound variants, and defaults. Works with any framework. Powers the variant system in shadcn/ui.
Instructions
Step 1: Define Variants
// components/button.tsx — Button with CVA variants
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/lib/utils'
const buttonVariants = cva(
// Base styles — always applied
'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50',
{
variants: {
variant: {
default: 'bg-blue-600 text-white hover:bg-blue-700',
secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200',
destructive: 'bg-red-600 text-white hover:bg-red-700',
outline: 'border border-gray-300 bg-transparent hover:bg-gray-50',
ghost: 'hover:bg-gray-100',
link: 'text-blue-600 underline-offset-4 hover:underline',
},
size: {
sm: 'h-8 px-3 text-xs',
md: 'h-10 px-4 text-sm',
lg: 'h-12 px-6 text-base',
icon: 'h-10 w-10',
},
},
compoundVariants: [
// Destructive + outline = red border
{ variant: 'outline', className: 'border-2' },
{ variant: 'destructive', size: 'lg', className: 'text-lg font-bold' },
],
defaultVariants: {
variant: 'default',
size: 'md',
},
}
)
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {}
function Button({ className, variant, size, ...props }: ButtonProps) {
return <button className={cn(buttonVariants({ variant, size }), className)} {...props} />
}
Step 2: Complex Components
const badgeVariants = cva(
'inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold',
{
variants: {
status: {
active: 'bg-green-100 text-green-800',
inactive: 'bg-gray-100 text-gray-600',
warning: 'bg-yellow-100 text-yellow-800',
error: 'bg-red-100 text-red-800',
},
size: {
sm: 'text-[10px] px-1.5 py-0',
md: 'text-xs px-2.5 py-0.5',
lg: 'text-sm px-3 py-1',
},
},
defaultVariants: { status: 'active', size: 'md' },
}
)
// Usage
<Badge status="active">Online</Badge>
<Badge status="error" size="sm">Failed</Badge>
Guidelines
- CVA is for defining variants. Use
cn()(clsx + tailwind-merge) for conditional classes. compoundVariantsfor combinations that need special treatment (e.g., destructive + outline).VariantProps<typeof variants>gives you TypeScript types for free.- Keep CVA definitions close to their component — one file per component.
- Works with any CSS framework, but shines with Tailwind's utility classes.
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决前端开发中条件类名管理的实际痛点
- 适用于 Tailwind + React 技术栈,受众明确
Highlights
- 触发词覆盖合理,边界清晰
- description 明确说明适用场景和技术栈
Areas to improve
-
缺少 When to Use 显式章节 Reported severity: Minor
文档结构完整但缺少显式的 When to Use 使用场景说明章节
Recommendation: 建议添加 When to Use 章节,更清晰地说明具体使用时机和场景
Highlights
- 结构清晰,步骤划分明确
- 包含完整代码示例和 TypeScript 类型定义
- frontmatter 信息完整规范
Highlights
- 工具来源明确,参数使用正确
- 包含 compoundVariants 和 defaultVariants 高级用法
- 遵循 CVA 最佳实践(配合 cn() 使用)
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.