parent
16654795d2
commit
b6e937675a
2 changed files with 145 additions and 14 deletions
@ -1,14 +1,63 @@ |
|||||||
import React from 'react'; |
import React, { useState } from 'react'; |
||||||
import { AppBar as MuiAppBar, Box } from '@material-ui/core'; |
import { AppBar as MuiAppBar, Box, Tab as MuiTab, Tabs, IconButton } from '@material-ui/core'; |
||||||
|
import CloseIcon from '@material-ui/icons/Close'; |
||||||
|
import AddIcon from '@material-ui/icons/Add'; |
||||||
|
|
||||||
export interface IProps { |
export interface IProps { |
||||||
|
tabLabels: string[], |
||||||
|
selectedTab: number, |
||||||
|
setSelectedTab: (n: number) => void, |
||||||
|
onCloseTab: (idx: number) => void, |
||||||
|
onAddTab: () => void, |
||||||
|
} |
||||||
|
|
||||||
|
export interface TabProps { |
||||||
|
onClose: () => void, |
||||||
|
} |
||||||
|
|
||||||
|
export function Tab(props: any) { |
||||||
|
const { onClose, label, ...restProps } = props; |
||||||
|
const [hover, setHover] = useState<boolean>(false); |
||||||
|
|
||||||
|
const labelElem = <Box |
||||||
|
display="flex" |
||||||
|
alignItems="center" |
||||||
|
justifyContent="center" |
||||||
|
> |
||||||
|
{label} |
||||||
|
{hover && <Box ml={1}> |
||||||
|
<IconButton |
||||||
|
size="small" |
||||||
|
color="inherit" |
||||||
|
onClick={onClose} |
||||||
|
> |
||||||
|
<CloseIcon /> |
||||||
|
</IconButton> |
||||||
|
</Box>} |
||||||
|
</Box>; |
||||||
|
|
||||||
|
return <MuiTab |
||||||
|
onMouseEnter={() => setHover(true)} |
||||||
|
onMouseLeave={() => setHover(false)} |
||||||
|
label={labelElem} |
||||||
|
{...restProps} |
||||||
|
/> |
||||||
} |
} |
||||||
|
|
||||||
export default function AppBar(props: IProps) { |
export default function AppBar(props: IProps) { |
||||||
return <MuiAppBar position="static" style={{ background: 'grey' }}> |
return <MuiAppBar position="static" style={{ background: 'grey' }}> |
||||||
|
<Box display="flex" alignItems="center"> |
||||||
<Box m={0.5} display="flex" alignItems="center"> |
<Box m={0.5} display="flex" alignItems="center"> |
||||||
<img height="30px" src={process.env.PUBLIC_URL + "/logo.svg"} alt="error"></img> |
<img height="30px" src={process.env.PUBLIC_URL + "/logo.svg"} alt="error"></img> |
||||||
</Box> |
</Box> |
||||||
|
<Tabs value={props.selectedTab} onChange={(e: any, v: number) => props.setSelectedTab(v)}> |
||||||
|
{props.tabLabels.map((l: string, idx: number) => <Tab |
||||||
|
label={l} |
||||||
|
value={idx} |
||||||
|
onClose={() => props.onCloseTab(idx)} |
||||||
|
/>)} |
||||||
|
</Tabs> |
||||||
|
<IconButton color="inherit" onClick={props.onAddTab}><AddIcon/></IconButton> |
||||||
|
</Box> |
||||||
</MuiAppBar> |
</MuiAppBar> |
||||||
} |
} |
Loading…
Reference in new issue