Introduction
Installation
Learn how to get HapplyUI set up in your React project.
Prerequisites
Before installing HapplyUI, make sure your project has:
- React 18+ — HapplyUI components are built for modern React
- Tailwind CSS v3 or v4 — For styling the components
- TypeScript (recommended) — For the best developer experience
Automatic Installation
The easiest way to get started is using the HapplyUI CLI:
Initialize your project
bunx @happlyui/cli@latest init
The CLI will ask you a few questions to configure your project:
- Framework detection — Automatically detects Next.js, Vite, etc.
- TypeScript — Whether to use TypeScript or JavaScript
- Component location — Where to install components (default:
src/components/happly-ui) - Utility location — Where to put the
cn()utility function (default:src/lib/happly-ui/happly-ui-utils.ts)
Add components
Once initialized, add components as needed:
# Add a single component
bunx @happlyui/cli@latest add button
# Add multiple components
bunx @happlyui/cli@latest add button input card
# List all available components
bunx @happlyui/cli@latest list
Alternative package managers
You can use any package manager:
bun:
bunx @happlyui/cli@latest add buttonnpm:
npx @happlyui/cli@latest add buttonpnpm:
pnpx @happlyui/cli@latest add button
Manual Installation
If you prefer to set things up manually:
1. Install dependencies
bun add clsx tailwind-merge class-variance-authority tailwindcss-animate
2. Configure Tailwind CSS
We provide ready-to-use configuration files for both Tailwind v3 and v4 in the tailwind-manual-installation directory of the repository.
Tailwind v3
- Copy
tailwind-manual-installation/v3/happly-tailwind.preset.jsto your project root. - Add it to your
tailwind.config.js:module.exports = { presets: [require('./happly-tailwind.preset.js')], // ... rest of your config }; - Copy the CSS variables from
tailwind-manual-installation/v3/globals.cssinto your global CSS file.
Tailwind v4
- Copy
tailwind-manual-installation/v4/happly-theme.cssto your project (e.g.,src/happly-theme.css). - Import it in your main CSS file:
@import './happly-theme.css';
Conflict Resolution & Overrides
When using happly-tailwind.preset.js (Tailwind v3), Happly's configuration is provided as a preset. This means:
Your configuration overrides the preset: Any keys defined in your
tailwind.config.jswill take precedence over Happly's defaults.Use
theme.extend: To add custom colors or fonts without removing Happly's tokens, always usetheme.extend.// ✅ Good: Extends Happly defaults module.exports = { theme: { extend: { colors: { brand: '#ff0000' }, }, }, }; // ❌ Bad: Overrides Happly defaults (removes semantic tokens) module.exports = { theme: { colors: { brand: '#ff0000' }, }, };
Tailwind v4 Conflict Resolution
For Tailwind v4:
Import Order Matters: Ensure
@import "./happly-theme.css";comes before your own@themeblock or variable definitions.Overriding Variables: You can override any Happly variable by redefining it in your
:rootor@themeblock after the import.@import './happly-theme.css'; @theme { /* Overrides Happly's --color-primary */ --color-primary: red; }
3. Add the utility function
Create src/lib/happly-ui/happly-ui-utils.ts:
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
4. Configure path aliases
In your tsconfig.json, add path aliases:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
5. Copy components
Browse the components section and copy the source code directly into your project.
Configuration
HapplyUI stores its configuration in happly-ui-components.json:
{
"$schema": "https://cdn.jsdelivr.net/gh/Mindful-Connect/happly-ui-npm@production/schemas/happly-ui-components.json",
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/styles/globals.css",
"baseColor": "slate",
"cssVariables": true
},
"aliases": {
"components": "@/components",
"utils": "@/lib/happly-ui/happly-ui-utils",
"ui": "@/components/happly-ui",
"lib": "@/lib",
"hooks": "@/hooks"
}
}
Configuration options
| Option | Description |
|---|---|
tsx | Whether to use TypeScript (true) or JavaScript (false) |
tailwind.css | Path to your global CSS file |
aliases.ui | Where components will be installed (default: components/happly-ui) |
aliases.utils | Where the cn() utility lives (default: lib/happly-ui-utils) |
Next Steps
Now that HapplyUI is set up, explore the components:
- Button — Start with the most common component