forked from pavlitoPogosov/React-Table-Component
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableHeadSorter.tsx
More file actions
52 lines (43 loc) · 1.19 KB
/
Copy pathTableHeadSorter.tsx
File metadata and controls
52 lines (43 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, {type ReactNode} from 'react';
import {Flex} from 'reflexbox';
import styled from 'styled-components';
import {COLOR, TRANSITION} from '../../lib';
import {ArrowDownSvg, ArrowUpSvg, SorterSvg} from '../icons';
import {Spacer} from '../Spacer';
type TableHeadSorterProps = {
text?: ReactNode;
value?: boolean | null;
onChange?: (value: boolean | null) => void;
};
export function TableHeadSorter({text, value, onChange}: TableHeadSorterProps) {
const handleClick = () => {
if (value === null) {
return onChange?.(true);
}
if (value === true) {
return onChange?.(false);
}
onChange?.(null);
};
return (
<Flex alignItems="center">
{text}
<Spacer direction="horizontal" size={8} />
<StyledIcon alignItems="center" justifyContent="center" onClick={handleClick}>
{value === null && <SorterSvg />}
{value === true && <ArrowUpSvg />}
{value === false && <ArrowDownSvg />}
</StyledIcon>
</Flex>
);
}
const StyledIcon = styled(Flex)`
width: 16px;
height: 16px;
color: ${COLOR.gray[50]};
cursor: pointer;
transition: color ${TRANSITION.basic};
&:hover {
color: ${COLOR.gray[60]};
}
`;