|
| 1 | +--- |
| 2 | +description: Enforce HeroUI usage for all UI components, styling, and theming. |
| 3 | +globs: **/*.{ts,tsx,js,jsx} |
| 4 | +--- |
| 5 | + |
| 6 | +# HeroUI Usage Rules |
| 7 | + |
| 8 | +## Core Principle |
| 9 | +- Use **HeroUI** (formerly NextUI) for ALL UI components, layout, and styling where possible. |
| 10 | +- Avoid using raw Radix UI primitives unless HeroUI does not provide a suitable component. HeroUI is already built on top of `react-aria` and `framer-motion`, so additional headless libraries are rarely needed. |
| 11 | + |
| 12 | +## Installation & Management |
| 13 | +- **CLI**: Use the HeroUI CLI to add new components. |
| 14 | + ```bash |
| 15 | + npx heroui-cli@latest add <component-name> |
| 16 | + ``` |
| 17 | +- Do not manually install component packages unless necessary. |
| 18 | + |
| 19 | +## Setup & Providers |
| 20 | +- Ensure the application is wrapped in `HeroUIProvider`. |
| 21 | +- For Next.js (App Router), this should be in a client component (e.g., `app/providers.tsx`) that wraps the `children` in the root layout. |
| 22 | +- Use `next-themes` for dark mode support, wrapping the `HeroUIProvider`. |
| 23 | + |
| 24 | +```tsx |
| 25 | +// app/providers.tsx |
| 26 | +"use client"; |
| 27 | + |
| 28 | +import { HeroUIProvider } from "@heroui/system"; |
| 29 | +import { ThemeProvider as NextThemesProvider } from "next-themes"; |
| 30 | + |
| 31 | +export function Providers({ children }: { children: React.ReactNode }) { |
| 32 | + return ( |
| 33 | + <HeroUIProvider> |
| 34 | + <NextThemesProvider attribute="class" defaultTheme="dark"> |
| 35 | + {children} |
| 36 | + </NextThemesProvider> |
| 37 | + </HeroUIProvider> |
| 38 | + ); |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## Styling & Theming |
| 43 | +- **Tailwind CSS**: HeroUI relies on Tailwind CSS. Ensure `tailwind.config.ts` (or `.js`) is configured with the `heroui()` plugin. |
| 44 | +- **Customization**: Customize themes (colors, layout, radii) inside the `heroui()` plugin configuration in `tailwind.config.ts`. |
| 45 | + - Define custom color palettes (semantic colors like `primary`, `secondary`, `success`, etc.). |
| 46 | + - Create custom variants using `tv` (Tailwind Variants) if needed for specific component overrides. |
| 47 | + |
| 48 | +## Components |
| 49 | +Always prioritize using these HeroUI components over standard HTML elements or other libraries: |
| 50 | + |
| 51 | +- **Layout**: `Navbar`, `Divider`, `Spacer`, `ScrollShadow` |
| 52 | +- **Forms**: `Input`, `Textarea`, `Select`, `Checkbox`, `RadioGroup`, `Switch`, `Slider`, `DateInput`, `DatePicker`, `DateRangePicker`, `TimeInput`, `NumberInput`, `InputOTP`, `Form` |
| 53 | +- **Navigation**: `Link`, `Breadcrumbs`, `Pagination`, `Tabs`, `Listbox`, `Dropdown` |
| 54 | +- **Feedback**: `Alert`, `Spinner`, `Progress`, `CircularProgress`, `Skeleton`, `Chip`, `Badge`, `Toast`, `Tooltip`, `Popover` |
| 55 | +- **Overlays**: `Modal`, `Drawer` |
| 56 | +- **Data Display**: `Table`, `Card`, `Accordion`, `User`, `Avatar`, `Image`, `Code`, `Snippet`, `Kbd` |
| 57 | +- **Interactive**: `Button`, `Ripple` (internal) |
| 58 | + |
| 59 | +## Best Practices |
| 60 | +- **Server vs Client**: HeroUI components are interactive and generally require `"use client"`. Keep server components as parents and pass data down to HeroUI client components. |
| 61 | +- **Accessibility**: HeroUI handles most a11y requirements. Ensure you provide `aria-label` or `aria-labelledby` for inputs and buttons without visible text. |
| 62 | +- **Icons**: Use a compatible icon library like `lucide-react` or `heroicons` passed as props to components (e.g., `startContent`, `endContent`). |
| 63 | + |
| 64 | +## Example: Adding a Button |
| 65 | +Do NOT use `<button className="...">`. |
| 66 | +Use: |
| 67 | +```tsx |
| 68 | +import { Button } from "@heroui/button"; |
| 69 | + |
| 70 | +<Button color="primary" variant="shadow" onPress={handlePress}> |
| 71 | + Action |
| 72 | +</Button> |
| 73 | +``` |
0 commit comments