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
|
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) {
|
|
|
|
|
useTankPerformanceSort.setState({
|
|
|
|
|
direction: -sort.direction as 1 | -1,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2024-07-01 20:21:42 -05:00
|
|
|
useTankPerformanceSort.setState({ type, direction: -1 });
|
2024-07-01 20:18:09 -05:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{!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>
|
|
|
|
|
);
|
|
|
|
|
}
|