Made tooltip optional in IconButton

This commit is contained in:
unknown 2021-09-02 19:17:33 +05:30
parent 0ae994de56
commit 6c1a602bdc

View file

@ -16,11 +16,8 @@ import Text from '../text/Text';
const IconButton = React.forwardRef(({
variant, size, type,
tooltip, tooltipPlacement, src, onClick,
}, ref) => (
<Tooltip
placement={tooltipPlacement}
content={<Text variant="b2">{tooltip}</Text>}
>
}, ref) => {
const btn = (
<button
ref={ref}
className={`ic-btn-${variant}`}
@ -30,13 +27,23 @@ const IconButton = React.forwardRef(({
>
<RawIcon size={size} src={src} />
</button>
</Tooltip>
));
);
if (tooltip === null) return btn;
return (
<Tooltip
placement={tooltipPlacement}
content={<Text variant="b2">{tooltip}</Text>}
>
{btn}
</Tooltip>
);
});
IconButton.defaultProps = {
variant: 'surface',
size: 'normal',
type: 'button',
tooltip: null,
tooltipPlacement: 'top',
onClick: null,
};
@ -45,7 +52,7 @@ IconButton.propTypes = {
variant: PropTypes.oneOf(['surface']),
size: PropTypes.oneOf(['normal', 'small', 'extra-small']),
type: PropTypes.oneOf(['button', 'submit']),
tooltip: PropTypes.string.isRequired,
tooltip: PropTypes.string,
tooltipPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
src: PropTypes.string.isRequired,
onClick: PropTypes.func,