2025-11-08 09:34:57 +01:00
|
|
|
'use client';
|
|
|
|
|
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
import { useState, useEffect, useCallback } from 'react';
|
2025-11-08 10:20:32 +01:00
|
|
|
import { Copy, Star, Check, ArrowLeftRight, BarChart3 } from 'lucide-react';
|
2025-11-08 09:34:57 +01:00
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
|
|
|
import { Input } from '@/components/ui/input';
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
import SearchUnits from './SearchUnits';
|
|
|
|
|
import ConversionHistory from './ConversionHistory';
|
2025-11-08 10:20:32 +01:00
|
|
|
import VisualComparison from './VisualComparison';
|
|
|
|
|
import CommandPalette from '@/components/ui/CommandPalette';
|
2025-11-08 09:34:57 +01:00
|
|
|
import {
|
|
|
|
|
getAllMeasures,
|
|
|
|
|
getUnitsForMeasure,
|
|
|
|
|
convertToAll,
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
convertUnit,
|
2025-11-08 09:34:57 +01:00
|
|
|
formatMeasureName,
|
|
|
|
|
getCategoryColor,
|
2025-11-08 10:31:35 +01:00
|
|
|
getCategoryColorHex,
|
2025-11-08 09:34:57 +01:00
|
|
|
type Measure,
|
|
|
|
|
type ConversionResult,
|
|
|
|
|
} from '@/lib/units';
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
import { parseNumberInput, formatNumber, cn } from '@/lib/utils';
|
|
|
|
|
import { saveToHistory, getFavorites, toggleFavorite } from '@/lib/storage';
|
2025-11-08 09:34:57 +01:00
|
|
|
|
|
|
|
|
export default function MainConverter() {
|
|
|
|
|
const [selectedMeasure, setSelectedMeasure] = useState<Measure>('length');
|
|
|
|
|
const [selectedUnit, setSelectedUnit] = useState<string>('m');
|
2025-11-08 10:20:32 +01:00
|
|
|
const [targetUnit, setTargetUnit] = useState<string>('ft');
|
2025-11-08 09:34:57 +01:00
|
|
|
const [inputValue, setInputValue] = useState<string>('1');
|
|
|
|
|
const [conversions, setConversions] = useState<ConversionResult[]>([]);
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
const [favorites, setFavorites] = useState<string[]>([]);
|
|
|
|
|
const [copiedUnit, setCopiedUnit] = useState<string | null>(null);
|
2025-11-08 10:20:32 +01:00
|
|
|
const [showVisualComparison, setShowVisualComparison] = useState(false);
|
2025-11-08 10:54:05 +01:00
|
|
|
const [isDragging, setIsDragging] = useState(false);
|
2025-11-08 09:34:57 +01:00
|
|
|
|
|
|
|
|
const measures = getAllMeasures();
|
|
|
|
|
const units = getUnitsForMeasure(selectedMeasure);
|
|
|
|
|
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
// Load favorites
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setFavorites(getFavorites());
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-11-08 09:34:57 +01:00
|
|
|
// Update conversions when input changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const numValue = parseNumberInput(inputValue);
|
|
|
|
|
if (numValue !== null && selectedUnit) {
|
|
|
|
|
const results = convertToAll(numValue, selectedUnit);
|
|
|
|
|
setConversions(results);
|
|
|
|
|
} else {
|
|
|
|
|
setConversions([]);
|
|
|
|
|
}
|
|
|
|
|
}, [inputValue, selectedUnit]);
|
|
|
|
|
|
|
|
|
|
// Update selected unit when measure changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const availableUnits = getUnitsForMeasure(selectedMeasure);
|
|
|
|
|
if (availableUnits.length > 0) {
|
|
|
|
|
setSelectedUnit(availableUnits[0]);
|
2025-11-08 10:20:32 +01:00
|
|
|
setTargetUnit(availableUnits[1] || availableUnits[0]);
|
2025-11-08 09:34:57 +01:00
|
|
|
}
|
|
|
|
|
}, [selectedMeasure]);
|
|
|
|
|
|
2025-11-08 10:20:32 +01:00
|
|
|
// Swap units
|
|
|
|
|
const handleSwapUnits = useCallback(() => {
|
|
|
|
|
const temp = selectedUnit;
|
|
|
|
|
setSelectedUnit(targetUnit);
|
|
|
|
|
setTargetUnit(temp);
|
|
|
|
|
|
|
|
|
|
// Convert the value
|
|
|
|
|
const numValue = parseNumberInput(inputValue);
|
|
|
|
|
if (numValue !== null) {
|
|
|
|
|
const converted = convertUnit(numValue, selectedUnit, targetUnit);
|
|
|
|
|
setInputValue(converted.toString());
|
|
|
|
|
}
|
|
|
|
|
}, [selectedUnit, targetUnit, inputValue]);
|
|
|
|
|
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
// Copy to clipboard
|
|
|
|
|
const copyToClipboard = useCallback(async (value: number, unit: string) => {
|
|
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(`${formatNumber(value)} ${unit}`);
|
|
|
|
|
setCopiedUnit(unit);
|
|
|
|
|
setTimeout(() => setCopiedUnit(null), 2000);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Failed to copy:', error);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
// Toggle favorite
|
|
|
|
|
const handleToggleFavorite = useCallback((unit: string) => {
|
|
|
|
|
const isFavorite = toggleFavorite(unit);
|
|
|
|
|
setFavorites(getFavorites());
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-11-08 10:54:05 +01:00
|
|
|
// Save to history when conversion happens (but not during dragging)
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
useEffect(() => {
|
2025-11-08 10:54:05 +01:00
|
|
|
if (isDragging) return; // Don't save to history while dragging
|
|
|
|
|
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
const numValue = parseNumberInput(inputValue);
|
|
|
|
|
if (numValue !== null && selectedUnit && conversions.length > 0) {
|
|
|
|
|
// Save first conversion to history
|
|
|
|
|
const firstConversion = conversions.find(c => c.unit !== selectedUnit);
|
|
|
|
|
if (firstConversion) {
|
|
|
|
|
saveToHistory({
|
|
|
|
|
from: { value: numValue, unit: selectedUnit },
|
|
|
|
|
to: { value: firstConversion.value, unit: firstConversion.unit },
|
|
|
|
|
measure: selectedMeasure,
|
|
|
|
|
});
|
|
|
|
|
// Dispatch custom event for same-window updates
|
|
|
|
|
window.dispatchEvent(new Event('historyUpdated'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-08 10:54:05 +01:00
|
|
|
}, [inputValue, selectedUnit, conversions, selectedMeasure, isDragging]);
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
|
|
|
|
|
// Handle search selection
|
|
|
|
|
const handleSearchSelect = useCallback((unit: string, measure: Measure) => {
|
|
|
|
|
setSelectedMeasure(measure);
|
|
|
|
|
setSelectedUnit(unit);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
// Handle history selection
|
|
|
|
|
const handleHistorySelect = useCallback((record: any) => {
|
|
|
|
|
setInputValue(record.from.value.toString());
|
|
|
|
|
setSelectedMeasure(record.measure);
|
|
|
|
|
setSelectedUnit(record.from.unit);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-11-08 10:40:30 +01:00
|
|
|
// Handle value change from draggable bars
|
2025-11-08 10:54:05 +01:00
|
|
|
const handleValueChange = useCallback((value: number, unit: string, dragging: boolean) => {
|
|
|
|
|
setIsDragging(dragging);
|
2025-11-08 10:59:57 +01:00
|
|
|
|
|
|
|
|
// Convert the dragged unit's value back to the currently selected unit
|
|
|
|
|
// This keeps the source unit stable while updating the value
|
|
|
|
|
const convertedValue = convertUnit(value, unit, selectedUnit);
|
|
|
|
|
setInputValue(convertedValue.toString());
|
|
|
|
|
// Keep selectedUnit unchanged
|
|
|
|
|
}, [selectedUnit]);
|
2025-11-08 10:40:30 +01:00
|
|
|
|
2025-11-08 09:34:57 +01:00
|
|
|
return (
|
|
|
|
|
<div className="w-full max-w-6xl mx-auto space-y-6">
|
2025-11-08 10:20:32 +01:00
|
|
|
{/* Command Palette */}
|
|
|
|
|
<CommandPalette
|
|
|
|
|
onSelectMeasure={setSelectedMeasure}
|
|
|
|
|
onSelectUnit={handleSearchSelect}
|
|
|
|
|
/>
|
|
|
|
|
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
{/* Search */}
|
|
|
|
|
<div className="flex justify-center">
|
|
|
|
|
<SearchUnits onSelectUnit={handleSearchSelect} />
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-11-08 09:34:57 +01:00
|
|
|
{/* Category Selection */}
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Select Category</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-2">
|
|
|
|
|
{measures.map((measure) => (
|
|
|
|
|
<Button
|
|
|
|
|
key={measure}
|
|
|
|
|
variant={selectedMeasure === measure ? 'default' : 'outline'}
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => setSelectedMeasure(measure)}
|
|
|
|
|
className="justify-start"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor:
|
|
|
|
|
selectedMeasure === measure
|
2025-11-08 10:36:26 +01:00
|
|
|
? getCategoryColorHex(measure)
|
2025-11-08 09:34:57 +01:00
|
|
|
: undefined,
|
2025-11-08 10:36:26 +01:00
|
|
|
borderColor: selectedMeasure !== measure
|
|
|
|
|
? getCategoryColorHex(measure)
|
|
|
|
|
: undefined,
|
|
|
|
|
color: selectedMeasure === measure ? 'white' : undefined,
|
2025-11-08 09:34:57 +01:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{formatMeasureName(measure)}
|
|
|
|
|
</Button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* Input Section */}
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Convert {formatMeasureName(selectedMeasure)}</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="space-y-4">
|
2025-11-08 10:20:32 +01:00
|
|
|
<div className="flex gap-2 items-end">
|
2025-11-08 09:34:57 +01:00
|
|
|
<div className="flex-1">
|
|
|
|
|
<label className="text-sm font-medium mb-2 block">Value</label>
|
|
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
inputMode="decimal"
|
|
|
|
|
value={inputValue}
|
|
|
|
|
onChange={(e) => setInputValue(e.target.value)}
|
|
|
|
|
placeholder="Enter value"
|
|
|
|
|
className="text-lg"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-11-08 10:20:32 +01:00
|
|
|
<div className="w-40">
|
|
|
|
|
<label className="text-sm font-medium mb-2 block">From</label>
|
2025-11-08 09:34:57 +01:00
|
|
|
<select
|
|
|
|
|
value={selectedUnit}
|
|
|
|
|
onChange={(e) => setSelectedUnit(e.target.value)}
|
|
|
|
|
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
|
|
|
>
|
|
|
|
|
{units.map((unit) => (
|
|
|
|
|
<option key={unit} value={unit}>
|
|
|
|
|
{unit}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
2025-11-08 10:20:32 +01:00
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={handleSwapUnits}
|
|
|
|
|
className="flex-shrink-0"
|
|
|
|
|
title="Swap units"
|
|
|
|
|
>
|
|
|
|
|
<ArrowLeftRight className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<div className="w-40">
|
|
|
|
|
<label className="text-sm font-medium mb-2 block">To</label>
|
|
|
|
|
<select
|
|
|
|
|
value={targetUnit}
|
|
|
|
|
onChange={(e) => setTargetUnit(e.target.value)}
|
|
|
|
|
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
|
|
|
>
|
|
|
|
|
{units.map((unit) => (
|
|
|
|
|
<option key={unit} value={unit}>
|
|
|
|
|
{unit}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
2025-11-08 09:34:57 +01:00
|
|
|
</div>
|
2025-11-08 10:20:32 +01:00
|
|
|
|
|
|
|
|
{/* Quick result */}
|
|
|
|
|
{parseNumberInput(inputValue) !== null && (
|
|
|
|
|
<div className="p-4 rounded-lg bg-accent/50 border-l-4" style={{
|
2025-11-08 10:36:26 +01:00
|
|
|
borderLeftColor: getCategoryColorHex(selectedMeasure),
|
2025-11-08 10:20:32 +01:00
|
|
|
}}>
|
|
|
|
|
<div className="text-sm text-muted-foreground">Result</div>
|
2025-11-08 10:36:26 +01:00
|
|
|
<div className="text-3xl font-bold mt-1" style={{
|
|
|
|
|
color: getCategoryColorHex(selectedMeasure),
|
|
|
|
|
}}>
|
2025-11-08 10:20:32 +01:00
|
|
|
{formatNumber(convertUnit(parseNumberInput(inputValue)!, selectedUnit, targetUnit))} {targetUnit}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-08 09:34:57 +01:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* Results */}
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
2025-11-08 10:20:32 +01:00
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<CardTitle>All Conversions</CardTitle>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={() => setShowVisualComparison(!showVisualComparison)}
|
|
|
|
|
>
|
|
|
|
|
<BarChart3 className="h-4 w-4 mr-2" />
|
|
|
|
|
{showVisualComparison ? 'Grid View' : 'Chart View'}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-11-08 09:34:57 +01:00
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
2025-11-08 10:20:32 +01:00
|
|
|
{showVisualComparison ? (
|
|
|
|
|
<VisualComparison
|
|
|
|
|
conversions={conversions}
|
2025-11-08 10:31:35 +01:00
|
|
|
color={getCategoryColorHex(selectedMeasure)}
|
2025-11-08 10:40:30 +01:00
|
|
|
onValueChange={handleValueChange}
|
2025-11-08 10:20:32 +01:00
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
|
|
|
{conversions.map((conversion) => {
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
const isFavorite = favorites.includes(conversion.unit);
|
|
|
|
|
const isCopied = copiedUnit === conversion.unit;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={conversion.unit}
|
|
|
|
|
className="group relative p-4 rounded-lg border bg-card hover:bg-accent/50 transition-colors"
|
|
|
|
|
style={{
|
|
|
|
|
borderLeftWidth: '4px',
|
2025-11-08 10:36:26 +01:00
|
|
|
borderLeftColor: getCategoryColorHex(selectedMeasure),
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{/* Favorite & Copy buttons */}
|
|
|
|
|
<div className="absolute top-2 right-2 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-8 w-8"
|
|
|
|
|
onClick={() => handleToggleFavorite(conversion.unit)}
|
|
|
|
|
>
|
|
|
|
|
<Star
|
|
|
|
|
className={cn(
|
|
|
|
|
'h-4 w-4',
|
|
|
|
|
isFavorite && 'fill-yellow-400 text-yellow-400'
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="h-8 w-8"
|
|
|
|
|
onClick={() => copyToClipboard(conversion.value, conversion.unit)}
|
|
|
|
|
>
|
|
|
|
|
{isCopied ? (
|
|
|
|
|
<Check className="h-4 w-4 text-green-500" />
|
|
|
|
|
) : (
|
|
|
|
|
<Copy className="h-4 w-4" />
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="text-sm text-muted-foreground mb-1">
|
|
|
|
|
{conversion.unitInfo.plural}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-2xl font-bold">
|
|
|
|
|
{formatNumber(conversion.value)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-sm text-muted-foreground mt-1">
|
|
|
|
|
{conversion.unit}
|
|
|
|
|
</div>
|
2025-11-08 09:34:57 +01:00
|
|
|
</div>
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
);
|
|
|
|
|
})}
|
2025-11-08 10:20:32 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-08 09:34:57 +01:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
feat: implement Phase 3 - Advanced UX features and interactivity
Add comprehensive UX enhancements with innovative features:
🔍 Fuzzy Search Component (SearchUnits.tsx):
- Powered by Fuse.js for intelligent fuzzy matching
- Searches across unit abbreviations, names, and categories
- Real-time dropdown with results
- Keyboard shortcut: Press "/" to focus search
- Press Escape to close
- Click outside to dismiss
- Shows measure category with color dot
- Top 10 results displayed
- Smart weighting: abbr (2x), singular/plural (1.5x), measure (1x)
💾 Conversion History (ConversionHistory.tsx):
- LocalStorage persistence (max 50 entries)
- Auto-saves conversions as user types
- Collapsible history panel
- Click to restore previous conversion
- Clear all with confirmation
- Shows relative time (just now, 5m ago, etc.)
- Live updates across tabs with storage events
- Custom event dispatch for same-window updates
🌓 Dark Mode Support:
- ThemeProvider with light/dark/system modes
- Persistent theme preference in localStorage
- Smooth theme transitions
- ThemeToggle component with animated sun/moon icons
- Gradient text adapts to theme
- System preference detection
⭐ Favorites & Copy Features:
- Star button to favorite units (localStorage)
- Copy to clipboard with visual feedback
- Hover to reveal action buttons
- Check icon confirmation for 2 seconds
- Yellow star fill for favorited units
⌨️ Keyboard Shortcuts:
- "/" - Focus search input
- "Escape" - Close search, blur inputs
- More shortcuts ready to add (Tab, Ctrl+K, etc.)
📦 LocalStorage Utilities (lib/storage.ts):
- saveToHistory() - Add conversion record
- getHistory() - Retrieve history
- clearHistory() - Clear all history
- getFavorites() / addToFavorites() / removeFromFavorites()
- toggleFavorite() - Toggle favorite status
- Type-safe ConversionRecord interface
- Automatic error handling
🎨 Enhanced MainConverter:
- Integrated search at top
- Conversion history at bottom
- Copy & favorite buttons on each result card
- Hover effects with opacity transitions
- Auto-save to history on conversion
- Click history item to restore conversion
- Visual feedback for all interactions
📱 Updated Layout & Page:
- ThemeProvider wraps entire app
- suppressHydrationWarning for SSR
- Top navigation bar with theme toggle
- Keyboard hint for search
- Dark mode gradient text variants
Dependencies Added:
- fuse.js 7.1.0 - Fuzzy search engine
- lucide-react 0.553.0 - Icon library (Search, Copy, Star, Check, etc.)
Features Now Working:
✅ Intelligent fuzzy search across 187 units
✅ Conversion history with persistence
✅ Dark mode with system detection
✅ Copy any result to clipboard
✅ Favorite units for quick access
✅ Keyboard shortcuts (/, Esc)
✅ Smooth animations and transitions
✅ Mobile-responsive design
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 10:14:03 +01:00
|
|
|
|
|
|
|
|
{/* Conversion History */}
|
|
|
|
|
<ConversionHistory onSelectConversion={handleHistorySelect} />
|
2025-11-08 09:34:57 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|