Files
blitzkit/src/app/tools/tank-performance/components/Header.tsx
T

65 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-07-01 20:18:09 -05:00
'use client';
import {
CaretDownIcon,
CaretSortIcon,
CaretUpIcon,
} from '@radix-ui/react-icons';
import { Flex, IconButton, Table } from '@radix-ui/themes';
2024-07-08 19:59:15 -05:00
import * as TankPerformanceSort from '../../../../stores/tankPerformanceSort';
2024-07-01 20:18:09 -05:00
import {
tankPerformanceSortTypeNames,
tankPerformanceSortTypeNamesArray,
2024-07-08 19:59:15 -05:00
} from '../../../../stores/tankPerformanceSort/constants';
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();
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">
2024-06-30 19:59:32 -05:00
<Table.ColumnHeaderCell>Tank</Table.ColumnHeaderCell>
2024-07-01 20:18:09 -05:00
{tankPerformanceSortTypeNamesArray.map((type) => {
const isSelected = sort.type === type;
return (
<Table.ColumnHeaderCell
2024-07-07 21:06:02 -05:00
px="2"
2024-07-01 20:18:09 -05:00
key={type}
width="0"
justify="center"
minWidth="0px"
>
<Flex align="center" gap="1">
2024-07-07 18:59:01 -05:00
{tankPerformanceSortTypeNames[type]}
2024-07-01 20:18:09 -05:00
<IconButton
2024-07-07 18:07:07 -05:00
size={isSelected ? '1' : '2'}
2024-07-01 20:18:09 -05:00
variant={isSelected ? 'soft' : 'ghost'}
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
}
}}
>
{!isSelected && <CaretSortIcon />}
{isSelected && (
<>
{sort.direction === 1 && <CaretUpIcon />}
{sort.direction === -1 && <CaretDownIcon />}
</>
)}
</IconButton>
</Flex>
</Table.ColumnHeaderCell>
);
})}
2024-06-30 19:59:32 -05:00
</Table.Row>
</Table.Header>
);
}