diff --git a/src/Components/Buttons/LifeCounterButton.tsx b/src/Components/Buttons/LifeCounterButton.tsx index 007da84..a5743f5 100644 --- a/src/Components/Buttons/LifeCounterButton.tsx +++ b/src/Components/Buttons/LifeCounterButton.tsx @@ -1,8 +1,9 @@ -import { useRef, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { TwcComponentProps, twc } from 'react-twc'; import { lifeLongPressMultiplier } from '../../Data/constants'; -import { Rotation } from '../../Types/Player'; +import { Player, Rotation } from '../../Types/Player'; import { MAX_TAP_MOVE_DISTANCE } from './CommanderDamage'; +import { checkContrast } from '../../Utils/checkContrast'; type RotationButtonProps = TwcComponentProps<'div'> & { $align?: string; @@ -13,7 +14,6 @@ const LifeCounterButtonTwc = twc.button` h-full w-full flex - text-lifeCounter-text font-semibold bg-transparent border-none @@ -40,17 +40,15 @@ const TextContainer = twc.div((props) => [ ]); type LifeCounterButtonProps = { - lifeTotal: number; + player: Player; setLifeTotal: (lifeTotal: number) => void; - rotation: number; operation: 'add' | 'subtract'; increment: number; }; const LifeCounterButton = ({ - lifeTotal, + player, setLifeTotal, - rotation, operation, increment, }: LifeCounterButtonProps) => { @@ -59,8 +57,20 @@ const LifeCounterButton = ({ const [hasPressedDown, setHasPressedDown] = useState(false); const downPositionRef = useRef({ x: 0, y: 0 }); + const [iconColor, setIconColor] = useState<'dark' | 'light'>('dark'); + + useEffect(() => { + const contrast = checkContrast(player.color, '#00000080'); + + if (contrast === 'Fail') { + setIconColor('light'); + } else { + setIconColor('dark'); + } + }, [player.color]); + const handleLifeChange = (increment: number) => { - setLifeTotal(lifeTotal + increment); + setLifeTotal(player.lifeTotal + increment); }; const handleDownInput = (event: React.PointerEvent) => { @@ -102,7 +112,8 @@ const LifeCounterButton = ({ }; const fontSize = - rotation === Rotation.SideFlipped || rotation === Rotation.Side + player.settings.rotation === Rotation.SideFlipped || + player.settings.rotation === Rotation.Side ? '8vmax' : '12vmin'; @@ -118,8 +129,11 @@ const LifeCounterButton = ({ aria-label={`${operation === 'add' ? 'Add' : 'Subtract'} life`} > {operation === 'add' ? '\u002B' : '\u2212'} diff --git a/src/Components/LifeCounter/Health.tsx b/src/Components/LifeCounter/Health.tsx index a3b1e2b..2128776 100644 --- a/src/Components/LifeCounter/Health.tsx +++ b/src/Components/LifeCounter/Health.tsx @@ -118,9 +118,8 @@ const Health = ({ return ( @@ -148,9 +147,8 @@ const Health = ({ diff --git a/tailwind.config.ts b/tailwind.config.ts index 44b0e56..df02515 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -55,8 +55,8 @@ export default { settings: 'rgba(20, 20, 0, 0.9)', }, icons: { - dark: '#000000', - light: '#FFFFFF', + dark: '#00000080', + light: '#ffffff4f', }, text: { primary: '#F5F5F5',