There are two ways to install this application.
After using these methods, if you intend to use components with links please see the Router Provider instructions at the bottom.
Create project
Run the init
command to create a new Next.js project or to setup an existing one:
You will be asked a few questions to configure components.json
:
App structure
Here's how I structure my Next.js apps. You can use this as a reference:
- I place the UI components in the
components/ui
folder.
- The rest of the components such as
<PageHeader />
and <MainNav />
are placed in the components
folder.
- The
lib
folder contains all the utility functions. I have a utils.ts
where I define the cn
helper.
- The
styles
folder contains the global CSS.
That's it
You can now start adding components to your project. Either copy and paste, or use the CLI
The command above will add the Button
component to your project. You can then import it like this:
Add Tailwind CSS
Components are styled using Tailwind CSS. You need to install Tailwind CSS in your project.
Follow the Tailwind CSS installation instructions to get started.
Add dependencies
Add the following dependencies to your project:
Add icon library
If you're using the default
style, install lucide-react
:
If you're using the new-york
style, install @radix-ui/react-icons
:
I use the @
alias. This is how I configure it in tsconfig.json:
The @
alias is a preference. You can use other aliases if you want.
If you use a different alias such as ~, you'll need to update import statements when adding components.
Here's what my tailwind.config.js
file looks like:
Add the following to your styles/globals.css file. You can learn more about using CSS variables for theming in the theming section.
Add a cn helper
I use a cn
helper to make it easier to conditionally add Tailwind CSS classes. Here's how I define it in lib/utils.ts
:
That's it
You can now start adding components to your project.