Skip to content

Instantly share code, notes, and snippets.

@aderbas
Last active November 14, 2019 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aderbas/70a88573eda9b7d541bd1c984c7c4f44 to your computer and use it in GitHub Desktop.
Save aderbas/70a88573eda9b7d541bd1c984c7c4f44 to your computer and use it in GitHub Desktop.
Icon Button with Badge
import React from 'react';
import Badge from '@material-ui/core/Badge';
import IconButton from '@material-ui/core/IconButton';
import { withStyles } from '@material-ui/core/styles';
import Tooltip from '@material-ui/core/Tooltip';
const style = theme => ({
badge: {
top: '50%',
right: -3,
border: `2px solid ${
theme.palette.type === 'light' ? theme.palette.grey[200] : theme.palette.grey[900]
}`,
},
});
const IconButtonWithDot = ({...props}) => {
const {onClick,icon,showdot,value,tooltip,tooltipPosition} = props;
const render = () => {
return (
<IconButton aria-label="cart" onClick={onClick}>
<Badge color="secondary" variant={value?'standard':'dot'} invisible={!showdot} badgeContent={value?value:null}>
{icon}
</Badge>
</IconButton>
);
}
if(tooltip){
return (
<Tooltip placement={tooltipPosition?tooltipPosition:'bottom'} title={tooltip}>
{render()}
</Tooltip>
)
}
return render();
};
export default withStyles(style)(IconButtonWithDot);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment