-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement help menu and some changes on user info menu
- Loading branch information
1 parent
634e524
commit 404356c
Showing
5 changed files
with
197 additions
and
83 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,120 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Box, Menu, MenuItem, makeStyles, ClickAwayListener } from '@material-ui/core'; | ||
import HelpOutlineIcon from '@material-ui/icons/HelpOutline'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
menuTrigger: { | ||
backgroundRepeat: 'no-repeat', | ||
minWidth: '32px', | ||
height: '32px', | ||
backgroundSize: '32px', | ||
borderRadius: '50%', | ||
flexShrink: 0, | ||
transition: 'box-shadow ease-in-out 0.2s', | ||
'&:hover': { | ||
cursor: 'pointer', | ||
}, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
flexWrap: 'nowrap', | ||
justifyContent: 'center', | ||
alignItems: 'stretch', | ||
}, | ||
menu: { | ||
transform: 'translate3d(0,30px,0) !important', | ||
}, | ||
menuContainer: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
}, | ||
link: { | ||
color: theme.palette.text.primary, | ||
}, | ||
menuIcon: { | ||
color: theme.palette.primary.main, | ||
fontSize: 32, | ||
}, | ||
})); | ||
|
||
export const HelpMenu = (props) => { | ||
const classes = useStyles(); | ||
const [isMenuOpen, setMenuOpen] = useState(false); | ||
const [anchorEl, setAnchorEl] = useState(null); | ||
|
||
const handleClose = () => { | ||
setMenuOpen(false); | ||
}; | ||
|
||
const handleClick = (event) => { | ||
setAnchorEl(event.target); | ||
setMenuOpen(!isMenuOpen); | ||
}; | ||
|
||
const { documentationUrl, supportUrl, labels } = props; | ||
|
||
return ( | ||
<ClickAwayListener onClickAway={handleClose}> | ||
<div> | ||
<Box | ||
data-cy="help-menu" | ||
aria-haspopup="true" | ||
onClick={handleClick} | ||
className={`${classes.menuTrigger} ${isMenuOpen ? 'active' : ''}`} | ||
> | ||
<HelpOutlineIcon className={classes.menuIcon} /> | ||
</Box> | ||
<Menu className={classes.menu} keepMounted anchorEl={anchorEl} open={isMenuOpen} onClose={handleClick}> | ||
{documentationUrl && ( | ||
<MenuItem data-cy="download-documentation" className={classes.link} onClick={handleClick}> | ||
<a href={documentationUrl} className={classes.link} target="_blank" rel="noreferrer"> | ||
{labels.documentation} | ||
</a> | ||
</MenuItem> | ||
)} | ||
{supportUrl && ( | ||
<MenuItem data-cy="support" className={classes.link} onClick={handleClick}> | ||
<a href={supportUrl} className={classes.link} target="_blank" rel="noreferrer"> | ||
{labels.support} | ||
</a> | ||
</MenuItem> | ||
)} | ||
</Menu> | ||
</div> | ||
</ClickAwayListener> | ||
); | ||
}; | ||
|
||
HelpMenu.propTypes = { | ||
/** | ||
* Documentation url | ||
*/ | ||
documentationUrl: PropTypes.string, | ||
/** | ||
* Support page url | ||
*/ | ||
supportUrl: PropTypes.string, | ||
/** | ||
* Component's labels: | ||
* Structure: | ||
* <pre> | ||
{ | ||
documentation: 'string', | ||
suuport: 'string', | ||
} | ||
* </pre> | ||
*/ | ||
labels: PropTypes.shape({ | ||
documentation: PropTypes.string.isRequired, | ||
support: PropTypes.string, | ||
}), | ||
}; | ||
|
||
HelpMenu.defaultProps = { | ||
supportUrl: null, | ||
labels: { | ||
documentation: 'Documentation', | ||
support: 'Contact support', | ||
}, | ||
}; |
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,4 @@ | ||
// Copyright (c) Cosmo Tech. | ||
// Licensed under the MIT license. | ||
|
||
export { HelpMenu } from './HelpMenu'; |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
// Licensed under the MIT license. | ||
|
||
export { UserInfo } from './UserInfo'; | ||
export { HelpMenu } from './HelpMenu'; |