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

63 lines
1.9 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';
import {
tankPerformanceSortTypeNames,
tankPerformanceSortTypeNamesArray,
useTankPerformanceSort,
} from '../../../../stores/tankPerformanceSort';
2024-06-30 19:59:32 -05:00
export function Header() {
2024-07-01 20:18:09 -05:00
const sort = useTankPerformanceSort();
2024-06-30 19:59:32 -05:00
return (
2024-07-01 19:41:13 -05:00
<Table.Header style={{ whiteSpace: 'nowrap' }}>
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
key={type}
width="0"
justify="center"
minWidth="0px"
>
<Flex align="center" gap="1">
<IconButton
variant={isSelected ? 'soft' : 'ghost'}
color={isSelected ? undefined : 'gray'}
highContrast={!isSelected}
onClick={() => {
if (isSelected) {
useTankPerformanceSort.setState({
direction: -sort.direction as 1 | -1,
});
} else {
useTankPerformanceSort.setState({ type });
}
}}
>
{!isSelected && <CaretSortIcon />}
{isSelected && (
<>
{sort.direction === 1 && <CaretUpIcon />}
{sort.direction === -1 && <CaretDownIcon />}
</>
)}
</IconButton>
{tankPerformanceSortTypeNames[type]}
</Flex>
</Table.ColumnHeaderCell>
);
})}
2024-06-30 19:59:32 -05:00
</Table.Row>
</Table.Header>
);
}