6.5 KiB
6.5 KiB
Tailwind 4 + Shadcn/ui Setup Complete ✅
What's Been Configured
1. Tailwind CSS 4 (CSS-First Approach)
- Using
@importdirective (no PostCSS required) - Clean CSS variables for theming
- Dark mode support built-in
- Responsive utilities
2. Shadcn/ui Components
- Card: Display article content
- CardHeader
- CardTitle
- CardDescription
- CardContent
- CardFooter
- Button: Interactive elements (available but not used yet)
3. Utilities
cn()function for merging Tailwind classes- Uses
clsxfor conditional classes - Uses
tailwind-mergefor Tailwind-specific merging
4. TypeScript Configuration
- Path aliases configured:
@/→./src/ - shadcn/ui aliases:
@/components,@/utils
How to Use
Using Existing Components
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '@/components/ui/card'
export function MyComponent() {
return (
<Card>
<CardHeader>
<CardTitle>Title</CardTitle>
<CardDescription>Description</CardDescription>
</CardHeader>
<CardContent>
<p>Content goes here</p>
</CardContent>
<CardFooter>
<span>Footer content</span>
</CardFooter>
</Card>
)
}
Using Tailwind Classes
export function MyComponent() {
return (
<div className="p-4 bg-background text-foreground">
<h1 className="text-2xl font-bold">Title</h1>
<p className="text-muted-foreground">Description</p>
</div>
)
}
Using the cn() Utility
import { cn } from '@/lib/utils'
export function MyComponent({ className, isActive }: Props) {
return (
<div className={cn(
"base-class p-4",
isActive && "active-class",
className
)}>
Content
</div>
)
}
Adding More Shadcn/ui Components
Using the CLI
cd frontend
npx shadcn@latest add [component-name]
Recommended Components to Add
npx shadcn@latest add badge # For article tags
npx shadcn@latest add input # For search
npx shadcn@latest add dialog # For article details modal
npx shadcn@latest add tabs # For organizing content
npx shadcn@latest add separator # For visual separation
npx shadcn@latest add skeleton # For loading states
npx shadcn@latest add pagination # For article list navigation
Manual Installation
If CLI doesn't work, you can manually create components:
- Visit ui.shadcn.com
- Find the component you want
- Copy the code
- Create file:
frontend/src/components/ui/[component].tsx - Import and use
Customization
Theme Colors
Edit src/index.css:
:root {
--background: 0 0% 100%; /* Background color */
--foreground: 222.2 84% 4.9%; /* Text color */
--primary: 222.2 47.4% 11.2%; /* Primary color */
--card: 0 0% 100%; /* Card background */
/* ... more variables */
}
Adding Custom Colors to Tailwind
Edit tailwind.config.js:
theme: {
extend: {
colors: {
brand: {
50: '#f0f9ff',
100: '#e0e7ff',
500: '#3b82f6',
// ... more shades
}
}
}
}
Current Implementation
App.tsx
The main app displays:
- Header with "Placebo.mk" title
- Subtitle "Sarcastic news from Macedonia"
- Responsive grid of article cards (1/2/3 columns)
- Each card shows:
- Featured image (if available)
- Title (truncated to 2 lines)
- Excerpt (truncated to 3 lines)
- Content preview (truncated to 4 lines)
- Creation date
- View count
- Loading and error states
- Empty state when no articles
Dark Mode
To enable dark mode, add a toggle:
import { useEffect } from 'react'
export function ThemeToggle() {
useEffect(() => {
const isDark = localStorage.getItem('theme') === 'dark'
document.documentElement.classList.toggle('dark', isDark)
}, [])
const toggleTheme = () => {
const isDark = document.documentElement.classList.toggle('dark')
localStorage.setItem('theme', isDark ? 'dark' : 'light')
}
return (
<button onClick={toggleTheme}>
Toggle Theme
</button>
)
}
Troubleshooting
Tailwind Classes Not Applying
- Check that
@tailwinddirectives are insrc/index.css - Restart dev server:
npm run dev - Hard refresh browser: Ctrl+Shift+R
- Check browser DevTools → Elements → Computed Styles
Component Not Found
- Check file exists:
frontend/src/components/ui/[component].tsx - Check export name matches:
export const ComponentName = ... - Check import path:
@/components/ui/component - Restart TypeScript server (VSCode: Cmd+Shift+P → "TypeScript: Restart TS Server")
TypeScript Errors
- Check
tsconfig.jsonhas@/paths configured - Restart TypeScript server
- Run:
npm run type-check - Check
components.jsonaliases
Performance Tips
- Image Optimization: Add
loading="lazy"to article images - Code Splitting: Use
lazy()for large components - Query Caching: TanStack Query caches automatically
- Bundle Analysis: Run
npm run buildand check bundle size
File Structure
frontend/
├── src/
│ ├── components/
│ │ └── ui/ # shadcn/ui components
│ │ ├── button.tsx
│ │ └── card.tsx
│ ├── lib/
│ │ ├── api.ts # API functions
│ │ ├── query-client.ts # TanStack Query
│ │ └── utils.ts # cn() utility
│ ├── App.tsx # Main application
│ ├── index.css # Tailwind + CSS variables
│ └── main.tsx
├── components.json # shadcn config
├── tailwind.config.js # Tailwind configuration
└── package.json
Next Steps
- Add article detail page: Click on card to view full article
- Add search input: Filter articles by title/content
- Add category filter: Filter by article category
- Add tag badges: Display article tags
- Add pagination: Navigate through large article lists
- Add dark mode toggle: Switch between light/dark themes
- Add article detail modal: View article without leaving page
Resources
- Tailwind CSS 4 Docs
- Shadcn/ui Documentation
- Radix UI - Underlying component library
- Lucide Icons - Icon library (installed)
- TanStack Query Docs