Files
blitzkit/packages/website/src/components/TanksEmbed.tsx
T

128 lines
3.9 KiB
TypeScript
Raw Normal View History

2024-09-07 21:45:00 -05:00
import {
previewCompositeStat,
2024-10-05 20:55:44 -05:00
TankClass,
2024-09-07 21:45:00 -05:00
TankDefinition,
2024-10-05 20:55:44 -05:00
TankType,
type CompositeStatsKey,
2024-09-07 21:45:00 -05:00
} from '@blitzkit/core';
import strings from '@blitzkit/core/lang/en-US.json';
2024-08-08 14:22:04 -05:00
import { amberDark, blueDark } from '@radix-ui/colors';
2024-08-05 14:25:12 -05:00
import { Flex, Text } from '@radix-ui/themes';
2024-09-14 19:43:14 -05:00
import { times } from 'lodash-es';
2024-10-05 20:55:44 -05:00
import type { ReactNode } from 'react';
2024-09-08 21:52:12 -05:00
import { breakdownConfig } from '../constants/embeds';
2024-10-05 20:55:44 -05:00
import { toRadiusVar } from '../core/radix/utils';
import { useEmbedStateCurry } from '../stores/embedState/utilities';
2024-09-07 21:45:00 -05:00
import { ClassHeavy } from './ClassIcon/components/ClassHeavy';
import { ClassLight } from './ClassIcon/components/ClassLight';
import { ClassMedium } from './ClassIcon/components/ClassMedium';
import { ClassTankDestroyer } from './ClassIcon/components/ClassTankDestroyer';
2024-08-05 12:52:40 -05:00
2024-08-07 12:03:45 -05:00
interface BreakdownEmbedWrapperProps {
2024-08-05 12:52:40 -05:00
children: ReactNode;
}
2024-08-07 12:03:45 -05:00
export function BreakdownEmbedWrapper({
children,
}: BreakdownEmbedWrapperProps) {
2024-08-08 14:18:22 -05:00
const { useState } = useEmbedStateCurry<typeof breakdownConfig>();
2024-08-05 12:52:40 -05:00
return (
2024-08-11 13:05:11 -05:00
<Flex direction="column" gap={useState('listGap')} height="100%">
2024-08-05 12:52:40 -05:00
{children}
</Flex>
);
}
2024-08-07 12:03:45 -05:00
interface BreakdownEmbedCardProps {
2024-08-06 13:33:39 -05:00
tank: TankDefinition | null;
2024-08-05 12:52:40 -05:00
}
2024-08-08 14:18:22 -05:00
export function BreakdownEmbedCard({ tank }: BreakdownEmbedCardProps) {
const { useState, useRichText } =
useEmbedStateCurry<typeof breakdownConfig>();
2024-08-05 12:52:40 -05:00
return (
<Flex
2024-08-11 13:05:11 -05:00
flexShrink="0"
2024-08-05 12:52:40 -05:00
direction="column"
style={{
2024-08-08 14:18:22 -05:00
borderRadius: toRadiusVar(useState('cardRadius')),
2024-08-05 12:52:40 -05:00
overflow: 'hidden',
2024-08-08 14:18:22 -05:00
backgroundColor: useState('cardBodyBackgroundColor'),
2024-08-05 12:52:40 -05:00
}}
>
<Flex
justify="center"
style={{
2024-08-08 14:18:22 -05:00
backgroundColor: useState('cardHeaderBackgroundColor'),
2024-08-05 12:52:40 -05:00
}}
2024-08-08 14:18:22 -05:00
p={useState('cardHeaderPadding')}
2024-08-05 12:52:40 -05:00
>
2024-08-06 13:33:39 -05:00
<Text
2024-08-08 14:22:04 -05:00
{...{
...useRichText('cardTitle'),
style:
tank === null
? undefined
2024-10-05 20:55:44 -05:00
: tank.type === TankType.RESEARCHABLE ||
2024-09-08 21:52:12 -05:00
!useState('cardTitleTypeColor')
? undefined
: {
color:
2024-10-05 20:55:44 -05:00
tank.type === TankType.PREMIUM
2024-09-08 21:52:12 -05:00
? amberDark.amber11
: blueDark.blue11,
},
2024-08-08 14:18:22 -05:00
}}
2024-08-06 13:33:39 -05:00
>
<Flex align="center" gap="1">
2024-08-08 14:18:22 -05:00
{useState('cardTitleClassIcon') && tank !== null && (
2024-08-06 13:33:39 -05:00
<>
2024-10-05 20:55:44 -05:00
{tank.class === TankClass.LIGHT && (
2024-08-06 13:33:39 -05:00
<ClassLight width="1em" height="1em" />
)}
2024-10-05 20:55:44 -05:00
{tank.class === TankClass.MEDIUM && (
2024-08-06 13:33:39 -05:00
<ClassMedium width="1em" height="1em" />
)}
2024-10-05 20:55:44 -05:00
{tank.class === TankClass.HEAVY && (
2024-08-06 13:33:39 -05:00
<ClassHeavy width="1em" height="1em" />
)}
2024-10-05 20:55:44 -05:00
{tank.class === TankClass.TANK_DESTROYER && (
2024-08-06 13:33:39 -05:00
<ClassTankDestroyer width="1em" height="1em" />
)}
</>
)}{' '}
{tank === null ? 'Total' : tank.name}
</Flex>
</Text>
2024-08-05 12:52:40 -05:00
</Flex>
2024-08-05 14:25:12 -05:00
2024-08-08 14:18:22 -05:00
<Flex p={useState('cardBodyPadding')}>
2024-08-05 14:25:12 -05:00
{times(4, (index) => {
const column = (index + 1) as 1 | 2 | 3 | 4;
2024-08-10 13:29:10 -05:00
const columnState = useState(`column${column}`) as CompositeStatsKey;
const customLabel = useState(`column${column}CustomLabel`);
2024-08-05 14:25:12 -05:00
return (
<Flex
direction="column"
align="center"
2024-08-08 14:18:22 -05:00
gap={useState('columnGap')}
2024-08-05 14:25:12 -05:00
flexGrow="1"
>
2024-08-08 14:18:22 -05:00
<Text {...useRichText('columnValue')}>
2024-08-10 13:29:10 -05:00
{previewCompositeStat(columnState)}
2024-08-05 14:25:12 -05:00
</Text>
2024-08-08 14:18:22 -05:00
<Text {...useRichText('columnLabel')}>
2024-08-10 13:29:10 -05:00
{customLabel.length === 0
? strings.common.composite_stats[columnState]
: customLabel}
2024-08-05 14:25:12 -05:00
</Text>
</Flex>
);
})}
</Flex>
2024-08-05 12:52:40 -05:00
</Flex>
);
}