-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathViewSelector.tsx
More file actions
74 lines (67 loc) · 2.17 KB
/
ViewSelector.tsx
File metadata and controls
74 lines (67 loc) · 2.17 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { ChartColumnBigIcon, Grid2x2Icon, ListTreeIcon, MapIcon, Table2Icon } from 'lucide-react';
import React from 'react';
import { View } from '@features/params/PageParamTypes';
import Selector from '@features/params/ui/Selector';
import { SelectorDisplay } from '@features/params/ui/SelectorDisplayContext';
import usePageParams from '@features/params/usePageParams';
const ViewSelector: React.FC = () => {
const { view, updatePageParams } = usePageParams();
return (
<Selector
options={Object.values(View)}
selected={view}
onChange={(nextView: View) => updatePageParams({ view: nextView })}
getOptionLabel={(option) => getViewIcon(option)}
getOptionDescription={(option) => getViewLabel(option)}
display={SelectorDisplay.ButtonGroup}
optionStyle={{
width: 'fit-content',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '0.5rem',
}}
selectorStyle={{ gap: '0.25rem' }}
/>
);
};
function getViewLabel(view: View): React.ReactNode {
const isBeta = [View.Map, View.Reports].includes(view);
return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '0.25rem' }}>
<span style={{ display: 'flex', gap: '0.125rem' }}>
{view} {isBeta && <em>β</em>}
</span>
<img src={getImageSrc(view)} width={180} />
</div>
);
}
function getImageSrc(view: View): string {
switch (view) {
case View.CardList:
return '/lang-nav/cardlist.png';
case View.Hierarchy:
return '/lang-nav/hierarchy.png';
case View.Map:
return '/lang-nav/map.png';
case View.Table:
return '/lang-nav/table.png';
case View.Reports:
return '/lang-nav/reports.png';
}
}
function getViewIcon(view: View): React.ReactNode {
switch (view) {
case View.CardList:
return <Grid2x2Icon size="1.2em" />;
case View.Hierarchy:
return <ListTreeIcon size="1.2em" />;
case View.Map:
return <MapIcon size="1.2em" />;
case View.Table:
return <Table2Icon size="1.2em" />;
case View.Reports:
return <ChartColumnBigIcon size="1.2em" />;
}
}
export default ViewSelector;