@kolkrabbi/kol-component 0.382.0 → 0.384.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -4
- package/src/atoms/Button.jsx +65 -121
- package/src/index.js +1 -6
- package/src/molecules/ButtonGroup.jsx +1 -1
- package/src/molecules/Modal.jsx +129 -272
- package/src/molecules/ModalShell.jsx +10 -12
- package/src/organisms/FindBar.jsx +3 -3
- package/src/utilities/Popover.jsx +170 -215
- package/src/organisms/LogoSystem.jsx +0 -38
- package/src/organisms/LogoTuner.jsx +0 -32
- package/src/organisms/logoBoard.jsx +0 -61
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneElement, createContext, forwardRef, isValidElement, useContext, useEffect, useLayoutEffect, useRef, useState, version as reactVersion } from 'react'
|
|
1
|
+
import { cloneElement, createContext, forwardRef, isValidElement, useContext, useEffect, useId, useLayoutEffect, useRef, useState, version as reactVersion } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
3
|
import { toneClass, TONE_VARS } from './tone.js'
|
|
4
4
|
import { floatMotion } from './motion.js'
|
|
@@ -155,7 +155,11 @@ export function usePopover({
|
|
|
155
155
|
* Unplaced, the layer is transparent, not hidden, so a Menu can take focus on its first frame. Nested layers: a layer
|
|
156
156
|
* opened later (a Dropdown's Menu inside a Popover or Modal) sits after it in the body, so a press inside it is not
|
|
157
157
|
* outside this one, and Escape closes only the last layer. Exported for a kolbox part that draws its own panel in it (the
|
|
158
|
-
* search window, until it moves).
|
|
158
|
+
* search window, until it moves).
|
|
159
|
+
* One set (plan-2026-11-29-one-set-fold 1.3): the layer every ModalDialog and PopoverPanel window sits in, whatever the
|
|
160
|
+
* theme. The dim is the theme's (`.kol-popover-layer-dim`, `--kol-modal-dim`) and so is a centred layer's stacking
|
|
161
|
+
* (`--kol-modal-z`). `container` (an Element): a centred layer portals there and fills it (`absolute`), as ModalDialog's
|
|
162
|
+
* specimen boxes need. Escape is left to an open floating-ui float (`.kol-popover-float`) first. */
|
|
159
163
|
const anchorEl = (anchor) => (anchor && 'current' in anchor ? anchor.current : anchor)
|
|
160
164
|
const later = (a, b) => !!(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
161
165
|
/* spend a press: stop it here, and swallow the mouse events and the click it raises until the press ends. Several
|
|
@@ -170,7 +174,7 @@ function spend(e) {
|
|
|
170
174
|
window.addEventListener('pointerup', end, { capture: true, once: true })
|
|
171
175
|
window.addEventListener('pointercancel', end, { capture: true, once: true })
|
|
172
176
|
}
|
|
173
|
-
export function PopoverLayer({ anchor, open, onClose, placement = 'bottom-start', kind, blocking = true, children }) {
|
|
177
|
+
export function PopoverLayer({ anchor, open, onClose, placement = 'bottom-start', kind, blocking = true, container, children }) {
|
|
174
178
|
const ref = useRef(null)
|
|
175
179
|
const [pos, setPos] = useState(null)
|
|
176
180
|
|
|
@@ -255,7 +259,8 @@ export function PopoverLayer({ anchor, open, onClose, placement = 'bottom-start'
|
|
|
255
259
|
}
|
|
256
260
|
const key = (e) => {
|
|
257
261
|
const all = document.querySelectorAll('[data-kolbox-overlay]')
|
|
258
|
-
|
|
262
|
+
/* a floating-ui float open over this layer (a default Dropdown's list in a dialog) takes its own Escape first */
|
|
263
|
+
if (e.key === 'Escape' && all[all.length - 1] === ref.current && !document.querySelector('.kol-popover-float')) onClose?.()
|
|
259
264
|
}
|
|
260
265
|
window.addEventListener('pointerdown', down, true)
|
|
261
266
|
document.addEventListener('keydown', key)
|
|
@@ -267,50 +272,95 @@ export function PopoverLayer({ anchor, open, onClose, placement = 'bottom-start'
|
|
|
267
272
|
<div
|
|
268
273
|
ref={ref}
|
|
269
274
|
data-kolbox-overlay={kind}
|
|
270
|
-
className={placement !== 'center' ? 'fixed z-50' :
|
|
275
|
+
className={placement !== 'center' ? 'fixed z-50' : `kol-popover-layer-center ${container ? 'absolute' : 'fixed'} inset-0 flex items-center justify-center ${blocking ? 'kol-popover-layer-dim' : 'pointer-events-none [&>*]:pointer-events-auto'}`}
|
|
271
276
|
onClick={placement === 'center' && blocking ? (e) => e.target === e.currentTarget && onClose?.() : undefined}
|
|
272
277
|
style={placement === 'center' ? undefined : { left: pos?.x ?? 0, top: pos?.y ?? 0, opacity: pos ? 1 : 0 }}
|
|
273
278
|
>
|
|
274
279
|
{children}
|
|
275
280
|
</div>,
|
|
276
|
-
document.body,
|
|
281
|
+
(placement === 'center' && container) || document.body,
|
|
277
282
|
)
|
|
278
283
|
}
|
|
279
284
|
|
|
280
|
-
/*
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
285
|
+
/* how many floats this one is opened from inside — context crosses portals, the DOM order does not */
|
|
286
|
+
const FloatDepth = (globalThis[Symbol.for('@kolkrabbi/kol-component/FloatDepth')] ??= createContext(0))
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Tooltip — THE tooltip (plan-2026-11-29-one-set-fold 1.1): the measured tip kolbox built (W31.2 batch 4, W23.2,
|
|
290
|
+
* KolboxTooltipDelayAndSize 2026-11-28) for everyone. Its look is the theme's (`--kol-tooltip-*`, kol-theme
|
|
291
|
+
* `.kol-tooltip`): the default theme draws KOL's mono plate, `data-theme-variant="kolbox"` Figma's dark tip with its
|
|
292
|
+
* point. `variant` ("kolbox", "folio") is accepted and does nothing (the folio CSS-only tip went to
|
|
293
|
+
* `_tmp/2026-11-29-one-set-fold/`).
|
|
294
|
+
*
|
|
295
|
+
* <Tooltip label="Pattern" shortcut="P" placement="bottom">
|
|
296
|
+
* <Button iconOnly="ptrn-checker" ... />
|
|
297
|
+
* </Tooltip>
|
|
298
|
+
*
|
|
299
|
+
* Portalled to <body>, fixed, placed from the trigger's box, so no overflow-hidden parent cuts it. It opens after the
|
|
300
|
+
* trigger has held the pointer or the keyboard focus `delay` ms (unset: the theme's `--kol-tooltip-delay`), at once
|
|
301
|
+
* when another tip closed under 500 ms ago, and closes at once on leave, press, blur or Escape. A touch never opens it.
|
|
302
|
+
*
|
|
303
|
+
* placement unset: under the trigger, centred, over it when there is no room under; inside a rail (`[data-rail]`)
|
|
304
|
+
* level with the trigger at its left, so it never sits over a section's divider, and a tip too long for
|
|
305
|
+
* the rail wraps to its width. 'top' | 'bottom' | 'left' | 'right' (a `-start` / `-end` suffix is read as
|
|
306
|
+
* its side): that side, flipped to the other when there is no room. Kept 8 inside the window.
|
|
307
|
+
* offset the gap to the trigger (6)
|
|
308
|
+
* shortcut a key chip after the label (`.kol-tooltip-key`)
|
|
309
|
+
* asChild no wrapper: the tip hangs on its one child element, whose own ref and handlers are kept (React 18: a
|
|
310
|
+
* component only if it forwards its ref). Use when the trigger's box IS the layout.
|
|
311
|
+
* triggerClassName the wrapper's class (unset: inline, filling its row when the trigger is `w-full`)
|
|
312
|
+
* disabled stays mounted, never opens (a jack mid-patch: dropping the label would remount the trigger)
|
|
313
|
+
* No label: no tooltip, the children as they are. A tooltip inside another's trigger hides the outer one while it is
|
|
314
|
+
* open. The trigger's resolved `--kol-tone-*` ride onto the portalled tip, so a tip in a `kol-tone-*` wrapper wears
|
|
315
|
+
* that tone in the default theme.
|
|
316
|
+
*/
|
|
292
317
|
const TIP_EDGE = 8
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
the focus `delay` ms (1000), and closes at once on leave, press or blur; a tip asked for within TIP_WARM ms of the last
|
|
296
|
-
one closing opens at once, so moving along a toolbar reads each name without the wait */
|
|
318
|
+
/* a tip asked for within TIP_WARM ms of the last one closing opens at once, so moving along a toolbar reads each name
|
|
319
|
+
without the wait */
|
|
297
320
|
const TIP_WARM = 500
|
|
298
321
|
let tipClosedAt = -Infinity
|
|
299
|
-
/* true inside a
|
|
300
|
-
|
|
301
|
-
|
|
322
|
+
/* true inside a tooltip's trigger: an icon-only Button there leaves the tip to it (Button.jsx). The symbol keeps its
|
|
323
|
+
old name so two copies of the package still share one context. */
|
|
324
|
+
export const InTooltip = (globalThis[Symbol.for('@kolkrabbi/kol-component/InTooltipKolbox')] ??= createContext(false))
|
|
325
|
+
/** @deprecated 2026-11-29 → InTooltip (plan-2026-11-29-one-set-fold 1.1) */
|
|
326
|
+
export const InTooltipKolbox = InTooltip
|
|
327
|
+
/* A tooltip inside a tooltip's trigger (a disabled switch's reason inside its row's hint) hides the outer one while it
|
|
328
|
+
* is open, and hands it back on leave — the innermost wins, as the native `title` it replaced behaved. */
|
|
329
|
+
const TooltipNest = (globalThis[Symbol.for('@kolkrabbi/kol-component/TooltipNest')] ??= createContext(null))
|
|
330
|
+
const childRefOf = (el) => ('ref' in (el.props ?? {}) ? el.props.ref : reactVersion.startsWith('18') ? el.ref : undefined)
|
|
331
|
+
/* the theme's open delay, read where the trigger sits (`400ms`, `1s`); 400 when nothing says */
|
|
332
|
+
const tipDelay = (el) => {
|
|
333
|
+
const v = el ? getComputedStyle(el).getPropertyValue('--kol-tooltip-delay').trim() : ''
|
|
334
|
+
const n = parseFloat(v)
|
|
335
|
+
return Number.isFinite(n) ? (/[^m]s$/.test(v) ? n * 1000 : n) : 400
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function Tooltip({ variant, ...props }) { // eslint-disable-line no-unused-vars
|
|
339
|
+
/* no label → no tooltip: several call sites pass an optional hint, and an empty plate is worse than none. A separate
|
|
340
|
+
* component so the hooks below never run conditionally. */
|
|
341
|
+
if (props.label == null || props.label === '') return props.children
|
|
342
|
+
return <TooltipOn {...props} />
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function TooltipOn({ label, shortcut, placement, offset = 6, delay, children, triggerClassName, asChild = false, disabled = false }) {
|
|
302
346
|
const wrap = useRef(null)
|
|
303
347
|
const tip = useRef(null)
|
|
304
348
|
const timer = useRef(null)
|
|
305
349
|
const [open, setOpenState] = useState(false)
|
|
350
|
+
const [covered, setCovered] = useState(false)
|
|
306
351
|
const [pos, setPos] = useState(null)
|
|
307
|
-
const
|
|
352
|
+
const [ambient, setAmbient] = useState(null)
|
|
353
|
+
const parent = useContext(TooltipNest)
|
|
354
|
+
const depth = useContext(FloatDepth)
|
|
355
|
+
const id = useId()
|
|
356
|
+
const show = open && !covered && !disabled
|
|
308
357
|
const shown = useRef(false); shown.current = show
|
|
309
358
|
const setOpen = (v) => {
|
|
310
359
|
clearTimeout(timer.current)
|
|
311
|
-
if (!v) { if (shown.current) tipClosedAt = performance.now();
|
|
312
|
-
|
|
313
|
-
|
|
360
|
+
if (!v) { if (shown.current) tipClosedAt = performance.now(); setOpenState(false); parent?.(false); return }
|
|
361
|
+
const go = () => { setOpenState(true); parent?.(true) }
|
|
362
|
+
if (performance.now() - tipClosedAt < TIP_WARM) return go()
|
|
363
|
+
timer.current = setTimeout(go, delay ?? tipDelay(wrap.current))
|
|
314
364
|
}
|
|
315
365
|
useEffect(() => () => { clearTimeout(timer.current); if (shown.current) tipClosedAt = performance.now() }, [])
|
|
316
366
|
|
|
@@ -318,43 +368,70 @@ function TooltipKolbox({ label, asChild = false, delay = 1000, children }) {
|
|
|
318
368
|
if (!show) return setPos(null)
|
|
319
369
|
const t = tip.current, w0 = wrap.current
|
|
320
370
|
if (!t || !w0) return
|
|
371
|
+
/* THE TONE OF WHERE IT IS (user, 2026-09-26: "tooltip should probably use same tone as dropdowns and buttons"): the
|
|
372
|
+
* surroundings' resolved `--kol-tone-*` (an `asChild` trigger's parent: the trigger may be a variant button with
|
|
373
|
+
* its own) ride onto the portalled tip; no tone in effect, nothing is copied */
|
|
374
|
+
const toned = asChild ? w0.parentElement : w0
|
|
375
|
+
if (toned) {
|
|
376
|
+
const cs = getComputedStyle(toned), vars = {}
|
|
377
|
+
for (const v of TONE_VARS) { const val = cs.getPropertyValue(v).trim(); if (val) vars[v] = val }
|
|
378
|
+
setAmbient(vars)
|
|
379
|
+
}
|
|
321
380
|
const r = w0.getBoundingClientRect()
|
|
322
|
-
const railEl = w0.closest('[data-rail]')
|
|
323
|
-
const rail = railEl?.getBoundingClientRect()
|
|
324
381
|
const vw = window.innerWidth, vh = window.innerHeight
|
|
325
382
|
t.style.maxWidth = ''; t.style.whiteSpace = ''; t.style.height = ''
|
|
326
383
|
let w = t.offsetWidth, h = t.offsetHeight
|
|
327
|
-
let x, y, wrapped = null
|
|
328
|
-
|
|
329
|
-
if (
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
384
|
+
let x, y, wrapped = null
|
|
385
|
+
let side = placement ? placement.split('-')[0] : 'bottom'
|
|
386
|
+
if (placement) {
|
|
387
|
+
/* the side asked for, flipped to the other when the window ends */
|
|
388
|
+
if (side === 'top' || side === 'bottom') {
|
|
389
|
+
x = r.left + r.width / 2 - w / 2
|
|
390
|
+
y = side === 'bottom' ? r.bottom + offset : r.top - offset - h
|
|
391
|
+
if (side === 'bottom' && y + h > vh - TIP_EDGE) { y = r.top - offset - h; side = 'top' }
|
|
392
|
+
else if (side === 'top' && y < TIP_EDGE) { y = r.bottom + offset; side = 'bottom' }
|
|
393
|
+
} else {
|
|
394
|
+
y = r.top + r.height / 2 - h / 2
|
|
395
|
+
x = side === 'right' ? r.right + offset : r.left - offset - w
|
|
396
|
+
if (side === 'right' && x + w > vw - TIP_EDGE) { x = r.left - offset - w; side = 'left' }
|
|
397
|
+
else if (side === 'left' && x < TIP_EDGE) { x = r.right + offset; side = 'right' }
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
const railEl = w0.closest('[data-rail]')
|
|
401
|
+
const rail = railEl?.getBoundingClientRect()
|
|
402
|
+
/* inside a rail the tip stands level with its trigger, at its left, so it never sits over a section's divider */
|
|
403
|
+
if (rail && r.left - offset - w >= rail.left + TIP_EDGE) { x = r.left - offset - w; y = r.top + r.height / 2 - h / 2; side = 'left' }
|
|
404
|
+
else {
|
|
405
|
+
/* a tip too long for the rail wraps to the rail's width */
|
|
406
|
+
if (rail && w > rail.width - 2 * TIP_EDGE) {
|
|
407
|
+
wrapped = rail.width - 2 * TIP_EDGE
|
|
408
|
+
Object.assign(t.style, { maxWidth: `${wrapped}px`, whiteSpace: 'normal', height: 'auto' })
|
|
409
|
+
w = t.offsetWidth; h = t.offsetHeight
|
|
410
|
+
}
|
|
411
|
+
const lo = (rail ? rail.left : 0) + TIP_EDGE, hi = (rail ? rail.right : vw) - TIP_EDGE - w
|
|
412
|
+
x = Math.max(lo, Math.min(r.left + r.width / 2 - w / 2, hi))
|
|
413
|
+
/* under the trigger, centred; no room under: over it */
|
|
414
|
+
y = r.bottom + offset
|
|
415
|
+
if (y + h > vh - TIP_EDGE) { y = r.top - offset - h; side = 'top' }
|
|
336
416
|
}
|
|
337
|
-
const lo = (rail ? rail.left : 0) + TIP_EDGE, hi = (rail ? rail.right : vw) - TIP_EDGE - w
|
|
338
|
-
x = Math.max(lo, Math.min(r.left + r.width / 2 - w / 2, hi))
|
|
339
|
-
/* under the trigger, centred; no room under: over it */
|
|
340
|
-
y = r.bottom + TIP_GAP
|
|
341
|
-
if (y + h > vh - TIP_EDGE) { y = r.top - TIP_GAP - h; side = 'top' }
|
|
342
417
|
}
|
|
343
418
|
x = Math.max(TIP_EDGE, Math.min(x, vw - TIP_EDGE - w))
|
|
344
419
|
y = Math.max(TIP_EDGE, Math.min(y, vh - TIP_EDGE - h))
|
|
345
420
|
/* the point stays on the trigger's centre when the box was shifted inside the window */
|
|
346
421
|
setPos({ x, y, wrapped, side, point: Math.max(10, Math.min(r.left + r.width / 2 - x, w - 10)) })
|
|
347
|
-
}, [show, label])
|
|
422
|
+
}, [show, label, shortcut, placement, offset]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
348
423
|
|
|
349
424
|
const tipNode = show && typeof document !== 'undefined' && createPortal(
|
|
350
425
|
<span
|
|
351
426
|
ref={tip}
|
|
427
|
+
id={id}
|
|
352
428
|
role="tooltip"
|
|
353
429
|
data-side={pos?.side}
|
|
354
|
-
className="kol-tooltip
|
|
355
|
-
style={{ left: pos?.x ?? 0, top: pos?.y ?? 0, opacity: pos ? 1 : 0, '--kol-tip-point': pos ? `${pos.point}px` : undefined, ...(pos?.wrapped ? { maxWidth: pos.wrapped, whiteSpace: 'normal', height: 'auto', paddingTop: 'var(--kol-spacing-1)', paddingBottom: 'var(--kol-spacing-1)' } : null) }}
|
|
430
|
+
className="kol-tooltip pointer-events-none fixed"
|
|
431
|
+
style={{ ...ambient, left: pos?.x ?? 0, top: pos?.y ?? 0, opacity: pos ? 1 : 0, '--kol-tip-point': pos ? `${pos.point}px` : undefined, ...(depth ? { '--kol-float-depth': depth } : null), ...(pos?.wrapped ? { maxWidth: pos.wrapped, whiteSpace: 'normal', height: 'auto', paddingTop: 'var(--kol-spacing-1)', paddingBottom: 'var(--kol-spacing-1)' } : null) }}
|
|
356
432
|
>
|
|
357
433
|
{label}
|
|
434
|
+
{shortcut && <span className="kol-tooltip-key">{shortcut}</span>}
|
|
358
435
|
</span>,
|
|
359
436
|
document.body,
|
|
360
437
|
)
|
|
@@ -364,9 +441,9 @@ function TooltipKolbox({ label, asChild = false, delay = 1000, children }) {
|
|
|
364
441
|
onPointerDown: () => setOpen(false),
|
|
365
442
|
onFocus: (e) => e.target.matches?.(':focus-visible') && setOpen(true),
|
|
366
443
|
onBlur: () => setOpen(false),
|
|
444
|
+
onKeyDown: (e) => e.key === 'Escape' && shown.current && setOpen(false),
|
|
367
445
|
}
|
|
368
|
-
|
|
369
|
-
whose parent's rules address it as a direct child); the child's own handlers run first */
|
|
446
|
+
const described = show ? id : undefined
|
|
370
447
|
if (asChild && isValidElement(children)) {
|
|
371
448
|
const own = children.props
|
|
372
449
|
const chain = (k) => (e) => { own[k]?.(e); on[k](e) }
|
|
@@ -375,211 +452,89 @@ function TooltipKolbox({ label, asChild = false, delay = 1000, children }) {
|
|
|
375
452
|
const ref = (node) => { wrap.current = node; if (typeof theirs === 'function') theirs(node); else if (theirs) theirs.current = node }
|
|
376
453
|
return (
|
|
377
454
|
<>
|
|
378
|
-
|
|
455
|
+
<TooltipNest.Provider value={setCovered}>
|
|
456
|
+
{cloneElement(children, { ref, 'aria-describedby': described ?? own['aria-describedby'], ...Object.fromEntries(Object.keys(on).map((k) => [k, chain(k)])) })}
|
|
457
|
+
</TooltipNest.Provider>
|
|
379
458
|
{tipNode}
|
|
380
459
|
</>
|
|
381
460
|
)
|
|
382
461
|
}
|
|
383
462
|
return (
|
|
384
463
|
/* a trigger that fills its row (w-full) makes the wrapper fill it too, so wrapping a control never narrows it */
|
|
385
|
-
<span ref={wrap} data-kol-tooltip="" className=
|
|
386
|
-
<
|
|
464
|
+
<span ref={wrap} data-kol-tooltip="" aria-describedby={described} className={triggerClassName ?? 'relative inline-flex has-[>.w-full]:flex has-[>.w-full]:w-full'} {...on}>
|
|
465
|
+
<TooltipNest.Provider value={setCovered}>
|
|
466
|
+
<InTooltip.Provider value>{children}</InTooltip.Provider>
|
|
467
|
+
</TooltipNest.Provider>
|
|
387
468
|
{tipNode}
|
|
388
469
|
</span>
|
|
389
470
|
)
|
|
390
471
|
}
|
|
391
472
|
|
|
392
|
-
/* Tooltip `variant="folio"` (Folio migration batch A, 2026-11-22): Folio's Tooltip carried class for class (apps/folio
|
|
393
|
-
* EditorChrome.jsx): a hairline box at radius 4 padded 4 by 8, 6 over its trigger, the text 11 / 15; shown on hover or
|
|
394
|
-
* focus inside its wrapper, placed in CSS, no portal (so it keeps the frame's `data-folio-*`; an overflow-hidden parent
|
|
395
|
-
* clips it, as Folio's did). Chrome in kol-theme `.kol-tooltip--folio`. */
|
|
396
|
-
function TooltipFolio({ label, children }) {
|
|
397
|
-
return (
|
|
398
|
-
<span className="group relative inline-flex">
|
|
399
|
-
{children}
|
|
400
|
-
<span role="tooltip" className="kol-tooltip--folio pointer-events-none invisible absolute bottom-[calc(100%+6px)] left-1/2 z-50 -translate-x-1/2 whitespace-nowrap rounded-[4px] border px-[8px] py-[4px] group-focus-within:visible group-hover:visible">{label}</span>
|
|
401
|
-
</span>
|
|
402
|
-
)
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Tooltip — hover-triggered popover with text content. Wraps any trigger
|
|
407
|
-
* element. Built on `usePopover` with `hover: true`, `click: false`,
|
|
408
|
-
* `role: 'tooltip'`. Includes keyboard focus trigger so tab-focused
|
|
409
|
-
* controls also reveal the tooltip.
|
|
410
|
-
*
|
|
411
|
-
* <Tooltip label="Pattern" shortcut="P" placement="bottom">
|
|
412
|
-
* <Button iconOnly="ptrn-checker" ... />
|
|
413
|
-
* </Tooltip>
|
|
414
|
-
*/
|
|
415
|
-
/* A tooltip inside a tooltip's trigger (a disabled switch's reason inside its
|
|
416
|
-
* row's hint) hides the outer one while it is open, and hands it back on leave
|
|
417
|
-
* — the innermost wins, as the native `title` it replaced behaved. */
|
|
418
|
-
const TooltipNest = (globalThis[Symbol.for('@kolkrabbi/kol-component/TooltipNest')] ??= createContext(null))
|
|
419
|
-
|
|
420
|
-
/* `asChild` (the native-title sweep, 2026-09-26): the tooltip attaches to its one child element
|
|
421
|
-
* instead of wrapping it in a span — for a trigger whose box IS the layout (a grid cell, a rail row,
|
|
422
|
-
* an absolutely placed handle), where an inline-flex wrapper would move it. The child must be an
|
|
423
|
-
* element that takes a ref: an intrinsic tag always does; a component only if it forwards one
|
|
424
|
-
* (React 18 needs forwardRef), so Button / IconFrame keep the wrapper. Its own ref and handlers are
|
|
425
|
-
* kept — the reference props merge over the child's. */
|
|
426
|
-
/* `disabled` (HardwareNativeTitle, kol-monitor 2026-10-15): the tooltip stays mounted but never
|
|
427
|
-
* opens — a jack mid-patch. Dropping the label instead would swap the tree and remount the trigger
|
|
428
|
-
* under the pointer. */
|
|
429
|
-
const childRefOf = (el) => ('ref' in (el.props ?? {}) ? el.props.ref : reactVersion.startsWith('18') ? el.ref : undefined)
|
|
430
|
-
|
|
431
|
-
export function Tooltip(props) {
|
|
432
|
-
if (props.variant === 'kolbox') return <TooltipKolbox label={props.label} asChild={props.asChild} delay={props.delay}>{props.children}</TooltipKolbox>
|
|
433
|
-
if (props.variant === 'folio') return <TooltipFolio label={props.label}>{props.children}</TooltipFolio>
|
|
434
|
-
/* no label → no tooltip: several call sites pass an optional hint, and an empty panel is worse
|
|
435
|
-
* than none. A separate component so the hooks below never run conditionally. */
|
|
436
|
-
if (props.label == null || props.label === '') return props.children
|
|
437
|
-
return <TooltipOn {...props} />
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function TooltipOn({
|
|
441
|
-
label,
|
|
442
|
-
shortcut,
|
|
443
|
-
placement = 'bottom',
|
|
444
|
-
offset = 6,
|
|
445
|
-
children,
|
|
446
|
-
triggerClassName = 'inline-flex',
|
|
447
|
-
asChild = false,
|
|
448
|
-
disabled = false,
|
|
449
|
-
}) {
|
|
450
|
-
const [open, setOpen] = useState(false)
|
|
451
|
-
const [covered, setCovered] = useState(false)
|
|
452
|
-
const parent = useContext(TooltipNest)
|
|
453
|
-
const popover = usePopover({
|
|
454
|
-
open: open && !covered && !disabled,
|
|
455
|
-
onOpenChange: (v) => { setOpen(v); parent?.(v) },
|
|
456
|
-
placement,
|
|
457
|
-
offset,
|
|
458
|
-
role: 'tooltip',
|
|
459
|
-
click: false,
|
|
460
|
-
hover: true,
|
|
461
|
-
focus: true,
|
|
462
|
-
})
|
|
463
|
-
|
|
464
|
-
/* THE TONE OF WHERE IT IS (user, 2026-09-26: "tooltip should probably use same tone as dropdowns
|
|
465
|
-
* and buttons"). The panel is portalled to body, outside the `kol-tone-*` wrapper that tones the
|
|
466
|
-
* controls around the trigger — Dropdown's problem, solved the same way: on open, copy the
|
|
467
|
-
* trigger's RESOLVED `--kol-tone-*` onto the panel. No tone in effect = nothing copied, and the
|
|
468
|
-
* tooltip keeps its own surface. */
|
|
469
|
-
const [ambient, setAmbient] = useState(null)
|
|
470
|
-
const shown = open && !covered && !disabled
|
|
471
|
-
useLayoutEffect(() => {
|
|
472
|
-
const ref = popover.refs.reference.current
|
|
473
|
-
/* the SURROUNDINGS' tone, not the trigger's own: an `asChild` trigger can be a variant button
|
|
474
|
-
* (`kol-btn-ghost` carries its own `--kol-tone-*`), so read its parent; the wrapper span has no
|
|
475
|
-
* variant and inherits the ambient values as it is */
|
|
476
|
-
const el = asChild ? ref?.parentElement : ref
|
|
477
|
-
if (!shown || !(el instanceof Element)) return
|
|
478
|
-
const cs = getComputedStyle(el)
|
|
479
|
-
const vars = {}
|
|
480
|
-
for (const v of TONE_VARS) { const val = cs.getPropertyValue(v).trim(); if (val) vars[v] = val }
|
|
481
|
-
setAmbient(vars)
|
|
482
|
-
}, [shown]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
483
|
-
|
|
484
|
-
const child = asChild && isValidElement(children) ? children : null
|
|
485
|
-
const childRef = child ? childRefOf(child) : undefined
|
|
486
|
-
const setRef = (node) => {
|
|
487
|
-
popover.refs.setReference(node)
|
|
488
|
-
if (typeof childRef === 'function') childRef(node)
|
|
489
|
-
else if (childRef) childRef.current = node
|
|
490
|
-
}
|
|
491
|
-
return (
|
|
492
|
-
<>
|
|
493
|
-
{child ? (
|
|
494
|
-
<TooltipNest.Provider value={setCovered}>
|
|
495
|
-
{cloneElement(child, { ...popover.getReferenceProps(child.props), ref: setRef })}
|
|
496
|
-
</TooltipNest.Provider>
|
|
497
|
-
) : (
|
|
498
|
-
<span
|
|
499
|
-
ref={popover.refs.setReference}
|
|
500
|
-
{...popover.getReferenceProps()}
|
|
501
|
-
className={triggerClassName}
|
|
502
|
-
>
|
|
503
|
-
<TooltipNest.Provider value={setCovered}>{children}</TooltipNest.Provider>
|
|
504
|
-
</span>
|
|
505
|
-
)}
|
|
506
|
-
<PopoverPanel
|
|
507
|
-
popover={popover}
|
|
508
|
-
focus={false}
|
|
509
|
-
panel={false}
|
|
510
|
-
className="kol-tooltip"
|
|
511
|
-
style={ambient ?? undefined}
|
|
512
|
-
>
|
|
513
|
-
<span>{label}</span>
|
|
514
|
-
{shortcut && <span className="kol-tooltip-key">{shortcut}</span>}
|
|
515
|
-
</PopoverPanel>
|
|
516
|
-
</>
|
|
517
|
-
)
|
|
518
|
-
}
|
|
519
|
-
|
|
520
473
|
/**
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
* focus — wrap in FloatingFocusManager (default: true)
|
|
528
|
-
* className — extra classes on the panel
|
|
529
|
-
* style — extra inline styles merged with floatingStyles
|
|
530
|
-
* motion — the float card's enter and leave (FloatActionStatesAndMotion, 2026-11-04): unset, the panel
|
|
531
|
-
* mounts and unmounts as it always has; `true` · `{ duration, ease }` fades it in and out from its
|
|
532
|
-
* trigger's side (`.kol-float-motion`, `--kol-float-*`), held in the tree while it leaves; `false`
|
|
533
|
-
* the same card with no motion
|
|
474
|
+
* PanelShell — THE panel shell (plan-2026-11-29-one-set-fold 1.3; kolbox's PopoverShell, W31.2 batch 4, for everyone):
|
|
475
|
+
* the window every popover window, ModalDialog and useModal prompt draws. Header: a `leading` slot (tabs, or an icon and
|
|
476
|
+
* a name), the `title`, the `actions`, the close (only with `onClose`: a dialog with none cannot be dismissed). The body
|
|
477
|
+
* is the children and scrolls; `footer`, when given, is a row of buttons under it. `width` any CSS length (unset: the
|
|
478
|
+
* theme's `--kol-popover-w`). Its look is the theme's (`--kol-modal-*`, kol-theme `.kol-panel-shell`). Other props
|
|
479
|
+
* (role, aria-*, data-*, style, handlers) and the ref go on the dialog. `KolboxShell` is its old name.
|
|
534
480
|
*/
|
|
535
|
-
|
|
536
|
-
const FloatDepth = (globalThis[Symbol.for('@kolkrabbi/kol-component/FloatDepth')] ??= createContext(0))
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
/* The kolbox panel shell (W31.2 batch 4): kolbox's PopoverShell carried line for line, the panel every kolbox popover
|
|
540
|
-
* and window draws: radius 16, the secondary surface on the one floating surface (`.kol-kolbox-surface`), 240 wide
|
|
541
|
-
* (`--kol-kolbox-popover-w`) unless `width` says otherwise. Header: a `leading` slot (tabs, or an icon and name), the
|
|
542
|
-
* `title`, the `actions`, close (only with `onClose`: a dialog with none cannot be dismissed). The body is the
|
|
543
|
-
* children; `footer`, when given, is a row of buttons under it. Drawn by `PopoverPanel variant="kolbox"` beside its
|
|
544
|
-
* anchor, by `ModalDialog variant="kolbox"` centred, and on its own as `ModalShell variant="kolbox"`. Other props
|
|
545
|
-
* (aria-modal, data-*) and the ref go on the dialog. Not exported from the package. */
|
|
546
|
-
export const KolboxShell = forwardRef(function KolboxShell({ onClose, title, leading, actions, footer, width, className = '', children, ...rest }, ref) {
|
|
481
|
+
export const PanelShell = forwardRef(function PanelShell({ onClose, title, leading, actions, footer, width, className = '', children, ...rest }, ref) {
|
|
547
482
|
return (
|
|
548
483
|
<section
|
|
549
484
|
ref={ref}
|
|
550
485
|
role="dialog"
|
|
551
486
|
aria-label={typeof title === 'string' ? title : undefined}
|
|
552
487
|
data-kolbox-popover=""
|
|
553
|
-
className={`kol-
|
|
488
|
+
className={`kol-panel-shell flex flex-col overflow-hidden ${className}`}
|
|
554
489
|
style={width ? { width } : undefined}
|
|
555
490
|
{...rest}
|
|
556
491
|
>
|
|
557
492
|
<header className="flex shrink-0 items-center gap-1 py-2 pr-2 pl-4">
|
|
558
493
|
{leading}
|
|
559
|
-
{title && <h2 className="kol-
|
|
494
|
+
{title && <h2 className="kol-panel-shell-title min-w-0 flex-1 truncate">{title}</h2>}
|
|
560
495
|
{!title && <span className="flex-1" />}
|
|
561
496
|
{actions}
|
|
562
|
-
{onClose && <Button
|
|
497
|
+
{onClose && <Button size="sm" tone="ghost" iconOnly="x" aria-label="Close" onClick={onClose} />}
|
|
563
498
|
</header>
|
|
564
499
|
<div className="flex min-h-0 flex-1 flex-col overflow-y-auto">{children}</div>
|
|
565
500
|
{footer && <footer className="flex shrink-0 items-center justify-end gap-2 px-4 pb-4">{footer}</footer>}
|
|
566
501
|
</section>
|
|
567
502
|
)
|
|
568
503
|
})
|
|
504
|
+
/** @deprecated 2026-11-29 → PanelShell (plan-2026-11-29-one-set-fold 1.3) */
|
|
505
|
+
export const KolboxShell = PanelShell
|
|
569
506
|
|
|
570
|
-
/*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
function
|
|
507
|
+
/* A window beside its anchor: PanelShell in `PopoverLayer` — `anchor`, `open`, `onClose`, `placement` (left-start by
|
|
508
|
+
* default, beside the right rail), and the shell's `title`, `leading`, `actions`, `footer`, `width`, `aria-label`,
|
|
509
|
+
* `className`, `children`. */
|
|
510
|
+
function PopoverWindow({ anchor, open, onClose, placement = 'left-start', variant, ...shell }) { // eslint-disable-line no-unused-vars
|
|
574
511
|
return (
|
|
575
512
|
<PopoverLayer anchor={anchor} open={open} onClose={onClose} placement={placement} kind="popover">
|
|
576
|
-
<
|
|
513
|
+
<PanelShell onClose={onClose} {...shell} />
|
|
577
514
|
</PopoverLayer>
|
|
578
515
|
)
|
|
579
516
|
}
|
|
580
517
|
|
|
518
|
+
/**
|
|
519
|
+
* PopoverPanel — A floating panel in a portal. renders the floater into a portal with default panel chrome.
|
|
520
|
+
*
|
|
521
|
+
* Props:
|
|
522
|
+
* popover — the value returned from `usePopover`
|
|
523
|
+
* panel — apply default `.kol-popover` chrome (default: true)
|
|
524
|
+
* modal — focus modality (default: false — non-modal popover)
|
|
525
|
+
* focus — wrap in FloatingFocusManager (default: true)
|
|
526
|
+
* className — extra classes on the panel
|
|
527
|
+
* style — extra inline styles merged with floatingStyles
|
|
528
|
+
* motion — the float card's enter and leave (FloatActionStatesAndMotion, 2026-11-04): unset, the panel
|
|
529
|
+
* mounts and unmounts as it always has; `true` · `{ duration, ease }` fades it in and out from its
|
|
530
|
+
* trigger's side (`.kol-float-motion`, `--kol-float-*`), held in the tree while it leaves; `false`
|
|
531
|
+
* the same card with no motion
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
/* Two APIs, one look each, never a theme's: with `popover` (usePopover's) it is the floating primitive above; without
|
|
535
|
+
* one it is a window beside `anchor` (PopoverWindow). `variant` ("kolbox") is accepted and does nothing. */
|
|
581
536
|
export function PopoverPanel(props) {
|
|
582
|
-
if (props.
|
|
537
|
+
if (!props.popover) return <PopoverWindow {...props} />
|
|
583
538
|
return <PopoverPanelOn {...props} />
|
|
584
539
|
}
|
|
585
540
|
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { useMemo, useRef } from 'react'
|
|
2
|
-
import { system, systemDrag, grid } from '@kolkrabbi/kol-tuner'
|
|
3
|
-
import { Board, Keylines, Labels, inksOf, useLight } from './logoBoard.jsx'
|
|
4
|
-
|
|
5
|
-
/* LOGOSYSTEM (W27.4, 2026-11-19): the System board of @kolkrabbi/kol-tuner (the canvas's system-01-arcs), a mark built
|
|
6
|
-
* from measures, nothing placed by hand. It draws the form, the wedges, the construction and the math, the grid, the
|
|
7
|
-
* keylines, a reference image and the six handles (y, axisAt, x, angle, footAt, footSize). The settings are the host's:
|
|
8
|
-
* `settings` is the engine's System props as they stand, a handle drag calls `onDrag(key, value)` with the measure under
|
|
9
|
-
* the pointer, a double-click on a handle calls `onDragReset()`, a file dropped on the board calls `onFile(file)`.
|
|
10
|
-
* `reference` is `{ src, w, h }`, drawn faint behind the form. `peek` draws the form alone. */
|
|
11
|
-
export default function LogoSystem({ settings: p, reference, peek = false, onDrag, onDragReset, onFile, className = '' }) {
|
|
12
|
-
const inks = inksOf(p), themeLight = useLight(), light = inks ? inks.light : themeLight, svg = useRef(null), dragging = useRef(null)
|
|
13
|
-
const v = useMemo(() => system(p), [p])
|
|
14
|
-
const grey = p.fill === 'grey', strokeAlpha = grey ? 0.85 : 0.5
|
|
15
|
-
const gridD = p.grid && p.grid !== 'off' && !peek && v.measures ? grid(p.grid, (+p.gridStep || 1) * v.measures.x * (v.box || 480), +p.gridTurn || 0) : ''
|
|
16
|
-
const at = (e) => { const pt = svg.current.createSVGPoint(); pt.x = e.clientX; pt.y = e.clientY; const q = pt.matrixTransform(svg.current.getScreenCTM().inverse()); return [q.x - 600, q.y - 400] }
|
|
17
|
-
const move = (e) => { const k = dragging.current; if (!k) return; const m = at(e); onDrag?.(k, systemDrag(p, k, m[0], m[1])) }
|
|
18
|
-
const refBox = reference && (() => { const k = Math.min(v.box / reference.w, v.box / reference.h), w = reference.w * k, h = reference.h * k; return { x: -w / 2, y: -h / 2, w, h } })()
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div className={`h-full w-full ${className}`.trim()} onDragOver={(e) => e.preventDefault()} onDrop={(e) => { e.preventDefault(); onFile?.(e.dataTransfer.files[0]) }}>
|
|
22
|
-
<Board svgRef={svg} inks={inks} label="Mark built from a few measures">
|
|
23
|
-
{refBox && <image href={reference.src} x={refBox.x} y={refBox.y} width={refBox.w} height={refBox.h} className="kol-logo-ref" />}
|
|
24
|
-
{gridD && <path d={gridD} className="kol-logo-grid" />}
|
|
25
|
-
<path d={v.d} className={`kol-logo-form${grey && !peek ? ' is-grey' : ''}`} />
|
|
26
|
-
{!peek && p.math && <path d={v.wedges} className="kol-logo-wedges" />}
|
|
27
|
-
{!peek && <path d={(p.construction ? v.guides : '') + (p.math ? v.dims : '')} className="kol-logo-lines" opacity={strokeAlpha} />}
|
|
28
|
-
{!peek && p.handles && v.handlePts.map((h) => (
|
|
29
|
-
<circle key={h.k} data-handle={h.k} cx={h.p[0]} cy={h.p[1]} r="9" className="kol-logo-handle"
|
|
30
|
-
onPointerDown={(e) => { e.preventDefault(); e.stopPropagation(); dragging.current = h.k; e.currentTarget.setPointerCapture(e.pointerId) }}
|
|
31
|
-
onPointerMove={move} onPointerUp={() => { dragging.current = null }} onDoubleClick={(e) => { e.preventDefault(); dragging.current = null; onDragReset?.() }} />
|
|
32
|
-
))}
|
|
33
|
-
{p.keylines && !peek && <Keylines box={(v.box || 480) * 1.2} light={light} />}
|
|
34
|
-
{!peek && p.math && <Labels list={v.dimLabels} />}
|
|
35
|
-
</Board>
|
|
36
|
-
</div>
|
|
37
|
-
)
|
|
38
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import { tuner } from '@kolkrabbi/kol-tuner'
|
|
3
|
-
import { Board, Keylines, Labels, inksOf, useLight } from './logoBoard.jsx'
|
|
4
|
-
|
|
5
|
-
/* LOGOTUNER (W27.4, 2026-11-19): the Tuner board of @kolkrabbi/kol-tuner (the canvas's tuner-01-form), a dropped logo
|
|
6
|
-
* rebuilt from circles and lines on one ladder. It draws the form, the traced line, the circles and dots, the curvature
|
|
7
|
-
* comb, the grid, the keylines and the labels. The settings are the host's: `settings` is the engine's Tuner props,
|
|
8
|
-
* `image` the `Image` it reads (an SVG carries its text as `image.__svg`), and a file dropped on the board or picked by
|
|
9
|
-
* a click calls `onFile(file)`; the host reads it into `image`. `peek` draws the tuned form alone. */
|
|
10
|
-
export default function LogoTuner({ settings: p, image = null, peek = false, onFile, className = '' }) {
|
|
11
|
-
const inks = inksOf(p), themeLight = useLight(), light = inks ? inks.light : themeLight
|
|
12
|
-
const v = useMemo(() => tuner(peek ? { ...p, view: 'tuned' } : p, image), [p, image, peek])
|
|
13
|
-
const grey = p.fill !== 'ink', strokeAlpha = grey ? 0.85 : 0.5
|
|
14
|
-
const pick = (e) => { onFile?.(e.target.files[0]); e.target.value = '' }
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<label className={`block h-full w-full cursor-pointer ${className}`.trim()} title="Choose a logo: an SVG or a black and white image"
|
|
18
|
-
onDragOver={(e) => e.preventDefault()} onDrop={(e) => { e.preventDefault(); onFile?.(e.dataTransfer.files[0]) }}>
|
|
19
|
-
<Board inks={inks} label="A form rebuilt from circles and lines">
|
|
20
|
-
{!peek && v.gridD && <path d={v.gridD} className="kol-logo-grid" />}
|
|
21
|
-
<path d={v.d} className={`kol-logo-form${grey && !peek ? ' is-grey' : ''}`} fillRule={v.fillRule || 'evenodd'} />
|
|
22
|
-
{!peek && [v.comb0, v.comb1, v.comb2].map((d, i) => d && <path key={i} d={d} className={`kol-logo-comb is-${i}`} />)}
|
|
23
|
-
{!peek && p.outline && p.view !== 'original' && <path d={v.orig} className="kol-logo-trace" />}
|
|
24
|
-
{!peek && <path d={(p.construction ? v.circles : '') + (p.math ? v.guides : '')} className="kol-logo-lines" opacity={strokeAlpha} />}
|
|
25
|
-
{!peek && p.construction && <path d={v.dots} className="kol-logo-dots" />}
|
|
26
|
-
{!peek && p.keylines && <Keylines box={(v.box || 480) * 1.2} ox={v.boxX} oy={v.boxY} light={light} />}
|
|
27
|
-
{!peek && p.math && <Labels list={v.labels} />}
|
|
28
|
-
</Board>
|
|
29
|
-
<input type="file" accept="image/*,.svg" aria-label="Choose a logo: an SVG or a black and white image" className="sr-only" onChange={pick} />
|
|
30
|
-
</label>
|
|
31
|
-
)
|
|
32
|
-
}
|