existential-birds/beagle / plugins/beagle-react/skills/shadcn-code-review
shadcn-code-review
VerifiedReviews shadcn/ui components for CVA patterns, composition with asChild, accessibility states, and data-slot usage. Use when reviewing React components using shadcn/ui, Radix primitives, or Tailwind styling.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.5 KB |
| references/accessibility.md | markdown | 7.2 KB |
| references/composition.md | markdown | 6.0 KB |
| references/cva-patterns.md | markdown | 5.3 KB |
| references/data-slot.md | markdown | 7.1 KB |
references/cva-patterns.md
View on GitHub# CVA Patterns
## Critical Anti-Patterns
### 1. className Passed to CVA Instead of cn()
**Problem**: CVA variants cannot be overridden by consumers. The className should be passed to cn() after CVA, not as a CVA variant.
```tsx
// BAD - className in CVA
import { cva } from "class-variance-authority"
const buttonVariants = cva("base-styles", {
variants: {
variant: { default: "bg-primary", destructive: "bg-destructive" },
size: { sm: "h-9", lg: "h-11" },
className: {}, // WRONG - className is not a variant
},
})
export function Button({ variant, size, className }) {
return <button className={buttonVariants({ variant, size })} />
}
// GOOD - className in cn()
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva("base-styles", {
variants: {
variant: { default: "bg-primary", destructive: "bg-destructive" },
size: { sm: "h-9", lg: "h-11" },
},
defaultVariants: {
variant: "default",
size: "default",
},
})
export interface ButtonProps extends VariantProps<typeof buttonVariants> {
className?: string
}
export function Button({ variant, size, className, ...props }: ButtonProps) {
return (
<button
className={cn(buttonVariants({ variant, size }), className)}
{...props}
/>
)
}
```
### 2. Missing VariantProps Export
**Problem**: Consumers cannot type-check variant props correctly.
```tsx
// BAD - no type export
const buttonVariants = cva(...)
export function Button({ variant, size }: { variant?: string, size?: string }) {
return <button className={buttonVariants({ variant, size })} />
}
// GOOD - export VariantProps
import { type VariantProps } from "class-variance-authority"
const buttonVariants = cva(...)
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}
export function Button({ variant, size, className, ...props }: ButtonProps) {
return <button className={cn(buttonVariants({ variant, size }), className)} {...props} />
}
```
### 3. Not Using Compound Variants
**Problem**: Complex state combinations create verbose, repetitive variant definitions.
```tsx
// BAD - manual combinations
const buttonVariants = cva("rounded font-medium", {
variants: {
variant: {
default: "bg-primary text-primary-foreground",
outline: "border border-input bg-background",
ghost: "hover:bg-accent hover:text-accent-foreground",
},
size: {
sm: "h-9 px-3 text-xs",
default: "h-10 px-4 py-2",
lg: "h-11 px-8",
},
// Trying to handle all combinations manually - WRONG
variantSize: {
"outline-sm": "border-2", // Don't do this
"ghost-lg": "hover:bg-accent/50",
}
},
})
// GOOD - use compoundVariants
const buttonVariants = cva("rounded font-medium", {
variants: {
variant: {
default: "bg-primary text-primary-foreground",
outline: "border border-input bg-background",
ghost: "hover:bg-accent hover:text-accent-foreground",
},
size: {
sm: "h-9 px-3 text-xs",
default: "h-10 px-4 py-2",
lg: "h-11 px-8",
},
},
compoundVariants: [
{
variant: "outline",
size: "sm",
class: "border-2",
},
{
variant: "ghost",
size: "lg",
class: "hover:bg-accent/50",
},
],
defaultVariants: {
variant: "default",
size: "default",
},
})
```
### 4. Hardcoding State Classes Instead of Variants
**Problem**: State-dependent styling should be variants for consistency and reusability.
```tsx
// BAD - hardcoded state classes
export function Input({ disabled, invalid, className }) {
return (
<input
className={cn(
"rounded border px-3 py-2",
disabled && "opacity-50 cursor-not-allowed",
invalid && "border-red-500",
className
)}
disabled={disabled}
/>
)
}
// GOOD - state variants
const inputVariants = cva("rounded border px-3 py-2", {
variants: {
state: {
default: "",
invalid: "border-destructive focus-visible:ring-destructive",
disabled: "opacity-50 cursor-not-allowed",
},
},
defaultVariants: {
state: "default",
},
})
export function Input({ disabled, invalid, className, ...props }) {
const state = disabled ? "disabled" : invalid ? "invalid" : "default"
return (
<input
className={cn(inputVariants({ state }), className)}
disabled={disabled}
aria-invalid={invalid}
{...props}
/>
)
}
```
### 5. Missing defaultVariants
**Problem**: Component behavior is unpredictable without defaults.
```tsx
// BAD - no defaults
const buttonVariants = cva("base", {
variants: {
variant: { default: "bg-primary", outline: "border" },
size: { sm: "h-9", lg: "h-11" },
},
// Missing defaultVariants - what happens with <Button />?
})
// GOOD - explicit defaults
const buttonVariants = cva("base", {
variants: {
variant: { default: "bg-primary", outline: "border" },
size: { sm: "h-9", lg: "h-11" },
},
defaultVariants: {
variant: "default",
size: "sm",
},
})
```
## Review Questions
1. Is className passed to cn() after CVA variants?
2. Are VariantProps exported for type safety?
3. Are compound variants used for complex state combinations?
4. Are state-dependent styles defined as variants?
5. Are defaultVariants specified for all variant groups?
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies 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 colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |