Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Add, manage, and compose shadcn/ui components with correct patterns, styling, and CLI workflows.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/styling.md
1# Styling & Customization23See [customization.md](../customization.md) for theming, CSS variables, and adding custom colors.45## Contents67- Semantic colors8- Built-in variants first9- className for layout only10- No space-x-* / space-y-*11- Prefer size-* over w-* h-* when equal12- Prefer truncate shorthand13- No manual dark: color overrides14- Use cn() for conditional classes15- No manual z-index on overlay components16- Use shimmer / scroll-fade utilities, not custom animations1718---1920## Semantic colors2122**Incorrect:**2324```tsx25<div className="bg-blue-500 text-white">26<p className="text-gray-600">Secondary text</p>27</div>28```2930**Correct:**3132```tsx33<div className="bg-primary text-primary-foreground">34<p className="text-muted-foreground">Secondary text</p>35</div>36```3738---3940## No raw color values for status/state indicators4142For positive, negative, or status indicators, use Badge variants, semantic tokens like `text-destructive`, or define custom CSS variables — don't reach for raw Tailwind colors.4344**Incorrect:**4546```tsx47<span className="text-emerald-600">+20.1%</span>48<span className="text-green-500">Active</span>49<span className="text-red-600">-3.2%</span>50```5152**Correct:**5354```tsx55<Badge variant="secondary">+20.1%</Badge>56<Badge>Active</Badge>57<span className="text-destructive">-3.2%</span>58```5960If you need a success/positive color that doesn't exist as a semantic token, use a Badge variant or ask the user about adding a custom CSS variable to the theme (see [customization.md](../customization.md)).6162---6364## Built-in variants first6566**Incorrect:**6768```tsx69<Button className="border border-input bg-transparent hover:bg-accent">70Click me71</Button>72```7374**Correct:**7576```tsx77<Button variant="outline">Click me</Button>78```7980---8182## className for layout only8384Use `className` for layout (e.g. `max-w-md`, `mx-auto`, `mt-4`), **not** for overriding component colors or typography. To change colors, use semantic tokens, built-in variants, or CSS variables.8586**Incorrect:**8788```tsx89<Card className="bg-blue-100 text-blue-900 font-bold">90<CardContent>Dashboard</CardContent>91</Card>92```9394**Correct:**9596```tsx97<Card className="max-w-md mx-auto">98<CardContent>Dashboard</CardContent>99</Card>100```101102To customize a component's appearance, prefer these approaches in order:1031. **Built-in variants** — `variant="outline"`, `variant="destructive"`, etc.1042. **Semantic color tokens** — `bg-primary`, `text-muted-foreground`.1053. **CSS variables** — define custom colors in the global CSS file (see [customization.md](../customization.md)).106107---108109## No space-x-* / space-y-*110111Use `gap-*` instead. `space-y-4` → `flex flex-col gap-4`. `space-x-2` → `flex gap-2`.112113```tsx114<div className="flex flex-col gap-4">115<Input />116<Input />117<Button>Submit</Button>118</div>119```120121---122123## Prefer size-* over w-* h-* when equal124125`size-10` not `w-10 h-10`. Applies to icons, avatars, skeletons, etc.126127---128129## Prefer truncate shorthand130131`truncate` not `overflow-hidden text-ellipsis whitespace-nowrap`.132133---134135## No manual dark: color overrides136137Use semantic tokens — they handle light/dark via CSS variables. `bg-background text-foreground` not `bg-white dark:bg-gray-950`.138139---140141## Use cn() for conditional classes142143Use the `cn()` utility from the project for conditional or merged class names. Don't write manual ternaries in className strings.144145**Incorrect:**146147```tsx148<div className={`flex items-center ${isActive ? "bg-primary text-primary-foreground" : "bg-muted"}`}>149```150151**Correct:**152153```tsx154import { cn } from "@/lib/utils"155156<div className={cn("flex items-center", isActive ? "bg-primary text-primary-foreground" : "bg-muted")}>157```158159---160161## No manual z-index on overlay components162163`Dialog`, `Sheet`, `Drawer`, `AlertDialog`, `DropdownMenu`, `Popover`, `Tooltip`, `HoverCard` handle their own stacking. Never add `z-50` or `z-[999]`.164165---166167## Use shimmer / scroll-fade utilities, not custom animations168169For a live "thinking…" or loading-text shimmer, apply the `shimmer` utility. Don't author a custom `@keyframes` or a `bg-clip-text` gradient sweep.170171For scroll-aware edge fading on a scroll container, use `scroll-fade` (and the axis variants `scroll-fade-x` / `scroll-fade-b`). Don't hand-roll mask gradients. The chat components already apply these internally: `Attachment` shimmers its title during upload, and `MessageScrollerViewport` fades its edges.172173**Incorrect:**174175```tsx176<span className="animate-pulse bg-gradient-to-r from-muted-foreground/40 via-foreground/70 to-muted-foreground/40 bg-clip-text text-transparent [animation:shimmer_1.6s_infinite]">177Thinking…178</span>179```180181**Correct:**182183```tsx184<span className="shimmer">Thinking…</span>185```186