-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SidebarContainer with resizable tabs.
- Loading branch information
1 parent
96de362
commit c6ab307
Showing
16 changed files
with
402 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
|
||
import { | ||
ListItem, | ||
ListItemContent, | ||
ListItemDecorator, | ||
Typography, | ||
} from "@mui/joy"; | ||
|
||
|
||
interface CustomListItemProps { | ||
content: string, | ||
icon: React.ReactNode, | ||
title: string | ||
} | ||
|
||
/** | ||
* Renders a custom list item with an icon, a title and a context text. | ||
* | ||
* @param props | ||
* @param props.content | ||
* @param props.icon | ||
* @param props.title | ||
* @return | ||
*/ | ||
const CustomListItem = ({content, icon, title}: CustomListItemProps) => ( | ||
<ListItem> | ||
<ListItemDecorator> | ||
{icon} | ||
</ListItemDecorator> | ||
<ListItemContent> | ||
<Typography level={"title-sm"}> | ||
{title} | ||
</Typography> | ||
<Typography | ||
level={"body-sm"} | ||
> | ||
{content} | ||
</Typography> | ||
</ListItemContent> | ||
</ListItem> | ||
); | ||
|
||
export default CustomListItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
new-log-viewer/src/components/SidebarContainer/PanelTabs/FileInfoTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {useContext} from "react"; | ||
|
||
import { | ||
DialogContent, | ||
DialogTitle, | ||
Divider, | ||
List, | ||
TabPanel, | ||
} from "@mui/joy"; | ||
|
||
import AbcIcon from "@mui/icons-material/Abc"; | ||
import StorageIcon from "@mui/icons-material/Storage"; | ||
|
||
import {StateContext} from "../../../contexts/StateContextProvider"; | ||
import {formatSizeInBytes} from "../../../utils/units"; | ||
import CustomListItem from "../../CustomListItem"; | ||
import {TAB_NAME} from "./index"; | ||
|
||
import "./index.css"; | ||
|
||
|
||
/** | ||
* Display the file name and original size of the selected file. | ||
* | ||
* @return | ||
*/ | ||
const FileInfoTab = () => { | ||
const {fileName, originalFileSizeInBytes} = useContext(StateContext); | ||
|
||
return ( | ||
<TabPanel value={TAB_NAME.FILE_INFO}> | ||
<DialogTitle>File Info</DialogTitle> | ||
<DialogContent> | ||
<List> | ||
<CustomListItem | ||
content={fileName} | ||
icon={<AbcIcon/>} | ||
title={"File Info"}/> | ||
<Divider/> | ||
<CustomListItem | ||
content={formatSizeInBytes(originalFileSizeInBytes)} | ||
icon={<StorageIcon/>} | ||
title={"Original Size"}/> | ||
</List> | ||
</DialogContent> | ||
</TabPanel> | ||
); | ||
}; | ||
|
||
|
||
export default FileInfoTab; |
9 changes: 9 additions & 0 deletions
9
new-log-viewer/src/components/SidebarContainer/PanelTabs/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.sidebar-tabs { | ||
height: 100%; | ||
flex-grow: 1; | ||
width: calc(100% - var(--ylv-panel-resize-handle-width)); | ||
} | ||
|
||
.sidebar-tab-list-spacing { | ||
flex-grow: 1; | ||
} |
109 changes: 109 additions & 0 deletions
109
new-log-viewer/src/components/SidebarContainer/PanelTabs/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { | ||
forwardRef, | ||
useContext, | ||
useState, | ||
} from "react"; | ||
|
||
import { | ||
Tab, | ||
TabList, | ||
Tabs, | ||
} from "@mui/joy"; | ||
|
||
import FileOpenIcon from "@mui/icons-material/FileOpen"; | ||
import InfoIcon from "@mui/icons-material/Info"; | ||
import SettingsIcon from "@mui/icons-material/Settings"; | ||
|
||
import {StateContext} from "../../../contexts/StateContextProvider"; | ||
import {CURSOR_CODE} from "../../../typings/worker"; | ||
import {openFile} from "../../../utils/file"; | ||
import SettingsModal from "../../modals/SettingsModal"; | ||
import FileInfoTab from "./FileInfoTab"; | ||
|
||
|
||
enum TAB_NAME { | ||
OPEN_FILE = "openFile", | ||
FILE_INFO = "fileInfo", | ||
SETTINGS = "settings", | ||
} | ||
|
||
/** | ||
* Displays a set of tabs in a vertical orientation. | ||
* | ||
* @param tabListRef Reference object used to access the TabList DOM element. | ||
* @return | ||
*/ | ||
const PanelTabs = forwardRef<HTMLDivElement>((_, tabListRef) => { | ||
const {loadFile} = useContext(StateContext); | ||
|
||
const [activeTabName, setActiveTabName] = useState<TAB_NAME>(TAB_NAME.FILE_INFO); | ||
const [isSettingsModalOpen, setIsSettingsModalOpen] = useState<boolean>(false); | ||
|
||
const handleOpenFile = () => { | ||
openFile((file) => { | ||
loadFile(file, {code: CURSOR_CODE.LAST_EVENT, args: null}); | ||
}); | ||
}; | ||
|
||
const handleSettingsModalClose = () => { | ||
setIsSettingsModalOpen(false); | ||
}; | ||
|
||
const handleTabChange = (__: React.SyntheticEvent | null, value: number | string | null) => { | ||
switch (value) { | ||
case TAB_NAME.OPEN_FILE: | ||
handleOpenFile(); | ||
break; | ||
case TAB_NAME.SETTINGS: | ||
setIsSettingsModalOpen(true); | ||
break; | ||
default: | ||
setActiveTabName(value as TAB_NAME); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Tabs | ||
className={"sidebar-tabs"} | ||
orientation={"vertical"} | ||
value={activeTabName} | ||
variant={"plain"} | ||
onChange={handleTabChange} | ||
> | ||
<TabList | ||
ref={tabListRef} | ||
size={"lg"} | ||
> | ||
{[ | ||
{tabName: TAB_NAME.OPEN_FILE, icon: <FileOpenIcon/>}, | ||
{tabName: TAB_NAME.FILE_INFO, icon: <InfoIcon/>}, | ||
].map(({tabName, icon}) => ( | ||
<Tab | ||
color={"neutral"} | ||
key={tabName} | ||
value={tabName} | ||
> | ||
{icon} | ||
</Tab> | ||
))} | ||
<div className={"sidebar-tab-list-spacing"}/> | ||
<Tab | ||
color={"neutral"} | ||
value={TAB_NAME.SETTINGS} | ||
> | ||
<SettingsIcon/> | ||
</Tab> | ||
</TabList> | ||
<FileInfoTab/> | ||
</Tabs> | ||
<SettingsModal | ||
isOpen={isSettingsModalOpen} | ||
onClose={handleSettingsModalClose}/> | ||
</> | ||
); | ||
}); | ||
|
||
PanelTabs.displayName = "PanelTabs"; | ||
export default PanelTabs; | ||
export {TAB_NAME}; |
11 changes: 11 additions & 0 deletions
11
new-log-viewer/src/components/SidebarContainer/ResizeHandle.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.resize-handle { | ||
cursor: ew-resize; | ||
width: 3px; | ||
height: 100%; | ||
background-color: var(--joy-palette-neutral-outlinedBorder, #cdd7e1); | ||
z-index: 1; | ||
} | ||
|
||
.resize-handle:hover { | ||
background-color: var(--joy-palette-primary-solidHoverBg, #0258a8); | ||
} |
Oops, something went wrong.