bitburner-src/src/ui/React/StdButtonPurchased.tsx

69 lines
1.4 KiB
TypeScript
Raw Normal View History

/**
* 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;
}
type IInnerHTMLMarkup = {
2021-09-05 01:09:30 +02:00
__html: string;
};
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(),
};
}
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>
);
}
}