diff --git a/packages/web/components/elements/LabelChip.tsx b/packages/web/components/elements/LabelChip.tsx index 412915a00..648977c84 100644 --- a/packages/web/components/elements/LabelChip.tsx +++ b/packages/web/components/elements/LabelChip.tsx @@ -1,6 +1,8 @@ +import { getLuminance, lighten, toHsla } from 'color2k' import { useRouter } from 'next/router' import { Button } from './Button' import { SpanBox } from './LayoutPrimitives' +import { isDarkTheme } from '../../lib/themeUpdater' type LabelChipProps = { text: string @@ -9,6 +11,7 @@ type LabelChipProps = { export function LabelChip(props: LabelChipProps): JSX.Element { const router = useRouter() + const hexToRgb = (hex: string) => { const bigint = parseInt(hex.substring(1), 16) const r = (bigint >> 16) & 255 @@ -17,27 +20,39 @@ export function LabelChip(props: LabelChipProps): JSX.Element { return [r, g, b] } + const isDarkMode = isDarkTheme() + const luminance = getLuminance(props.color) + const lightenColor = lighten(props.color, 0.2) const color = hexToRgb(props.color) - + const darkThemeTextColor = + luminance > 0.2 + ? `rgba(${color[0]}, ${color[1]}, ${color[2]}, 1)` + : lightenColor + const lightThemeTextColor = luminance > 0.5 ? '#000000' : '#ffffff' return ( -