-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathSidebar.tsx
More file actions
70 lines (62 loc) · 1.76 KB
/
Sidebar.tsx
File metadata and controls
70 lines (62 loc) · 1.76 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
import { useState } from 'react';
import { FiList, FiSearch } from 'react-icons/fi';
import Explorer from './explorer/Explorer';
import { useDataContext } from './providers/DataProvider';
import SearchContainer from './search/SearchContainer';
import styles from './Sidebar.module.css';
interface Props {
selectedPath: string;
onSelect: (path: string) => void;
}
enum Tab {
Explore = 'explore',
Search = 'search',
}
function Sidebar(props: Props) {
const { selectedPath, onSelect } = props;
const [tab, setTab] = useState<Tab>(Tab.Explore);
const [searchValue, setSearchValue] = useState<string>('');
const { getSearchablePaths } = useDataContext();
if (!getSearchablePaths) {
return <Explorer selectedPath={selectedPath} onSelect={onSelect} />;
}
return (
<>
<div className={styles.tabBar}>
<button
className={styles.tab}
type="button"
role="tab"
aria-selected={tab === Tab.Explore}
onClick={() => setTab(Tab.Explore)}
aria-label="Explorer"
>
<FiList />
</button>
<button
className={styles.tab}
type="button"
role="tab"
aria-selected={tab === Tab.Search}
onClick={() => setTab(Tab.Search)}
aria-label="Search"
>
<FiSearch />
</button>
</div>
{tab === Tab.Explore && (
<Explorer selectedPath={selectedPath} onSelect={onSelect} />
)}
{tab === Tab.Search && (
<SearchContainer
selectedPath={selectedPath}
onSelect={onSelect}
searchValue={searchValue}
setSearchValue={setSearchValue}
getSearchablePaths={getSearchablePaths}
/>
)}
</>
);
}
export default Sidebar;