feat(manager): help tips open after 1.5 s of hover, at once on click

Owner 2026-11-23 (plan 6F.1a): InfoTip waits INFOTIP_HOVER_MS (1500 ms) with the pointer on the i
before opening (leaving earlier cancels); a click or tap still opens it at once and keeps it open.
ui e2e checks the delay, the cancel and the click, and now runs without any backend (a Docker stack
left on :8000 in Greek made the i18n sample fail).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 06:34:55 +02:00
co-authored by Claude Opus 5.5
parent 33a5125abc
commit 99145e83da
3 changed files with 41 additions and 10 deletions
+24 -7
View File
@@ -5,11 +5,17 @@ import { useLabels } from './labels.js'
const GAP = 8
const MARGIN = 8
/** How long the pointer rests on the "i" before its tip opens (owner 2026-11-23, plan 6F.1a).
* A click or a tap opens it at once. */
export const INFOTIP_HOVER_MS = 1500
/**
* The "(i)" help tip next to a setting or label (D-12: every manager page gets them).
* Opens while the pointer rests on it (2026-11-20) and on click/tap (touch screens: a tap keeps
* it open), closes on Escape, a click outside, a second click or the pointer leaving. Placed above the button, or below when there's no room.
* Opens when the pointer has rested on it for 1.5 s (INFOTIP_HOVER_MS; leaving earlier cancels it), and
* at once on click / tap (it then stays open: touch screens). Closes on Escape, a click outside, a
* second click, or the pointer leaving the "i" and the tip (a hover-opened tip). Placed above the
* button, or below when there's no room. The same component in the manager, the waiter app and the
* terminal (6F.1a).
*
* <label>Alert after failures <InfoTip>How many failed print attempts before managers are notified. 0 turns it off.</InfoTip></label>
*
@@ -20,11 +26,22 @@ export function InfoTip({ children, label, side = 'top', className }) {
const [pinned, setPinned] = useState(false)
const [hover, setHover] = useState(false)
const leaveTimer = useRef(null)
const enterTimer = useRef(null)
const open = pinned || hover
const setOpen = v => { setPinned(v); if (!v) setHover(false) }
const enter = () => { clearTimeout(leaveTimer.current); setHover(true) }
const leave = () => { clearTimeout(leaveTimer.current); leaveTimer.current = setTimeout(() => setHover(false), 120) }
useEffect(() => () => clearTimeout(leaveTimer.current), [])
const setOpen = v => { clearTimeout(enterTimer.current); setPinned(v); if (!v) setHover(false) }
// the pointer on the "i": open after the delay; on the open tip: keep it open
const enter = () => {
clearTimeout(leaveTimer.current)
if (hover) return
clearTimeout(enterTimer.current)
enterTimer.current = setTimeout(() => setHover(true), INFOTIP_HOVER_MS)
}
const stay = () => clearTimeout(leaveTimer.current)
const leave = () => {
clearTimeout(enterTimer.current); clearTimeout(leaveTimer.current)
leaveTimer.current = setTimeout(() => setHover(false), 120)
}
useEffect(() => () => { clearTimeout(leaveTimer.current); clearTimeout(enterTimer.current) }, [])
const [pos, setPos] = useState(null)
const button = useRef(null)
const tip = useRef(null)
@@ -89,7 +106,7 @@ export function InfoTip({ children, label, side = 'top', className }) {
ref={tip}
id={id}
role="tooltip"
onPointerEnter={enter}
onPointerEnter={stay}
onPointerLeave={leave}
className={cx('x-infotip__popover', pos && (pos.above ? 'x-infotip__popover--above' : 'x-infotip__popover--below'))}
style={pos ? { top: pos.top, left: pos.left, '--x-arrow-x': `${pos.arrow}px` } : { top: 0, left: 0, visibility: 'hidden' }}