import * as React from "react"; import { createRoot, Root } from 'react-dom/client'; import { ButtonListener } from "../types"; export interface TooltipProps { text?: string; link?: string; linkOnClick?: () => void; referenceNode: HTMLElement; prependElement?: HTMLElement; // Element to append before bottomOffset?: string; leftOffset?: string; rightOffset?: string; timeout?: number; opacity?: number; displayTriangle?: boolean; extraClass?: string; showLogo?: boolean; showGotIt?: boolean; positionRealtive?: boolean; buttons?: ButtonListener[]; } export class Tooltip { text?: string; container: HTMLDivElement; timer: NodeJS.Timeout; root: Root; constructor(props: TooltipProps) { props.bottomOffset ??= "70px"; props.leftOffset ??= "inherit"; props.rightOffset ??= "inherit"; props.opacity ??= 0.7; props.displayTriangle ??= true; props.extraClass ??= ""; props.showLogo ??= true; props.showGotIt ??= true; props.positionRealtive ??= true; this.text = props.text; this.container = document.createElement('div'); this.container.id = "sponsorTooltip" + props.text; if (props.positionRealtive) 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})`; this.root = createRoot(this.container); this.root.render(