@kolkrabbi/kol-component 0.383.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.
@@ -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
- if (e.key === 'Escape' && all[all.length - 1] === ref.current) onClose?.()
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' : blocking ? 'kol-popover-layer--kolbox-dim fixed inset-0 z-50 flex items-center justify-center' : 'pointer-events-none fixed inset-0 z-50 flex items-center justify-center [&>*]:pointer-events-auto'}
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
- /* Tooltip `variant="kolbox"` (W31.2 batch 4): kolbox's Tooltip carried line for line, CSS-placed, no floating-ui. It
281
- * wraps its trigger; the tip shows under it, 6 clear, after `delay` ms (1000) of hover or keyboard focus, at once when
282
- * another tip closed under 500 ms ago, and closes at once on leave, press or blur (KolboxTooltipDelayAndSize, 2026-11-28).
283
- * Centred on the trigger with its point, then shifted back inside the window (8 from its edge) when a trigger near the
284
- * edge would push it past; over the trigger when there is no room under it. Inside a rail (`[data-rail]`) the tip stands level with its trigger, at
285
- * its left, so it never sits over a section's divider line above the trigger's row; a tip too long to stand there
286
- * wraps to the rail's width. Takes `label`, `children` and `asChild` (no wrapper: the tip hangs on the one child element);
287
- * renders its wrapper even with no label, as kolbox's did. */
288
- /* ON THE LAYER ABOVE (plan-2026-11-18-kolbox-system W23.2, 2026-11-18): the tip was placed in CSS inside its trigger's
289
- * wrapper, so any ancestor with overflow hidden (every kolbox window and popover shell) cut it; "a popup … clipped by
290
- * modal container". It is now portalled to <body>, fixed, and placed from the trigger's box, as the kolbox menus and
291
- * dropdowns are (PopoverLayer); same plate, same places. Shown on hover or keyboard focus; no label, no plate. */
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
- const TIP_GAP = 6
294
- /* Figma's manner (KolboxTooltipDelayAndSize, kol-fxr 2026-11-28): a tip opens after its trigger has held the pointer or
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 kolbox tooltip's trigger: an icon-only kolbox Button there leaves the tip to it (Button.jsx) */
300
- export const InTooltipKolbox = (globalThis[Symbol.for('@kolkrabbi/kol-component/InTooltipKolbox')] ??= createContext(false))
301
- function TooltipKolbox({ label, asChild = false, delay = 1000, children }) {
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 show = label != null && label !== '' && open
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(); return setOpenState(false) }
312
- if (performance.now() - tipClosedAt < TIP_WARM) return setOpenState(true)
313
- timer.current = setTimeout(() => setOpenState(true), delay)
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, side = 'bottom'
328
- /* inside a rail the tip stands level with its trigger, at its left, so it never sits over a section's divider */
329
- if (rail && r.left - TIP_GAP - w >= rail.left + TIP_EDGE) { x = r.left - TIP_GAP - w; y = r.top + r.height / 2 - h / 2; side = 'left' }
330
- else {
331
- /* a tip too long for the rail wraps to the rail's width */
332
- if (rail && w > rail.width - 2 * TIP_EDGE) {
333
- wrapped = rail.width - 2 * TIP_EDGE
334
- Object.assign(t.style, { maxWidth: `${wrapped}px`, whiteSpace: 'normal', height: 'auto' })
335
- w = t.offsetWidth; h = t.offsetHeight
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--kolbox pointer-events-none fixed z-[60] flex h-6 items-center px-2 py-1 whitespace-nowrap"
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
- /* `asChild`: the tip hangs on its one child element itself, no wrapper in the layout (an icon-only kolbox Button,
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
- {cloneElement(children, { ref, onPointerEnter: chain('onPointerEnter'), onPointerLeave: chain('onPointerLeave'), onPointerDown: chain('onPointerDown'), onFocus: chain('onFocus'), onBlur: chain('onBlur') })}
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="relative inline-flex has-[>.w-full]:flex has-[>.w-full]:w-full" {...on}>
386
- <InTooltipKolbox.Provider value>{children}</InTooltipKolbox.Provider>
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
- * PopoverPanel — A floating panel in a portal. renders the floater into a portal with default panel chrome.
522
- *
523
- * Props:
524
- * popover — the value returned from `usePopover`
525
- * panel — apply default `.kol-popover` chrome (default: true)
526
- * modal — focus modality (default: false — non-modal popover)
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
- /* how many floats this one is opened from inside — context crosses portals, the DOM order does not */
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-modal--kolbox kol-kolbox-surface flex flex-col overflow-hidden ${className}`}
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-modal-title--kolbox min-w-0 flex-1 truncate">{title}</h2>}
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 variant="kolbox" iconOnly="x" aria-label="Close" onClick={onClose} />}
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
- /* `variant="kolbox"` (W31.2 batch 4): kolbox's Popover carried line for line, `ModalShell variant="kolbox"` (its shell)
571
- * in `PopoverLayer`, beside its anchor: `anchor`, `open`, `onClose`, `placement` (left-start by default, beside the right
572
- * rail), and the shell's `title`, `leading`, `actions`, `footer`, `width`, `aria-label`, `className`, `children`. */
573
- function PopoverKolbox({ anchor, open, onClose, placement = 'left-start', variant, ...shell }) {
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
- <KolboxShell onClose={onClose} {...shell} />
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.variant === 'kolbox') return <PopoverKolbox {...props} />
537
+ if (!props.popover) return <PopoverWindow {...props} />
583
538
  return <PopoverPanelOn {...props} />
584
539
  }
585
540