Docs
Next.js
Next.js
Install and configure Next.js.
Create project
Start by creating a new Next.js project using create-next-app
:
npx create-next-app@latest my-app --typescript --tailwind --eslint
Run the CLI
Run the pm-ui
init command to setup your project:
npx @pujan-modha/pm-ui init
Configure components.json
Your components.json
file will be configured automatically.
Fonts
I use Inter as the default font. Inter is not required. You can replace it with any other font.
Here's how I configure Inter for Next.js:
1. Import the font in the root layout:
import "@/styles/globals.css"
import { Inter as FontSans } from "next/font/google"
import { cn } from "@/lib/utils"
const fontSans = FontSans({
subsets: ["latin"],
variable: "--font-sans",
})
export default function RootLayout({ children }: RootLayoutProps) {
return (
<html lang="en" suppressHydrationWarning>
<head />
<body
className={cn(
"min-h-screen bg-background font-sans antialiased",
fontSans.variable
)}
>
...
</body>
</html>
)
}
2. Configure theme.extend.fontFamily
in tailwind.config.js
const { fontFamily } = require("tailwindcss/defaultTheme")
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["app/**/*.{ts,tsx}", "components/**/*.{ts,tsx}"],
theme: {
extend: {
fontFamily: {
sans: ["var(--font-sans)", ...fontFamily.sans],
},
},
},
}
App structure
Here's how I structure my Next.js apps. You can use this as a reference:
.
├── app
│ ├── layout.tsx
│ └── page.tsx
├── components
│ ├── ui
│ │ ├── alert-dialog.tsx
│ │ ├── button.tsx
│ │ ├── dropdown-menu.tsx
│ │ └── ...
│ ├── main-nav.tsx
│ ├── page-header.tsx
│ └── ...
├── lib
│ └── utils.ts
├── styles
│ └── globals.css
├── next.config.js
├── package.json
├── postcss.config.js
├── tailwind.config.js
└── tsconfig.json
- I place the UI components in the
components/ui
folder. - The rest of the components such as
<PageHeader />
and<MainNav />
are placed in thecomponents
folder. - The
lib
folder contains all the utility functions. I have autils.ts
where I define thecn
helper. - The
styles
folder contains the global CSS.
That's it
You can now start adding components to your project.
npx @pujan-modha/pm-ui add button
The command above will add the Button
component to your project. You can then import it like this:
import { Button } from "@/components/ui/button"
export default function Home() {
return (
<div>
<Button>Click me</Button>
</div>
)
}