Files
blitzkit/packages/website/src/components/Performance/Header.tsx
T

64 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-07-01 20:18:09 -05:00
import {
CaretDownIcon,
CaretSortIcon,
CaretUpIcon,
} from '@radix-ui/react-icons';
2024-11-14 20:55:22 -06:00
import { Button, Flex, Table } from '@radix-ui/themes';
2025-01-07 12:47:55 -06:00
import { useLocale } from '../../hooks/useLocale';
2024-10-07 17:31:13 -05:00
import { TankPerformanceSort } from '../../stores/tankPerformanceSort';
2025-01-07 12:47:55 -06:00
import { TankPerformanceSortTypeNamesArray } from '../../stores/tankPerformanceSort/constants';
2024-10-07 17:31:13 -05:00
import { StickyColumnHeaderCell } from '../StickyColumnHeaderCell';
2024-06-30 19:59:32 -05:00
export function Header() {
2024-07-08 19:59:15 -05:00
const sort = TankPerformanceSort.use();
const store = TankPerformanceSort.useStore();
2025-01-07 12:47:55 -06:00
const { strings } = useLocale();
2024-07-01 20:18:09 -05:00
2024-06-30 19:59:32 -05:00
return (
2024-07-07 21:06:02 -05:00
<Table.Header>
2024-07-01 20:18:09 -05:00
<Table.Row align="center">
2025-01-07 12:47:55 -06:00
<StickyColumnHeaderCell>
{strings.website.tools.performance.table.tanks.header}
</StickyColumnHeaderCell>
2024-07-12 13:53:11 -05:00
{TankPerformanceSortTypeNamesArray.map((type) => {
2024-07-01 20:18:09 -05:00
const isSelected = sort.type === type;
return (
2024-07-12 13:01:10 -05:00
<StickyColumnHeaderCell
2024-07-07 21:06:02 -05:00
px="2"
2024-07-01 20:18:09 -05:00
key={type}
width="0"
justify="center"
>
<Flex align="center" gap="1">
2024-11-14 20:55:22 -06:00
<Button
variant="ghost"
2024-07-01 20:18:09 -05:00
color={isSelected ? undefined : 'gray'}
highContrast={!isSelected}
onClick={() => {
if (isSelected) {
2024-07-08 19:59:15 -05:00
store.setState({ direction: -sort.direction as 1 | -1 });
2024-07-01 20:18:09 -05:00
} else {
2024-07-08 19:59:15 -05:00
store.setState({ type, direction: -1 });
2024-07-01 20:18:09 -05:00
}
}}
>
2025-01-07 12:47:55 -06:00
{strings.website.tools.performance.table.stats[type]}
2024-11-14 20:55:22 -06:00
2024-07-01 20:18:09 -05:00
{!isSelected && <CaretSortIcon />}
{isSelected && (
<>
{sort.direction === 1 && <CaretUpIcon />}
{sort.direction === -1 && <CaretDownIcon />}
</>
)}
2024-11-14 20:55:22 -06:00
</Button>
2024-07-01 20:18:09 -05:00
</Flex>
2024-07-12 13:01:10 -05:00
</StickyColumnHeaderCell>
2024-07-01 20:18:09 -05:00
);
})}
2024-06-30 19:59:32 -05:00
</Table.Row>
</Table.Header>
);
}