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

73 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-11-29 13:20:27 -06:00
import { asset } from '@blitzkit/core';
2024-02-13 09:40:00 -06:00
import { ClockIcon, ReloadIcon } from '@radix-ui/react-icons';
import { Flex, Text } from '@radix-ui/themes';
2024-11-29 13:20:27 -06:00
import { awaitableConsumableDefinitions } from '../../core/awaitables/consumableDefinitions';
2024-09-22 22:04:03 -05:00
import { useDelta } from '../../hooks/useDelta';
2024-02-12 19:24:34 -06:00
import { GenericTankComponentButton } from './GenericTankComponentButton';
2024-09-22 22:04:03 -05:00
import type { TankComponentButtonProps } from './TankComponentButton';
2024-02-12 19:24:34 -06:00
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
}
2024-11-29 13:20:27 -06:00
const consumableDefinitions = await awaitableConsumableDefinitions;
2024-09-21 20:26:58 -05:00
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-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-21 19:45:33 -05:00
style={{ width: '6rem' }}
2024-10-05 20:55:44 -05:00
tooltip={consumableDefinitions.consumables[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-09-08 10:11:24 -05:00
? 'tomato'
: undefined
2024-04-06 19:37:57 -05:00
}
>
<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
2024-09-08 10:11:24 -05:00
? 'tomato'
: undefined
2024-04-06 19:37:57 -05:00
}
>
<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
);
}