-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Misc refactors for view container (#3994)
- Loading branch information
Showing
9 changed files
with
130 additions
and
92 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
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,66 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import { IconButton } from '@mui/material' | ||
import { makeStyles } from 'tss-react/mui' | ||
import { observer } from 'mobx-react' | ||
import { IBaseViewModel } from '@jbrowse/core/pluggableElementTypes/models' | ||
|
||
// icons | ||
import CloseIcon from '@mui/icons-material/Close' | ||
import MinimizeIcon from '@mui/icons-material/Minimize' | ||
import AddIcon from '@mui/icons-material/Add' | ||
|
||
// locals | ||
import ViewMenu from './ViewMenu' | ||
import ViewContainerTitle from './ViewContainerTitle' | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
icon: { | ||
color: theme.palette.secondary.contrastText, | ||
}, | ||
grow: { | ||
flexGrow: 1, | ||
}, | ||
viewHeader: { | ||
display: 'flex', | ||
}, | ||
})) | ||
|
||
const ViewHeader = observer(function ({ | ||
view, | ||
onClose, | ||
onMinimize, | ||
}: { | ||
view: IBaseViewModel | ||
onClose: () => void | ||
onMinimize: () => void | ||
}) { | ||
const { classes } = useStyles() | ||
const scrollRef = useRef<HTMLDivElement>(null) | ||
|
||
// scroll the view into view when first mounted. note: this effect will run | ||
// only once, because of the empty array second param | ||
useEffect(() => { | ||
scrollRef.current?.scrollIntoView?.({ block: 'center' }) | ||
}, []) | ||
return ( | ||
<div ref={scrollRef} className={classes.viewHeader}> | ||
<ViewMenu model={view} IconProps={{ className: classes.icon }} /> | ||
<div className={classes.grow} /> | ||
|
||
<ViewContainerTitle view={view} /> | ||
<div className={classes.grow} /> | ||
<IconButton data-testid="minimize_view" onClick={onMinimize}> | ||
{view.minimized ? ( | ||
<AddIcon className={classes.icon} fontSize="small" /> | ||
) : ( | ||
<MinimizeIcon className={classes.icon} fontSize="small" /> | ||
)} | ||
</IconButton> | ||
<IconButton data-testid="close_view" onClick={onClose}> | ||
<CloseIcon className={classes.icon} fontSize="small" /> | ||
</IconButton> | ||
</div> | ||
) | ||
}) | ||
|
||
export default ViewHeader |
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
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