# 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'; Title Subtitle Content goes here Footer content ``` ### Using Alert Component ```jsx import { Alert, AlertTitle, AlertDescription } from '../lib/ui'; Success Operation completed successfully ``` ### Using Dialog/Modal ```jsx import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '../lib/ui'; import { Button } from '../lib/ui'; Confirm Action

Are you sure?

``` ## Tailwind Utility Classes ### Text Colors ```jsx // Predefined text colors

Primary text

Secondary text

Tertiary text

// Accent

Warm accent

``` ### Background Colors ```jsx
Primary background
Secondary background
``` ### Semantic Colors ```jsx

Success message

Warning message

Error message

Info message

``` ### Form Utilities ```jsx

Error message

Success message

``` ### Grid Utilities ```jsx // 3-column responsive grid
{/* items */}
// 2-column responsive grid
{/* items */}
``` ## Migration Checklist Pages and components that still need refactoring with ShadCN: - [ ] LoginPage.jsx - [ ] RegisterPage.jsx - [ ] HomePage.jsx - [ ] DashboardPage.jsx - [ ] ActiveVotesPage.jsx - [ ] UpcomingVotesPage.jsx - [ ] HistoriquePage.jsx - [ ] ArchivesPage.jsx - [ ] ElectionDetailsPage.jsx - [ ] VotingPage.jsx - [ ] ProfilePage.jsx - [ ] ElectionDetailsModal.jsx **Refactoring suggestions for these pages**: 1. Replace form inputs with ShadCN Input component 2. Replace form groups with form utility classes 3. Use Button component for all actions 4. Use Card for content grouping 5. Use Alert for notifications 6. Replace dividers with Tailwind borders 7. Use Badge for status indicators 8. Use consistent spacing with Tailwind (gap-4, mb-6, etc.) ## Installation & Setup ### 1. Install Dependencies ```bash cd frontend npm install ``` ### 2. Build Process No additional build steps needed. Tailwind CSS is processed via PostCSS during the build. ### 3. Development ```bash npm start ``` The development server will compile Tailwind CSS on the fly. ## Benefits 1. **Consistency**: Unified component API across the application 2. **Maintainability**: Easier to update styles globally 3. **Accessibility**: Radix UI components include ARIA labels and keyboard navigation 4. **Type Safety**: Can be extended with TypeScript in the future 5. **Performance**: Tailwind purges unused CSS in production 6. **Dark Theme**: Complete dark theme implementation out of the box 7. **Responsive Design**: Mobile-first Tailwind approach 8. **Animation Support**: Built-in animation utilities with tailwindcss-animate ## Future Enhancements 1. **Forms**: Implement complete form library with validation 2. **Data Tables**: Add data table component for displaying election results 3. **Charts**: Add charting library for result visualization 4. **Modals**: Create specialized modal dialogs for specific use cases 5. **TypeScript**: Convert components to TypeScript 6. **Theme Switcher**: Add ability to switch between light/dark themes 7. **Storybook**: Document components with Storybook ## Files Modified ### Core Configuration - `/frontend/package.json` - Added dependencies - `/frontend/tailwind.config.js` - New file - `/frontend/postcss.config.js` - New file ### Styling - `/frontend/src/index.css` - Updated with Tailwind directives - `/frontend/src/App.css` - Updated with utility classes ### Components - `/frontend/src/components/Header.jsx` - Refactored to use ShadCN Button - `/frontend/src/components/VoteCard.jsx` - Refactored to use ShadCN Card, Badge, Button - `/frontend/src/components/Alert.jsx` - Refactored to use ShadCN Alert - `/frontend/src/components/Modal.jsx` - Refactored to use ShadCN Dialog - `/frontend/src/components/LoadingSpinner.jsx` - Refactored with Tailwind - `/frontend/src/components/Footer.jsx` - Refactored with Tailwind ### UI Library (New) - `/frontend/src/lib/` - New directory - `/frontend/src/lib/utils.js` - Utility functions - `/frontend/src/lib/ui/` - Component library - `button.jsx` - `card.jsx` - `alert.jsx` - `dialog.jsx` - `input.jsx` - `label.jsx` - `badge.jsx` - `dropdown-menu.jsx` - `index.js` ### Removed (CSS files now handled by Tailwind) - `/frontend/src/components/Header.css` - `/frontend/src/components/Alert.css` - `/frontend/src/components/Modal.css` - `/frontend/src/components/LoadingSpinner.css` - `/frontend/src/components/Footer.css` - `/frontend/src/components/VoteCard.css` - `/frontend/src/styles/globals.css` (integrated into index.css) - `/frontend/src/styles/components.css` (handled by Tailwind) ## Next Steps 1. **Install dependencies**: `npm install` 2. **Test the application**: `npm start` 3. **Refactor remaining pages**: Use the migration checklist above 4. **Customize components**: Extend ShadCN components as needed 5. **Add dark mode detection**: Implement automatic dark/light theme switching 6. **Performance testing**: Verify CSS bundle size and performance --- **Created**: November 6, 2025 **Version**: 1.0 **Status**: Initial refactoring complete, ready for page component refactoring