Overview
This lesson focuses on integrating Shadcn UI into a Next.js application that resides within your Turborepo monorepo. Shadcn UI provides beautifully designed, accessible, and customizable components that can be easily added and managed.
Key Points
-
Shadcn UI Philosophy: Unlike traditional component libraries, Shadcn UI is not installed as a dependency. Instead, you use a CLI to add components directly into your codebase, giving you full control over their styling and behavior.
-
Installation Prerequisites: Ensure Tailwind CSS is correctly configured in your Next.js application, as Shadcn UI relies heavily on it for styling.
-
Using Shadcn CLI: Run
npx shadcn-ui@latest initwithin your Next.js app's directory (apps/web). This command sets up necessary configuration files likecomponents.json. -
Adding Components: Use
npx shadcn-ui@latest add <component-name>to pull specific components into your project. They will typically land in acomponents/uidirectory within your Next.js app. -
Theming and Customization: Since components are part of your codebase, you can directly modify their Tailwind classes, extend them, or customize them to match your design system.
Quick Example
-
Navigate into your Next.js app workspace: bash cd apps/web
Initialize Shadcn UI (follow prompts):
bash npx shadcn-ui@latest init
Add a Button component:
bash npx shadcn-ui@latest add button
This will create a components/ui/button.tsx file in your apps/web directory.
Summary
Shadcn UI offers a powerful and flexible way to integrate high-quality UI components into your Next.js applications within a monorepo. Its code-first approach provides unparalleled control, making it ideal for creating a consistent and customizable design system.