diff --git a/src/actions/actionExport.tsx b/src/actions/actionExport.tsx index 46ed8baa9..61f6933f7 100644 --- a/src/actions/actionExport.tsx +++ b/src/actions/actionExport.tsx @@ -67,11 +67,7 @@ export const actionChangeExportEmbedScene = register({ onChange={(event) => updateData(event.target.checked)} />{" "} {t("labels.exportEmbedScene")} - +
{questionCircle}
diff --git a/src/components/Tooltip.scss b/src/components/Tooltip.scss index 75b79bf56..e9c324528 100644 --- a/src/components/Tooltip.scss +++ b/src/components/Tooltip.scss @@ -1,58 +1,25 @@ @import "../css/variables.module"; -.excalidraw { - .Tooltip { - position: relative; - } +.excalidraw-tooltip { + position: absolute; + z-index: 1000; - .Tooltip__label { - --arrow-size: 4px; - visibility: hidden; - background: $oc-black; - color: $oc-white; - text-align: center; - border-radius: 6px; - padding: 8px; - position: absolute; - z-index: 10; - font-size: 13px; - line-height: 1.5; - font-weight: 500; - // extra pixel offset for unknown reasons - left: calc(50% + var(--arrow-size) / 2 - 1px); - transform: translateX(-50%); - word-wrap: break-word; + padding: 8px; + border-radius: 6px; + box-sizing: border-box; + pointer-events: none; + word-wrap: break-word; - &::after { - content: ""; - border: var(--arrow-size) solid transparent; - position: absolute; - left: calc(50% - var(--arrow-size)); - } + background: $oc-black; - &--above { - bottom: calc(100% + var(--arrow-size) + 3px); + line-height: 1.5; + text-align: center; + font-size: 13px; + font-weight: 500; + color: $oc-white; - &::after { - border-top-color: $oc-black; - top: 100%; - } - } + display: none; - &--below { - top: calc(100% + var(--arrow-size) + 3px); - - &::after { - border-bottom-color: $oc-black; - bottom: 100%; - } - } - } - - .Tooltip:hover .Tooltip__label { - visibility: visible; - } - - .Tooltip__label:hover { - visibility: visible; + &.excalidraw-tooltip--visible { + display: block; } } diff --git a/src/components/Tooltip.tsx b/src/components/Tooltip.tsx index d96fb8234..a6f1b2583 100644 --- a/src/components/Tooltip.tsx +++ b/src/components/Tooltip.tsx @@ -1,31 +1,92 @@ import "./Tooltip.scss"; -import React from "react"; +import React, { useEffect } from "react"; + +const getTooltipDiv = () => { + const existingDiv = document.querySelector( + ".excalidraw-tooltip", + ); + if (existingDiv) { + return existingDiv; + } + const div = document.createElement("div"); + document.body.appendChild(div); + div.classList.add("excalidraw-tooltip"); + return div; +}; + +const updateTooltip = ( + item: HTMLDivElement, + tooltip: HTMLDivElement, + label: string, + long: boolean, +) => { + tooltip.classList.add("excalidraw-tooltip--visible"); + tooltip.style.minWidth = long ? "50ch" : "10ch"; + tooltip.style.maxWidth = long ? "50ch" : "15ch"; + + tooltip.textContent = label; + + const { + x: itemX, + bottom: itemBottom, + top: itemTop, + width: itemWidth, + } = item.getBoundingClientRect(); + + const { + width: labelWidth, + height: labelHeight, + } = tooltip.getBoundingClientRect(); + + const viewportWidth = window.innerWidth; + const viewportHeight = window.innerHeight; + + const margin = 5; + + const left = itemX + itemWidth / 2 - labelWidth / 2; + const offsetLeft = + left + labelWidth >= viewportWidth ? left + labelWidth - viewportWidth : 0; + + const top = itemBottom + margin; + const offsetTop = + top + labelHeight >= viewportHeight + ? itemBottom - itemTop + labelHeight + margin * 2 + : 0; + + Object.assign(tooltip.style, { + top: `${top - offsetTop}px`, + left: `${left - offsetLeft}px`, + }); +}; type TooltipProps = { children: React.ReactNode; label: string; - position?: "above" | "below"; long?: boolean; }; -export const Tooltip = ({ - children, - label, - position = "below", - long = false, -}: TooltipProps) => ( -
- { + useEffect(() => { + return () => + getTooltipDiv().classList.remove("excalidraw-tooltip--visible"); + }, []); + + return ( +
+ updateTooltip( + event.currentTarget as HTMLDivElement, + getTooltipDiv(), + label, + long, + ) + } + onPointerLeave={() => + getTooltipDiv().classList.remove("excalidraw-tooltip--visible") } - style={{ width: long ? "50ch" : "10ch" }} > - {label} - - {children} -
-); + {children} +
+ ); +}; diff --git a/src/excalidraw-app/index.tsx b/src/excalidraw-app/index.tsx index 258b34b4c..299339514 100644 --- a/src/excalidraw-app/index.tsx +++ b/src/excalidraw-app/index.tsx @@ -340,7 +340,7 @@ const ExcalidrawWrapper = () => { rel="noopener noreferrer" aria-label={t("encrypted.link")} > - + {shield}