@kolkrabbi/kol-component 0.311.2 → 0.312.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.311.2",
3
+ "version": "0.312.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -67,6 +67,8 @@ export { default as InspectorSection, default as Section } from './molecules/Ins
67
67
  export { default as SectionText, SECTION_TEXT_LEVELS } from './molecules/SectionText.jsx'
68
68
  export { default as SectionLabel } from './atoms/SectionLabel.jsx'
69
69
  export { default as SegmentedToggle } from './atoms/SegmentedToggle.jsx'
70
+ /* a page's variants — the pinned slider button and its panel of segmented rows (OneVariantsControl, 2026-10-29; catalog's) */
71
+ export { default as VariantsControl } from './molecules/VariantsControl.jsx'
70
72
  export { default as Stepper } from './molecules/Stepper.jsx'
71
73
  export { default as Kbd } from './atoms/Kbd.jsx'
72
74
  export { default as OptionRow } from './molecules/OptionRow.jsx'
@@ -0,0 +1,39 @@
1
+ import { useState } from 'react'
2
+ import Button from '../atoms/Button.jsx'
3
+ import SegmentedToggle from '../atoms/SegmentedToggle.jsx'
4
+ import { usePopover, PopoverPanel } from '../utilities/Popover.jsx'
5
+
6
+ const cap = (v) => String(v).charAt(0).toUpperCase() + String(v).slice(1)
7
+
8
+ /**
9
+ * VariantsControl — a page's variants: a round `slider-01` button pinned top-right at the shell's page pad that opens a
10
+ * panel of labelled segmented rows, one per axis. apps/catalog's `VariantsButton`, shipped (OneVariantsControl, kol-website
11
+ * 2026-10-29 — user: *"why are they reinventing the wheel? we already have a component for this"*); catalog, rails, shell
12
+ * and layouts each had it, by hand or reinvented. Each axis is a SEGMENTED row, not a dropdown (user 2026-10-22, on a
13
+ * dropdown list opening over the panel in the panel's own colour): every option visible, one click, nothing floats over the
14
+ * panel.
15
+ *
16
+ * @param {Array} axes `[{ key, label, values }]` (each value labelled with its first letter capitalised) or
17
+ * `[{ key, label, options: [{ value, label }] }]`
18
+ * @param {Object} value the current value by axis key
19
+ * @param {Function} onChange `(key, value)`
20
+ * @param {Object} [style] merged onto the pinned wrapper — a host whose own chrome holds that corner moves it
21
+ */
22
+ export default function VariantsControl({ axes = [], value = {}, onChange, style, className = '' }) {
23
+ const [open, setOpen] = useState(false)
24
+ const popover = usePopover({ open, onOpenChange: setOpen, placement: 'bottom-end', offset: 8 })
25
+ return (
26
+ <div className={`fixed z-10 ${className}`.trim()} style={{ top: 'var(--kol-shell-page-pad, 24px)', right: 'var(--kol-shell-page-pad, 24px)', ...style }}>
27
+ <span ref={popover.refs.setReference} {...popover.getReferenceProps()} className="inline-flex">
28
+ <Button iconOnly="slider-01" size="lg" tone="inverted" radius="full" aria-label="Variants" style={{ boxShadow: 'var(--kol-shadow-lg)' }} pressed={open} />
29
+ </span>
30
+ <PopoverPanel popover={popover} className="grid grid-cols-[auto_1fr] items-center gap-x-4 gap-y-2 p-3">
31
+ {axes.map((a) => [
32
+ <span key={`${a.key}-l`} className="kol-mono-12 text-fg-64">{a.label}</span>,
33
+ <SegmentedToggle key={a.key} size="sm" ariaLabel={a.label} value={value[a.key]} onChange={(v) => onChange?.(a.key, v)}
34
+ options={a.options ?? (a.values ?? []).map((v) => ({ value: v, label: cap(v) }))} />,
35
+ ])}
36
+ </PopoverPanel>
37
+ </div>
38
+ )
39
+ }
@@ -149,17 +149,23 @@ function Firework({ x, y, type, onDone }) {
149
149
  const frames = allFrameSets[type]
150
150
 
151
151
  useEffect(() => {
152
- const interval = setInterval(() => {
153
- setFrame((f) => {
154
- if (f >= frames.length - 1) {
155
- onDone()
156
- return f
157
- }
158
- return f + 1
159
- })
160
- }, 130)
152
+ // Advance frames on a clock; report completion from an effect. `onDone` used
153
+ // to be called inside the setFrame updater — React runs updaters during the
154
+ // child's render, so the parent's setFireworks fired mid-render ("Cannot
155
+ // update a component (AsciiCursorOverlay) while rendering Firework") on every
156
+ // burst. The updater also restarted the interval on each parent re-render
157
+ // (onDone is a fresh closure per render), stalling the burst while the
158
+ // cursor moved. (kolkrabbi.io's mobile audit 2026-08-25, lost in the DS copy —
159
+ // AsciiCursorFireworkSetStateInRender 2026-10-29)
160
+ const interval = setInterval(() => setFrame((f) => Math.min(f + 1, frames.length - 1)), 130)
161
161
  return () => clearInterval(interval)
162
- }, [frames, onDone])
162
+ }, [frames])
163
+ const doneRef = useRef(false)
164
+ useEffect(() => {
165
+ if (doneRef.current || frame < frames.length - 1) return
166
+ doneRef.current = true
167
+ onDone()
168
+ }, [frame, frames, onDone])
163
169
 
164
170
  return (
165
171
  <div
@@ -387,8 +393,9 @@ function AsciiCrosshair({ overlayRef }) {
387
393
  </div>
388
394
  ))
389
395
  )}
390
- {/* Foreground layer */}
391
- <div style={{ color: 'var(--kol-surface-on-primary)', opacity: 0.5, position: 'relative' }}>
396
+ {/* Foreground layer — 0.9 in light, 0.5 in dark (kolkrabbi.io's `.ascii-cursor-fg`, carried 2026-10-29): at one 0.5
397
+ * the glyphs washed out on light surfaces */}
398
+ <div className="opacity-90 [:is([data-theme=dark],.dark)_&]:opacity-50" style={{ color: 'var(--kol-surface-on-primary)', position: 'relative' }}>
392
399
  {crosshair.map((line, i) => (
393
400
  <div key={i}>{line}</div>
394
401
  ))}
@@ -460,7 +467,6 @@ function AsciiCursorOverlay({ hideCursor }) {
460
467
  }
461
468
 
462
469
  const handleContextMenu = (e) => {
463
- e.preventDefault()
464
470
  const now = Date.now()
465
471
  if (now - lastInvaderTime.current < 2500) return
466
472
  lastInvaderTime.current = now
@@ -499,8 +505,10 @@ function AsciiCursorOverlay({ hideCursor }) {
499
505
  * with an ASCII crosshair (diamond variant over interactive elements) and
500
506
  * layers ambient effects on top of the page: drifting cursor stars,
501
507
  * click-triggered ASCII fireworks, and a right-click Space Invader that
502
- * drops in, fires, and exits (rate-limited to one per 2.5s; contextmenu is
503
- * suppressed while mounted).
508
+ * drops in, fires, and exits (rate-limited to one per 2.5s). The context menu
509
+ * still opens — the invader is an easter egg, the menu is the browser's
510
+ * (kolkrabbi.io 2026-08-25: swallowing it took copy, open-in-new-tab and
511
+ * inspect off every page).
504
512
  *
505
513
  * Singleton — mount once at the app root. Portals into `document.body` so
506
514
  * it floats above any scroll context. Pure decoration, so it hard-gates: