Convert TextWithTooltip to TS
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>pull/21833/head
parent
96d1519ac5
commit
8bf5d97b9e
|
@ -15,42 +15,44 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import * as sdk from '../../../index';
|
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
import Tooltip from "./Tooltip";
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
class?: string;
|
||||||
|
tooltipClass?: string;
|
||||||
|
tooltip: React.ReactNode;
|
||||||
|
tooltipProps?: {};
|
||||||
|
onClick?: (ev?: React.MouseEvent) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IState {
|
||||||
|
hover: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.elements.TextWithTooltip")
|
@replaceableComponent("views.elements.TextWithTooltip")
|
||||||
export default class TextWithTooltip extends React.Component {
|
export default class TextWithTooltip extends React.Component<IProps, IState> {
|
||||||
static propTypes = {
|
constructor(props: IProps) {
|
||||||
class: PropTypes.string,
|
super(props);
|
||||||
tooltipClass: PropTypes.string,
|
|
||||||
tooltip: PropTypes.node.isRequired,
|
|
||||||
tooltipProps: PropTypes.object,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
hover: false,
|
hover: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseOver = () => {
|
private onMouseOver = (): void => {
|
||||||
this.setState({ hover: true });
|
this.setState({ hover: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
onMouseLeave = () => {
|
private onMouseLeave = (): void => {
|
||||||
this.setState({ hover: false });
|
this.setState({ hover: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
public render(): JSX.Element {
|
||||||
const Tooltip = sdk.getComponent("elements.Tooltip");
|
|
||||||
|
|
||||||
const { class: className, children, tooltip, tooltipClass, tooltipProps, ...props } = this.props;
|
const { class: className, children, tooltip, tooltipClass, tooltipProps, ...props } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span {...props} onMouseOver={this.onMouseOver} onMouseLeave={this.onMouseLeave} className={className}>
|
<span {...props} onMouseOver={this.onMouseOver} onMouseLeave={this.onMouseLeave} onClick={this.props.onClick} className={className}>
|
||||||
{ children }
|
{ children }
|
||||||
{ this.state.hover && <Tooltip
|
{ this.state.hover && <Tooltip
|
||||||
{...tooltipProps}
|
{...tooltipProps}
|
Loading…
Reference in New Issue