Skip to content

Commit

Permalink
Merge pull request #388 from layer5io/376-tooltipicon
Browse files Browse the repository at this point in the history
feat(components): create TooltipIcon
  • Loading branch information
nebula-aac authored Dec 4, 2023
2 parents b76b610 + 863cfc2 commit f536b91
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/components/src/custom/TooltipIcon.tsx
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;
1 change: 1 addition & 0 deletions packages/components/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export {
type ResponsiveDataTableProps
} from './custom/ResponsiveDataTable';
export { default as SearchBar, type SearchBarProps } from './custom/SearchBar';
export { default as TooltipIcon } from './custom/TooltipIcon';
export {
default as UniversalFilter,
type FilterColumn,
Expand Down
20 changes: 20 additions & 0 deletions packages/components/src/patches/Tooltip.tsx
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;

0 comments on commit f536b91

Please sign in to comment.