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