generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from layer5io/376-tooltipicon
feat(components): create TooltipIcon
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 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,36 @@ | ||
import { SxProps } from '@mui/material/styles'; | ||
import React from 'react'; | ||
import { IconButton } from '../base/IconButton'; | ||
import Tooltip from '../patches/Tooltip'; | ||
|
||
interface TooltipIconProps { | ||
title: string; | ||
onClick: (event: React.MouseEvent<HTMLElement>) => void; | ||
icon: React.ReactNode; | ||
arrow?: boolean; | ||
style?: React.CSSProperties; | ||
} | ||
|
||
export function TooltipIcon({ title, onClick, icon, style, arrow = false }: TooltipIconProps) { | ||
return ( | ||
<Tooltip title={title} arrow={arrow}> | ||
<IconButton | ||
onClick={onClick} | ||
sx={{ | ||
'&:hover': { | ||
'& svg': { | ||
fill: '#00d3a9' | ||
}, | ||
borderRadius: '4px' | ||
}, | ||
...(style as SxProps) | ||
}} | ||
disableRipple | ||
> | ||
{icon} | ||
</IconButton> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
export default TooltipIcon; |
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,20 @@ | ||
import MuiTooltip, { TooltipProps } from '@mui/material/Tooltip'; | ||
import React from 'react'; | ||
|
||
export interface ChildrenPropType<T> { | ||
children?: T; | ||
} | ||
|
||
/** | ||
* Create a custom Tooltip component to resolve the React.forwardRef warning | ||
*/ | ||
export const Tooltip = React.forwardRef< | ||
HTMLDivElement, | ||
TooltipProps & ChildrenPropType<React.ReactNode> | ||
>((props, ref) => ( | ||
<MuiTooltip {...props} ref={ref}> | ||
<span>{props.children}</span> | ||
</MuiTooltip> | ||
)); | ||
|
||
export default Tooltip; |