rxviz/components/TooltipText.js
Misha Moroshko b60456889f Cleanup
2018-07-01 10:42:45 -07:00

39 lines
876 B
JavaScript

import { Component } from 'react';
import PropTypes from 'prop-types';
export default class TooltipText extends Component {
static propTypes = {
x: PropTypes.number,
y: PropTypes.number,
text: PropTypes.string.isRequired,
textStyle: PropTypes.object
};
static defaultProps = {
x: 0,
y: 0
};
renderLine = (line, lineIndex) => {
const { x, y } = this.props;
return (
<tspan x={x} dy={lineIndex === 0 ? y : '1.2em'} key={lineIndex}>
{line}
</tspan>
);
};
render() {
const { text, textStyle } = this.props;
const lines = text.split('\n');
const style = {
/* Temporarily needed for Firefox. See: https://stackoverflow.com/a/44744392/247243 */
dominantBaseline: 'text-before-edge',
...textStyle
};
return <text style={style}>{lines.map(this.renderLine)}</text>;
}
}