Files
blitzkit/src/components/ModuleButtons/ConsumableButton.tsx
T

72 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-02-13 09:40:00 -06:00
import { ClockIcon, ReloadIcon } from '@radix-ui/react-icons';
import { Flex, Text } from '@radix-ui/themes';
2024-08-19 14:02:39 -05:00
import { use } from 'react';
2024-04-23 09:57:59 -05:00
import { asset } from '../../core/blitzkit/asset';
2024-08-19 14:02:39 -05:00
import { consumableDefinitions } from '../../core/blitzkit/consumableDefinitions';
2024-02-13 09:40:00 -06:00
import { useDelta } from '../../hooks/useDelta';
2024-02-12 19:24:34 -06:00
import { GenericTankComponentButton } from './GenericTankComponentButton';
import { TankComponentButtonProps } from './TankComponentButton';
interface ConsumableButtonProps extends TankComponentButtonProps {
consumable: number;
2024-02-13 09:40:00 -06:00
duration?: number;
2024-04-06 19:37:57 -05:00
cooldown?: number;
2024-02-12 19:24:34 -06:00
}
export function ConsumableButton({
consumable,
2024-02-13 09:40:00 -06:00
cooldown,
duration,
2024-02-12 19:24:34 -06:00
...props
}: ConsumableButtonProps) {
2024-08-19 14:02:39 -05:00
const awaitedConsumableDefinitions = use(consumableDefinitions);
2024-04-06 19:37:57 -05:00
const cooldownDelta = useDelta(cooldown ?? 0);
2024-02-13 09:40:00 -06:00
const durationDelta = useDelta(duration ?? 0);
2024-02-12 19:24:34 -06:00
return (
<GenericTankComponentButton
2024-08-19 14:02:39 -05:00
tooltip={awaitedConsumableDefinitions[consumable].name}
2024-02-12 19:24:34 -06:00
icon={asset(`icons/consumables/${consumable}.webp`)}
{...props}
2024-02-13 09:40:00 -06:00
>
2024-04-06 19:37:57 -05:00
{(cooldown || duration) && (
<Flex direction="column" gap="1" ml="-2" mr="2">
2024-04-06 19:37:57 -05:00
{duration && (
<Text
size="1"
2024-04-06 19:37:57 -05:00
color={
2024-04-20 11:45:41 -05:00
durationDelta > 0
2024-04-06 19:37:57 -05:00
? 'green'
2024-04-20 11:45:41 -05:00
: durationDelta < 0
2024-04-06 19:37:57 -05:00
? 'tomato'
: undefined
}
>
<Flex align="center" gap="1" style={{ marginBottom: -4 }}>
<ClockIcon width={12} height={12} />
{Math.round(duration)}s
</Flex>
</Text>
)}
{cooldown && (
<Text
size="1"
2024-04-06 19:37:57 -05:00
color={
cooldownDelta < 0
? 'green'
: cooldownDelta > 0
? 'tomato'
: undefined
}
>
<Flex align="center" gap="1">
<ReloadIcon width={12} height={12} />
{Math.round(cooldown)}s
</Flex>
</Text>
)}
</Flex>
)}
2024-02-13 09:40:00 -06:00
</GenericTankComponentButton>
2024-02-12 19:24:34 -06:00
);
}