Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Integrate and customize shadcn/ui components—discovery, installation, theming, and Radix/Base UI best practices
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
resources/setup-guide.md
1# shadcn/ui Setup Guide23This guide walks you through setting up shadcn/ui in both new and existing projects.45## Prerequisites67Before you begin, ensure you have:8- **Node.js 18+** installed9- **React 18+** in your project10- **Tailwind CSS 3.0+** configured11- A package manager: npm, yarn, pnpm, or bun1213## Quick Start (New Project)1415### Option 1: npx shadcn create (Recommended)1617The easiest way to start a new project with shadcn/ui is using the `create` command, which allows you to customize everything (framework, library, style, font, etc.).1819```bash20npx shadcn@latest create21```2223This interactive command will guide you through:241. **Project Name**: Directory for your app.252. **Visual Style**: Choose from Vega, Nova, Maia, Lyra, Mira, or Classic.263. **Base Color**: Select your primary theme color.274. **Framework**: Next.js, Vite, Laravel, etc.285. **Component Library**: Choose **Radix UI** or **Base UI**.296. **RTL Support**: Enable Right-to-Left support if needed.3031### Option 2: Classic Manual Setup (Next.js)3233```bash34# Create a new Next.js project35npx create-next-app@latest my-app36cd my-app3738# Initialize shadcn/ui39npx shadcn@latest init4041# Add your first component42npx shadcn@latest add button43```4445### Option 3: Classic Manual Setup (Vite + React)4647```bash48# Create a new Vite project49npm create vite@latest my-app -- --template react-ts50cd my-app51npm install5253# Install Tailwind CSS54npm install -D tailwindcss postcss autoprefixer55npx tailwindcss init -p5657# Initialize shadcn/ui58npx shadcn@latest init5960# Add your first component61npx shadcn@latest add button62```6364## Existing Project Setup6566### Step 1: Ensure Tailwind CSS is Installed6768If Tailwind is not installed:6970```bash71npm install -D tailwindcss postcss autoprefixer72npx tailwindcss init -p73```7475Configure `tailwind.config.js`:7677```javascript78/** @type {import('tailwindcss').Config} */79export default {80content: [81"./index.html",82"./src/**/*.{js,ts,jsx,tsx}",83],84theme: {85extend: {},86},87plugins: [],88}89```9091### Step 2: Initialize shadcn/ui9293Run the initialization command:9495```bash96npx shadcn@latest init97```9899You'll be asked to configure:1001011. **Style**: Choose between `default`, `new-york`, or one of the new styles (Vega, Nova, etc.)102- `default`: Clean and minimal design103- `new-york`: More refined with subtle details1041052. **Base Color**: Choose your primary color palette106- slate, gray, zinc, neutral, or stone1071083. **CSS Variables**: Recommend `yes` for easier theming1091104. **TypeScript**: Recommend `yes` for type safety1111125. **Import Alias**: Default is `@/components` (recommended)1131146. **React Server Components**: Choose based on your framework115- `yes` for Next.js 13+ with app directory116- `no` for Vite, CRA, or Next.js pages directory1171187. **RTL Support**: Answer `yes` if you need Right-to-Left layout support (this will use logical properties like `ms-4` instead of `ml-4`).119120## Advanced Features121122### Visual Styles123shadcn/ui now offers multiple visual styles beyond the defaults:124- **Vega**: The classic shadcn/ui look.125- **Nova**: Reduced padding/margins, compact.126- **Maia**: Soft, rounded, generous spacing.127- **Lyra**: Boxy, sharp, mono font friendly.128- **Mira**: Dense, compact.129130### Base UI Support131You can now choose between **Radix UI** and **Base UI** as the underlying primitive library. They share the same component API/abstraction, so your usage remains consistent.132133134### Step 3: Verify Configuration135136The init command creates/updates several files:137138**components.json** (root of project):139```json140{141"$schema": "https://ui.shadcn.com/schema.json",142"style": "default",143"rsc": false,144"tsx": true,145"tailwind": {146"config": "tailwind.config.js",147"css": "src/index.css",148"baseColor": "slate",149"cssVariables": true150},151"aliases": {152"components": "@/components",153"utils": "@/lib"154}155}156```157158**src/lib/utils.ts**:159```typescript160import { clsx, type ClassValue } from "clsx"161import { twMerge } from "tailwind-merge"162163export function cn(...inputs: ClassValue[]) {164return twMerge(clsx(inputs))165}166```167168**Updated tailwind.config.js**:169```javascript170/** @type {import('tailwindcss').Config} */171module.exports = {172darkMode: ["class"],173content: [174'./pages/**/*.{ts,tsx}',175'./components/**/*.{ts,tsx}',176'./app/**/*.{ts,tsx}',177'./src/**/*.{ts,tsx}',178],179theme: {180container: {181center: true,182padding: "2rem",183screens: {184"2xl": "1400px",185},186},187extend: {188colors: {189border: "hsl(var(--border))",190input: "hsl(var(--input))",191ring: "hsl(var(--ring))",192background: "hsl(var(--background))",193foreground: "hsl(var(--foreground))",194primary: {195DEFAULT: "hsl(var(--primary))",196foreground: "hsl(var(--primary-foreground))",197},198// ... more colors199},200borderRadius: {201lg: "var(--radius)",202md: "calc(var(--radius) - 2px)",203sm: "calc(var(--radius) - 4px)",204},205keyframes: {206"accordion-down": {207from: { height: 0 },208to: { height: "var(--radix-accordion-content-height)" },209},210"accordion-up": {211from: { height: "var(--radix-accordion-content-height)" },212to: { height: 0 },213},214},215animation: {216"accordion-down": "accordion-down 0.2s ease-out",217"accordion-up": "accordion-up 0.2s ease-out",218},219},220},221plugins: [require("tailwindcss-animate")],222}223```224225**Updated globals.css** (or equivalent):226```css227@tailwind base;228@tailwind components;229@tailwind utilities;230231@layer base {232:root {233--background: 0 0% 100%;234--foreground: 222.2 84% 4.9%;235--card: 0 0% 100%;236--card-foreground: 222.2 84% 4.9%;237--popover: 0 0% 100%;238--popover-foreground: 222.2 84% 4.9%;239--primary: 221.2 83.2% 53.3%;240--primary-foreground: 210 40% 98%;241--secondary: 210 40% 96.1%;242--secondary-foreground: 222.2 47.4% 11.2%;243--muted: 210 40% 96.1%;244--muted-foreground: 215.4 16.3% 46.9%;245--accent: 210 40% 96.1%;246--accent-foreground: 222.2 47.4% 11.2%;247--destructive: 0 84.2% 60.2%;248--destructive-foreground: 210 40% 98%;249--border: 214.3 31.8% 91.4%;250--input: 214.3 31.8% 91.4%;251--ring: 221.2 83.2% 53.3%;252--radius: 0.5rem;253}254255.dark {256--background: 222.2 84% 4.9%;257--foreground: 210 40% 98%;258/* ... dark mode variables */259}260}261262@layer base {263* {264@apply border-border;265}266body {267@apply bg-background text-foreground;268}269}270```271272### Step 4: Configure Path Aliases273274Ensure your `tsconfig.json` includes path aliases:275276```json277{278"compilerOptions": {279"baseUrl": ".",280"paths": {281"@/*": ["./src/*"]282}283}284}285```286287For Vite, also update `vite.config.ts`:288289```typescript290import path from "path"291import { defineConfig } from "vite"292import react from "@vitejs/plugin-react"293294export default defineConfig({295plugins: [react()],296resolve: {297alias: {298"@": path.resolve(__dirname, "./src"),299},300},301})302```303304### Step 5: Add Components305306Now you can add components:307308```bash309# Add individual components310npx shadcn@latest add button311npx shadcn@latest add card312npx shadcn@latest add dialog313314# Add multiple components at once315npx shadcn@latest add button card dialog input label316```317318Components will be added to `src/components/ui/` by default.319320## Framework-Specific Considerations321322### Next.js App Router323324- Set `rsc: true` in `components.json`325- Add `"use client"` to stateful components326- Import components work from server components by default327328### Next.js Pages Router329330- Set `rsc: false` in `components.json`331- All components are client-side by default332333### Vite334335- Ensure path aliases are configured in `vite.config.ts`336- Import `globals.css` in your main entry point (`main.tsx`)337338### Create React App339340- Use `craco` or `react-app-rewired` for path alias support341- Or use relative imports instead of aliases342343## Verification Steps3443451. **Check file structure**:346```347src/348├── components/349│ └── ui/350├── lib/351│ └── utils.ts352└── index.css (or globals.css)353```3543552. **Test a simple component**:356```tsx357import { Button } from "@/components/ui/button"358359export default function App() {360return <Button>Click me</Button>361}362```3633643. **Verify Tailwind is working**:365- Component should render with proper styling366- Check browser dev tools for applied classes3673684. **Test dark mode** (if using CSS variables):369```tsx370<html className="dark">371```372373## Troubleshooting374375### "Cannot find module '@/components/ui/button'"376377**Solution**: Check path alias configuration in `tsconfig.json` and framework config.378379### Styles not applying380381**Solution**:382- Ensure `globals.css` is imported in your app entry point383- Verify Tailwind config `content` paths include your files384- Check CSS variables are defined in `globals.css`385386### TypeScript errors in components387388**Solution**:389- Run `npm install` to ensure all dependencies are installed390- Check that `@types/react` is installed391- Restart TypeScript server in your editor392393### Components look broken394395**Solution**:396- Verify `tailwindcss-animate` is installed: `npm install tailwindcss-animate`397- Check that CSS variables are properly defined398- Ensure you're not overriding component styles globally399400## Next Steps4014021. Browse the [component catalog](./component-catalog.md)4032. Read the [customization guide](./customization-guide.md)4043. Check out example implementations in `/examples`4054. Join the [shadcn/ui Discord](https://discord.com/invite/vNvTqVaWm6)406407## Additional Resources408409- [Official Documentation](https://ui.shadcn.com)410- [Component Examples](https://ui.shadcn.com/examples)411- [GitHub Repository](https://github.com/shadcn-ui/ui)412- [Tailwind CSS Docs](https://tailwindcss.com/docs)413