import * as React from "react"; import * as ReactDOM from "react-dom"; export interface TooltipProps { text: string, link?: string, referenceNode: HTMLElement, prependElement?: HTMLElement, // Element to append before bottomOffset?: string timeout?: number; opacity?: number; displayTriangle?: boolean; showLogo?: boolean; showGotIt?: boolean; } export class Tooltip { text: string; container: HTMLDivElement; timer: NodeJS.Timeout; constructor(props: TooltipProps) { props.bottomOffset ??= "70px"; props.opacity ??= 0.7; props.displayTriangle ??= true; props.showLogo ??= true; props.showGotIt ??= true; this.text = props.text; this.container = document.createElement('div'); this.container.id = "sponsorTooltip" + props.text; this.container.style.position = "relative"; if (props.prependElement) { props.referenceNode.insertBefore(this.container, props.prependElement); } else { props.referenceNode.appendChild(this.container); } if (props.timeout) { this.timer = setTimeout(() => this.close(), props.timeout * 1000); } const backgroundColor = `rgba(28, 28, 28, ${props.opacity})`; ReactDOM.render(
{props.showLogo ? : null} {this.text + (props.link ? ". " : "")} {props.link ? {chrome.i18n.getMessage("LearnMore")} : null}
{props.showGotIt ? : null}
, this.container ) } close(): void { ReactDOM.unmountComponentAtNode(this.container); this.container.remove(); if (this.timer) clearTimeout(this.timer); } }