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';
|
2024-10-07 17:31:13 -05:00
|
|
|
import { TankPerformanceSort } from '../../stores/tankPerformanceSort';
|
2024-07-01 20:18:09 -05:00
|
|
|
import {
|
2024-07-12 13:53:11 -05:00
|
|
|
TankPerformanceSortTypeNames,
|
|
|
|
|
TankPerformanceSortTypeNamesArray,
|
2024-10-07 17:31:13 -05:00
|
|
|
} 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();
|
|
|
|
|
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-07-12 13:01:10 -05:00
|
|
|
<StickyColumnHeaderCell>Tank</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
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-11-14 20:55:22 -06:00
|
|
|
{TankPerformanceSortTypeNames[type]}
|
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|