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

74 lines
2.2 KiB
TypeScript
Raw Normal View History

2026-03-31 14:11:45 -05:00
import { ClockIcon, ReloadIcon } from "@radix-ui/react-icons";
import { Flex, Text } from "@radix-ui/themes";
2026-08-04 14:02:52 -05:00
import { api } from "../../core/blitzkit/api";
2026-03-31 14:11:45 -05:00
import { useDelta } from "../../hooks/useDelta";
import { useLocale } from "../../hooks/useLocale";
import { GenericTankComponentButton } from "./GenericTankComponentButton";
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
}
2026-08-04 14:02:52 -05:00
const consumableDefinitions = await api.consumableDefinitions();
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);
2025-01-14 19:22:41 -06:00
const { unwrap } = useLocale();
2024-02-13 09:40:00 -06:00
2024-02-12 19:24:34 -06:00
return (
<GenericTankComponentButton
2026-03-31 14:11:45 -05:00
style={{ width: "6rem" }}
tooltip={unwrap(consumableDefinitions.consumables[consumable].name!)}
2026-08-04 14:02:52 -05:00
icon={`/api/icons/consumables/${consumable}.webp`}
2024-02-12 19:24:34 -06:00
{...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
2026-03-31 14:11:45 -05:00
? "green"
2024-04-20 11:45:41 -05:00
: durationDelta < 0
2026-03-31 14:11:45 -05:00
? "tomato"
2024-09-08 10:11:24 -05:00
: 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
2026-03-31 14:11:45 -05:00
? "green"
2024-04-06 19:37:57 -05:00
: cooldownDelta > 0
2026-03-31 14:11:45 -05:00
? "tomato"
2024-09-08 10:11:24 -05:00
: 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
);
}