'use client'; import { ColorInfo as ColorInfoType } from '@/lib/api/types'; import { Button } from '@/components/ui/button'; import { Copy } from 'lucide-react'; import { toast } from 'sonner'; import { cn } from '@/lib/utils/cn'; interface ColorInfoProps { info: ColorInfoType; className?: string; } export function ColorInfo({ info, className }: ColorInfoProps) { const copyToClipboard = (value: string, label: string) => { navigator.clipboard.writeText(value); toast.success(`Copied ${label} to clipboard`); }; const formatRgb = (rgb: { r: number; g: number; b: number; a?: number }) => { if (rgb.a !== undefined && rgb.a < 1) { return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})`; } return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`; }; const formatHsl = (hsl: { h: number; s: number; l: number; a?: number }) => { if (hsl.a !== undefined && hsl.a < 1) { return `hsla(${Math.round(hsl.h)}°, ${Math.round(hsl.s * 100)}%, ${Math.round(hsl.l * 100)}%, ${hsl.a})`; } return `hsl(${Math.round(hsl.h)}°, ${Math.round(hsl.s * 100)}%, ${Math.round(hsl.l * 100)}%)`; }; const formatLab = (lab: { l: number; a: number; b: number }) => { return `lab(${lab.l.toFixed(1)}, ${lab.a.toFixed(1)}, ${lab.b.toFixed(1)})`; }; const formats = [ { label: 'Hex', value: info.hex }, { label: 'RGB', value: formatRgb(info.rgb) }, { label: 'HSL', value: formatHsl(info.hsl) }, { label: 'Lab', value: formatLab(info.lab) }, { label: 'OkLab', value: formatLab(info.oklab) }, ]; return (
{formats.map((format) => (
{format.label}
{format.value}
))}
Brightness
{(info.brightness * 100).toFixed(1)}%
Luminance
{(info.luminance * 100).toFixed(1)}%
Type
{info.is_light ? 'Light' : 'Dark'}
{info.name && typeof info.name === 'string' && (
Named
{info.name}
)}
); }