forked from y-scope/yscope-log-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
110 lines (96 loc) · 3.08 KB
/
index.tsx
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import {
forwardRef,
useContext,
} from "react";
import {
TabList,
Tabs,
} from "@mui/joy";
import SvgIcon from "@mui/material/SvgIcon";
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
import SearchIcon from "@mui/icons-material/Search";
import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined";
import {StateContext} from "../../../../contexts/StateContextProvider";
import {TAB_NAME} from "../../../../typings/tab";
import SettingsModal from "../../../modals/SettingsModal";
import FileInfoTabPanel from "./FileInfoTabPanel";
import SearchTabPanel from "./SearchTabPanel";
import TabButton from "./TabButton";
import "./index.css";
/**
* Lists information for each tab.
*/
const TABS_INFO_LIST: Readonly<Array<{
tabName: TAB_NAME,
Icon: typeof SvgIcon,
}>> = Object.freeze([
{tabName: TAB_NAME.FILE_INFO, Icon: InfoOutlinedIcon},
{tabName: TAB_NAME.SEARCH, Icon: SearchIcon},
]);
interface SidebarTabsProps {
activeTabName: TAB_NAME,
onActiveTabNameChange: (newValue: TAB_NAME) => void,
}
/**
* Displays a set of tabs in a vertical orientation.
*
* @param tabListRef Reference object used to access the TabList DOM element.
* @return
*/
const SidebarTabs = forwardRef<HTMLDivElement, SidebarTabsProps>((
{
activeTabName,
onActiveTabNameChange,
},
tabListRef
) => {
const {isSettingsModalOpen, setIsSettingsModalOpen} = useContext(StateContext);
const handleSettingsModalClose = () => {
setIsSettingsModalOpen(false);
};
const handleTabButtonClick = (tabName: TAB_NAME) => {
switch (tabName) {
case TAB_NAME.SETTINGS:
setIsSettingsModalOpen(true);
break;
default:
onActiveTabNameChange(tabName);
}
};
return (
<>
<Tabs
className={"sidebar-tabs"}
orientation={"vertical"}
value={activeTabName}
variant={"plain"}
>
<TabList
ref={tabListRef}
size={"lg"}
>
{TABS_INFO_LIST.map(({tabName, Icon}) => (
<TabButton
Icon={Icon}
key={tabName}
tabName={tabName}
onTabButtonClick={handleTabButtonClick}/>
))}
{/* Forces the settings tab to bottom of sidebar. */}
<div className={"sidebar-tab-list-spacing"}/>
<TabButton
Icon={SettingsOutlinedIcon}
tabName={TAB_NAME.SETTINGS}
onTabButtonClick={handleTabButtonClick}/>
</TabList>
<FileInfoTabPanel/>
<SearchTabPanel/>
</Tabs>
<SettingsModal
isOpen={isSettingsModalOpen}
onClose={handleSettingsModalClose}/>
</>
);
});
SidebarTabs.displayName = "SidebarTabs";
export default SidebarTabs;