# Frontend Refactoring: ShadCN/UI Integration
## Overview
The e-voting frontend has been comprehensively refactored to use **ShadCN/UI** components with a custom dark theme palette. This refactoring improves code consistency, maintainability, and provides a professional design system.
## What Changed
### 1. **Design System Setup**
#### New Color Palette (Dark Theme)
- **Primary Text**: `#e0e0e0` (primary), `#a3a3a3` (secondary), `#737373` (tertiary)
- **Background**: `#171717` (primary & secondary)
- **Accent**: `#e8704b` (warm orange-red)
- **Overlays**: `rgba(255, 255, 255, 0.05)` (light), `rgba(0, 0, 0, 0.8)` (dark)
- **Semantic Colors**:
- Success: `#10b981` (green)
- Warning: `#f97316` (orange)
- Danger: `#ef4444` (red)
- Info: `#3b82f6` (blue)
#### CSS Variables
All colors defined as CSS custom properties in `:root`:
```css
:root {
--color-accent-warm: #e8704b;
--text-primary: #e0e0e0;
--text-secondary: #a3a3a3;
--bg-primary: #171717;
/* ... etc */
}
```
### 2. **Tailwind CSS Configuration**
#### New Files
- **`tailwind.config.js`** - Tailwind configuration with custom theme
- **`postcss.config.js`** - PostCSS configuration for Tailwind processing
#### Key Features
- Extended Tailwind theme with custom colors matching the palette
- Custom spacing scale (xs, sm, md, lg, xl, 2xl)
- Custom border radius values
- Custom shadow utilities
- Support for `tailwindcss-animate` for animations
### 3. **ShadCN/UI Component Library**
Created a complete UI component library in `/src/lib/ui/`:
#### Core Components
1. **Button** (`button.jsx`)
- Variants: default, destructive, outline, secondary, ghost, link, success
- Sizes: sm, default, lg, icon
- Supports `asChild` prop for composability
2. **Card** (`card.jsx`)
- Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter
- Built on Tailwind with dark theme styling
3. **Alert** (`alert.jsx`)
- Alert, AlertTitle, AlertDescription
- Variants: default, destructive, success, warning, info
- Semantic color coding
4. **Dialog** (`dialog.jsx`)
- Dialog, DialogOverlay, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription
- Built on Radix UI Dialog primitive
5. **Input** (`input.jsx`)
- Text input with focus states and dark theme styling
6. **Label** (`label.jsx`)
- Form label component using Radix UI
7. **Badge** (`badge.jsx`)
- Status badges with multiple variants
8. **Dropdown Menu** (`dropdown-menu.jsx`)
- Full dropdown menu implementation with Radix UI
#### Utility Files
- **`utils.js`** - `cn()` utility for merging Tailwind classes with `clsx` and `tailwind-merge`
- **`index.js`** - Barrel export for all components
### 4. **Component Refactoring**
#### Header (`Header.jsx`)
**Before**: Custom CSS with `.header`, `.nav-link`, `.mobile-menu-btn` classes
**After**:
- Tailwind utility classes for layout
- ShadCN Button component for actions
- Sticky positioning with backdrop blur
- Responsive mobile menu with Tailwind
- Removed: Header.css (not needed)
#### VoteCard (`VoteCard.jsx`)
**Before**: Custom `.vote-card` styling with separate CSS
**After**:
- ShadCN Card component (Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter)
- ShadCN Badge component for status indicators
- ShadCN Button component for actions
- Improved visual hierarchy with better spacing
- Animated progress bars with Tailwind
- Responsive button layout
#### Alert (`Alert.jsx`)
**Before**: Custom `.alert` styling with type variants
**After**:
- ShadCN Alert component with variants
- Better visual consistency
- Improved icon handling
- Removed: Alert.css
#### Modal (`Modal.jsx`)
**Before**: Custom overlay and content positioning
**After**:
- ShadCN Dialog component (Radix UI based)
- DialogContent, DialogHeader, DialogFooter
- Smooth animations with backdrop blur
- Better accessibility support
- Removed: Modal.css
#### LoadingSpinner (`LoadingSpinner.jsx`)
**Before**: CSS animation in separate file
**After**:
- Tailwind `animate-spin` class
- Inline border-based spinner
- Dark theme colors
- Removed: LoadingSpinner.css
#### Footer (`Footer.jsx`)
**Before**: Multi-column flex layout with custom styling
**After**:
- Tailwind grid layout with responsive columns
- Better link styling with consistent hover effects
- Improved typography hierarchy
- Removed: Footer.css
### 5. **Global Styles**
#### `index.css` (Updated)
- Moved from vanilla CSS to Tailwind directives (`@tailwind base`, `components`, `utilities`)
- Integrated custom CSS variables with Tailwind
- Maintained animations (fadeIn, spin, pulse) with @keyframes
- Added utility classes for common patterns
- Scrollbar styling with custom colors
#### `App.css` (Updated)
- Converted to Tailwind @apply directives
- Added form utility classes (`.form-group`, `.form-input`, `.form-textarea`, `.form-error`)
- Added grid utilities (`.grid-responsive`, `.grid-two`)
- Added section utilities (`.section-header`, `.section-title`)
- Maintained app layout structure with flexbox
### 6. **Dependencies Added**
```json
{
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-slot": "^2.0.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"react-hook-form": "^7.48.0",
"tailwind-merge": "^2.2.0",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"autoprefixer": "^10.4.16",
"postcss": "^8.4.32",
"tailwindcss": "^3.3.6"
}
}
```
## Usage Examples
### Using Button Component
```jsx
import { Button } from '../lib/ui';
// Basic button
// With variants
// With sizes
// As child (wrapping a Link)
```
### Using Card Component
```jsx
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '../lib/ui';
Primary text
Secondary text
Tertiary text
// AccentWarm accent
``` ### Background Colors ```jsxSuccess message
Warning message
Error message
Info message
``` ### Form Utilities ```jsxError message
Success message
``` ### Grid Utilities ```jsx // 3-column responsive grid