@kolkrabbi/kol-component 0.384.0 → 0.386.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,5 +1,5 @@
1
1
  import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'
2
- import Input, { selectOnFirstPress } from '../atoms/Input.jsx'
2
+ import Input from '../atoms/Input.jsx'
3
3
  import SliderPanel from './SliderPanel.jsx'
4
4
  import LabeledControl from './LabeledControl.jsx'
5
5
 
@@ -47,9 +47,8 @@ import LabeledControl from './LabeledControl.jsx'
47
47
  * @param {Object} props.style - forwarded to the wrapper; the seam for `--kol-slider-track` / `--kol-slider-playhead`
48
48
  * @param {number} props.defaultValue - alt-click the control resets to this (falls back to `min`). Same contract on Knob
49
49
  * @param {'input'|'value'|'none'} props.readout - `input` (default) an editable Input · `value` a plain right-aligned span, Knob's own display-only readout · `none`.
50
- * @param {'minimal'|'dual'|'scrub'|'panel'|'kolbox'} props.variant - `kolbox` (W31.2 batch 3): kolbox's track (2px oq-24, the run in the ink to the value, a 12 ink thumb) in a 24 row (`--kol-kolbox-ctl`); `readout` `value` (its default) the mono 12 value beside it, 40 wide, or `input` the track in an oq-16 field and the value in a text field 2 apart; no visible label (`aria-label` names it), `formatValue` defaults to the raw value · `dual` = two thumbs on one rail · `scrub` = a media scrubber: the thin track with the 4 × 28 pill knob (`.kol-playback-scrub`; `PlaybackBar`'s, 2026-10-02) · `panel` = the rack slider (was kol-hardware `Fader`, merged 2026-10-01): a drawn 2px track for a hardware panel; takes `value · onChange · min · max · step · label` plus `onHold`
51
- * @param {'folio'} props.variant - also `folio` (Folio migration batch A, 2026-11-22): Folio's slider, a 24 row, the 2px track in the rule with the run in the accent to a 12 accent thumb, the value (JetBrains Mono 12 / 16, `formatValue` its words, raw by default) 32 wide at the right, 12 off; no visible label (`aria-label`). Chrome in kol-theme `.kol-slider--folio`
52
- * @param {number[]} props.stops - kolbox only: values marked on the track, a 2 mark each under the thumb's centre (a variable font's named weights)
50
+ * @param {'minimal'|'dual'|'scrub'|'panel'} props.variant - `dual` = two thumbs on one rail; `scrub` = a media scrubber: the thin track with the 4 × 28 pill knob (`.kol-playback-scrub`; `PlaybackBar`'s, 2026-10-02); `panel` = the rack slider (was kol-hardware `Fader`, merged 2026-10-01): a drawn 2px track for a hardware panel; takes `value`, `onChange`, `min`, `max`, `step` and `label` plus `onHold`. `kolbox` and `folio` are accepted and draw `minimal` with the `value` readout by default (plan-2026-11-29-one-set-fold W2 run 2): ONE SLIDER, ITS LOOK THE THEME'S, the row's gap, the range's hit height and field, the run, the readout's width, padding and type are `--kol-slider-*` (kol-theme, Slider); the default theme leaves them unset, `data-theme-variant="kolbox"` sets kolbox's (the 2px oq-24 track with the run in the ink, a 16 range, the value mono 12 / 16 40 wide; with the `input` readout the track in an oq-16 field and the number 2 apart, at least 48). The old branches are in `_tmp/2026-11-29-one-set-fold/`
51
+ * @param {number[]} props.stops - values marked on the track, a 2 mark each under the thumb's centre (a variable font's named weights); every horizontal slider's since W2 run 2
53
52
  * @param {'horizontal'|'vertical'} props.direction - `vertical` stands the track upright at `height`, label above and readout below (2026-10-02 — the volume ranges were hand-drawn for want of it). On `panel`, horizontal takes the row and shows a readout
54
53
  * @param {number} props.height - vertical only — the track's length in px (default 96; panel 60)
55
54
  * @param {string} props['aria-label'] - names the range when there is no visible `label`
@@ -61,83 +60,9 @@ import LabeledControl from './LabeledControl.jsx'
61
60
  * @param {number|null} props.playhead - dual only — marker position in min…max; null renders nothing and attaches no listeners
62
61
  * @param {Function} props.onPlayheadChange - dual only — (next: number) => void; omit and the marker is not draggable and the rail does not seek
63
62
  */
64
- /* `variant="kolbox"` (plan-2026-11-18-kolbox-system W31.2 batch 3, 2026-11-18): kolbox's Slider carried class for
65
- * class, its own component so its draft is its own state. `readout` value (its default): the bare track, the value
66
- * beside it, 12 apart; `input`: the track in its own field, then 2 apart the number in a field as wide as its value
67
- * and at least 48. The number is a text field, not type="number": Chrome draws a number field's value in the OS
68
- * region's format ("0,08" on an Icelandic Mac) whatever the page's lang. A draft holds what is typed until it reads
69
- * as a number; kolbox's field keys: one press selects it, the arrows step it (Shift ten steps), Escape restores the value
70
- * from before the edit. Chrome in kol-theme `.kol-slider--kolbox`. */
71
- function SliderKolbox({ value, min, max, step, onChange, formatValue, readout = 'value', ariaLabel, stops, className = '', accent }) {
72
- const [draft, setDraft] = useState(null)
73
- const before = useRef(value)
74
- const format = formatValue ?? ((v) => v)
75
- const p = Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100))
76
- /* a stop: a 2 mark on the track, under the thumb's centre at that value (the thumb is 12, so its centre runs 6 to
77
- the width less 6) */
78
- const marks = stops?.length > 0 && stops.map((v) => (
79
- <span key={v} data-slider-stop={v} className="pointer-events-none absolute top-1/2 size-0.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-oq-64"
80
- style={{ left: `calc(6px + (100% - 12px) * ${(v - min) / (max - min)})` }} />
81
- ))
82
- const input = (
83
- <input
84
- type="range"
85
- className="kol-slider-input min-w-0 flex-1"
86
- style={{ '--p': `${p}%` }}
87
- aria-label={ariaLabel}
88
- value={value}
89
- min={min}
90
- max={max}
91
- step={step}
92
- onChange={(e) => onChange?.(Number(e.target.value))}
93
- />
94
- )
95
- const range = marks ? <span className="relative flex min-w-0 flex-1 items-center">{input}{marks}</span> : input
96
- if (readout === 'input') {
97
- return (
98
- <div data-accent={accent === 'secondary' ? accent : undefined} className={`kol-slider--kolbox flex h-(--kol-kolbox-ctl) min-w-0 items-center gap-0.5 ${className}`}>
99
- <div className="kol-slider-field flex h-(--kol-kolbox-ctl) min-w-0 flex-1 items-center px-2">{range}</div>
100
- <input
101
- type="text"
102
- inputMode="decimal"
103
- aria-label={ariaLabel}
104
- className="kol-slider-number field-sizing-content h-(--kol-kolbox-ctl) min-w-12 shrink-0 px-2 text-left outline-none focus-visible:outline-1 focus-visible:-outline-offset-1"
105
- value={draft ?? String(format(value))}
106
- onChange={(e) => {
107
- /* parseFloat: a formatted value keeps its unit while it is typed ("45°") */
108
- const s = e.target.value, n = parseFloat(s)
109
- setDraft(s)
110
- if (s.trim() !== '' && Number.isFinite(n)) onChange?.(n)
111
- }}
112
- onMouseDown={selectOnFirstPress}
113
- onFocus={() => { before.current = value }}
114
- onBlur={() => setDraft(null)}
115
- onKeyDown={(e) => {
116
- if (e.key === 'Enter') { e.preventDefault(); e.currentTarget.blur(); return }
117
- /* Escape puts back the value from before the edit and leaves the field (kolbox's field, useKolboxField) */
118
- if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); setDraft(null); if (before.current !== value) onChange?.(before.current); e.currentTarget.blur(); return }
119
- if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return
120
- e.preventDefault()
121
- const dec = String(step).split('.')[1]?.length ?? 0
122
- const by = (e.shiftKey ? 10 : 1) * (e.key === 'ArrowUp' ? step : -step)
123
- const n = Math.min(max, Math.max(min, value + by))
124
- setDraft(null)
125
- before.current = Number(n.toFixed(dec))
126
- onChange?.(before.current)
127
- const el = e.currentTarget
128
- requestAnimationFrame(() => { if (document.activeElement === el) el.select() })
129
- }}
130
- />
131
- </div>
132
- )
133
- }
134
- return (
135
- <div data-accent={accent === 'secondary' ? accent : undefined} className={`kol-slider--kolbox flex h-(--kol-kolbox-ctl) min-w-0 items-center gap-3 ${className}`}>
136
- {range}
137
- <span className="kol-slider-value w-10 shrink-0 text-right">{format(value)}</span>
138
- </div>
139
- )
140
- }
63
+ /* the old theme words in `variant`: accepted, drawn as the minimal slider with their old default readout, `value`
64
+ (plan-2026-11-29-one-set-fold W2 run 2, on the retirement ledger) */
65
+ const THEME_WORDS = ['kolbox', 'folio']
141
66
 
142
67
  const Slider = ({
143
68
  label,
@@ -173,6 +98,9 @@ const Slider = ({
173
98
  /* Label ↔ input pairing — the <label> is a sibling of the range input, so
174
99
  * without an htmlFor/id pair the visible label confers no accessible name. */
175
100
  const sliderId = useId()
101
+ const themeWord = THEME_WORDS.includes(variant)
102
+ if (themeWord) variant = 'minimal'
103
+ const readoutKind = readout ?? (themeWord ? 'value' : 'input')
176
104
 
177
105
  const handleChange = (e) => {
178
106
  if (onChange) {
@@ -239,8 +167,10 @@ const Slider = ({
239
167
  [onPlayheadChange, seekTo],
240
168
  )
241
169
 
170
+ const skipCommit = useRef(false)
242
171
  const commit = () => {
243
172
  setEditing(false)
173
+ if (skipCommit.current) { skipCommit.current = false; return }
244
174
  /* parseFloat, so a formatted value typed back (`45°`, `0,5`) still reads; an empty field reverts */
245
175
  const parsed = parseFloat(String(draft).replace(',', '.'))
246
176
  if (!Number.isFinite(parsed) || onChange == null) {
@@ -252,9 +182,21 @@ const Slider = ({
252
182
  setDraft(String(clamped))
253
183
  }
254
184
 
185
+ /* the readout's keys, every slider's (kolbox's, adopted in W2 run 2): Enter commits, Escape puts back the value from
186
+ * before the edit and leaves the field, ArrowUp and ArrowDown move it one `step` (Shift ten) and commit at once */
255
187
  const onKeyDown = (e) => {
256
188
  if (e.key === 'Enter') { e.currentTarget.blur() }
257
- if (e.key === 'Escape') { setDraft(displayValue); setEditing(false); e.currentTarget.blur() }
189
+ if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); setDraft(displayValue); setEditing(false); skipCommit.current = true; e.currentTarget.blur() }
190
+ if ((e.key === 'ArrowUp' || e.key === 'ArrowDown') && onChange && !disabled) {
191
+ e.preventDefault()
192
+ const dec = String(step).split('.')[1]?.length ?? 0
193
+ const by = (e.shiftKey ? 10 : 1) * (e.key === 'ArrowUp' ? step : -step)
194
+ const next = Number(Math.min(max, Math.max(min, value + by)).toFixed(dec))
195
+ onChange(next)
196
+ setDraft(fmt(next))
197
+ const el = e.currentTarget
198
+ requestAnimationFrame(() => { if (document.activeElement === el) el.select() })
199
+ }
258
200
  }
259
201
 
260
202
  /* alt-click anywhere on the control resets — Knob carries the same
@@ -266,24 +208,6 @@ const Slider = ({
266
208
  onChange(defaultValue ?? min)
267
209
  }
268
210
 
269
- if (variant === 'kolbox') {
270
- return <SliderKolbox value={value} min={min} max={max} step={step} onChange={onChange} formatValue={formatValue} readout={readout} ariaLabel={ariaLabel} stops={stops} className={className} accent={accent} />
271
- }
272
-
273
- /* folio (Folio migration batch A, 2026-11-22): Folio's Slider carried class for class (apps/folio Chrome.jsx): a 24
274
- * row, the native range (its track and thumb in kol-theme `.kol-slider--folio`), the value beside it, 32 wide */
275
- if (variant === 'folio') {
276
- const format = formatValue ?? ((n) => n)
277
- const run = `${((value - min) / (max - min)) * 100}%`
278
- return (
279
- <div data-accent={accent === 'secondary' ? accent : undefined} className={`kol-slider--folio flex h-[24px] w-full items-center gap-[12px] ${className}`}>
280
- <input type="range" min={min} max={max} step={step} value={value} onChange={handleChange} aria-label={ariaLabel} style={{ '--run': run }}
281
- className="kol-slider-input h-[24px] min-w-0 flex-1 cursor-pointer appearance-none bg-transparent" />
282
- <span className="kol-slider-value w-[32px] shrink-0 text-right tabular-nums">{format(value)}</span>
283
- </div>
284
- )
285
- }
286
-
287
211
  if (variant === 'panel') {
288
212
  return <SliderPanel value={value} onChange={onChange} min={min} max={max} step={step} label={label} direction={direction} height={height} onHold={onHold} />
289
213
  }
@@ -298,11 +222,11 @@ const Slider = ({
298
222
  const labelClass = `kol-helper-12 text-fg-80 ${disabled ? 'opacity-50' : ''}`.trim()
299
223
  const row = ({ className: cls, style: st, onClick, children }) => {
300
224
  if (!label) return <div data-accent={accent === 'secondary' ? accent : undefined} className={cls} style={st} onClick={onClick}>{children}</div>
301
- const outer = cls.split(/\s+/).filter((c) => !/^(control-slider|shadow-none|h-7)$/.test(c)).join(' ')
225
+ const outer = cls.split(/\s+/).filter((c) => !/^(control-slider|control-slider--input|shadow-none|h-7)$/.test(c)).join(' ')
302
226
  return (
303
227
  <LabeledControl data-accent={accent === 'secondary' ? accent : undefined} horizontal label={labelEl} labelWidth="fit-content" labelClass={labelClass}
304
228
  className={`${/(^|\s)(hidden|block|flex|inline-flex|grid)(?=\s|$)/.test(outer) ? '' : 'inline-flex'} ${outer}`} style={st} onClick={onClick}>
305
- <div className={`flex w-full ${cls.split(/\s+/).filter((c) => /^(control-slider|shadow-none|h-7|gap-3)$/.test(c)).join(' ')}`}>{children}</div>
229
+ <div className={`flex w-full ${cls.split(/\s+/).filter((c) => /^(control-slider|control-slider--input|shadow-none|h-7)$/.test(c)).join(' ')}`}>{children}</div>
306
230
  </LabeledControl>
307
231
  )
308
232
  }
@@ -316,7 +240,7 @@ const Slider = ({
316
240
  /* an empty label is no label: `label1="" label2=""` (SettingsRange, RailSettings) drew an empty 16px row that pushed the rail low */
317
241
  const showLabels = !!(label1 || label2)
318
242
  const ratio = max > min ? (playhead - min) / (max - min) : 0
319
- return row({ className: `control-slider gap-3 shadow-none ${className}`, style, children: <>
243
+ return row({ className: `control-slider shadow-none ${className}`, style, children: <>
320
244
  <div className="flex-1">
321
245
  {showLabels && (
322
246
  <div
@@ -372,7 +296,7 @@ const Slider = ({
372
296
  const scrub = variant === 'scrub'
373
297
  const length = vertical ? height ?? 96 : size
374
298
 
375
- const range = (
299
+ const rangeInput = (
376
300
  <input
377
301
  id={sliderId}
378
302
  type="range"
@@ -384,12 +308,24 @@ const Slider = ({
384
308
  disabled={disabled}
385
309
  aria-label={ariaLabel}
386
310
  className={`${scrub ? 'kol-playback-scrub' : 'slider-black cursor-pointer disabled:cursor-default'} disabled:opacity-50 ${vertical ? '-rotate-90 flex-none' : length ? 'flex-none' : 'flex-1 w-full min-w-0'}`}
387
- /* upright, the drag is vertical — so the page's pan is the horizontal one */
388
- style={length ? { width: length, ...(vertical && { touchAction: 'pan-x' }) } : undefined}
311
+ /* upright, the drag is vertical — so the page's pan is the horizontal one. `--p` is the run's end, for a theme
312
+ * that draws the run (`--kol-slider-run`; kolbox the ink) */
313
+ style={{ '--p': `${Math.min(100, Math.max(0, ((value - min) / ((max - min) || 1)) * 100))}%`, ...(length && { width: length, ...(vertical && { touchAction: 'pan-x' }) }) }}
389
314
  />
390
315
  )
316
+ /* a stop (kolbox's, every slider's since W2 run 2): a 2 mark on the track under the thumb's centre at that value (the
317
+ thumb is 12, so its centre runs 6 in from each end of the track, which sits `--kol-slider-field-px` in) */
318
+ const range = stops?.length > 0 && !vertical && !scrub ? (
319
+ <span className={`relative flex items-center ${length ? 'flex-none' : 'min-w-0 flex-1'}`}>
320
+ {rangeInput}
321
+ {stops.map((v) => (
322
+ <span key={v} data-slider-stop={v} className="pointer-events-none absolute top-1/2 size-0.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-oq-64"
323
+ style={{ left: `calc(var(--kol-slider-field-px, 0px) + 6px + (100% - 12px - 2 * var(--kol-slider-field-px, 0px)) * ${(v - min) / ((max - min) || 1)})` }} />
324
+ ))}
325
+ </span>
326
+ ) : rangeInput
391
327
 
392
- const readoutNode = (readout ?? 'input') === 'input' ? (
328
+ const readoutNode = readoutKind === 'input' ? (
393
329
  <Input
394
330
  type="text"
395
331
  inputMode="decimal"
@@ -399,18 +335,19 @@ const Slider = ({
399
335
  chars={displayWidth}
400
336
  value={draft}
401
337
  disabled={disabled}
338
+ aria-label={ariaLabel}
402
339
  onFocus={(e) => { setEditing(true); e.target.select() }}
403
340
  onChange={(e) => setDraft(e.target.value)}
404
341
  onBlur={commit}
405
342
  onKeyDown={onKeyDown}
406
- inputClassName="text-center"
343
+ className="kol-slider-number"
407
344
  />
408
- ) : readout === 'value' ? (
345
+ ) : readoutKind === 'value' ? (
409
346
  /* `value` is Knob's readout, not a second design — a mixer running
410
347
  * ~23 faders in a 24px row cannot afford an input chip on every one, and
411
348
  * that is why the easy call sites could not move. */
412
349
  <span
413
- className={`kol-helper-12 shrink-0 w-fit text-right ${disabled ? 'opacity-50' : ''}`}
350
+ className={`kol-slider-value shrink-0 ${disabled ? 'opacity-50' : ''}`}
414
351
  style={fontSize ? { fontSize } : undefined}
415
352
  >
416
353
  {displayValue}
@@ -425,7 +362,7 @@ const Slider = ({
425
362
  </> })
426
363
  }
427
364
 
428
- return row({ className: `control-slider gap-3 shadow-none ${scrub ? 'h-7' : ''} ${className}`, style, onClick: onAltReset, children: <>
365
+ return row({ className: `control-slider shadow-none ${readoutKind === 'input' ? 'control-slider--input' : ''} ${scrub ? 'h-7' : ''} ${className}`, style, onClick: onAltReset, children: <>
429
366
  {range}
430
367
  {readoutNode}
431
368
  </> })