2019-04-14 11:08:10 +02:00
|
|
|
/**
|
|
|
|
* Basic paragraph (p Element) that automatically re-renders itself every X seconds
|
|
|
|
*
|
|
|
|
* NOT recommended for usage - only if you really have to
|
|
|
|
*/
|
|
|
|
import * as React from "react";
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
intervalTime?: number;
|
|
|
|
style?: object;
|
2021-03-31 06:45:21 +02:00
|
|
|
getContent: () => JSX.Element;
|
|
|
|
getTooltip?: () => JSX.Element;
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
i: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
type IInnerHTMLMarkup = {
|
|
|
|
__html: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class AutoupdatingParagraph extends React.Component<IProps, IState> {
|
|
|
|
/**
|
|
|
|
* Timer ID for auto-updating implementation (returned value from setInterval())
|
|
|
|
*/
|
|
|
|
interval: number = 0;
|
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
i: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const time = this.props.intervalTime ? this.props.intervalTime : 1000;
|
|
|
|
this.interval = setInterval(() => this.tick(), time);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
tick() {
|
|
|
|
this.setState(prevState => ({
|
|
|
|
i: prevState.i + 1
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-05-02 00:20:14 +02:00
|
|
|
let hasTooltip = this.props.getTooltip != null;
|
2021-03-31 06:45:21 +02:00
|
|
|
let tooltip: JSX.Element | null;
|
2019-05-02 00:20:14 +02:00
|
|
|
if (hasTooltip) {
|
|
|
|
tooltip = this.props.getTooltip!();
|
2021-03-31 06:45:21 +02:00
|
|
|
if (!tooltip) {
|
2019-05-02 00:20:14 +02:00
|
|
|
hasTooltip = false;
|
|
|
|
}
|
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
|
|
|
|
return (
|
2021-03-31 06:45:21 +02:00
|
|
|
<p className="tooltip" style={this.props.style}>
|
|
|
|
{this.props.getContent()}
|
2019-04-14 11:08:10 +02:00
|
|
|
{
|
|
|
|
hasTooltip &&
|
2021-03-31 06:45:21 +02:00
|
|
|
<span className={"tooltiptext"}>{tooltip!}</span>
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
</p>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|