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

68 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-07-01 20:18:09 -05:00
import {
CaretDownIcon,
CaretSortIcon,
CaretUpIcon,
2025-09-02 16:24:13 -05:00
} from "@radix-ui/react-icons";
import { Button, Flex, Table } from "@radix-ui/themes";
import { useLocale } from "../../hooks/useLocale";
import { TankPerformanceSort } from "../../stores/tankPerformanceSort";
import { TankPerformanceSortTypeNamesArray } from "../../stores/tankPerformanceSort/constants";
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();
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"
2025-09-02 16:24:13 -05:00
color={isSelected ? undefined : "gray"}
2024-07-01 20:18:09 -05:00
highContrast={!isSelected}
onClick={() => {
if (isSelected) {
2025-09-02 16:24:13 -05:00
TankPerformanceSort.mutate((draft) => {
draft.direction *= -1;
});
2024-07-01 20:18:09 -05:00
} else {
2025-09-02 16:24:13 -05:00
TankPerformanceSort.mutate((draft) => {
draft.type = type;
draft.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>
);
}