Add equipment planner toolbox module
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s

This commit is contained in:
Shinuwa 2026-08-09 10:03:55 +02:00
parent ac33a55c8b
commit d53d4160af
33 changed files with 3522 additions and 20 deletions

View file

@ -4,6 +4,7 @@ import { DrawingControls } from "../features/toolboxes/modules/DrawingControls.j
import { DrawingOverlay } from "../features/toolboxes/modules/DrawingOverlay.jsx";
import { lockBodyScroll } from "../utils/bodyScrollLock.js";
import { Icon } from "./Icon.jsx";
import { Tooltip } from "./Tooltip.jsx";
const DRAWING_COLORS = ["#f5f7ff", "#b4bdd3", "#f6c453", "#22d3ee", "#8b5cf6", "#d946ef"];
const DRAWING_WIDTHS = [2, 4, 8, 12];
@ -188,14 +189,16 @@ export function ImageViewer({ image, onClose, createMarkerId = () => globalThis.
/>
)}
{viewerMarkers.map((marker, index) => (
<span
<Tooltip
as="span"
className="annotation-marker image-viewer-marker"
key={marker.id || `${marker.x}-${marker.y}-${index}`}
content={marker.label || `${image.markerPrefix || "Marqueur"} ${index + 1}`}
position="top"
style={{ "--marker-x": `${marker.x}%`, "--marker-y": `${marker.y}%` }}
title={marker.label || `${image.markerPrefix || "Marqueur"} ${index + 1}`}
>
{index + 1}
</span>
</Tooltip>
))}
</div>
</div>

View file

@ -0,0 +1,70 @@
// Rôle : fournit une infobulle accessible et réutilisable pour les contrôles et données denses.
import { useEffect, useId, useRef, useState } from "react";
import { createPortal } from "react-dom";
export function Tooltip({ as: Component = "span", children, content, className = "", tooltipClassName = "", position = "top", ...props }) {
const tooltipId = useId();
const anchorRef = useRef(null);
const [open, setOpen] = useState(false);
const [style, setStyle] = useState({});
function placeTooltip() {
const anchor = anchorRef.current;
if (!anchor) return;
const rect = anchor.getBoundingClientRect();
if (position === "top-start") {
setStyle({ top: `${Math.max(8, rect.top - 8)}px`, left: `${Math.max(8, rect.left)}px` });
return;
}
setStyle({ top: `${Math.max(8, rect.top - 8)}px`, left: `${Math.min(window.innerWidth - 8, Math.max(8, rect.left + rect.width / 2))}px` });
}
useEffect(() => {
if (!open) return undefined;
placeTooltip();
window.addEventListener("resize", placeTooltip);
window.addEventListener("scroll", placeTooltip, true);
return () => {
window.removeEventListener("resize", placeTooltip);
window.removeEventListener("scroll", placeTooltip, true);
};
}, [open, position]);
if (!content) return <Component className={className} {...props}>{children}</Component>;
return (
<Component
{...props}
className={`ui-tooltip-anchor ${className}`.trim()}
ref={anchorRef}
tabIndex={props.tabIndex ?? 0}
aria-describedby={tooltipId}
onMouseEnter={(event) => {
placeTooltip();
setOpen(true);
props.onMouseEnter?.(event);
}}
onMouseLeave={(event) => {
setOpen(false);
props.onMouseLeave?.(event);
}}
onFocus={(event) => {
placeTooltip();
setOpen(true);
props.onFocus?.(event);
}}
onBlur={(event) => {
setOpen(false);
props.onBlur?.(event);
}}
>
{children}
{open && createPortal(
<span id={tooltipId} className={`ui-tooltip ui-tooltip-${position} ${tooltipClassName}`.trim()} role="tooltip" style={style}>
{content}
</span>,
document.body
)}
</Component>
);
}