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