-
Notifications
You must be signed in to change notification settings - Fork 12
/
BestMatchSort.jsx
40 lines (37 loc) · 1.16 KB
/
BestMatchSort.jsx
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
import React from 'react';
import { Tooltip, Chip } from '@mui/material';
import {
ArrowDownward as ArrowDownwardIcon,
ArrowUpward as ArrowUpwardIcon,
} from '@mui/icons-material';
import { get } from 'lodash';
const SORT_ICON_STYLES = {width: '14px', height: '14px'};
const BestMatchSort = ({ selected, onSelect, size }) => {
const isSelected = !selected || selected.sortDesc === '_score' || selected.sortAsc === '_score';
const isAsc = get(selected, 'sortAsc') === '_score';
const onClick = () => {
if(!isSelected || isAsc)
onSelect({sortDesc: '_score'})
else
onSelect({sortAsc: '_score'})
};
return (
<span>
<Tooltip arrow title='Sort By Best Match (score)'>
<Chip
icon={
isAsc ?
<ArrowUpwardIcon fontSize="inherit" style={SORT_ICON_STYLES} /> :
<ArrowDownwardIcon fontSize="inherit" style={SORT_ICON_STYLES} />
}
variant="outlined"
color={isSelected ? "primary" : "secondary"}
label="Best Match"
onClick={onClick}
size={size || 'medium'}
/>
</Tooltip>
</span>
)
}
export default BestMatchSort;