Installation
Get your project ready for BeniUI components in a few simple steps.
1. Set up Tailwind CSS
If you haven't already, install Tailwind CSS in your project. Follow the official Tailwind CSS installation guide for your framework.
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -pnpm install -D tailwindcss postcss autoprefixer npx tailwindcss init -pConfigure your tailwind.config.js:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {},
},
plugins: [],
}Add Tailwind directives to your CSS file (e.g., globals.css):
@tailwind base;
@tailwind components;
@tailwind utilities;2. Install Dependencies
BeniUI components use a few utility libraries for better class name handling and icons. Install them with:
npm install tailwind-merge clsx lucide-reactWhat each package does:
tailwind-merge
Intelligently merges Tailwind CSS classes without conflicts
clsx
Utility for constructing className strings conditionally
lucide-react
Beautiful, consistent icon set used throughout our components
Using yarn or pnpm? Use these commands instead:
yarn add tailwind-merge clsx lucide-reactpnpm add tailwind-merge clsx lucide-react3. Create the cn() Utility Function
The cn() function is a helper that combines clsx and tailwind-merge to make it easy to conditionally join class names and resolve Tailwind conflicts.
Create a file at lib/utils.ts (or src/lib/utils.ts):
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}š” Why use cn()?
The cn() function helps you:
- Conditionally apply classes based on props or state
- Merge component classes with custom overrides without conflicts
- Handle edge cases like conflicting padding or margin classes
Example usage:
import { cn } from "@/lib/utils";
// Conditional classes
<button className={cn(
"px-4 py-2 rounded-lg",
isActive && "bg-blue-500 text-white",
isDisabled && "opacity-50 cursor-not-allowed"
)}>
Click me
</button>
// Merging with overrides (bg-red-500 wins over bg-blue-500)
<div className={cn("bg-blue-500 p-4", customClassName)}>
{/* If customClassName = "bg-red-500", the result is "p-4 bg-red-500" */}
</div>4. Recommended Project Structure
We recommend organizing your UI components in a dedicated folder:
your-project/
āāā src/
ā āāā components/
ā ā āāā ui/ # BeniUI components go here
ā ā āāā button.tsx
ā ā āāā input.tsx
ā ā āāā modal.tsx
ā ā āāā index.ts # Export all components
ā āāā lib/
ā ā āāā utils.ts # cn() utility function
ā āāā app/ # Your app pages
āāā tailwind.config.jsCreate an index.ts barrel file to easily import multiple components:
// components/ui/index.ts
export { Button } from "./button";
export { Input } from "./input";
export { Modal } from "./modal";
// ... add more as you goā You're Ready!
Your project is now set up to use BeniUI components. Head over to the Components section to start copying components into your project.