@kolkrabbi/kol-component 0.386.0 → 0.388.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/index.js +1 -1
- package/src/molecules/AlignmentGrid.jsx +13 -7
- package/src/molecules/ColorInputRow.jsx +31 -23
- package/src/molecules/ColorSwatch.jsx +17 -49
- package/src/molecules/ContextMenu.jsx +1 -1
- package/src/molecules/Dropdown.jsx +24 -56
- package/src/molecules/Menu.jsx +190 -255
- package/src/molecules/MenuItem.jsx +45 -12
- package/src/molecules/MenuList.jsx +48 -17
- package/src/molecules/ParamBindDot.jsx +33 -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/src/utilities/Popover.jsx +8 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.388.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",
|
package/src/index.js
CHANGED
|
@@ -192,7 +192,7 @@ export { default as ContentRow } from './molecules/ContentRow.jsx'
|
|
|
192
192
|
export { default as ContentItem } from './molecules/ContentItem.jsx'
|
|
193
193
|
export { default as ContentCollection } from './organisms/ContentCollection.jsx'
|
|
194
194
|
export { MenuItem, MenuRow, MenuDivider, MenuFlyout, MenuDropdownItem, MenuDropdownDivider, MenuDropdownNest } from './molecules/MenuItem.jsx'
|
|
195
|
-
export { Menu, MenuTrigger, MenuPanel, MenuLabel, MenuFilter, MenuDatePicker, MenuMore, MenuScroll } from './molecules/Menu.jsx'
|
|
195
|
+
export { Menu, MenuTrigger, MenuPanel, MenuLabel, MenuFilter, MenuDatePicker, MenuMore, MenuScroll, MenuKolbox, MenuFolio } from './molecules/Menu.jsx'
|
|
196
196
|
export { MenuList } from './molecules/MenuList.jsx'
|
|
197
197
|
export { ModalProvider, useModal, ModalDialog, ModalDialog as Dialog } from './molecules/Modal.jsx'
|
|
198
198
|
export { default as ModalShell } from './molecules/ModalShell.jsx'
|
|
@@ -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,
|
|
@@ -50,7 +50,7 @@ export default function ContextMenu({ menu, children, variant, className = '' })
|
|
|
50
50
|
}, [menu.open])
|
|
51
51
|
if (!menu.open) return null
|
|
52
52
|
return (
|
|
53
|
-
<Menu anchor={{ x: menu.x, y: menu.y }} open onOpenChange={(v) => { if (!v) menu.close() }} variant={variant} panelClassName={`min-w-44 ${className}`.trim()}>
|
|
53
|
+
<Menu anchor={{ x: menu.x, y: menu.y }} placement="right-start" offset={2} open onOpenChange={(v) => { if (!v) menu.close() }} variant={variant} panelClassName={`min-w-44 ${className}`.trim()}>
|
|
54
54
|
{/* Any click inside closes — a menu item that leaves the menu open after acting is the one interaction people
|
|
55
55
|
* report as broken. Items keep their own onClick; this runs after it on the way up. */}
|
|
56
56
|
<div onClick={menu.close} role="none" className="flex flex-col gap-[var(--kol-spacing-0-5)]">
|
|
@@ -61,25 +61,24 @@ const ROW = { xs: `kol-mono-8 ${ROW_PAD.xs} ${ROW_H.xs}`, sm: `kol-mono-12 ${ROW
|
|
|
61
61
|
|
|
62
62
|
const LEGACY_VARIANTS = { default: 'primary', subtle: 'primary', minimal: 'outline' }
|
|
63
63
|
|
|
64
|
-
/*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* field,
|
|
69
|
-
* align left (unset): the list's left edge on the field's; right: its right edge on the field's.
|
|
70
|
-
* `options` strings or `{ value, label }`; `onChange` gets the value as a string
|
|
71
|
-
* menu the arrows move, Enter picks, a letter jumps, Escape closes; focus comes back to
|
|
72
|
-
*
|
|
64
|
+
/* THE FIELD (plan-2026-11-29-one-set-fold W3; kolbox's Dropdown, W31.2 batch 4, carried line for line): `fused={false}`.
|
|
65
|
+
* The closed field with the 12 chevron at the right: a button that opens the one `Menu` UNDER itself, 4 apart, and over
|
|
66
|
+
* it only when there is no room under (KolboxDropdownOpensUnder, kol-fxr 2026-11-28, as Figma's lists), at least as wide
|
|
67
|
+
* as the field, with a check on the current option. Its look is the theme's (`--kol-dd-field-*`, kol-theme `.kol-dd-field`):
|
|
68
|
+
* the default theme draws KOL's field, `data-theme-variant="kolbox"` kolbox's (28, xs the 24 filter, the kolbox line).
|
|
69
|
+
* align left (unset): the list's left edge on the field's; right (or Folio's bottom-right): its right edge on the field's.
|
|
70
|
+
* `options` strings or `{ value, label }`; `onChange` gets the value as a string (a number option's as a number). Enter,
|
|
71
|
+
* Space or ArrowDown opens; in the menu the arrows move, Enter picks, a letter jumps, Escape closes; focus comes back to
|
|
72
|
+
* the field.
|
|
73
|
+
* size sm (unset) the field; xs the filter (Home's), no fill, Figma's filter measured (plan-2026-11-23-editor-
|
|
73
74
|
* measured-against-figma W7): the value 8 in, the chevron's glyph 5 after it and 7 off the right edge
|
|
74
|
-
* tone unset: the outlined field, the
|
|
75
|
-
*
|
|
76
|
-
* after the value, so it hugs its value (the top rail's zoom)
|
|
75
|
+
* tone unset: the outlined field, the line only; `grey`: the unbordered field (the field fill at sm, bare at xs),
|
|
76
|
+
* padding 12 left and 4 right, the chevron 4 after the value, so it hugs its value (the top rail's zoom)
|
|
77
77
|
* menu a trigger for its own overlay instead of the option list (the zoom's): menu({ anchor, open, onClose }) is drawn
|
|
78
78
|
* in place of the Menu, and the field reads `value` as it is
|
|
79
79
|
* ariaLabel what it chooses, as KOL's Dropdown; other props (disabled, data-*) land on the button
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
function DropdownKolbox({ size, tone, value, options = [], onChange, menu, ariaLabel, align = 'left', className = '', variant, accent, ...rest }) {
|
|
80
|
+
* a `value` no option holds is shown as it is (Folio on kolbox, 2026-11-22) */
|
|
81
|
+
function DropdownField({ size, tone, value, options = [], onChange, menu, ariaLabel, align = 'left', className = '', variant, accent, ...rest }) { // eslint-disable-line no-unused-vars
|
|
83
82
|
const ref = useRef(null)
|
|
84
83
|
const [open, setOpen] = useState(false)
|
|
85
84
|
const outlined = tone !== 'grey'
|
|
@@ -98,6 +97,7 @@ function DropdownKolbox({ size, tone, value, options = [], onChange, menu, ariaL
|
|
|
98
97
|
const on = o === current
|
|
99
98
|
groups.at(-1).push({ label: o.label, value: o.value, check: held ? on : undefined, highlighted: on })
|
|
100
99
|
}
|
|
100
|
+
/* `kol-dd--kolbox` and `kol-dd-caret--kolbox` ride along as hooks for kol-fxr's own rules, on the retirement ledger */
|
|
101
101
|
return (
|
|
102
102
|
<>
|
|
103
103
|
<button
|
|
@@ -115,20 +115,19 @@ function DropdownKolbox({ size, tone, value, options = [], onChange, menu, ariaL
|
|
|
115
115
|
e.preventDefault(); e.stopPropagation()
|
|
116
116
|
if (e.key !== 'ArrowUp') setOpen(true)
|
|
117
117
|
}}
|
|
118
|
-
className={`kol-dd--kolbox${outlined ? ' kol-dd--
|
|
118
|
+
className={`kol-dd-field kol-dd--kolbox${outlined ? ' kol-dd-field--outlined' : ''}${outlined && open ? ' is-open' : ''}${!outlined && !xs ? ' kol-dd-field--filled' : ''} relative flex min-w-0 cursor-pointer items-center disabled:cursor-default disabled:opacity-40 ${xs ? 'h-[var(--kol-dd-field-xs-h,var(--kol-ctl-xs))] bg-transparent' : 'h-[var(--kol-dd-field-h,var(--kol-ctl-sm))]'} text-left outline-none ${outlined ? (xs ? 'gap-0.5 border pr-[3px] pl-[7px]' : 'gap-2 border px-2') : 'gap-1 pr-1 pl-3 focus-visible:outline-1'} ${className}`}
|
|
119
119
|
{...rest}
|
|
120
120
|
>
|
|
121
121
|
<span className="min-w-0 flex-1 truncate">{current?.label}</span>
|
|
122
|
-
<KolboxGlyph name="chevron-down" className="kol-dd-caret--kolbox pointer-events-none" />
|
|
122
|
+
<KolboxGlyph name="chevron-down" className="kol-dd-field-caret kol-dd-caret--kolbox pointer-events-none" />
|
|
123
123
|
</button>
|
|
124
124
|
{menu ? menu({ anchor: ref, open, onClose: close }) : <Menu
|
|
125
|
-
variant="kolbox"
|
|
126
125
|
anchor={ref}
|
|
127
126
|
open={open}
|
|
128
127
|
onClose={close}
|
|
129
128
|
onSelect={(row) => onChange?.(typeof row.value === 'number' ? row.value : String(row.value))}
|
|
130
129
|
groups={groups}
|
|
131
|
-
placement={align
|
|
130
|
+
placement={/right/.test(align) ? 'bottom-end' : 'bottom-start'}
|
|
132
131
|
accent={accent}
|
|
133
132
|
aria-label={ariaLabel}
|
|
134
133
|
minWidth={ref.current?.offsetWidth}
|
|
@@ -137,42 +136,11 @@ function DropdownKolbox({ size, tone, value, options = [], onChange, menu, ariaL
|
|
|
137
136
|
)
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
/*
|
|
141
|
-
*
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
* bottom-right: the list's edge and side. */
|
|
146
|
-
function DropdownFolio({ value, options = [], onChange, ariaLabel, disabled, align = 'left', className = '', accent }) {
|
|
147
|
-
const [open, setOpen] = useState(false)
|
|
148
|
-
const box = useRef(null)
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
if (!open) return undefined
|
|
151
|
-
const off = (e) => { if (!box.current?.contains(e.target)) setOpen(false) }
|
|
152
|
-
const esc = (e) => e.key === 'Escape' && setOpen(false)
|
|
153
|
-
addEventListener('mousedown', off); addEventListener('keydown', esc)
|
|
154
|
-
return () => { removeEventListener('mousedown', off); removeEventListener('keydown', esc) }
|
|
155
|
-
}, [open])
|
|
156
|
-
const current = options.find((o) => o.value === value)?.label ?? value
|
|
157
|
-
return (
|
|
158
|
-
<span data-accent={accent === 'secondary' ? accent : undefined} ref={box} className="relative inline-flex">
|
|
159
|
-
<button type="button" aria-label={ariaLabel} aria-haspopup="listbox" aria-expanded={open} disabled={disabled} onClick={() => setOpen(!open)} className={`kol-dd--folio inline-flex items-center gap-[4px] rounded-[3px] disabled:cursor-default ${className}`}>
|
|
160
|
-
{current}{!disabled && <span aria-hidden className="kol-dd-caret--folio">⌄</span>}
|
|
161
|
-
</button>
|
|
162
|
-
{open && (
|
|
163
|
-
<span role="listbox" aria-label={ariaLabel} className={`kol-dd-list--folio absolute z-50 flex min-w-[160px] flex-col rounded-[3px] border py-[4px] ${/right/.test(align) ? 'right-0' : 'left-0'} ${/bottom/.test(align) ? 'bottom-[calc(100%+6px)]' : 'top-[calc(100%+6px)]'}`}>
|
|
164
|
-
{options.map((o) => (
|
|
165
|
-
<button key={o.value} type="button" role="option" aria-selected={o.value === value} onClick={() => { setOpen(false); onChange?.(o.value) }} className={`kol-dd-option--folio${o.value === value ? ' is-current' : ''} flex items-center gap-[8px] whitespace-nowrap px-[12px] py-[7px] text-left`}>
|
|
166
|
-
<span aria-hidden className="kol-dd-check--folio inline-flex size-[16px] shrink-0 items-center justify-center">{o.value === value ? '✓' : ''}</span>{o.label}
|
|
167
|
-
</button>
|
|
168
|
-
))}
|
|
169
|
-
</span>
|
|
170
|
-
)}
|
|
171
|
-
</span>
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const Dropdown = (props) => (props.variant === 'kolbox' ? <DropdownKolbox {...props} /> : props.variant === 'folio' ? <DropdownFolio {...props} /> : <DropdownOn {...props} />)
|
|
139
|
+
/* the old theme words in `variant`: accepted, and they ask for the field (`fused={false}`), the build kolbox and Folio
|
|
140
|
+
* drew (W3, on the retirement ledger); the theme draws its look. Folio's own list went to _tmp/2026-11-29-one-set-fold/. */
|
|
141
|
+
const THEME_WORDS = ['kolbox', 'folio']
|
|
142
|
+
/* `fused` (true unset): the one-piece select, its list continuing the trigger; false: the field, its list a Menu under it */
|
|
143
|
+
const Dropdown = ({ fused, ...props }) => ((fused ?? !THEME_WORDS.includes(props.variant)) ? <DropdownOn {...props} /> : <DropdownField {...props} />)
|
|
176
144
|
|
|
177
145
|
const DropdownOn = ({
|
|
178
146
|
options = [],
|
|
@@ -271,7 +239,7 @@ const DropdownOn = ({
|
|
|
271
239
|
|
|
272
240
|
/* `variant="raised"` retires into `tone="faint"` (2026-10-31) — the alias, until nobody passes it */
|
|
273
241
|
if (variant === 'raised') { variant = undefined; tone = 'faint' }
|
|
274
|
-
const resolvedVariant = LEGACY_VARIANTS[variant] || variant
|
|
242
|
+
const resolvedVariant = THEME_WORDS.includes(variant) ? undefined : LEGACY_VARIANTS[variant] || variant
|
|
275
243
|
|
|
276
244
|
/* The panel is `Menu fused` (plan-2026-10-31-menu-engine W1.3): below the trigger, never flipped (the fused edge
|
|
277
245
|
* assumes below), the trigger's width, a listbox. */
|