P PasteCode
Rule

Regras do Cursor para Tailwind CSS e shadcn/ui

Regras do Cursor que aplicam convenções do Tailwind v4 e padrões de componentes shadcn/ui, evitando que agentes reinventem primitivas que já existem.

Cursor Next.jsTypeScriptTailwind
.md .json Atualizado 8 de jun. de 2026

Cole isso em .cursor/rules/tailwind-shadcn.mdc (ou no arquivo de regras do Cursor do seu projeto). O Cursor carrega todos os arquivos .mdc em .cursor/rules/ automaticamente ao abrir o projeto.

Arquivo de Regras do Cursor

Cursor Rules
# Tailwind CSS + shadcn/ui Rules
## Tailwind conventions
- Use Tailwind CSS v4. Class names follow the v4 API — do NOT use deprecated v3
class names (e.g. use `shadow-sm` not `drop-shadow-sm` for box shadows on elements).
- All utility classes must be static strings so Tailwind's content scanner can detect
them. Never build class names with string concatenation or template literals unless
the full class name is in the source (e.g. `bg-${color}` is forbidden; use a lookup
object instead).
- Class order: layout → box model → typography → visual (bg, border, shadow) →
interactive (hover, focus) → responsive breakpoints. Use `prettier-plugin-tailwindcss`
to enforce this automatically — do not manually reorder.
- Never write custom CSS for spacing, color, or typography that can be expressed with a
Tailwind utility. Custom CSS lives in `src/styles/` and must be justified by a comment.
- Use `cn()` from `@/lib/utils` to merge conditional classes. Never use `clsx` or
`classnames` directly elsewhere — they are already re-exported from `cn()`.
## shadcn/ui conventions
- Before creating a new UI component, check `src/components/ui/` for an existing
shadcn/ui primitive. Use it. Do not re-implement Button, Dialog, Input, Select,
Tooltip, or any other component that shadcn already provides.
- Add new shadcn components with `npx shadcn@latest add <component>` — never copy-paste
component source manually from the docs.
- Extend shadcn components by wrapping them, not by editing the file in
`src/components/ui/` directly. Edits there are overwritten by future `shadcn add` runs.
- Use shadcn's `variant` and `size` props before adding className overrides. If a new
variant is needed, add it to the component's `cva()` definition in `src/components/ui/`.
- Dark mode is handled by the `dark` class on `<html>`. Never use `prefers-color-scheme`
media queries alongside shadcn — they conflict with the class strategy.
- Do not install `@radix-ui/*` packages directly. They are transitive dependencies of
shadcn components; adding them directly risks version mismatches.
## Accessibility
- Every interactive shadcn component must have an accessible label. Use `aria-label`,
`aria-labelledby`, or a visually-hidden `<span>` — never omit it.
- Icon-only buttons must include `<span className="sr-only">Description</span>`.
## Definition of done
- `bun run build` completes without Tailwind class warnings.
- No `className` strings contain dynamic concatenation (`bg-` + variable).
- No new Radix packages in `package.json` that aren't installed via `shadcn add`.
- Storybook (if present) renders the new/modified component without console errors.

Por que essas regras

  • “Verifique src/components/ui/ antes de criar qualquer coisa” é a regra de maior valor para projetos shadcn. Os agentes tendem a escrever componentes personalizados — um <Button> customizado, um <Select> feito à mão — que duplicam as primitivas shadcn já existentes no repositório. Isso desperdiça tokens, cria inconsistência e ignora o trabalho de acessibilidade que o shadcn oferece gratuitamente.
  • Strings de nome de classe estáticas é uma restrição rígida do scanner do Tailwind. Os agentes produzem rotineiramente interpolações no estilo bg-${color}-500 que compilam mas não geram CSS em tempo de execução, causando bugs de estilo invisíveis que só aparecem em builds de produção.

Boa adequação

  • Projetos Next.js ou Astro que já usam shadcn/ui com Tailwind v4, onde o principal risco é os agentes duplicarem primitivas existentes ou lutarem contra o sistema de design.

Não é adequado

  • Projetos que usam CSS Modules, Emotion ou Styled Components — as regras de ordem de classes do Tailwind são irrelevantes e cn() não existe.