2019-04-01 11:23:25 +02:00
|
|
|
/**
|
|
|
|
* Stateless button that represents something that has been purchased.
|
|
|
|
*/
|
|
|
|
import * as React from "react";
|
|
|
|
|
|
|
|
interface IStdButtonPurchasedProps {
|
|
|
|
onClick?: (e: React.MouseEvent<HTMLElement>) => any;
|
2021-05-01 09:17:31 +02:00
|
|
|
style?: any;
|
2019-04-01 11:23:25 +02:00
|
|
|
text: string;
|
2019-04-23 10:23:08 +02:00
|
|
|
tooltip?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
type IInnerHTMLMarkup = {
|
|
|
|
__html: string;
|
2019-04-01 11:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class StdButtonPurchased extends React.Component<IStdButtonPurchasedProps, any> {
|
2021-05-01 09:17:31 +02:00
|
|
|
|
|
|
|
constructor(props: IStdButtonPurchasedProps) {
|
|
|
|
super(props);
|
|
|
|
this.hasTooltip = this.hasTooltip.bind(this);
|
|
|
|
this.tooltip = this.tooltip.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
hasTooltip(): boolean {
|
|
|
|
return this.props.tooltip != null && this.props.tooltip !== "";
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip(): string {
|
|
|
|
if(!this.props.tooltip) return "";
|
|
|
|
return this.props.tooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): React.ReactNode {
|
2019-04-23 10:23:08 +02:00
|
|
|
let className = "std-button-bought";
|
2021-05-01 09:17:31 +02:00
|
|
|
if (this.hasTooltip()) {
|
2019-04-23 10:23:08 +02:00
|
|
|
className += " tooltip";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tooltip will be set using inner HTML
|
2021-05-01 09:17:31 +02:00
|
|
|
let tooltipMarkup: IInnerHTMLMarkup = {
|
|
|
|
__html: "",
|
|
|
|
}
|
|
|
|
if (this.hasTooltip()) {
|
2019-04-23 10:23:08 +02:00
|
|
|
tooltipMarkup = {
|
2021-05-01 09:17:31 +02:00
|
|
|
__html: this.tooltip(),
|
2019-04-23 10:23:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 11:23:25 +02:00
|
|
|
return (
|
2019-04-23 10:23:08 +02:00
|
|
|
<button className={className} onClick={this.props.onClick} style={this.props.style}>
|
2019-04-01 11:23:25 +02:00
|
|
|
{this.props.text}
|
2019-04-23 10:23:08 +02:00
|
|
|
{
|
2021-05-01 09:17:31 +02:00
|
|
|
this.hasTooltip() &&
|
|
|
|
<span className={"tooltiptext"} dangerouslySetInnerHTML={tooltipMarkup}></span>
|
2019-04-23 10:23:08 +02:00
|
|
|
}
|
2019-04-01 11:23:25 +02:00
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|