@kolkrabbi/kol-component 0.386.0 → 0.387.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 -3
- package/src/molecules/AlignmentGrid.jsx +13 -7
- package/src/molecules/ColorInputRow.jsx +31 -23
- package/src/molecules/ColorSwatch.jsx +17 -49
- package/src/molecules/ParamBindDot.jsx +49 -54
- package/src/molecules/SwatchControls.jsx +12 -7
- package/src/molecules/SwatchGrid.jsx +6 -9
- package/src/organisms/ColorPickerPopover.jsx +1 -1
- package/src/organisms/SpectrumControls.jsx +54 -137
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.387.0",
|
|
4
4
|
"description": "The core component library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"embla-carousel-react": "^8.6.0",
|
|
33
33
|
"pdfjs-dist": "^6.3.289",
|
|
34
34
|
"react-syntax-highlighter": "^16.1.1",
|
|
35
|
+
"@kolkrabbi/kol-search": "^0.3.0",
|
|
35
36
|
"@kolkrabbi/kol-growth": "^0.5.0",
|
|
36
|
-
"@kolkrabbi/kol-markdown": "^0.2.0"
|
|
37
|
-
"@kolkrabbi/kol-search": "^0.3.0"
|
|
37
|
+
"@kolkrabbi/kol-markdown": "^0.2.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@kolkrabbi/kol-icons": ">=0.69.0",
|
|
@@ -24,9 +24,14 @@ import { glyphSize } from '../hooks/glyphLadders.js'
|
|
|
24
24
|
* @param {Array} items - `[{ axis, mode, icon, title }]` cells (default the standard 6, three per axis)
|
|
25
25
|
* @param {'xs'|'sm'|'md'|'lg'} size - The strips' rung (default 'sm')
|
|
26
26
|
* @param {string} className - Extra classes on the wrapper
|
|
27
|
-
* @param {'
|
|
28
|
-
*
|
|
27
|
+
* @param {'stacked'|'strips'} [layout='stacked'] - `stacked`: the X strip over the Y strip. `strips` (kolbox's align row,
|
|
28
|
+
* plan-2026-11-18-kolbox-system W31.2 batch 3; a layout of its own since plan-2026-11-29-one-set-fold W2 run 4): the X
|
|
29
|
+
* and Y strips side by side, each filling its cell of a slot `FieldPair` (two cells 8 apart), each cell its own action;
|
|
30
|
+
* `items` carry the set's glyph names. The strips are ButtonGroup's icon group, which still takes its theme word until
|
|
31
|
+
* ButtonGroup folds (W3). `variant="kolbox"` and `"folio"` are accepted and draw `strips`; the old branch is in
|
|
32
|
+
* `_tmp/2026-11-29-one-set-fold/AlignmentGrid.pre-fields3.jsx`.
|
|
29
33
|
*/
|
|
34
|
+
const THEME_WORDS = ['kolbox', 'folio']
|
|
30
35
|
const ALIGN_BUTTONS = [
|
|
31
36
|
{ axis: 'h', mode: 'start', icon: 'align-horizontal-left-solid', title: 'Align left' },
|
|
32
37
|
{ axis: 'h', mode: 'center', icon: 'align-horizontal-center-solid', title: 'Align horizontal center' },
|
|
@@ -36,16 +41,17 @@ const ALIGN_BUTTONS = [
|
|
|
36
41
|
{ axis: 'v', mode: 'end', icon: 'align-vertical-bottom-solid', title: 'Align bottom' },
|
|
37
42
|
]
|
|
38
43
|
|
|
39
|
-
export default function AlignmentGrid({ onAlign, items = ALIGN_BUTTONS, size = 'sm', className = '', variant }) {
|
|
44
|
+
export default function AlignmentGrid({ onAlign, items = ALIGN_BUTTONS, size = 'sm', className = '', layout: layoutProp, variant }) {
|
|
40
45
|
const strip = (axis) => items.filter((b) => b.axis === axis)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
const layout = layoutProp ?? (THEME_WORDS.includes(variant) ? 'strips' : 'stacked')
|
|
47
|
+
/* layout="strips" (kolbox's AlignmentRow carried): the two strips as icon groups, each filling its cell of a slot
|
|
48
|
+
* FieldPair (two cells 8 apart). `variant="kolbox"` on the ButtonGroup names its icon group build until W3 folds it. */
|
|
49
|
+
if (layout === 'strips') {
|
|
44
50
|
const group = (axis) => (
|
|
45
51
|
<ButtonGroup layout="joined" variant="kolbox" className="w-full"
|
|
46
52
|
options={strip(axis).map((b) => ({ icon: b.icon, ariaLabel: b.title, onPress: () => onAlign?.(b.axis, b.mode) }))} />
|
|
47
53
|
)
|
|
48
|
-
return <FieldPair
|
|
54
|
+
return <FieldPair className={className} first={group('h')} second={group('v')} />
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
return (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo, useRef, useState } from 'react'
|
|
2
2
|
import { IconLoader } from '@kolkrabbi/kol-icons'
|
|
3
3
|
import ColorSwatch from './ColorSwatch.jsx'
|
|
4
|
-
import Input, { selectOnFirstPress,
|
|
4
|
+
import Input, { selectOnFirstPress, useFieldCommit } from '../atoms/Input.jsx'
|
|
5
5
|
import FieldPair from './FieldPair.jsx'
|
|
6
6
|
import { usePopover, PopoverPanel, Tooltip } from '../utilities/Popover.jsx'
|
|
7
7
|
|
|
@@ -281,14 +281,14 @@ function ColorInputRowDefault({
|
|
|
281
281
|
)
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
/* ── kolbox
|
|
285
|
-
*
|
|
286
|
-
*
|
|
284
|
+
/* ── joined (kolbox's FillRow, plan-2026-11-18-kolbox-system W31.2 batch 5, 2026-11-18; `joined` for everyone since
|
|
285
|
+
* plan-2026-11-29-one-set-fold W2 run 3) ─────────────────────────────────────────────────────────────────────────────
|
|
286
|
+
* kolbox's FillRow (Figma 84:12831), carried from apps/kolbox/src/ui/FillRow.jsx: one joined field (the theme's field
|
|
287
|
+
* fill `--kol-color-row-bg`, radius 4, no outline) holding the hex segment (the 16 swatch and the hex in Inter 11, padding 6 and 8, gap 8) and, after a 1px
|
|
287
288
|
* gap in the rail ground (1 by 22, W16.5), the opacity segment (the value mono 11 and "%" muted, 8 in, the % 16 after the
|
|
288
|
-
* value and 4 off the end); with `actions` the row is FieldPair
|
|
289
|
-
* kolbox's: the field over both field columns of the rail's grid, the actions on its icon columns (R3.1). The
|
|
289
|
+
* value and 4 off the end); with `actions` the row is FieldPair's slot row: the field over both field columns of the rail's grid, the actions on its icon columns (R3.1). The
|
|
290
290
|
* swatch opens the caller's color overlay through `onSwatch` (with `lit` while it is open), or else the row's own
|
|
291
|
-
* `picker` (ColorPickerPopover
|
|
291
|
+
* `picker` (ColorPickerPopover: this row is a molecule and cannot import the organism, so the caller
|
|
292
292
|
* hands it in), beside the rail level with the swatch. The hex is edited in place (one press selects it, a short hex grows on Enter or blur: `expandHex`); a value that is not a plain hex shows
|
|
293
293
|
* `resolved` on the swatch and its own text in the field. `opacity` 0 to 100 through `onOpacity` (read-only without it);
|
|
294
294
|
* null draws no opacity segment. `clearable`: emptying the hex commits null (an optional color, unset). `hidden` (the paint's eye is off) dims the opacity value; the color stays readable. `label` names the row's parts for a reader; this look draws no label. */
|
|
@@ -302,7 +302,7 @@ export function expandHex(raw) {
|
|
|
302
302
|
if (d.length === 3) return [...d].map((c) => c + c).join('')
|
|
303
303
|
return d.length === 6 ? d : null
|
|
304
304
|
}
|
|
305
|
-
function
|
|
305
|
+
function ColorInputRowJoined({ label, value, resolved, onChange, onSwatch, opacity, onOpacity, actions, lit = false, hidden = false, clearable = false, picker: Picker, accent }) {
|
|
306
306
|
const hex = HEX_KOLBOX.test(String(value ?? '').replace('#', '')) ? String(value).replace('#', '').toUpperCase() : null
|
|
307
307
|
const swatch = resolved ?? (hex ? `#${hex}` : null)
|
|
308
308
|
const swatchRef = useRef(null)
|
|
@@ -316,18 +316,18 @@ function ColorInputRowKolbox({ label, value, resolved, onChange, onSwatch, opaci
|
|
|
316
316
|
},
|
|
317
317
|
contains: (t) => !!swatchRef.current?.contains(t),
|
|
318
318
|
}), [])
|
|
319
|
-
/* the hex and the opacity are
|
|
320
|
-
const hexField =
|
|
319
|
+
/* the hex and the opacity are commit fields (Input's useFieldCommit): Escape restores, the opacity's arrows step */
|
|
320
|
+
const hexField = useFieldCommit(hex ?? String(value ?? ''), (text) => {
|
|
321
321
|
if (clearable && !text) { if (value) onChange?.(null); return }
|
|
322
322
|
const d = expandHex(text)
|
|
323
323
|
if (d) onChange?.(`#${d.toLowerCase()}`)
|
|
324
324
|
}, { step: false })
|
|
325
325
|
const op = opacity == null ? null : Math.round(opacity)
|
|
326
|
-
const opField =
|
|
326
|
+
const opField = useFieldCommit(op, (text) => { const n = parseFloat(text); if (Number.isFinite(n)) onOpacity?.(Math.min(100, Math.max(0, n))) })
|
|
327
327
|
const field = (
|
|
328
328
|
<div className={`kol-color-row-field flex h-(--kol-kolbox-ctl) min-w-0 flex-1 items-stretch${lit || picking ? ' is-lit' : ''}`} data-fill-field>
|
|
329
329
|
<div className="flex min-w-0 flex-1 items-center gap-2 pr-2 pl-1.5" data-fill-hex>
|
|
330
|
-
<Tooltip
|
|
330
|
+
<Tooltip asChild label={label}>
|
|
331
331
|
<button
|
|
332
332
|
ref={swatchRef}
|
|
333
333
|
type="button"
|
|
@@ -374,21 +374,22 @@ function ColorInputRowKolbox({ label, value, resolved, onChange, onSwatch, opaci
|
|
|
374
374
|
onChange={({ value: v, opacity: o }) => { onChange?.(v.toLowerCase()); if (op != null && o !== op) onOpacity?.(o) }}
|
|
375
375
|
/>
|
|
376
376
|
)
|
|
377
|
-
const root = `kol-color-row--
|
|
377
|
+
const root = `kol-color-row--joined min-w-0 flex-1 ${hidden ? 'is-hidden' : ''}`
|
|
378
378
|
/* with actions the row is a rail row: the field spans the grid's two field columns, the actions sit on its icon
|
|
379
379
|
columns (FieldPair kolbox, R3.1); alone it is a field that fills its cell */
|
|
380
380
|
return actions
|
|
381
|
-
? <><FieldPair
|
|
381
|
+
? <><FieldPair span className={root} data-accent={accent === 'secondary' ? accent : undefined} data-fill-row first={field} trailing={actions} />{picker}</>
|
|
382
382
|
: <div className={`${root} flex h-(--kol-kolbox-ctl) items-center`} data-accent={accent === 'secondary' ? accent : undefined} data-fill-row>{field}{picker}</div>
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
-
/* ──
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
|
|
385
|
+
/* ── variant="readonly" (Folio's SwatchRow, Folio batch C, 2026-11-22, carried class for class; a variant of its own since
|
|
386
|
+
* plan-2026-11-29-one-set-fold W2 run 3, a different job: a colour shown, not typed). The swatch (the `picker`,
|
|
387
|
+
* ColorPickerPopover, handed in as the joined row's is: a molecule cannot import the organism), the `label` (12 / 16
|
|
388
|
+
* medium, taking the room) and the hex (mono 12 / 16, capitals, muted), 12 apart. `swatches` ([name, hex]) go to the
|
|
389
|
+
* picker; `onChange(hex)`. Chrome in kol-theme `.kol-color-row--readonly`, the hex in oq-64 (was Folio's muted). ── */
|
|
390
|
+
function ColorInputRowReadonly({ label, value, swatches, onChange, picker: Picker, className = '' }) {
|
|
390
391
|
return (
|
|
391
|
-
<div className=
|
|
392
|
+
<div className={`kol-color-row--readonly flex w-full items-center gap-[12px] ${className}`.trim()}>
|
|
392
393
|
{Picker && <Picker variant="folio" label={label} color={value} swatches={swatches} onChange={onChange} />}
|
|
393
394
|
<p className="kol-color-row-label min-w-0 flex-1 truncate">{label}</p>
|
|
394
395
|
<p className="kol-color-row-value shrink-0 uppercase">{value}</p>
|
|
@@ -396,7 +397,14 @@ function ColorInputRowFolio({ label, value, swatches, onChange, picker: Picker }
|
|
|
396
397
|
)
|
|
397
398
|
}
|
|
398
399
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
/* ONE ROW, ITS LOOK THE THEME'S (plan-2026-11-29-one-set-fold W2 run 3). Three builds, picked by what the row is for,
|
|
401
|
+
* never by the theme: the labelled row (default: palette refs, lock, token column), `joined` (the swatch, hex and
|
|
402
|
+
* opacity in one commit field, with `actions`, `picker`, `onSwatch`, `lit`, `hidden`, `clearable`), and
|
|
403
|
+
* `variant="readonly"` (a colour line, no field). `variant="kolbox"` draws `joined` and `variant="folio"` draws
|
|
404
|
+
* `readonly`, the builds those words named; the old branches are in `_tmp/2026-11-29-one-set-fold/`. */
|
|
405
|
+
const THEME_WORDS = { kolbox: 'joined', folio: 'readonly' }
|
|
406
|
+
export default function ColorInputRow({ variant, joined, ...props }) {
|
|
407
|
+
const build = THEME_WORDS[variant] ?? variant
|
|
408
|
+
if (build === 'readonly') return <ColorInputRowReadonly {...props} />
|
|
409
|
+
return (joined ?? build === 'joined') ? <ColorInputRowJoined {...props} /> : <ColorInputRowDefault {...props} />
|
|
402
410
|
}
|
|
@@ -16,28 +16,22 @@
|
|
|
16
16
|
* or 'control-sm' (26px — the kol-control-sm row height, so
|
|
17
17
|
* a swatch sits flush beside sm input chrome in a paint bar;
|
|
18
18
|
* ColorSwatchFieldSizing 2026-08-12). Default 24.
|
|
19
|
-
* radius — 'sm' (4px
|
|
19
|
+
* radius — 'sm' (4px) | 'tight' (2px) | 'none' | 'full' (circle).
|
|
20
|
+
* Unset, the theme's (`--kol-swatch-r`, 4px; kolbox 2px).
|
|
20
21
|
* Default was 'tight' until 2026-08-12 — flipped to 'sm' per
|
|
21
22
|
* the system radius law (containers are 4px everywhere);
|
|
22
23
|
* square-corner contexts opt out via 'tight'/'none'.
|
|
23
|
-
* frame — boolean (default true).
|
|
24
|
-
*
|
|
24
|
+
* frame — boolean (default true). The theme's ring inside the chip
|
|
25
|
+
* (`--kol-swatch-frame`; unset none, kolbox a 1px oq-24 line);
|
|
26
|
+
* false, none — used by tightly-packed grid layouts.
|
|
25
27
|
* variant — 'default' (border-based chrome) |
|
|
26
28
|
* 'halo' (macOS-port double box-shadow halo). Halo
|
|
27
|
-
* overrides `frame` since it provides its own ring.
|
|
28
|
-
* '
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* it (an accent swatch: `data-folio-accent` and `hex`
|
|
34
|
-
* `var(--kol-folio-green)`). Chrome in kol-theme
|
|
35
|
-
* `.kol-color-swatch--folio`. |
|
|
36
|
-
* 'kolbox' (Folio on kolbox, 2026-11-22): SwatchGrid kolbox's
|
|
37
|
-
* cell as one chip, always a button: `size` square (24), radius
|
|
38
|
-
* 2, `frame` its 1px oq-24 ring inside it, `selected` the 2px
|
|
39
|
-
* accent ring 1 off the secondary surface (chrome
|
|
40
|
-
* `.kol-swatch-grid-cell`); `title` names it in Tooltip kolbox.
|
|
29
|
+
* overrides `frame` since it provides its own ring.
|
|
30
|
+
* 'kolbox' and 'folio' are accepted and draw the default:
|
|
31
|
+
* ONE SWATCH, ITS LOOK THE THEME'S (plan-2026-11-29-one-set-fold
|
|
32
|
+
* W2 run 3; their branches are in _tmp/2026-11-29-one-set-fold/).
|
|
33
|
+
* The selected chrome is the theme's too (`--kol-swatch-sel-border`,
|
|
34
|
+
* `-sel-ring`; kolbox the 2px accent ring 1 off the secondary surface).
|
|
41
35
|
* hoverable — boolean (default true). When false, no hover border
|
|
42
36
|
* state is applied even if `onClick` is set. For static
|
|
43
37
|
* chips that just open a popover (e.g. inspector fill /
|
|
@@ -66,6 +60,7 @@ const NAMED_PX = {
|
|
|
66
60
|
'control-sm': 26, // kol-control-sm outer height — paint-bar swatch flush with sm input chrome
|
|
67
61
|
}
|
|
68
62
|
|
|
63
|
+
/* unset: no class, the theme's `--kol-swatch-r` (kol-theme `.kol-color-swatch`) */
|
|
69
64
|
const RADIUS_CLASSES = {
|
|
70
65
|
none: 'rounded-none',
|
|
71
66
|
tight: 'rounded-[var(--kol-radius-2)]',
|
|
@@ -86,7 +81,7 @@ export default function ColorSwatch({
|
|
|
86
81
|
hex,
|
|
87
82
|
selected = false,
|
|
88
83
|
size = 24,
|
|
89
|
-
radius
|
|
84
|
+
radius,
|
|
90
85
|
frame = true,
|
|
91
86
|
variant = 'default',
|
|
92
87
|
hoverable = true,
|
|
@@ -97,34 +92,6 @@ export default function ColorSwatch({
|
|
|
97
92
|
className = '',
|
|
98
93
|
...rest
|
|
99
94
|
}) {
|
|
100
|
-
if (variant === 'kolbox') {
|
|
101
|
-
return (
|
|
102
|
-
<Tooltip variant="kolbox" asChild label={title}>
|
|
103
|
-
<button
|
|
104
|
-
type="button"
|
|
105
|
-
aria-pressed={selected}
|
|
106
|
-
onClick={onClick}
|
|
107
|
-
{...rest}
|
|
108
|
-
className={`kol-swatch-grid-cell${selected ? ' is-current ring-2 ring-offset-1' : frame ? ' ring-1 ring-inset' : ''} shrink-0 outline-none ${className}`.trim()}
|
|
109
|
-
style={{ width: size, height: size, background: hex, ...rest.style }}
|
|
110
|
-
/>
|
|
111
|
-
</Tooltip>
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
if (variant === 'folio') {
|
|
115
|
-
return (
|
|
116
|
-
<button
|
|
117
|
-
type="button"
|
|
118
|
-
aria-pressed={selected}
|
|
119
|
-
/* title-ok: a port, verbatim (Folio batch C): Folio's swatches name their color in the browser's own tooltip */
|
|
120
|
-
title={title}
|
|
121
|
-
onClick={onClick}
|
|
122
|
-
{...rest}
|
|
123
|
-
className={`kol-color-swatch--folio size-[24px] rounded-[4px] ${frame ? 'border ' : ''}${selected ? 'is-selected outline outline-2 outline-offset-2' : ''} ${className}`}
|
|
124
|
-
style={hex ? { background: hex, ...rest.style } : rest.style}
|
|
125
|
-
/>
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
95
|
const interactive = typeof onClick === 'function'
|
|
129
96
|
const resolvedSize = NAMED_PX[size] ?? size
|
|
130
97
|
const isNamed = typeof resolvedSize === 'string'
|
|
@@ -132,7 +99,7 @@ export default function ColorSwatch({
|
|
|
132
99
|
const sizeStyle = isNamed ? null : { width: resolvedSize, height: resolvedSize }
|
|
133
100
|
|
|
134
101
|
const isHalo = variant === 'halo'
|
|
135
|
-
const radiusCls = RADIUS_CLASSES[radius] ??
|
|
102
|
+
const radiusCls = RADIUS_CLASSES[radius] ?? ''
|
|
136
103
|
|
|
137
104
|
/* Halo provides its own ring via box-shadow → no border classes.
|
|
138
105
|
* frame=false → consumer wants a borderless chip (e.g. swatch grids
|
|
@@ -146,9 +113,10 @@ export default function ColorSwatch({
|
|
|
146
113
|
* `frame` and `hoverable` are kept on the API but no longer drive a
|
|
147
114
|
* default-state border; they're advisory for future variants. */
|
|
148
115
|
const cls = [
|
|
149
|
-
'relative shrink-0 inline-flex overflow-hidden',
|
|
116
|
+
'kol-color-swatch relative shrink-0 inline-flex overflow-hidden',
|
|
150
117
|
radiusCls,
|
|
151
|
-
!isHalo && selected ? '
|
|
118
|
+
!isHalo && selected ? 'is-selected' : '',
|
|
119
|
+
showBorder && !selected ? 'is-framed' : '',
|
|
152
120
|
interactive ? 'cursor-pointer' : '',
|
|
153
121
|
sizeCls,
|
|
154
122
|
className,
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import { useRef, useState } from 'react'
|
|
1
|
+
import { forwardRef, useRef, useState } from 'react'
|
|
2
2
|
import { Menu } from './Menu.jsx'
|
|
3
3
|
import { Tooltip } from '../utilities/Popover.jsx'
|
|
4
4
|
|
|
5
|
-
/* the hit box per control rung: a field's height, a narrow width; the dot inside it */
|
|
6
|
-
const SIZE = {
|
|
7
|
-
xs: 'w-4 h-[22px] [--bd-dot:6px]',
|
|
8
|
-
sm: 'w-5 h-[26px] [--bd-dot:7px]',
|
|
9
|
-
md: 'w-6 h-8 [--bd-dot:8px]',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
5
|
/**
|
|
13
6
|
* ParamBindDot — Show a param is bound and open its menu. the small dot beside a param row: hollow at rest,
|
|
14
7
|
* filled in the accent once the param is bound (modulated); a click opens a menu of actions.
|
|
@@ -39,8 +32,54 @@ const SIZE = {
|
|
|
39
32
|
* @param {'start'|'end'} [align='end'] - The menu's edge against the dot
|
|
40
33
|
* @param {number} [minWidth=180] - The menu's minimum width
|
|
41
34
|
* @param {string} [className] - Extra classes on the trigger
|
|
35
|
+
*
|
|
36
|
+
* ONE DOT, ITS LOOK THE THEME'S (plan-2026-11-29-one-set-fold W2 run 4): the hit box, the dot, its ring and the focus line are
|
|
37
|
+
* `--kol-bind-*` (kol-theme `.kol-param-bind-dot`), the default theme leaving them unset (the rung's box and dot, a 1.5
|
|
38
|
+
* ring in oq-48, oq-80 on hover and open, the quiet focus line) and `data-theme-variant="kolbox"` setting kolbox's (a 6
|
|
39
|
+
* dot in a round 16 box at every rung, a 1px ring in oq-64, the accent focus line). The menu is the one `Menu` with
|
|
40
|
+
* `items` (kolbox's `{ label, checked, onClick }` rows are Menu rows). `variant="kolbox"` and `"folio"` still open kolbox's
|
|
41
|
+
* Menu (the bridge below); the old branch is in `_tmp/2026-11-29-one-set-fold/ParamBindDot.pre-fields3.jsx`.
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
const THEME_WORDS = ['kolbox', 'folio']
|
|
44
|
+
export default function ParamBindDot({ variant, ...props }) {
|
|
45
|
+
/* bridge: a theme word keeps kolbox's Menu until W3's Menu fold removes this bridge */
|
|
46
|
+
return THEME_WORDS.includes(variant) ? <ParamBindDotMenuBridge {...props} /> : <ParamBindDotMenu {...props} />
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* the dot itself, the same button for both menus */
|
|
50
|
+
const Dot = forwardRef(function Dot({ bound, className = '', size = 'sm', accent, open, ...rest }, ref) {
|
|
51
|
+
return (
|
|
52
|
+
<button
|
|
53
|
+
ref={ref}
|
|
54
|
+
type="button"
|
|
55
|
+
data-accent={accent === 'secondary' ? accent : undefined}
|
|
56
|
+
data-size={['xs', 'sm', 'md'].includes(size) ? size : 'sm'}
|
|
57
|
+
{...rest}
|
|
58
|
+
className={`kol-param-bind-dot group inline-flex shrink-0 items-center justify-center p-0 border-0 bg-transparent cursor-pointer outline-none${open ? ' is-open' : ''} ${className}`.trim()}
|
|
59
|
+
>
|
|
60
|
+
<span aria-hidden="true" className={`kol-bind-dot-mark block rounded-full border-solid transition-colors${bound ? ' is-bound' : ''}`} />
|
|
61
|
+
</button>
|
|
62
|
+
)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
/* the kolbox Menu bridge, as the pre-fields3 kolbox build wired it: "Modulate" (or `tooltip`), Menu kolbox beside the dot,
|
|
66
|
+
`items` ({ label, checked, onClick }) as one group */
|
|
67
|
+
function ParamBindDotMenuBridge({ bound = false, items = [], label, tooltip, size, minWidth = 180, className, accent }) {
|
|
68
|
+
const ref = useRef(null)
|
|
69
|
+
const [open, setOpen] = useState(false)
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
<Tooltip label={tooltip ?? 'Modulate'}>
|
|
73
|
+
<Dot ref={ref} bound={bound} size={size} className={className} accent={accent} open={open} data-bind-dot
|
|
74
|
+
aria-label={`Modulate${label ? ` ${label}` : ''}`} aria-haspopup="menu" aria-expanded={open} onClick={() => setOpen((o) => !o)} />
|
|
75
|
+
</Tooltip>
|
|
76
|
+
<Menu variant="kolbox" accent={accent} aria-label="Modulate" anchor={ref} open={open} onClose={() => setOpen(false)} minWidth={minWidth}
|
|
77
|
+
groups={[items.map((it, i) => ({ label: it.label, value: i, check: !!it.checked }))]} onSelect={(r) => items[r.value]?.onClick?.()} />
|
|
78
|
+
</>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ParamBindDotMenu({
|
|
44
83
|
bound = false,
|
|
45
84
|
mode,
|
|
46
85
|
items = [],
|
|
@@ -57,52 +96,8 @@ function ParamBindDotDefault({
|
|
|
57
96
|
return (
|
|
58
97
|
<Menu align={align} minWidth={minWidth} items={items} trigger={({ open, props }) => (
|
|
59
98
|
<Tooltip label={open ? null : tip}>
|
|
60
|
-
<
|
|
61
|
-
type="button"
|
|
62
|
-
aria-label={name}
|
|
63
|
-
data-accent={accent === 'secondary' ? accent : undefined}
|
|
64
|
-
{...props}
|
|
65
|
-
className={[
|
|
66
|
-
'kol-param-bind-dot group inline-flex shrink-0 items-center justify-center p-0 border-0 bg-transparent cursor-pointer rounded-[var(--kol-radius-2)] outline-none',
|
|
67
|
-
'focus-visible:outline focus-visible:outline-1 focus-visible:outline-[var(--kol-focus-ring-quiet)]',
|
|
68
|
-
SIZE[size] ?? SIZE.sm,
|
|
69
|
-
className,
|
|
70
|
-
].filter(Boolean).join(' ')}
|
|
71
|
-
>
|
|
72
|
-
<span
|
|
73
|
-
aria-hidden="true"
|
|
74
|
-
className={`block rounded-full border-[1.5px] border-solid transition-colors size-[var(--bd-dot)] ${bound
|
|
75
|
-
? 'bg-[var(--kol-accent-primary)] border-[var(--kol-accent-primary)]'
|
|
76
|
-
: `bg-transparent group-hover:border-[var(--kol-oq-80)] ${open ? 'border-[var(--kol-oq-80)]' : 'border-[var(--kol-oq-48)]'}`}`}
|
|
77
|
-
/>
|
|
78
|
-
</button>
|
|
99
|
+
<Dot aria-label={name} bound={bound} size={size} className={className} accent={accent} open={open} {...props} />
|
|
79
100
|
</Tooltip>
|
|
80
101
|
)} />
|
|
81
102
|
)
|
|
82
103
|
}
|
|
83
|
-
|
|
84
|
-
/* kolbox (plan-2026-11-18-kolbox-system W31.2 batch 5, 2026-11-18): kolbox's BindDot (round 4, W5), its drawing carried
|
|
85
|
-
* from apps/kolbox/src/labs/Params.jsx (the binding itself stays the caller's): a 16 hit box, a 6 dot hollow on the muted
|
|
86
|
-
* ring, filled in the accent once `bound`; the kolbox Tooltip (`tooltip`, else "Modulate"); a press opens Menu kolbox
|
|
87
|
-
* beside it with `items` ({ label, checked, onClick }) as one group. */
|
|
88
|
-
function ParamBindDotKolbox({ bound = false, items = [], label, tooltip, minWidth = 180, accent }) {
|
|
89
|
-
const ref = useRef(null)
|
|
90
|
-
const [open, setOpen] = useState(false)
|
|
91
|
-
return (
|
|
92
|
-
<>
|
|
93
|
-
<Tooltip variant="kolbox" label={tooltip ?? 'Modulate'}>
|
|
94
|
-
<button ref={ref} type="button" aria-label={`Modulate${label ? ` ${label}` : ''}`} aria-haspopup="menu" aria-expanded={open} data-bind-dot data-accent={accent === 'secondary' ? accent : undefined}
|
|
95
|
-
onClick={() => setOpen((o) => !o)}
|
|
96
|
-
className="kol-bind-dot--kolbox inline-flex size-4 shrink-0 items-center justify-center rounded-full outline-none focus-visible:outline-solid focus-visible:outline-1">
|
|
97
|
-
<span className={`kol-bind-dot-mark${bound ? ' is-bound' : ''} size-1.5 rounded-full`} />
|
|
98
|
-
</button>
|
|
99
|
-
</Tooltip>
|
|
100
|
-
<Menu variant="kolbox" accent={accent} aria-label="Modulate" anchor={ref} open={open} onClose={() => setOpen(false)} minWidth={minWidth}
|
|
101
|
-
groups={[items.map((it, i) => ({ label: it.label, value: i, check: !!it.checked }))]} onSelect={(r) => items[r.value]?.onClick?.()} />
|
|
102
|
-
</>
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export default function ParamBindDot(props) {
|
|
107
|
-
return props.variant === 'kolbox' ? <ParamBindDotKolbox {...props} /> : <ParamBindDotDefault {...props} />
|
|
108
|
-
}
|
|
@@ -35,6 +35,9 @@ import { Tooltip } from '../utilities/Popover.jsx'
|
|
|
35
35
|
/* Fixed chip slots inside the 44×44 stack — identical in both variants; only
|
|
36
36
|
* the render order changes. Positions live on absolutely-placed wrappers so
|
|
37
37
|
* ColorSwatch keeps its own `relative` root (its box-shadow halo needs it). */
|
|
38
|
+
/* theme words a caller may still pass; they draw `compact`, the build they named (W2 run 3) */
|
|
39
|
+
const THEME_WORDS = ['kolbox', 'folio']
|
|
40
|
+
|
|
38
41
|
const FILL_SLOT = 'left-[5px] top-[6px]'
|
|
39
42
|
const STROKE_SLOT = 'left-[15px] top-[16px]'
|
|
40
43
|
|
|
@@ -68,11 +71,13 @@ function PaintChip({ id, label, color, slot, onSwap }) {
|
|
|
68
71
|
* @param {'fill'|'stroke'} activePaint which chip paints on top. Default 'fill'
|
|
69
72
|
* @param {Function} onSwap () => void — either chip or the swap arrow
|
|
70
73
|
* @param {Function} onClear () => void — the "set to none" marker
|
|
71
|
-
* @param {'default'|'
|
|
72
|
-
* carried class for class
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
74
|
+
* @param {'default'|'compact'} variant `compact` (kolbox's SwatchStack, plan-2026-11-18-kolbox-system W31.2, 2026-11-18,
|
|
75
|
+
* carried class for class; a variant of its own since plan-2026-11-29-one-set-fold W2 run 3): the stack scaled into a
|
|
76
|
+
* 32 dock cell, 16 chips at 4 / 4 and 12 / 11, each with a halo of the ground then the theme's line
|
|
77
|
+
* (`--kol-swatch-stack-line`; unset fg-32, kolbox its line); the swap arrow (your icons' `swap`, 12) top right in oq-64,
|
|
78
|
+
* the ink on hover; the none marker an 8 disc of the ink with the error slash. Chrome in kol-theme
|
|
79
|
+
* `.kol-swatch-stack--compact`. `variant="kolbox"` and `"folio"` are accepted and draw `compact`.
|
|
80
|
+
* @param {string} className compact: extra classes on the stack
|
|
76
81
|
*/
|
|
77
82
|
export function SwatchStack({
|
|
78
83
|
fillColor = '#FFFFFF',
|
|
@@ -84,7 +89,7 @@ export function SwatchStack({
|
|
|
84
89
|
className = '',
|
|
85
90
|
accent,
|
|
86
91
|
}) {
|
|
87
|
-
if (variant === '
|
|
92
|
+
if (variant === 'compact' || THEME_WORDS.includes(variant)) {
|
|
88
93
|
const chip = (key, label, pos) => (
|
|
89
94
|
<button key={key} type="button" aria-label={label} onClick={onSwap} data-paint={label}
|
|
90
95
|
className={`kol-swatch-stack-chip absolute size-4 rounded-full outline-none focus-visible:outline-solid focus-visible:outline-1 ${pos}`}
|
|
@@ -93,7 +98,7 @@ export function SwatchStack({
|
|
|
93
98
|
const fill = chip('fill', 'Fill color', 'top-1 left-1')
|
|
94
99
|
const stroke = chip('stroke', 'Stroke color', 'top-3 left-[11px]')
|
|
95
100
|
return (
|
|
96
|
-
<div data-accent={accent === 'secondary' ? accent : undefined} className={`kol-swatch-stack--
|
|
101
|
+
<div data-accent={accent === 'secondary' ? accent : undefined} className={`kol-swatch-stack--compact relative size-8 shrink-0 ${className}`.trim()} data-swatch-stack={activePaint}>
|
|
97
102
|
{activePaint === 'fill' ? [stroke, fill] : [fill, stroke]}
|
|
98
103
|
<button type="button" aria-label="Swap colors" onClick={onSwap}
|
|
99
104
|
className="kol-swatch-stack-swap absolute top-0 right-0 inline-flex outline-none focus-visible:outline-solid focus-visible:outline-1">
|
|
@@ -10,16 +10,13 @@
|
|
|
10
10
|
* @param {string} [value] the current one
|
|
11
11
|
* @param {Function} [onChange] `(color)`
|
|
12
12
|
* @param {string} [className]
|
|
13
|
-
* @param {
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* @param {React.ReactNode} [children] the caller's own swatches (`ColorSwatch`) instead of `colors`: a row of them, 8 apart,
|
|
14
|
+
* wrapping, a group named by `aria-label`; `colors`, `value` and `onChange` are not read. Was `variant="kolbox"` with
|
|
15
|
+
* children and `variant="folio"`; one row now (plan-2026-11-29-one-set-fold W2 run 3, the branches in
|
|
16
|
+
* _tmp/2026-11-29-one-set-fold/). `variant` is accepted and does nothing.
|
|
17
17
|
*/
|
|
18
|
-
export default function SwatchGrid({ colors = [], value, onChange, className = '',
|
|
19
|
-
|
|
20
|
-
8 apart as the grid's, wrapping; a group named by `aria-label` */
|
|
21
|
-
if (variant === 'kolbox' && children) return <div role="group" aria-label={rest['aria-label']} className={`flex flex-wrap gap-2 ${className}`.trim()}>{children}</div>
|
|
22
|
-
if (variant === 'folio') return <div role="group" aria-label={rest['aria-label']} className={`flex gap-[8px] ${className}`.trim()}>{children}</div>
|
|
18
|
+
export default function SwatchGrid({ colors = [], value, onChange, className = '', children, ...rest }) {
|
|
19
|
+
if (children) return <div role="group" aria-label={rest['aria-label']} className={`flex flex-wrap gap-2 ${className}`.trim()}>{children}</div>
|
|
23
20
|
return (
|
|
24
21
|
<div role="listbox" aria-label="Swatches" className={`grid grid-cols-8 gap-2 ${className}`}>
|
|
25
22
|
{colors.map((c) => (
|
|
@@ -328,7 +328,7 @@ function ColorPickerPopoverKolbox({ anchor, open, onClose, placement, color, opa
|
|
|
328
328
|
<Button variant="kolbox" key={p.value} iconOnly={p.icon} aria-label={p.value} pressed={p.value === paint} onClick={() => set(hsv, opacity, p.value)} />
|
|
329
329
|
))}
|
|
330
330
|
</div>
|
|
331
|
-
<SBSquare variant="kolbox" hue={hsv.hue} sat={hsv.sat} val={hsv.val} onChange={(sat, val) => set({ ...hsv, sat, val })} className="rounded-sm" />
|
|
331
|
+
<SBSquare variant="kolbox" hue={hsv.hue} sat={hsv.sat} val={hsv.val} onChange={(sat, val) => set({ ...hsv, sat, val })} className="aspect-square rounded-sm" />
|
|
332
332
|
<div className="flex items-center gap-2">
|
|
333
333
|
<Button variant="kolbox" iconOnly="eyedropper" aria-label="Eyedropper" onClick={eyedrop} />
|
|
334
334
|
<div className="flex flex-1 flex-col gap-2">
|
|
@@ -37,11 +37,20 @@ import { useCallback, useEffect, useId, useRef } from 'react'
|
|
|
37
37
|
* half the knob hangs off the edge. */
|
|
38
38
|
const HANDLE_R = 7
|
|
39
39
|
|
|
40
|
+
/* ONE SET, ITS LOOK THE THEME'S (plan-2026-11-29-one-set-fold W2 run 4): the handle, the strips and the checker are
|
|
41
|
+
* `--kol-spectrum-*` (kol-theme kol-components-organisms.css, Spectrum controls), the default theme leaving them unset
|
|
42
|
+
* and `data-theme-variant="kolbox"` setting kolbox's. The inset is read here too, so the drag math matches the drawing
|
|
43
|
+
* (kolbox's handle runs to the box's edge, inset 0). `variant="kolbox"` is accepted and does nothing; its branches are in
|
|
44
|
+
* `_tmp/2026-11-29-one-set-fold/SpectrumControls.pre-fields3.jsx`. */
|
|
45
|
+
const insetOf = (node) => {
|
|
46
|
+
const v = parseFloat(getComputedStyle(node).getPropertyValue('--kol-spectrum-inset'))
|
|
47
|
+
return Number.isFinite(v) ? v : HANDLE_R
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
const HUE_GRADIENT =
|
|
41
51
|
'linear-gradient(to right, hsl(0,100%,50%), hsl(60,100%,50%), hsl(120,100%,50%), hsl(180,100%,50%), hsl(240,100%,50%), hsl(300,100%,50%), hsl(360,100%,50%))'
|
|
42
52
|
|
|
43
|
-
/*
|
|
44
|
-
*
|
|
53
|
+
/*
|
|
45
54
|
* HueStrip — A hue slider. 1D hue slider: a rainbow bar with a draggable knob. Pointer
|
|
46
55
|
* drag anywhere on the strip; focus + Left/Right (or Down/Up) arrow keys
|
|
47
56
|
* nudge hue by 1° (role="slider").
|
|
@@ -49,7 +58,7 @@ const HUE_GRADIENT =
|
|
|
49
58
|
* @param {number} hue controlled hue, 0–360
|
|
50
59
|
* @param {Function} onChange (hue: number) => void — fires on press, drag, and arrow keys
|
|
51
60
|
*/
|
|
52
|
-
function
|
|
61
|
+
export function HueStrip({ hue, onChange, className = '' }) {
|
|
53
62
|
const ref = useRef(null)
|
|
54
63
|
const dragging = useRef(false)
|
|
55
64
|
|
|
@@ -57,10 +66,11 @@ function HueStripDefault({ hue, onChange }) {
|
|
|
57
66
|
const node = ref.current
|
|
58
67
|
if (!node) return
|
|
59
68
|
const rect = node.getBoundingClientRect()
|
|
60
|
-
const
|
|
69
|
+
const inset = insetOf(node)
|
|
70
|
+
const inner = rect.width - 2 * inset
|
|
61
71
|
if (inner <= 0) return
|
|
62
|
-
const ratio = Math.max(0, Math.min(1, (clientX - rect.left -
|
|
63
|
-
onChange(ratio * 360)
|
|
72
|
+
const ratio = Math.max(0, Math.min(1, (clientX - rect.left - inset) / inner))
|
|
73
|
+
onChange?.(ratio * 360)
|
|
64
74
|
}, [onChange])
|
|
65
75
|
|
|
66
76
|
const onDown = (e) => {
|
|
@@ -88,7 +98,7 @@ function HueStripDefault({ hue, onChange }) {
|
|
|
88
98
|
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') next = Math.max(0, hue - 1)
|
|
89
99
|
if (next === null) return
|
|
90
100
|
e.preventDefault()
|
|
91
|
-
onChange(next)
|
|
101
|
+
onChange?.(next)
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
const pos = (hue / 360) * 100
|
|
@@ -104,12 +114,12 @@ function HueStripDefault({ hue, onChange }) {
|
|
|
104
114
|
aria-valuenow={Math.round(hue)}
|
|
105
115
|
onPointerDown={onDown}
|
|
106
116
|
onKeyDown={onKeyDown}
|
|
107
|
-
className=
|
|
108
|
-
style={{
|
|
117
|
+
className={`kol-spectrum-strip kol-hue-strip relative cursor-pointer touch-none ${className}`.trim()}
|
|
118
|
+
style={{ background: HUE_GRADIENT, '--kol-spectrum-hue': `hsl(${hue} 100% 50%)` }}
|
|
109
119
|
>
|
|
110
120
|
{/* Handle positions inside an inset region so 0..100% maps to the
|
|
111
121
|
* area where the knob can sit without spilling out. */}
|
|
112
|
-
<div className="absolute inset-y-0"
|
|
122
|
+
<div className="kol-spectrum-inset absolute inset-y-0">
|
|
113
123
|
<Handle left={`${pos}%`} top="50%" />
|
|
114
124
|
</div>
|
|
115
125
|
</div>
|
|
@@ -119,8 +129,7 @@ function HueStripDefault({ hue, onChange }) {
|
|
|
119
129
|
/* the transparency checker behind an alpha ramp — literal greys, like the spectra (not themeable) */
|
|
120
130
|
const CHECKER = 'repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0 0 / 8px 8px'
|
|
121
131
|
|
|
122
|
-
/*
|
|
123
|
-
*
|
|
132
|
+
/*
|
|
124
133
|
* AlphaStrip — An opacity slider. HueStrip's twin for alpha: the colour ramped from transparent to
|
|
125
134
|
* opaque over a checker, same knob, same inset (ColorPickerPopover, kol-monitor 2026-10-17). Focus +
|
|
126
135
|
* Left/Right (or Down/Up) nudge alpha by 1% (role="slider").
|
|
@@ -129,7 +138,7 @@ const CHECKER = 'repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0 0 / 8px 8p
|
|
|
129
138
|
* @param {string} color the opaque colour the ramp ends on (any CSS colour)
|
|
130
139
|
* @param {Function} onChange (alpha: number) => void — fires on press, drag, and arrow keys
|
|
131
140
|
*/
|
|
132
|
-
function
|
|
141
|
+
export function AlphaStrip({ alpha = 1, color = 'currentColor', onChange, className = '' }) {
|
|
133
142
|
const ref = useRef(null)
|
|
134
143
|
const dragging = useRef(false)
|
|
135
144
|
|
|
@@ -137,9 +146,10 @@ function AlphaStripDefault({ alpha, color, onChange }) {
|
|
|
137
146
|
const node = ref.current
|
|
138
147
|
if (!node) return
|
|
139
148
|
const rect = node.getBoundingClientRect()
|
|
140
|
-
const
|
|
149
|
+
const inset = insetOf(node)
|
|
150
|
+
const inner = rect.width - 2 * inset
|
|
141
151
|
if (inner <= 0) return
|
|
142
|
-
onChange(Math.max(0, Math.min(1, (clientX - rect.left -
|
|
152
|
+
onChange?.(Math.max(0, Math.min(1, (clientX - rect.left - inset) / inner)))
|
|
143
153
|
}, [onChange])
|
|
144
154
|
|
|
145
155
|
useEffect(() => {
|
|
@@ -161,7 +171,7 @@ function AlphaStripDefault({ alpha, color, onChange }) {
|
|
|
161
171
|
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') next = Math.max(0, alpha - 0.01)
|
|
162
172
|
if (next === null) return
|
|
163
173
|
e.preventDefault()
|
|
164
|
-
onChange(next)
|
|
174
|
+
onChange?.(next)
|
|
165
175
|
}
|
|
166
176
|
|
|
167
177
|
return (
|
|
@@ -175,18 +185,17 @@ function AlphaStripDefault({ alpha, color, onChange }) {
|
|
|
175
185
|
aria-valuenow={Math.round(alpha * 100)}
|
|
176
186
|
onPointerDown={(e) => { dragging.current = true; update(e.clientX); e.preventDefault() }}
|
|
177
187
|
onKeyDown={onKeyDown}
|
|
178
|
-
className=
|
|
179
|
-
style={{
|
|
188
|
+
className={`kol-spectrum-strip relative cursor-pointer touch-none ${className}`.trim()}
|
|
189
|
+
style={{ background: `linear-gradient(to right, transparent, ${color}), var(--kol-spectrum-checker, ${CHECKER})` }}
|
|
180
190
|
>
|
|
181
|
-
<div className="absolute inset-y-0"
|
|
191
|
+
<div className="kol-spectrum-inset absolute inset-y-0">
|
|
182
192
|
<Handle left={`${alpha * 100}%`} top="50%" />
|
|
183
193
|
</div>
|
|
184
194
|
</div>
|
|
185
195
|
)
|
|
186
196
|
}
|
|
187
197
|
|
|
188
|
-
/*
|
|
189
|
-
*
|
|
198
|
+
/*
|
|
190
199
|
* SBSquare — Pick saturation and value on a square. 2D saturation/value picker: white→hue horizontal gradient with
|
|
191
200
|
* a black overlay fading upward, crosshair handle. Fills its container
|
|
192
201
|
* (consumer owns the size — and the rounding: apply `rounded-[var(--kol-radius-2)]
|
|
@@ -198,7 +207,7 @@ function AlphaStripDefault({ alpha, color, onChange }) {
|
|
|
198
207
|
* @param {number} val controlled value/brightness, 0–100
|
|
199
208
|
* @param {Function} onChange (sat: number, val: number) => void
|
|
200
209
|
*/
|
|
201
|
-
function
|
|
210
|
+
export function SBSquare({ hue = 0, sat = 100, val = 100, onChange, className = '' }) {
|
|
202
211
|
const ref = useRef(null)
|
|
203
212
|
const dragging = useRef(false)
|
|
204
213
|
|
|
@@ -206,12 +215,13 @@ function SBSquareDefault({ hue, sat, val, onChange }) {
|
|
|
206
215
|
const node = ref.current
|
|
207
216
|
if (!node) return
|
|
208
217
|
const rect = node.getBoundingClientRect()
|
|
209
|
-
const
|
|
210
|
-
const
|
|
218
|
+
const inset = insetOf(node)
|
|
219
|
+
const innerW = rect.width - 2 * inset
|
|
220
|
+
const innerH = rect.height - 2 * inset
|
|
211
221
|
if (innerW <= 0 || innerH <= 0) return
|
|
212
|
-
const sx = Math.max(0, Math.min(1, (clientX - rect.left -
|
|
213
|
-
const sy = Math.max(0, Math.min(1, (clientY - rect.top -
|
|
214
|
-
onChange(sx * 100, (1 - sy) * 100)
|
|
222
|
+
const sx = Math.max(0, Math.min(1, (clientX - rect.left - inset) / innerW))
|
|
223
|
+
const sy = Math.max(0, Math.min(1, (clientY - rect.top - inset) / innerH))
|
|
224
|
+
onChange?.(sx * 100, (1 - sy) * 100)
|
|
215
225
|
}, [onChange])
|
|
216
226
|
|
|
217
227
|
const onDown = (e) => {
|
|
@@ -235,6 +245,7 @@ function SBSquareDefault({ hue, sat, val, onChange }) {
|
|
|
235
245
|
|
|
236
246
|
const onKeyDown = (e) => {
|
|
237
247
|
const clamp = (v) => Math.max(0, Math.min(100, v))
|
|
248
|
+
if (!onChange) return
|
|
238
249
|
if (e.key === 'ArrowRight') onChange(clamp(sat + 1), val)
|
|
239
250
|
else if (e.key === 'ArrowLeft') onChange(clamp(sat - 1), val)
|
|
240
251
|
else if (e.key === 'ArrowUp') onChange(sat, clamp(val + 1))
|
|
@@ -260,10 +271,10 @@ function SBSquareDefault({ hue, sat, val, onChange }) {
|
|
|
260
271
|
aria-valuetext={`Saturation ${Math.round(sat)}%, brightness ${Math.round(val)}%`}
|
|
261
272
|
onPointerDown={onDown}
|
|
262
273
|
onKeyDown={onKeyDown}
|
|
263
|
-
className=
|
|
274
|
+
className={`kol-spectrum-sb relative cursor-crosshair touch-none w-full h-full ${className}`.trim()}
|
|
264
275
|
style={{ background: sb }}
|
|
265
276
|
>
|
|
266
|
-
<div className="absolute"
|
|
277
|
+
<div className="kol-spectrum-inset absolute">
|
|
267
278
|
<Handle left={`${sat}%`} top={`${100 - val}%`} />
|
|
268
279
|
</div>
|
|
269
280
|
</div>
|
|
@@ -316,13 +327,12 @@ function vertexAt(angleRad) {
|
|
|
316
327
|
* @param {number} val controlled value/brightness, 0–100
|
|
317
328
|
* @param {Function} onChangeHue (hue: number) => void — ring drag / hue arrow keys
|
|
318
329
|
* @param {Function} onChangeSV (sat: number, val: number) => void — triangle drag / value arrow keys
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
330
|
+
* The handles' halo and ring and the wrapper's focus ring are the theme's (`--kol-wheel-*`, kol-theme Spectrum controls):
|
|
331
|
+
* kolbox's ring in the ink over a hairline of the ground and a round accent focus ring 2 out. `variant` is accepted and
|
|
332
|
+
* does nothing (W2 run 4).
|
|
322
333
|
* @param {string} [className] extra classes on the wrapper
|
|
323
334
|
*/
|
|
324
|
-
export function WheelTriangle({ hue, sat, val, onChangeHue, onChangeSV,
|
|
325
|
-
const kolbox = variant === 'kolbox'
|
|
335
|
+
export function WheelTriangle({ hue, sat, val, onChangeHue, onChangeSV, className = '' }) {
|
|
326
336
|
const svgRef = useRef(null)
|
|
327
337
|
const dragMode = useRef(null) /* { type: 'ring' } | { type: 'tri', offsetX, offsetY } | null */
|
|
328
338
|
|
|
@@ -467,9 +477,7 @@ export function WheelTriangle({ hue, sat, val, onChangeHue, onChangeSV, variant
|
|
|
467
477
|
aria-valuenow={Math.round(hue)}
|
|
468
478
|
aria-valuetext={`Hue ${Math.round(hue)} degrees, saturation ${Math.round(sat)}%, brightness ${Math.round(val)}%`}
|
|
469
479
|
onKeyDown={onKeyDown}
|
|
470
|
-
className={
|
|
471
|
-
? `kol-wheel-triangle--kolbox aspect-square max-h-full max-w-full rounded-full outline-none focus-visible:outline-solid focus-visible:outline-1 focus-visible:outline-offset-2 ${className}`
|
|
472
|
-
: `aspect-square max-h-full max-w-full ${className}`.trim()}
|
|
480
|
+
className={`kol-wheel-triangle aspect-square max-h-full max-w-full ${className}`.trim()}
|
|
473
481
|
>
|
|
474
482
|
<svg
|
|
475
483
|
ref={svgRef}
|
|
@@ -519,8 +527,8 @@ export function WheelTriangle({ hue, sat, val, onChangeHue, onChangeSV, variant
|
|
|
519
527
|
<polygon points={trianglePoints} fill={`url(#${blackFadeId})`} />
|
|
520
528
|
|
|
521
529
|
{/* Handles. Ring handle is larger than the SV handle to match the Ref. */}
|
|
522
|
-
<SvgHandle cx={ringHx} cy={ringHy} r={3.2}
|
|
523
|
-
<SvgHandle cx={handleX} cy={handleY} r={2.0}
|
|
530
|
+
<SvgHandle cx={ringHx} cy={ringHy} r={3.2} />
|
|
531
|
+
<SvgHandle cx={handleX} cy={handleY} r={2.0} />
|
|
524
532
|
</svg>
|
|
525
533
|
</div>
|
|
526
534
|
)
|
|
@@ -529,29 +537,20 @@ export function WheelTriangle({ hue, sat, val, onChangeHue, onChangeSV, variant
|
|
|
529
537
|
/* ────────── Internal helpers (not exported) ────────── */
|
|
530
538
|
|
|
531
539
|
/* DOM handle for HueStrip / SBSquare. Solid white-stroked circle with thin
|
|
532
|
-
* black halo (matching the macOS-port look)
|
|
540
|
+
* black halo (matching the macOS-port look); size, fill and ring the theme's
|
|
541
|
+
* (`.kol-spectrum-handle`). */
|
|
533
542
|
function Handle({ left, top }) {
|
|
534
|
-
return
|
|
535
|
-
<span
|
|
536
|
-
className="absolute pointer-events-none rounded-full bg-fg"
|
|
537
|
-
style={{
|
|
538
|
-
left, top,
|
|
539
|
-
width: 14, height: 14,
|
|
540
|
-
transform: 'translate(-50%, -50%)',
|
|
541
|
-
boxShadow: '0 0 0 1px #000, 0 0 0 2px #505050',
|
|
542
|
-
}}
|
|
543
|
-
/>
|
|
544
|
-
)
|
|
543
|
+
return <span className="kol-spectrum-handle absolute pointer-events-none rounded-full" style={{ left, top }} />
|
|
545
544
|
}
|
|
546
545
|
|
|
547
546
|
/* SVG handle for WheelTriangle. Two concentric circles to stay sharp at any
|
|
548
547
|
* zoom — outer black halo + white outline. */
|
|
549
|
-
function SvgHandle({ cx, cy, r = 2.4
|
|
550
|
-
/*
|
|
548
|
+
function SvgHandle({ cx, cy, r = 2.4 }) {
|
|
549
|
+
/* the strokes are the theme's (`--kol-wheel-halo`, `--kol-wheel-ring`; unset, #000 and #FFF) */
|
|
551
550
|
return (
|
|
552
551
|
<g pointerEvents="none">
|
|
553
|
-
<circle cx={cx} cy={cy} r={r + 0.5} fill="none"
|
|
554
|
-
<circle cx={cx} cy={cy} r={r} fill="none"
|
|
552
|
+
<circle cx={cx} cy={cy} r={r + 0.5} fill="none" className="kol-wheel-triangle-halo" strokeOpacity="0.7" strokeWidth="0.5" />
|
|
553
|
+
<circle cx={cx} cy={cy} r={r} fill="none" className="kol-wheel-triangle-ring" strokeWidth="1.4" />
|
|
555
554
|
</g>
|
|
556
555
|
)
|
|
557
556
|
}
|
|
@@ -581,85 +580,3 @@ export default function SpectrumControls({ value, onChange }) {
|
|
|
581
580
|
</div>
|
|
582
581
|
)
|
|
583
582
|
}
|
|
584
|
-
|
|
585
|
-
/* ── kolbox (plan-2026-11-18-kolbox-system W31.2 batch 5, 2026-11-18) ─────────────────────────────────────────────────
|
|
586
|
-
* kolbox's ColorField, HueSlider and OpacitySlider, carried from apps/kolbox/src/ui as `variant="kolbox"` of SBSquare,
|
|
587
|
-
* HueStrip and AlphaStrip, on these parts' own words (`hue`, `sat` and `val` 0–100, `alpha` 0–1). Pointer down and drag,
|
|
588
|
-
* no keys (kolbox's have none); the handle a 12 ring in the ink. `className` lands on the part. */
|
|
589
|
-
|
|
590
|
-
/* pointer down on the element and drag: move(x, y), each clamped to 0..1 of its box */
|
|
591
|
-
function dragKolbox(e, move) {
|
|
592
|
-
const box = e.currentTarget
|
|
593
|
-
const at = (ev) => { const r = box.getBoundingClientRect(); move(Math.min(1, Math.max(0, (ev.clientX - r.left) / r.width)), Math.min(1, Math.max(0, (ev.clientY - r.top) / r.height))) }
|
|
594
|
-
box.setPointerCapture(e.pointerId)
|
|
595
|
-
at(e)
|
|
596
|
-
const up = () => { box.removeEventListener('pointermove', at); box.removeEventListener('pointerup', up) }
|
|
597
|
-
box.addEventListener('pointermove', at)
|
|
598
|
-
box.addEventListener('pointerup', up)
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/* the saturation and brightness square at the hue (Figma plan W13 state 4); onChange(sat, val) */
|
|
602
|
-
function SBSquareKolbox({ hue = 0, sat = 100, val = 100, onChange, className = '' }) {
|
|
603
|
-
return (
|
|
604
|
-
<div
|
|
605
|
-
role="slider"
|
|
606
|
-
aria-label="Saturation and brightness"
|
|
607
|
-
aria-valuetext={`${Math.round(sat)}%, ${Math.round(val)}%`}
|
|
608
|
-
onPointerDown={(e) => dragKolbox(e, (x, y) => onChange?.(x * 100, (1 - y) * 100))}
|
|
609
|
-
className={`relative aspect-square w-full cursor-crosshair touch-none ${className}`}
|
|
610
|
-
style={{ background: `linear-gradient(to top, black, transparent), linear-gradient(to right, white, hsl(${hue} 100% 50%))` }}
|
|
611
|
-
>
|
|
612
|
-
<span className="kol-spectrum-handle--kolbox pointer-events-none absolute size-3 -translate-1/2 rounded-full" style={{ left: `${sat}%`, top: `${100 - val}%` }} />
|
|
613
|
-
</div>
|
|
614
|
-
)
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/* the hue run, 0 to 360, 12 high, its thumb the hue */
|
|
618
|
-
function HueStripKolbox({ hue = 0, onChange, className = '' }) {
|
|
619
|
-
return (
|
|
620
|
-
<div
|
|
621
|
-
role="slider"
|
|
622
|
-
aria-label="Hue"
|
|
623
|
-
aria-valuemin={0}
|
|
624
|
-
aria-valuemax={360}
|
|
625
|
-
aria-valuenow={Math.round(hue)}
|
|
626
|
-
onPointerDown={(e) => dragKolbox(e, (x) => onChange?.(x * 360))}
|
|
627
|
-
className={`relative h-3 w-full cursor-pointer touch-none rounded-full ${className}`}
|
|
628
|
-
style={{ background: 'linear-gradient(to right, hsl(0 100% 50%), hsl(60 100% 50%), hsl(120 100% 50%), hsl(180 100% 50%), hsl(240 100% 50%), hsl(300 100% 50%), hsl(360 100% 50%))' }}
|
|
629
|
-
>
|
|
630
|
-
<span className="kol-spectrum-handle--kolbox pointer-events-none absolute top-1/2 size-3 -translate-1/2 rounded-full" style={{ left: `${(hue / 360) * 100}%`, background: `hsl(${hue} 100% 50%)` }} />
|
|
631
|
-
</div>
|
|
632
|
-
)
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/* the opacity run, clear to `color` over the checker; onChange(alpha), in whole percents */
|
|
636
|
-
function AlphaStripKolbox({ alpha = 1, color = 'currentColor', onChange, className = '' }) {
|
|
637
|
-
const value = alpha * 100
|
|
638
|
-
return (
|
|
639
|
-
<div
|
|
640
|
-
role="slider"
|
|
641
|
-
aria-label="Opacity"
|
|
642
|
-
aria-valuemin={0}
|
|
643
|
-
aria-valuemax={100}
|
|
644
|
-
aria-valuenow={Math.round(value)}
|
|
645
|
-
onPointerDown={(e) => dragKolbox(e, (x) => onChange?.(Math.round(x * 100) / 100))}
|
|
646
|
-
className={`kol-alpha-strip--kolbox relative h-3 w-full cursor-pointer touch-none rounded-full ${className}`}
|
|
647
|
-
>
|
|
648
|
-
<span className="absolute inset-0 rounded-full" style={{ background: `linear-gradient(to right, transparent, ${color})` }} />
|
|
649
|
-
<span className="kol-spectrum-handle--kolbox pointer-events-none absolute top-1/2 size-3 -translate-1/2 rounded-full" style={{ left: `${value}%` }} />
|
|
650
|
-
</div>
|
|
651
|
-
)
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
/** SBSquare — Pick saturation and value on a square. @param {'default'|'kolbox'} [variant] `kolbox`: kolbox's ColorField (above) */
|
|
655
|
-
export function SBSquare(props) {
|
|
656
|
-
return props.variant === 'kolbox' ? <SBSquareKolbox {...props} /> : <SBSquareDefault {...props} />
|
|
657
|
-
}
|
|
658
|
-
/** HueStrip — A hue slider. @param {'default'|'kolbox'} [variant] `kolbox`: kolbox's HueSlider (above) */
|
|
659
|
-
export function HueStrip(props) {
|
|
660
|
-
return props.variant === 'kolbox' ? <HueStripKolbox {...props} /> : <HueStripDefault {...props} />
|
|
661
|
-
}
|
|
662
|
-
/** AlphaStrip — An opacity slider. @param {'default'|'kolbox'} [variant] `kolbox`: kolbox's OpacitySlider (above) */
|
|
663
|
-
export function AlphaStrip(props) {
|
|
664
|
-
return props.variant === 'kolbox' ? <AlphaStripKolbox {...props} /> : <AlphaStripDefault {...props} />
|
|
665
|
-
}
|