Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marcos/Detailed Tooltip #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { DetailedToolTipBtn } from '@/sprintFiles/DetailedToolTipBtn/DetailedToolTipBtn'

const ManagerInformationTabContent = () => {
return <div>ManagerInformationTabContent</div>
return (
<div>
ManagerInformationTabContent
<DetailedToolTipBtn messagePopUp='Enter a custom message here!!!' placement='right'/>
</div>
)
}
export default ManagerInformationTabContent
85 changes: 85 additions & 0 deletions src/sprintFiles/DetailedToolTipBtn/DetailedToolTipBtn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as React from 'react'
import Tooltip, { tooltipClasses } from '@mui/material/Tooltip'
import {
Box,
ClickAwayListener,
IconButton,
Typography,
styled,
} from '@mui/material'
import { TooltipProps } from '@mui/material/Tooltip'
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'
import CloseIcon from '@mui/icons-material/Close'

type DetailedToolTipBtnProps = {
messagePopUp: string
placement?: TooltipProps['placement']
}

const HtmlTooltip = styled(({ className, ...props }: TooltipProps) => (
<Tooltip {...props} classes={{ popper: className }} />
))(({ theme }) => ({
[`& .${tooltipClasses.tooltip}`]: {
backgroundColor: 'black',
color: 'white',
maxWidth: 280,
fontSize: theme.typography.pxToRem(12),
border: '1px solid #dadde9',
},
}))

/* General ToolTip function
Displays a button with an information icon.
When clicked, it will display the custom messagePopUp next to the button.
Preferably should contain a message to help user with flow/control navigate.

Can also input a placement which consists of (no input defaults to "bottom"):
"bottom-end" | "bottom-start" | "bottom" | "left-end" | "left-start" |
"left" | "right-end" | "right-start" | "right" | "top-end" | "top-start" |"top"
*/
export const DetailedToolTipBtn: React.FC<DetailedToolTipBtnProps> = ({
messagePopUp,
placement,
}: DetailedToolTipBtnProps) => {
const [open, setOpen] = React.useState(false)

const handleTooltipClose = () => {
setOpen(false)
}

const handleTooltipOpen = () => {
setOpen(true)
}

return (
<ClickAwayListener onClickAway={handleTooltipClose}>
<div>
<HtmlTooltip
PopperProps={{
disablePortal: true,
}}
onClose={handleTooltipClose}
open={open}
disableFocusListener
disableHoverListener
disableTouchListener
placement={placement}
title={
<React.Fragment>
<Box sx={{ display: 'flex', flexDirection: 'row' }}>
<Typography color="inherit">{messagePopUp}</Typography>
<CloseIcon onClick={handleTooltipClose}>
<InfoOutlinedIcon color="primary" />
</CloseIcon>
</Box>
</React.Fragment>
}
>
<IconButton onClick={handleTooltipOpen}>
<InfoOutlinedIcon color="primary" />
</IconButton>
</HtmlTooltip>
</div>
</ClickAwayListener>
)
}