lbry-desktop/src/renderer/component/common/tooltip.jsx

52 lines
1.2 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as React from 'react';
2018-03-26 23:32:43 +02:00
import classnames from 'classnames';
type Props = {
body: string,
label?: string,
2018-06-20 05:55:25 +02:00
children?: React.Node,
icon?: boolean,
direction: string,
2018-06-20 05:55:25 +02:00
onComponent?: boolean, // extra padding to account for button/form field size
2018-03-26 23:32:43 +02:00
};
class ToolTip extends React.PureComponent<Props> {
static defaultProps = {
direction: 'bottom',
};
2018-03-26 23:32:43 +02:00
render() {
2018-06-20 05:55:25 +02:00
const { children, label, body, icon, direction, onComponent } = this.props;
const tooltipContent = children || label;
2018-06-20 05:55:25 +02:00
const bodyLength = body.length;
const isShortDescription = bodyLength < 30;
2018-03-26 23:32:43 +02:00
return (
<span
className={classnames('tooltip', {
'tooltip--label': label && !icon,
'tooltip--icon': icon,
'tooltip--top': direction === 'top',
'tooltip--right': direction === 'right',
'tooltip--bottom': direction === 'bottom',
'tooltip--left': direction === 'left',
2018-06-20 05:55:25 +02:00
'tooltip--on-component': onComponent,
})}
>
{tooltipContent}
2018-06-20 05:55:25 +02:00
<span
className={classnames('tooltip__body', {
'tooltip__body--short': isShortDescription,
})}
>
{body}
</span>
2018-03-26 23:32:43 +02:00
</span>
);
}
}
export default ToolTip;