Skip to content

React Components prompt

Rules that make your coding agent build and extend shadcn/ui in React 19 and Tailwind CSS v4: parts with data-slot, cva variants, oklch tokens, Radix or Base UI, and accessible forms.

What it makes your agent good at

Agents write the shadcn/ui of 2023: forwardRef, hsl(var(--primary)), tailwind.config.js, gray-500 next to the tokens, and asChild on Base UI components. This prompt gives them today's conventions: read components.json, add with the CLI, compose parts with data-slot, theme with oklch tokens, and keep Radix and Base UI apart.

  1. components.json firstStyle prefix, CSS file, icon library and aliases read first; components added with the CLI and registries asked for, never guessed.
  2. Components as shadcn writes themFunction components with ref as a prop, data-slot on every part, cva variants exported and cn() for className.
  3. Radix or Base UI, never bothasChild on Radix, render and nativeButton on Base UI, and the Select, Accordion and Slider props that differ.
  4. Tokens, not colorsbg-primary and text-muted-foreground over palette colors, oklch values mapped in @theme inline, no dark: pairs.
  5. Field forms and feedbackFieldGroup, Field and FieldError with data-invalid and aria-invalid, Controller for React Hook Form, Sonner for toasts.
  6. Accessible by defaultTitles on every dialog, items inside their groups, visible focus, labeled icon buttons and logical utilities for RTL.

The React Components rules

126 lines, current to React 19.3, Tailwind CSS 4.3, Radix UI 1.8 and Base UI 1.9. Last reviewed October 23, 2026. Plain Markdown, no front matter: each agent's is below.

Download

react-shadcn.md

# React Components

You are working in a React 19 project that uses shadcn/ui components with Tailwind CSS v4 and TypeScript. The components are source files you own, added by the shadcn CLI. Write code for the versions in `package.json` and the conventions below, not the shadcn/ui of your training data: `forwardRef`, `hsl(var(--x))` and `tailwind.config.js` are gone.

## Before you write code

- Read `components.json`. `style` names the primitive library by its prefix (`radix-nova`, `base-vega`; an older `new-york` project is Radix). `tailwind.css` is the stylesheet that holds the tokens. `iconLibrary` decides icon imports (`lucide` is `lucide-react`, `tabler` is `@tabler/icons-react`): never assume lucide. `aliases` give the import paths. With `rsc: true`, interactive components need `"use client"`.
- List the UI folder (the `ui` alias, usually `components/ui`). Do not import a component that was never added, and do not add one twice.
- Open a component's file before using it: its props, variants and parts are whatever that file says, including local changes.
- `npx shadcn@latest info` prints the resolved config; `npx shadcn@latest docs <name>` gives a component's documentation URLs. Use the project's runner (`pnpm dlx`, `bunx --bun`) instead of `npx` when it has one.

## Adding and updating components

Add with `npx shadcn@latest add button card dialog`. Other registries are namespaced in `components.json` (private ones read tokens from environment variables) and installed by name, as in `npx shadcn@latest add @acme/data-table`:

```json
{
  "registries": {
    "@acme": "https://acme.com/r/{name}.json",
    "@private": {
      "url": "https://registry.example.com/r/{name}.json",
      "headers": { "Authorization": "Bearer ${REGISTRY_TOKEN}" }
    }
  }
}
```

- When the user does not name a registry, ask; never guess one.
- After adding from a third-party registry, read every new file: rewrite imports to the project's aliases, swap icons to the project's library, and fix missing parts.
- To update a component the project has changed, preview with `add <name> --dry-run` and `--diff <file>`, then merge by hand. Never `--overwrite` without asking.

## Writing components

- Write function components that take `ComponentProps<"div">` (or the primitive's props type) and accept `ref` as an ordinary prop: React 19 needs no `forwardRef`.
- Put `data-slot="<part-name>"` on every part's root element, mirror variants as `data-variant` and `data-size`, and merge `className` last through `cn()` (`twMerge(clsx(…))` from `lib/utils`).
- Define variants with `cva` and export them, so links and other elements can reuse the look (`buttonVariants`). Where the project already uses `tailwind-variants`, use `tv` the same way.

```tsx
import { cva, type VariantProps } from "class-variance-authority";
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";

const statVariants = cva("flex flex-col gap-1 rounded-lg border p-4", {
  variants: {
    tone: {
      default: "bg-card text-card-foreground",
      muted: "bg-muted text-muted-foreground",
    },
  },
  defaultVariants: { tone: "default" },
});

function Stat({ className, tone = "default", ...props }: ComponentProps<"div"> & VariantProps<typeof statVariants>) {
  return <div data-slot="stat" data-variant={tone} className={cn(statVariants({ tone }), className)} {...props} />;
}

export { Stat, statVariants };
```

- Build from parts, not from props: `Card` with `CardHeader` (`CardTitle`, `CardDescription`, `CardAction`), `CardContent` and `CardFooter`, each exported. Style a part by its relatives with `data-slot` selectors (`has-data-[slot=card-action]:grid-cols-[1fr_auto]`) and named groups (`group/card`).
- Reuse before writing markup: `Alert` for callouts, `Empty` for empty states, `Skeleton` for placeholders, `Badge` for labels, `Separator` instead of `<hr>`, `Spinner` for progress.

## Radix or Base UI

shadcn/ui ships the same components on two primitive libraries. Use the one the project's files import, and never mix their APIs.

- Radix (`import { Dialog as DialogPrimitive } from "radix-ui"`, or the older `@radix-ui/react-*` packages; `Slot.Root` for `asChild`): `<DialogTrigger asChild><Button>Open</Button></DialogTrigger>`.
- Base UI (`@base-ui/react/<component>`): `<DialogTrigger render={<Button />}>Open</DialogTrigger>`. When `render` produces something other than a `<button>`, add `nativeButton={false}`: `<PopoverTrigger render={<InputGroupAddon />} nativeButton={false}>Pick a date</PopoverTrigger>`.
- A link that looks like a button is a link: `<Link href="/docs" className={buttonVariants({ variant: "outline" })}>Docs</Link>` on either library, or `<Button asChild><Link href="/docs">Docs</Link></Button>` on Radix. On Base UI, an `<a>` rendered through Button gets `role="button"` unless the project's Button file handles links; check it before writing `render={<a />}`.
- Other differences: Base UI's Select takes `items` on the root and positions with `alignItemWithTrigger`, Radix's uses `position="popper"`; Base UI's Accordion and ToggleGroup take `multiple` with array values where Radix takes `type="single"`; Base UI's Slider takes a number for one thumb, Radix an array; Base UI marks state as `data-open` or `data-checked`, Radix as `data-state="open"`.
- Never install the other library to get a prop, and never put `asChild` on a Base UI component or `render` on a Radix one.

## Tokens, theme and layout

- Use semantic tokens only: `bg-background text-foreground`, `bg-card`, `bg-popover`, `bg-primary text-primary-foreground`, `bg-secondary`, `bg-muted text-muted-foreground`, `bg-accent`, `text-destructive`, `border-border`, `border-input`, `ring-ring`, `bg-sidebar`, `chart-1` to `chart-5`. Never palette colors (`bg-gray-100`, `text-blue-600`) or hex values, and no `dark:` color pairs: tokens switch under `.dark`.
- Tokens live in the stylesheet from `components.json`: `oklch(…)` values in `:root` and `.dark`, mapped to utilities in `@theme inline` (`--color-primary: var(--primary)`). Use them as `var(--primary)`, never `hsl(var(--primary))`.
- To add a token, define it in both blocks and map it, then use it:

```css
:root { --warning: oklch(0.84 0.16 84); --warning-foreground: oklch(0.28 0.07 46); }
.dark { --warning: oklch(0.41 0.11 46); --warning-foreground: oklch(0.99 0.02 95); }
@theme inline {
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
}
```

- Dark mode is the `.dark` class on `<html>` (next-themes with `attribute="class"` in Next.js) with `@custom-variant dark (&:is(.dark *));`. Radius comes from `--radius` (`rounded-lg` is `var(--radius)`, smaller sizes derive from it).
- `className` on a shadcn component is for layout (width, margin, grid placement). Change its look with a variant, a token or a new variant in its file.
- Lay out with `flex` or `grid` and `gap-*`, not `space-y-*`; `size-*` for equal width and height; `truncate`. Never add `z-index` to dialogs, popovers, menus or tooltips.

## Icons

- Import icons from the `iconLibrary` package. lucide-react 1.x renders icons `aria-hidden` unless you give them a label, and no longer has brand icons.
- Inside Button, menu items and other components, add no size classes: the component sizes its `svg`. Mark a button icon's side with `data-icon="inline-start"` or `"inline-end"` where the project's Button supports it. Size standalone icons with `size-4`.
- Icon-only buttons use `size="icon"` and an `aria-label` on the button. Pass icons as components (`icon={CheckIcon}`), not as strings mapped to icons.

## Forms and feedback

- Build forms with the Field components: `FieldGroup` > `Field` > `FieldLabel htmlFor`, the control, `FieldDescription`, `FieldError`. Group checkboxes and radios in `FieldSet` with `FieldLegend`; use `orientation="horizontal"` for settings rows.
- Mark state on both: `data-invalid` on `Field` and `aria-invalid` on the control; `data-disabled` on `Field` and `disabled` on the control.
- With React Hook Form, render each control through `Controller` into a `Field` (`data-invalid={fieldState.invalid}`, `<FieldError errors={[fieldState.error]} />`) with a Zod resolver. Do not build new forms with the older `Form`, `FormField`, `FormItem` and `FormMessage` wrappers.
- Inputs with buttons or icons use `InputGroup` with `InputGroupInput` and `InputGroupAddon`, not absolute positioning. Two to seven options use `ToggleGroup`.
- Toasts are Sonner: render the project's `<Toaster />` once in the root layout, then `toast.success("Saved")`, `toast.error(…)` or `toast.promise(…)` from `sonner`.
- Loading buttons compose: `<Button disabled><Spinner data-icon="inline-start" />Saving</Button>`. Button has no `isLoading` prop.

## Accessibility and direction

- Every `Dialog`, `Sheet`, `Drawer` and `AlertDialog` has a title (`className="sr-only"` if it must be hidden). Use `AlertDialog` for destructive confirmations.
- Keep items inside their group (`SelectItem` in `SelectGroup`, `DropdownMenuItem` in `DropdownMenuGroup`, `CommandItem` in `CommandGroup`), `TabsTrigger` inside `TabsList`, and an `AvatarFallback` in every `Avatar`.
- Keep the visible focus styles (`focus-visible:ring-[3px] focus-visible:ring-ring/50`) when you restyle, and use buttons and links for anything clickable, never a `div` with `onClick`.
- Use logical utilities (`ms-*`, `pe-*`, `start-*`, `text-start`, `rounded-s-*`, `border-e`) and `rtl:rotate-180` on directional icons, so components work under `dir="rtl"`.

## Do not

- Do not write `forwardRef`, `hsl(var(--x))` tokens, a `tailwind.config.js`, or `tailwindcss-animate` (v4 projects use `tw-animate-css`).
- Do not copy component code from memory or from GitHub: add it with the CLI, then edit it.
- Do not override component colors with `className`, hard-code palette colors, or add `dark:` color classes.
- Do not mix Radix and Base UI APIs, or wrap a trigger's child in an extra `div` instead of using `asChild` or `render`.
- Do not build string-mapped icon registries, custom toast systems or hand-rolled modals when the component exists.

## Before you finish

- Run the type checker and the linter and fix what they report.
- Check every component you touched in light and dark mode, with the keyboard alone (focus visible, Escape closes, focus returns), and at a phone width.
- Report which components you added or changed in `components/ui`, so the reviewer knows what diverges from upstream.

10,486 characters, 1,413 words. Under Windsurf's 12,000-character limit for a rule, as every prompt here is.

Use it in your agent

The same rules, where your agent reads them. Each file has the front matter its agent needs, set to apply on every request.

Claude Code

A rule it loads every session

  1. Save it as .claude/rules/react-shadcn.md in your project, front matter included, or run the install command.
  2. Claude Code loads every file in .claude/rules with your CLAUDE.md when a session starts.
  3. Prefer one file? Paste it into CLAUDE.md under its own heading instead.

.claude/rules/react-shadcn.md

# React ComponentsYou are working in a React 19 project that uses shadcn/ui components with Tailwind CSS v4 and TypeScript. The components are source files you own, added by the shadcn CLI. Write code for the versions in `package.json` and the conventions below, not the shadcn/ui of your training data: `forwardRef`, `hsl(var(--x))` and `tailwind.config.js` are gone.## Before you write code- Read `components.json`. `style` names the primitive library by its prefix (`radix-nova`, `base-vega`; an older `new-york` project is Radix). `tailwind.css` is the stylesheet that holds the tokens. `iconLibrary` decides icon imports (`lucide` is `lucide-react`, `tabler` is `@tabler/icons-react`): never assume lucide. `aliases` give the import paths. With `rsc: true`, interactive components need `"use client"`.- List the UI folder (the `ui` alias, usually `components/ui`). Do not import a component that was never added, and do not add one twice.- Open a component's file before using it: its props, variants and parts are whatever that file says, including local changes.- `npx shadcn@latest info` prints the resolved config; `npx shadcn@latest docs <name>` gives a component's documentation URLs. Use the project's runner (`pnpm dlx`, `bunx --bun`) instead of `npx` when it has one.## Adding and updating components…

Or let the shadcn CLI write this file: sign in (free) for your command.

Cursor

A project rule with front matter

  1. Save it as .cursor/rules/react-shadcn.mdc, front matter included, or run the install command.
  2. alwaysApply: true adds it to every Agent request in this project.
  3. Check it under Cursor Settings, Rules, then commit the folder for your team.

.cursor/rules/react-shadcn.mdc

---description: "Building, adding or styling shadcn/ui components in React: components.json, the CLI, variants, tokens, Radix or Base UI, icons and forms."alwaysApply: true---# React ComponentsYou are working in a React 19 project that uses shadcn/ui components with Tailwind CSS v4 and TypeScript. The components are source files you own, added by the shadcn CLI. Write code for the versions in `package.json` and the conventions below, not the shadcn/ui of your training data: `forwardRef`, `hsl(var(--x))` and `tailwind.config.js` are gone.## Before you write code- Read `components.json`. `style` names the primitive library by its prefix (`radix-nova`, `base-vega`; an older `new-york` project is Radix). `tailwind.css` is the stylesheet that holds the tokens. `iconLibrary` decides icon imports (`lucide` is `lucide-react`, `tabler` is `@tabler/icons-react`): never assume lucide. `aliases` give the import paths. With `rsc: true`, interactive components need `"use client"`.- List the UI folder (the `ui` alias, usually `components/ui`). Do not import a component that was never added, and do not add one twice.- Open a component's file before using it: its props, variants and parts are whatever that file says, including local changes.- `npx shadcn@latest info` prints the resolved config; `npx shadcn@latest docs <name>` gives a component's documentation URLs. Use the project's runner (`pnpm dlx`, `bunx --bun`) instead of `npx` when it has one.## Adding and updating components…

Or let the shadcn CLI write this file: sign in (free) for your command.

Windsurf

A workspace rule for Cascade

  1. Save it as .windsurf/rules/react-shadcn.md, or run the install command.
  2. trigger: always_on applies it to every Cascade request in this workspace.
  3. Windsurf reads up to 12,000 characters per rule; this one is 10,486.

.windsurf/rules/react-shadcn.md

---trigger: always_on---# React ComponentsYou are working in a React 19 project that uses shadcn/ui components with Tailwind CSS v4 and TypeScript. The components are source files you own, added by the shadcn CLI. Write code for the versions in `package.json` and the conventions below, not the shadcn/ui of your training data: `forwardRef`, `hsl(var(--x))` and `tailwind.config.js` are gone.## Before you write code- Read `components.json`. `style` names the primitive library by its prefix (`radix-nova`, `base-vega`; an older `new-york` project is Radix). `tailwind.css` is the stylesheet that holds the tokens. `iconLibrary` decides icon imports (`lucide` is `lucide-react`, `tabler` is `@tabler/icons-react`): never assume lucide. `aliases` give the import paths. With `rsc: true`, interactive components need `"use client"`.- List the UI folder (the `ui` alias, usually `components/ui`). Do not import a component that was never added, and do not add one twice.- Open a component's file before using it: its props, variants and parts are whatever that file says, including local changes.- `npx shadcn@latest info` prints the resolved config; `npx shadcn@latest docs <name>` gives a component's documentation URLs. Use the project's runner (`pnpm dlx`, `bunx --bun`) instead of `npx` when it has one.## Adding and updating components…

Or let the shadcn CLI write this file: sign in (free) for your command.

GitHub Copilot

Instructions for the repository

  1. Save it as .github/instructions/react-shadcn.instructions.md, or run the install command.
  2. applyTo: "**" applies it to every request in this repository.
  3. Or paste it into .github/copilot-instructions.md, which Copilot reads for every request.

.github/instructions/react-shadcn.instructions.md

---description: "Building, adding or styling shadcn/ui components in React: components.json, the CLI, variants, tokens, Radix or Base UI, icons and forms."applyTo: "**"---# React ComponentsYou are working in a React 19 project that uses shadcn/ui components with Tailwind CSS v4 and TypeScript. The components are source files you own, added by the shadcn CLI. Write code for the versions in `package.json` and the conventions below, not the shadcn/ui of your training data: `forwardRef`, `hsl(var(--x))` and `tailwind.config.js` are gone.## Before you write code- Read `components.json`. `style` names the primitive library by its prefix (`radix-nova`, `base-vega`; an older `new-york` project is Radix). `tailwind.css` is the stylesheet that holds the tokens. `iconLibrary` decides icon imports (`lucide` is `lucide-react`, `tabler` is `@tabler/icons-react`): never assume lucide. `aliases` give the import paths. With `rsc: true`, interactive components need `"use client"`.- List the UI folder (the `ui` alias, usually `components/ui`). Do not import a component that was never added, and do not add one twice.- Open a component's file before using it: its props, variants and parts are whatever that file says, including local changes.- `npx shadcn@latest info` prints the resolved config; `npx shadcn@latest docs <name>` gives a component's documentation URLs. Use the project's runner (`pnpm dlx`, `bunx --bun`) instead of `npx` when it has one.## Adding and updating components…

Or let the shadcn CLI write this file: sign in (free) for your command.

Codex & AGENTS.md

The file most agents read

  1. Paste it into AGENTS.md at your project's root, under its own heading.
  2. Codex reads AGENTS.md before it starts work, and so do Cursor, Zed, Jules, Amp and Copilot's coding agent.
  3. A folder can have its own AGENTS.md: the one closest to the file being edited wins.

AGENTS.md

## React ComponentsYou are working in a React 19 project that uses shadcn/ui components with Tailwind CSS v4 and TypeScript. The components are source files you own, added by the shadcn CLI. Write code for the versions in `package.json` and the conventions below, not the shadcn/ui of your training data: `forwardRef`, `hsl(var(--x))` and `tailwind.config.js` are gone.### Before you write code- Read `components.json`. `style` names the primitive library by its prefix (`radix-nova`, `base-vega`; an older `new-york` project is Radix). `tailwind.css` is the stylesheet that holds the tokens. `iconLibrary` decides icon imports (`lucide` is `lucide-react`, `tabler` is `@tabler/icons-react`): never assume lucide. `aliases` give the import paths. With `rsc: true`, interactive components need `"use client"`.- List the UI folder (the `ui` alias, usually `components/ui`). Do not import a component that was never added, and do not add one twice.- Open a component's file before using it: its props, variants and parts are whatever that file says, including local changes.- `npx shadcn@latest info` prints the resolved config; `npx shadcn@latest docs <name>` gives a component's documentation URLs. Use the project's runner (`pnpm dlx`, `bunx --bun`) instead of `npx` when it has one.### Adding and updating components…

AGENTS.md is shared with your own instructions, so paste the rules in: the copy sets their headings a level down.

Rules teach it. The MCP equips it. With Pro, your agent installs every component, block and icon it needs, from a prompt.

Get Pro

Pricing

Give your agent the parts, with Pro

The prompts are free. Every Pro plan adds the MCP server, so your agent installs the components, blocks and icons it writes code around.

4.9/5 out of 5 · 150+ reviewsfrom 150+ founders and developers.

Billed once a year in USD. Cancel anytime.

Individual

For personal projects & open source

$32instead of $49/mo

$389 billed yearly

  • How many people can use the license.Seats: 1 seat
  • Client work, SaaS products and anything you charge for.Commercial use: Personal & open source only
  • Page sections in 56 categories, from heroes and pricing tables to dashboards and settings, on every framework and UI library, in your theme.Blocks: All 6,181 blocks
  • Complete Next.js sites for startups, SaaS, agencies and portfolios, every page designed, ready to ship.Templates: All 14 templates
  • Your AI agent searches, previews and installs any component, block, icon or DESIGN.md from a prompt: 22 tools in Claude Code, Cursor, VS Code and 35 more clients.MCP server: 38 AI clients
  • Buttons with motion and states of their own, from an arrow that slides in to a burst of confetti.Animated buttons: All 35 buttons
  • Typewriters, scrambles, counters and more, for headlines, labels and numbers.Text effects: All 97 effects
  • Animated backgrounds for heroes, sections and cards, from a soft aurora to a flock that flees the cursor. Most are pure CSS.Backgrounds: All 100 backgrounds
  • WebGPU shaders, from a slow aurora to a black hole, each drawing only while it's on screen.Shaders: All 100 shaders
  • One design and one theme on all four: the components, blocks and effects are built for each framework.Frameworks: React, Vue, Svelte, Solid
  • React on Base UI, Radix UI, React Aria or Ark UI: install the version for the library your project already uses. Vue, Svelte and Solid run on Ark UI.UI libraries: Base UI, Radix, Aria, Ark
  • From a button to a date picker, a color picker or a guided tour: accessible, typed in TypeScript, each with live demos.Components: All 174 components
  • Real-world patterns built from the components, in 53 galleries: forms, tables, menus, dialogs and more.Examples: All 1,103 examples
  • Area, bar, line, pie, radar and radial charts on TanStack Charts, on every framework. React also gets the Recharts originals.Charts: All 70 charts
  • Debounce, local storage, media queries and more: each hook is one typed file you own.React hooks: All 35 hooks
  • From 222 libraries, Lucide, Heroicons, Tabler and Material Symbols among them, as SVG or a React component in one command.Icons: 294k+ icons
  • Stripe, Linear, Apple and 497 more: a brand's colors, typography and components in one file your AI agent builds from.DESIGN.md files: All 500 brands
  • Restyle every component and block at once: 8 styles, 7 grays, 18 colors and 5 radii, shared as a shadcn preset code.Theme builder: 8 styles × 18 colors
  • Priority requests are answered first.Support: Standard

Team

Most popular

For freelancers, agencies & startups

$66instead of $99/mo

$789 billed yearly · ≈ $13/dev/mo

Everything in Individual, plus

  • How many people can use the license.Seats: Up to 5 seats
  • Client work, SaaS products and anything you charge for.Commercial use: Included
  • Priority requests are answered first.Support: Priority

Organization

For companies with larger teams

$132instead of $199/mo

$1,589 billed yearly

Everything in Team, plus

  • How many people can use the license.Seats: Unlimited seats
  • Secure checkout via Stripe
  • Code lives in your repo
  • Keep what you've shipped if you cancel
  • License terms

React Components prompt FAQ

What the React Components prompt covers and how to use it in your agent.

Why does the React Components prompt drop forwardRef?

React 19 passes ref to function components as an ordinary prop, and current shadcn/ui components are plain functions with a data-slot on each part. The prompt has the agent accept ref with the other props and never wrap a component in forwardRef.

Does the React Components prompt use cva for shadcn/ui variants?

Yes. Variants are defined with cva and exported, like buttonVariants, so a link can reuse a button's look, and each variant is mirrored as data-variant. Where a project already uses tailwind-variants, the agent writes tv the same way instead.

What is data-slot in shadcn/ui components?

An attribute on the root of every part, such as data-slot="card-header". It lets a parent style its children with selectors like has-data-[slot=card-action] without extra classes. The prompt makes the agent add one to every part it writes.

How does the agent add components from other shadcn registries?

Through namespaced registries in components.json, then npx shadcn@latest add @acme/name, with private registries reading tokens from environment variables. The agent asks which registry when you don't say, and reads every new file to fix aliases and icon imports.

4.9 out of 5 from 150+ developers

Rules teach it. The MCP equips it.

Every component, block and icon, installed by your AI agent on your stack. The prompts stay free.

Get Pro
  • Cancel anytime
  • Keep what you've shipped