'use client'; import { useState, useEffect } from 'react'; import { ColorPicker } from '@/components/pastel/ColorPicker'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { AppPage } from '@/components/layout/AppPage'; import { getContrastRatio, hexToRgb, checkWCAGCompliance } from '@/lib/pastel/utils/color'; import { ArrowLeftRight, Check, X } from 'lucide-react'; export default function ContrastPage() { const [foreground, setForeground] = useState('#000000'); const [background, setBackground] = useState('#ffffff'); const [ratio, setRatio] = useState(null); const [compliance, setCompliance] = useState(null); useEffect(() => { const fgRgb = hexToRgb(foreground); const bgRgb = hexToRgb(background); if (fgRgb && bgRgb) { const contrastRatio = getContrastRatio(fgRgb, bgRgb); setRatio(contrastRatio); setCompliance(checkWCAGCompliance(contrastRatio)); } }, [foreground, background]); const swapColors = () => { const temp = foreground; setForeground(background); setBackground(temp); }; const ComplianceItem = ({ label, passed, }: { label: string; passed: boolean; }) => (
{label} {passed ? ( <> Pass ) : ( <> Fail )}
); return (
{/* Color Pickers */}
Foreground Color
Background Color
{/* Results */}
{/* Preview */} Preview

Normal Text (16px)

Large Text (24px)

{/* Contrast Ratio */} {ratio !== null && ( Contrast Ratio
{ratio.toFixed(2)}:1

{ratio >= 7 ? 'Excellent contrast' : ratio >= 4.5 ? 'Good contrast' : ratio >= 3 ? 'Minimum contrast' : 'Poor contrast'}

)} {/* WCAG Compliance */} {compliance && ( WCAG 2.1 Compliance

Level AA

Level AAA

)}
); }