From 3aedc574d7dfa3189b01bc56b122eae6657e3214 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 26 Sep 2025 20:59:43 -0500 Subject: [PATCH] Add TailwindCSS @apply guidelines - Document prohibition of @apply at-rule in AGENTS.md - Add explanatory comment in index.css about @apply policy - Promote component-driven styling approach over @apply usage - Note exceptions for shadcn/ui base layer styles --- AGENTS.md | 38 ++++++++++++++++++++++++++++++++++++++ src/index.css | 11 +++++++++++ 2 files changed, 49 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index f6e89c6..15db6fb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1077,6 +1077,44 @@ When users specify color schemes: - Implement responsive design with Tailwind breakpoints - Add hover and focus states for interactive elements +### TailwindCSS Guidelines + +**CRITICAL**: Avoid using the `@apply` at-rule in CSS files. Instead, create custom components with the desired className and wrap elements where that style should be applied. + +The `@apply` directive is non-standard CSS and goes against the component-driven design philosophy of Tailwind. It creates implicit dependencies and makes styles harder to trace and maintain. + +**✅ Correct - Component-based approach:** +```tsx +// Create a custom component +function PrimaryButton({ children, className, ...props }: ButtonProps) { + return ( + + ); +} + +// Use the component +Click me +``` + +**❌ Wrong - Using @apply:** +```css +.primary-button { + @apply bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded; +} +``` + +This approach: +- Keeps styles co-located with components +- Makes styling explicit and traceable +- Follows React component patterns +- Enables better TypeScript integration +- Supports proper className composition with `cn()` + ## Writing Tests vs Running Tests There is an important distinction between **writing new tests** and **running existing tests**: diff --git a/src/index.css b/src/index.css index 33fdf9d..7aa1ccf 100644 --- a/src/index.css +++ b/src/index.css @@ -2,6 +2,17 @@ @tailwind components; @tailwind utilities; +/* + * IMPORTANT: The use of @apply is generally forbidden in this project. + * + * @apply is non-standard CSS and goes against the component-driven design philosophy + * of Tailwind. Instead of using @apply, create custom React components with the + * desired className and wrap elements where that style should be applied. + * + * The only exceptions are the base layer styles below, which are necessary for + * the shadcn/ui design system and global element defaults. + */ + @layer base { :root { --background: 0 0% 100%;