'use client'; import { useState } from 'react'; import { ColorPicker } from '@/components/color/ColorPicker'; import { ColorDisplay } from '@/components/color/ColorDisplay'; import { Button } from '@/components/ui/button'; import { useTextColor } from '@/lib/api/queries'; import { Loader2, Palette, Plus, X, CheckCircle2, XCircle } from 'lucide-react'; import { toast } from 'sonner'; export default function TextColorPage() { const [backgrounds, setBackgrounds] = useState(['#ff0099']); const [results, setResults] = useState< Array<{ background: string; textcolor: string; contrast_ratio: number; wcag_aa: boolean; wcag_aaa: boolean; }> >([]); const textColorMutation = useTextColor(); const handleOptimize = async () => { try { const result = await textColorMutation.mutateAsync({ backgrounds, }); setResults(result.colors); toast.success(`Optimized text colors for ${result.colors.length} background(s)`); } catch (error) { toast.error('Failed to optimize text colors'); console.error(error); } }; const addBackground = () => { if (backgrounds.length < 10) { setBackgrounds([...backgrounds, '#000000']); } }; const removeBackground = (index: number) => { if (backgrounds.length > 1) { setBackgrounds(backgrounds.filter((_, i) => i !== index)); } }; const updateBackground = (index: number, color: string) => { const newBackgrounds = [...backgrounds]; newBackgrounds[index] = color; setBackgrounds(newBackgrounds); }; return (

Text Color Optimizer

Automatically find the best text color (black or white) for any background color

{/* Input */}

Background Colors

{backgrounds.map((color, index) => (
updateBackground(index, newColor)} />
{backgrounds.length > 1 && ( )}
))}

How it works

This tool analyzes each background color and automatically selects either black or white text to ensure maximum readability. The algorithm guarantees WCAG AA compliance (4.5:1 contrast ratio) for normal text.

{/* Results */}
{results.length > 0 ? ( <>

Optimized Results

{results.map((result, index) => (
{result.background}

Sample Text Preview

The quick brown fox jumps over the lazy dog. This is how your text will look on this background color.

Text Color: {result.textcolor}
Contrast: {result.contrast_ratio.toFixed(2)}:1
{result.wcag_aa ? ( ) : ( )} WCAG AA
{result.wcag_aaa ? ( ) : ( )} WCAG AAA
))}
) : (

Add background colors and click Optimize to see results

)}
); }