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