ShadCN
This guide walks you through setting up a Next.js project with Shadcn components, using TypeScript and Tailwind CSS.
Introduction
By the end of this guide, you will have a fully configured Next.js project that includes a custom design system powered by Shadcn.
Step 1: Install and Configure Next.js
Create a New Project
Begin by creating a new Next.js project using the create-next-app CLI with TypeScript, Tailwind CSS, and ESLint:
This command initializes a new Next.js project with the specified configurations.
Step 2: Initialize Shadcn
Run the Shadcn Init Command
Next, set up your project with Shadcn by running the following command:
This command will walk you through the configuration process for Shadcn.
Step 3: Configure components.json
During the initialization process, you’ll be prompted with a few questions to set up components.json. Below are the recommended configurations:
• Which style would you like to use?: Default
• Which color would you like to use as base color?: Slate
• Do you want to use CSS variables for colors?: No
These settings will configure the base style for your project.
Step 4: Font Configuration
Import and Configure Inter Font
Inter is used as the default font for Shadcn components. Here’s how to configure it in your Next.js project.
1. Import the Font in the Root Layout:
In your layout.tsx, import the Inter font and configure it:
2. Configure theme.extend.fontFamily in tailwind.config.js:
Extend the default Tailwind CSS configuration to include the Inter font:
This ensures that the Inter font is correctly applied throughout your project.
Step 5: Project Structure
Below is a recommended project structure for organizing your Next.js app with Shadcn:
Key Points:
• UI Components: Place reusable UI components in the components/ui folder.
• Other Components: Non-UI components like <PageHeader /> and <MainNav /> should be placed in the components folder.
• Utility Functions: Place utility functions in the lib folder. For example, utils.ts can house helper functions like cn.
• Global CSS: Store global styles in the styles/globals.css file.
Step 6: Adding Components
You can now start adding components to your project. For example, to add a Button component, run:
This command adds the Button component to your project, which you can import and use as follows:
Last updated