import { useMemo } from "react"; export function getContrastColor( rgbColor: string, light: LightValue, dark: DarkValue, ): LightValue | DarkValue { const [r, g, b] = rgbColor .replace(/^(rgb|rgba)\(/, "") .replace(/\)$/, "") .replace(/\s/g, "") .split(",") .map(Number); return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? dark : light; } /** * * @kind 02-Colors */ export const useContrast = (color: string, light: LightValue, dark: DarkValue) => { const contrast = useMemo(() => { return getContrastColor(color, light, dark); }, [color, light, dark]); return contrast; };