-
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(#291): add popover helper in tracker form
- Loading branch information
Showing
5 changed files
with
163 additions
and
27 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,16 @@ | ||
import { Popover as MuiPopover, PopoverProps, Typography } from '@mui/material'; | ||
import { FC } from 'react'; | ||
|
||
interface Props extends PopoverProps { | ||
text: string; | ||
} | ||
|
||
const Popover: FC<Props> = ({ text, ...popoverProps }) => { | ||
return ( | ||
<MuiPopover {...popoverProps}> | ||
<Typography sx={{ p: 2 }}>{text}</Typography> | ||
</MuiPopover> | ||
); | ||
}; | ||
|
||
export default Popover; |
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,47 @@ | ||
import HelpIcon from '@mui/icons-material/Help'; | ||
import { IconButton, InputAdornment, InputAdornmentProps } from '@mui/material'; | ||
import { FC, useState } from 'react'; | ||
|
||
import Popover from '../../Popover/Popover'; | ||
|
||
interface Props extends InputAdornmentProps { | ||
name: string; | ||
text: string; | ||
} | ||
|
||
const HelperAdornment: FC<Props> = ({ name, text, ...inputAdormnentProps }) => { | ||
// Popover management | ||
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null); | ||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
const open = Boolean(anchorEl); | ||
const id = open ? 'popover-' + name : undefined; | ||
|
||
return ( | ||
<> | ||
<InputAdornment {...inputAdormnentProps}> | ||
<IconButton edge="end" onClick={handleClick} color="primary"> | ||
<HelpIcon /> | ||
</IconButton> | ||
</InputAdornment> | ||
<Popover | ||
sx={{ whiteSpace: 'pre-line' }} | ||
id={id} | ||
open={open} | ||
anchorEl={anchorEl} | ||
onClose={handleClose} | ||
text={text} | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: inputAdormnentProps.position === 'end' ? 'left' : 'right' | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default HelperAdornment; |
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