Made tooltip optional in IconButton
This commit is contained in:
parent
0ae994de56
commit
6c1a602bdc
1 changed files with 15 additions and 8 deletions
|
@ -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>
|
||||||
|
);
|
||||||
|
if (tooltip === null) return btn;
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
placement={tooltipPlacement}
|
||||||
|
content={<Text variant="b2">{tooltip}</Text>}
|
||||||
|
>
|
||||||
|
{btn}
|
||||||
</Tooltip>
|
</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,
|
||||||
|
|
Loading…
Reference in a new issue