@kolkrabbi/kol-component 0.328.0 → 0.330.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 +4 -4
- package/src/atoms/BezierPathEditor.jsx +171 -0
- package/src/atoms/FunctionPlot.jsx +109 -0
- package/src/atoms/OriginPicker.jsx +111 -0
- package/src/index.js +6 -0
- package/src/molecules/Combobox.jsx +5 -5
- package/src/molecules/ContextMenu.jsx +9 -39
- package/src/molecules/Dropdown.jsx +49 -72
- package/src/molecules/Menu.jsx +77 -38
- package/src/molecules/MenuItem.jsx +51 -53
- package/src/molecules/MultiSelect.jsx +44 -41
- package/src/molecules/ParamBindDot.jsx +79 -0
- package/src/molecules/ShapeDropdown.jsx +5 -5
- package/src/molecules/SplitToolButton.jsx +3 -2
- package/src/molecules/StepList.jsx +34 -8
- package/src/organisms/AppItemMenuProvider.jsx +4 -4
- package/src/organisms/ColorPickerPopover.jsx +7 -1
- package/src/organisms/LayerStack.jsx +7 -7
- package/src/organisms/MediaLibrary.jsx +4 -4
- package/src/organisms/MediaLibraryPages.jsx +46 -46
- package/src/organisms/NavRail.jsx +1 -1
- package/src/organisms/SettingsPanel.jsx +3 -6
- package/src/utilities/tone.js +4 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
2
|
-
import { toneClass
|
|
2
|
+
import { toneClass } from '../utilities/tone.js'
|
|
3
3
|
import { Icon } from '@kolkrabbi/kol-icons'
|
|
4
4
|
import { MenuRow, MenuDivider } from './MenuItem.jsx'
|
|
5
|
-
import {
|
|
5
|
+
import { Menu } from './Menu.jsx'
|
|
6
6
|
import { glyphSize, indicatorSize } from '../hooks/glyphLadders.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -22,8 +22,8 @@ import { glyphSize, indicatorSize } from '../hooks/glyphLadders.js'
|
|
|
22
22
|
* tone="inverse" — the dark chip (`fg-ab-24`) for a washed
|
|
23
23
|
* plane, the panel continuing it (ControlToneInverse,
|
|
24
24
|
* kol-website 2026-08-27); same prop on ViewToggle · Input
|
|
25
|
-
* variant="raised" —
|
|
26
|
-
*
|
|
25
|
+
* variant="raised" — RETIRING (2026-10-31): an alias of `tone="faint"`, the oq-06 tone it only ever
|
|
26
|
+
* differed by. Use the tone.
|
|
27
27
|
* variant="outline" — bordered trigger; open panel carries the
|
|
28
28
|
* same border, trigger's bottom edge acts as the divider
|
|
29
29
|
*
|
|
@@ -122,18 +122,17 @@ const Dropdown = ({
|
|
|
122
122
|
* as SegmentedToggle's. An aria-label replaces the button's text, so the current value rides along
|
|
123
123
|
* after it — "Color view, Hue" — and is still announced. */
|
|
124
124
|
ariaLabel,
|
|
125
|
+
/* `multiple` — many-of-N (SettingsMulti, metric 2026-10-31 — user: *"some werid bastardisation of multiselect"*).
|
|
126
|
+
* `value` is an array or Set, every row toggles (`onChange(value)` per click) and carries the check while on, the
|
|
127
|
+
* list stays open, and the trigger reads `label` — no fake summary row, no ✓ typed into labels. */
|
|
128
|
+
multiple = false,
|
|
129
|
+
label,
|
|
125
130
|
className = ''
|
|
126
131
|
}) => {
|
|
127
132
|
const [isOpen, setIsOpen] = useState(defaultOpen)
|
|
128
133
|
|
|
129
|
-
/*
|
|
130
|
-
* INHERITS from a toned wrapper never reaches it through the cascade — the
|
|
131
|
-
* exact failure the 2026-08-30 page-wash attempt hit. On open, copy the
|
|
132
|
-
* trigger's RESOLVED `--kol-tone-*` onto the panel as inline style: an
|
|
133
|
-
* explicit variant / tone class on the panel sets the same values, and the
|
|
134
|
-
* ambient case is the one only this can serve. */
|
|
134
|
+
/* the trigger's tone reaches the portalled panel through `Menu` (it copies `--kol-tone-*` on open) */
|
|
135
135
|
const triggerRef = useRef(null)
|
|
136
|
-
const [ambient, setAmbient] = useState(null)
|
|
137
136
|
/* …AND SO IS A ZOOM (2026-10-02, kol-monitor's rack — user: *"what about the dropdown in general?
|
|
138
137
|
* its kinda wrong no"*). A trigger inside a zoomed surface (the rack at 80%) is drawn smaller,
|
|
139
138
|
* but the portalled list was not: it kept its full-size type inside a panel pinned to the
|
|
@@ -144,10 +143,6 @@ const Dropdown = ({
|
|
|
144
143
|
const [inPanel, setInPanel] = useState(false)
|
|
145
144
|
useLayoutEffect(() => {
|
|
146
145
|
if (!isOpen || !triggerRef.current) return
|
|
147
|
-
const cs = getComputedStyle(triggerRef.current)
|
|
148
|
-
const vars = {}
|
|
149
|
-
for (const v of TONE_VARS) { const val = cs.getPropertyValue(v).trim(); if (val) vars[v] = val }
|
|
150
|
-
setAmbient(vars)
|
|
151
146
|
const laid = triggerRef.current.offsetWidth
|
|
152
147
|
const s = laid ? triggerRef.current.getBoundingClientRect().width / laid : 1
|
|
153
148
|
setScale(Math.abs(s - 1) > 0.01 ? s : 1)
|
|
@@ -159,22 +154,12 @@ const Dropdown = ({
|
|
|
159
154
|
// sm everywhere unless explicitly overridden (see docblock size law).
|
|
160
155
|
const resolvedSize = size || 'sm'
|
|
161
156
|
|
|
157
|
+
/* `variant="raised"` retires into `tone="faint"` (2026-10-31) — the alias, until nobody passes it */
|
|
158
|
+
if (variant === 'raised') { variant = undefined; tone = 'faint' }
|
|
162
159
|
const resolvedVariant = LEGACY_VARIANTS[variant] || variant
|
|
163
160
|
|
|
164
|
-
/*
|
|
165
|
-
*
|
|
166
|
-
* sits below; flipping above would visually disconnect them.
|
|
167
|
-
* `matchReferenceWidth: true` pins panel min-width to the button. */
|
|
168
|
-
const popover = usePopover({
|
|
169
|
-
open: isOpen,
|
|
170
|
-
onOpenChange: setIsOpen,
|
|
171
|
-
placement: 'bottom-start',
|
|
172
|
-
offset: -1,
|
|
173
|
-
flip: false,
|
|
174
|
-
matchReferenceWidth: true,
|
|
175
|
-
role: 'listbox',
|
|
176
|
-
dismiss: stayOpen ? { outsidePress: false } : true,
|
|
177
|
-
})
|
|
161
|
+
/* The panel is `Menu fused` (plan-2026-10-31-menu-engine W1.3): below the trigger, never flipped (the fused edge
|
|
162
|
+
* assumes below), the trigger's width, a listbox. */
|
|
178
163
|
|
|
179
164
|
/* Width belongs to the CALL SITE (2026-08-09 user call — "width without any
|
|
180
165
|
* regard to context"). The viewport-keyed resize listener that handed every
|
|
@@ -184,7 +169,7 @@ const Dropdown = ({
|
|
|
184
169
|
|
|
185
170
|
const handleSelect = (option) => {
|
|
186
171
|
onChange?.(option.value)
|
|
187
|
-
setIsOpen(false)
|
|
172
|
+
if (!multiple) setIsOpen(false)
|
|
188
173
|
}
|
|
189
174
|
|
|
190
175
|
/* the hover report, and the close that ends it. `hovered` is a ref, not
|
|
@@ -208,7 +193,8 @@ const Dropdown = ({
|
|
|
208
193
|
/* `{ heading: 'Variant' }` names the list (2026-10-01 — user: "first item 'variant' then divider
|
|
209
194
|
* then the list"): a row that says what the dropdown sets, never a choice. */
|
|
210
195
|
const choices = options.filter((opt) => !opt?.divider && !opt?.heading)
|
|
211
|
-
const
|
|
196
|
+
const picked = multiple ? (value instanceof Set ? value : new Set(value ?? [])) : null
|
|
197
|
+
const currentOption = multiple ? { label } : choices.find((opt) => opt.value === value) || choices[0]
|
|
212
198
|
|
|
213
199
|
/* A clamped list (Popover caps the panel to the viewport) can open with the
|
|
214
200
|
* checked row past the fold — scroll it into reach. Keyboard focus after
|
|
@@ -239,11 +225,10 @@ const Dropdown = ({
|
|
|
239
225
|
toneClass(tone),
|
|
240
226
|
].filter(Boolean).join(' ')
|
|
241
227
|
|
|
242
|
-
|
|
243
|
-
<div className={`kol-dd-root relative inline-block align-middle ${className}`}>
|
|
228
|
+
const trig = ({ props }) => (
|
|
244
229
|
<button
|
|
245
|
-
ref={
|
|
246
|
-
{...
|
|
230
|
+
ref={triggerRef}
|
|
231
|
+
{...props}
|
|
247
232
|
type="button"
|
|
248
233
|
className={triggerCls}
|
|
249
234
|
aria-haspopup="listbox"
|
|
@@ -269,6 +254,7 @@ const Dropdown = ({
|
|
|
269
254
|
{option.label}
|
|
270
255
|
</span>
|
|
271
256
|
))}
|
|
257
|
+
{multiple && <span className="kol-dd-ghost" aria-hidden="true">{label}</span>}
|
|
272
258
|
</span>
|
|
273
259
|
{/* chrome lives in .kol-dd-caret (trailing edge + open-state flip) —
|
|
274
260
|
* keyed off the trigger's data-state, no inline styles */}
|
|
@@ -279,40 +265,38 @@ const Dropdown = ({
|
|
|
279
265
|
here so the square keeps ONE implementation */}
|
|
280
266
|
{triggerAdornment}
|
|
281
267
|
</button>
|
|
268
|
+
)
|
|
282
269
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
270
|
+
return (
|
|
271
|
+
<Menu
|
|
272
|
+
fused
|
|
273
|
+
role="listbox"
|
|
274
|
+
open={isOpen}
|
|
275
|
+
onOpenChange={setIsOpen}
|
|
276
|
+
stayOpen={stayOpen}
|
|
277
|
+
closeOnSelect={!multiple}
|
|
278
|
+
rootClassName={`kol-dd-root relative inline-block align-middle ${className}`}
|
|
279
|
+
trigger={trig}
|
|
280
|
+
panelClassName={`${resolvedVariant ? `kol-dd-panel--${resolvedVariant}` : ''} ${toneClass(tone)} ${inPanel ? 'kol-hw-panel' : ''}`.replace(/\s+/g, ' ').trim()}
|
|
281
|
+
panelStyle={{
|
|
282
|
+
'--kol-dd-max-rows': maxRows ?? 10,
|
|
283
|
+
/* a row is the trigger's height; the panel's max-height reads it */
|
|
284
|
+
'--kol-dd-row-h': rowHeight == null ? `var(--kol-ctl-${resolvedSize})` : typeof rowHeight === 'number' ? `${rowHeight}px` : rowHeight,
|
|
285
|
+
}}
|
|
286
|
+
>
|
|
296
287
|
{/* THE HAIRLINE UNDER THE TRIGGER, ALWAYS (2026-10-02 — user: *"I see it sometimes and sometimes
|
|
297
|
-
* not"*).
|
|
298
|
-
* got none, and an outline one lost its divider too — the panel sits 1px over the trigger's
|
|
299
|
-
* bottom border, which was meant to be it. One rule: an open dropdown has the line. */}
|
|
288
|
+
* not"*). One rule: an open dropdown has the line. */}
|
|
300
289
|
<div className="kol-dd-div" />
|
|
301
290
|
|
|
302
|
-
<div ref={listRef} className="kol-dd-list" role="listbox" style={scale !== 1 ? { zoom: scale } : undefined}>
|
|
291
|
+
<div ref={listRef} className="kol-dd-list" role="listbox" aria-multiselectable={multiple || undefined} style={scale !== 1 ? { zoom: scale } : undefined}>
|
|
303
292
|
{options.map((option, i) => {
|
|
304
293
|
if (option?.divider) return <MenuDivider key={`divider-${i}`} />
|
|
305
294
|
if (option?.heading) return <div key={`heading-${i}`} className={`${resolvedSize === 'xs' ? 'kol-mono-8' : 'kol-helper-12'} ${ROW_H[resolvedSize] ?? ROW_H.sm} ${ROW_PAD[resolvedSize] ?? ROW_PAD.sm} flex shrink-0 items-center text-meta`}>{option.heading}</div>
|
|
306
|
-
const isActive = option.value === currentOption?.value
|
|
295
|
+
const isActive = multiple ? picked.has(option.value) : option.value === currentOption?.value
|
|
307
296
|
return (
|
|
308
297
|
<MenuRow
|
|
309
298
|
key={option.value}
|
|
310
|
-
/* NO HOVER STATE ANYWHERE ON A DROPDOWN (user 2026-08-28
|
|
311
|
-
* "delete any hover state on dropdowns"): the trigger was
|
|
312
|
-
* already pinned in all three variants — primary and outline
|
|
313
|
-
* back to rest in kol-theme, grey carrying no hover rule at
|
|
314
|
-
* all — and this was the last one left, the option row's ink
|
|
315
|
-
* brighten. The check mark is what marks the current value. */
|
|
299
|
+
/* NO HOVER STATE ANYWHERE ON A DROPDOWN (user 2026-08-28) — the indicator marks the current value. */
|
|
316
300
|
hover={false}
|
|
317
301
|
size={resolvedSize}
|
|
318
302
|
rowClass={ROW[resolvedSize] ?? ROW.sm}
|
|
@@ -320,17 +304,11 @@ const Dropdown = ({
|
|
|
320
304
|
onPointerEnter={onOptionHover ? () => reportHover(option.value) : undefined}
|
|
321
305
|
onPointerLeave={onOptionHover ? () => reportHover(null) : undefined}
|
|
322
306
|
onClick={() => handleSelect(option)}
|
|
323
|
-
/* The
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
* is armed (editor-set-is-behind-its-source, 2026-09-03). */
|
|
329
|
-
shortcut={
|
|
330
|
-
isActive
|
|
331
|
-
? <Icon name="check" size={resolvedSize === 'xs' ? indicatorSize('xs') : 11} />
|
|
332
|
-
: option.shortcut
|
|
333
|
-
}
|
|
307
|
+
/* The current row's mark is the INDICATOR, always — • for the one pick, ✓ (the check icon) for each
|
|
308
|
+
* row on in a `multiple` (plan-2026-10-31-menu-engine W2). An option's own `shortcut` shows on the
|
|
309
|
+
* rows that are not current — the tool-palette idiom (editor-set-is-behind-its-source, 2026-09-03). */
|
|
310
|
+
indicator={isActive ? (multiple ? 'check' : 'dot') : undefined}
|
|
311
|
+
shortcut={isActive ? undefined : option.shortcut}
|
|
334
312
|
>
|
|
335
313
|
{/* an option's leading glyph — the ADJACENT ladder, because it
|
|
336
314
|
* sits in a line box beside a label, never the solo rung */}
|
|
@@ -344,8 +322,7 @@ const Dropdown = ({
|
|
|
344
322
|
)
|
|
345
323
|
})}
|
|
346
324
|
</div>
|
|
347
|
-
|
|
348
|
-
</div>
|
|
325
|
+
</Menu>
|
|
349
326
|
)
|
|
350
327
|
}
|
|
351
328
|
|
package/src/molecules/Menu.jsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
2
2
|
import { Icon } from '@kolkrabbi/kol-icons'
|
|
3
3
|
import Button from '../atoms/Button.jsx'
|
|
4
|
-
import Kbd from '../atoms/Kbd.jsx'
|
|
5
4
|
import SearchInput from './SearchInput.jsx'
|
|
6
5
|
import { MenuRow, MenuDivider, MenuFlyout } from './MenuItem.jsx'
|
|
7
6
|
import { PopoverPanel, usePopover, Tooltip } from '../utilities/Popover.jsx'
|
|
7
|
+
import { TONE_VARS } from '../utilities/tone.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The Menu* family (metric Round 4, 2026-10-31) — one family, one prefix.
|
|
@@ -25,8 +25,8 @@ import { PopoverPanel, usePopover, Tooltip } from '../utilities/Popover.jsx'
|
|
|
25
25
|
* { label: 'Export stats', trailing: 'download', onClick },
|
|
26
26
|
* ]} />
|
|
27
27
|
*
|
|
28
|
-
* row keys: `icon` (kol-icons name or node) · `trailing` (+ `trailingSize`) · `current` fills the row · `
|
|
29
|
-
* (before the `kbd` cap) · `kbd` · `disabled` + `tooltip` (why) · `items` (a flyout of the same rows).
|
|
28
|
+
* row keys: `icon` (kol-icons name or node) · `trailing` (+ `trailingSize`) · `current` fills the row · `indicator`
|
|
29
|
+
* 'dot' (single pick) | 'check' (many-of-N) | 'chevron' · `checked` = 'check' (before the `kbd` cap) · `kbd` · `disabled` + `tooltip` (why) · `items` (a flyout of the same rows).
|
|
30
30
|
* `search` ({ placeholder, empty }) puts a search field above the rows and filters them by label.
|
|
31
31
|
* `children` sit above the rows.
|
|
32
32
|
*/
|
|
@@ -50,20 +50,9 @@ export const MenuPanel = ({ className = '', children, ...rest }) => (
|
|
|
50
50
|
export const MenuLabel = ({ children }) => <div className="kol-menu-label kol-helper-12">{children}</div>
|
|
51
51
|
|
|
52
52
|
const glyph = (icon, size) => (typeof icon === 'string' ? <Icon name={icon} size={size} /> : icon)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (it.kbd != null) {
|
|
57
|
-
return (
|
|
58
|
-
<span className="inline-flex items-center gap-2">
|
|
59
|
-
{it.checked && <Check />}
|
|
60
|
-
<Kbd size="md" className="kol-menu-kbd">{it.kbd}</Kbd>
|
|
61
|
-
</span>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
if (it.checked) return <Check />
|
|
65
|
-
return it.trailing ? <span className="text-oq-88 inline-flex">{glyph(it.trailing, it.trailingSize ?? 14)}</span> : undefined
|
|
66
|
-
}
|
|
53
|
+
/* a row's trailing marks — real icons and Kbd only (W2): `indicator` 'dot' | 'check' | 'chevron', `checked` = 'check',
|
|
54
|
+
* `kbd` a key cap, `trailing` an icon name for an action (download) */
|
|
55
|
+
const indicatorOf = (it) => it.indicator ?? (it.checked ? 'check' : undefined)
|
|
67
56
|
|
|
68
57
|
function Rows({ items }) {
|
|
69
58
|
return items.map((it, i) => {
|
|
@@ -76,7 +65,8 @@ function Rows({ items }) {
|
|
|
76
65
|
<Rows items={it.items} />
|
|
77
66
|
</MenuFlyout>
|
|
78
67
|
) : (
|
|
79
|
-
<MenuRow href={it.href} disabled={it.disabled} rowClass={cls} onClick={it.onClick} iconLeft={icon}
|
|
68
|
+
<MenuRow href={it.href} disabled={it.disabled} rowClass={cls} onClick={it.onClick} iconLeft={icon} indicator={indicatorOf(it)} kbd={it.kbd}
|
|
69
|
+
shortcut={it.trailing ? <span className="text-oq-88 inline-flex">{glyph(it.trailing, it.trailingSize ?? 14)}</span> : undefined}>
|
|
80
70
|
{it.label}
|
|
81
71
|
</MenuRow>
|
|
82
72
|
)
|
|
@@ -87,38 +77,87 @@ function Rows({ items }) {
|
|
|
87
77
|
})
|
|
88
78
|
}
|
|
89
79
|
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Menu — THE menu engine (plan-2026-10-31-menu-engine W1). Every list that floats over a trigger is this: the Menu*
|
|
82
|
+
* menus, Dropdown (a `fused` select), MultiSelect (columns), MenuItem (a menubar entry), ContextMenu (a point).
|
|
83
|
+
*
|
|
84
|
+
* trigger render prop `({ open, props })` — any trigger: MenuTrigger chip, a select, the ⋮, a menubar button
|
|
85
|
+
* anchor `{ x, y }` instead of a trigger — the panel opens at a point (right-click)
|
|
86
|
+
* align 'start' | 'end' — the panel's edge flush with the trigger's
|
|
87
|
+
* fused the panel continues the trigger: no gap, its width, top corners squared, never flips
|
|
88
|
+
* tone nothing to pass: the trigger's resolved `--kol-tone-*` ride onto the portalled panel, so a menu in a
|
|
89
|
+
* `kol-tone-*` wrapper floats on that tone's surface
|
|
90
|
+
* closeOnSelect false keeps the panel open while rows toggle (a multiselect)
|
|
91
|
+
* open / onOpenChange controlled, when the caller needs the state
|
|
92
|
+
*/
|
|
93
|
+
export function Menu({
|
|
94
|
+
items, trigger, anchor, align = 'start', minWidth, offset = 4, defaultOpen = false, open: openProp, onOpenChange,
|
|
95
|
+
stayOpen = false, closeOnSelect = true, fused = false, search, role = 'menu',
|
|
96
|
+
panelClassName = '', panelStyle, rootClassName, className = '', children,
|
|
97
|
+
}) {
|
|
98
|
+
const [own, setOwn] = useState(defaultOpen)
|
|
99
|
+
const controlled = openProp !== undefined
|
|
100
|
+
const open = controlled ? openProp : own
|
|
101
|
+
const setOpen = (v) => { if (!controlled) setOwn(v); onOpenChange?.(v) }
|
|
92
102
|
const [q, setQ] = useState('')
|
|
93
103
|
const popover = usePopover({
|
|
94
104
|
open,
|
|
95
105
|
onOpenChange: setOpen,
|
|
96
|
-
placement: align === 'end' ? 'bottom-end' : 'bottom-start',
|
|
97
|
-
offset,
|
|
98
|
-
|
|
106
|
+
placement: anchor ? 'right-start' : align === 'end' ? 'bottom-end' : 'bottom-start',
|
|
107
|
+
offset: fused ? -1 : anchor ? 2 : offset,
|
|
108
|
+
flip: !fused,
|
|
109
|
+
matchReferenceWidth: fused,
|
|
110
|
+
click: !anchor,
|
|
111
|
+
role,
|
|
99
112
|
dismiss: stayOpen ? { outsidePress: false } : true,
|
|
100
113
|
})
|
|
101
|
-
|
|
114
|
+
|
|
115
|
+
/* a point anchor is a zero-size virtual rect — `setPositionReference`, never `elements.reference` (ContextMenu) */
|
|
116
|
+
const { setPositionReference } = popover.refs
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (!anchor) return
|
|
119
|
+
const { x, y } = anchor
|
|
120
|
+
setPositionReference({ getBoundingClientRect: () => ({ width: 0, height: 0, x, y, top: y, left: x, right: x, bottom: y }) })
|
|
121
|
+
}, [anchor?.x, anchor?.y, setPositionReference]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
122
|
+
|
|
123
|
+
/* THE PANEL IS PORTALLED, so a tone the trigger inherits never reaches it through the cascade — copy it on open */
|
|
124
|
+
const rootRef = useRef(null)
|
|
125
|
+
const [ambient, setAmbient] = useState(null)
|
|
126
|
+
useLayoutEffect(() => {
|
|
127
|
+
if (!open || !rootRef.current) return
|
|
128
|
+
const cs = getComputedStyle(rootRef.current.firstElementChild ?? rootRef.current)
|
|
129
|
+
const vars = {}
|
|
130
|
+
for (const v of TONE_VARS) { const val = cs.getPropertyValue(v).trim(); if (val) vars[v] = val }
|
|
131
|
+
setAmbient(vars)
|
|
132
|
+
}, [open])
|
|
133
|
+
|
|
134
|
+
let rows = items ?? []
|
|
102
135
|
if (search) {
|
|
103
136
|
const s = q.toLowerCase()
|
|
104
|
-
rows =
|
|
137
|
+
rows = rows.filter((it) => it.label == null || String(it.label).toLowerCase().includes(s))
|
|
105
138
|
if (!rows.some((it) => it.label != null)) rows = [...rows, { key: 'empty', label: search.empty || 'Nothing matches', disabled: true }]
|
|
106
139
|
}
|
|
107
140
|
/* the wrapper takes the ref (a Button need not forward one); the trigger takes the handlers and the aria —
|
|
108
141
|
* `aria-pressed` cleared, an open menu is `aria-expanded`, its fill is the trigger's `pressed` */
|
|
109
142
|
return (
|
|
110
143
|
<>
|
|
111
|
-
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
144
|
+
{trigger && (
|
|
145
|
+
<span ref={(el) => { rootRef.current = el; popover.refs.setReference(el) }} className={rootClassName ?? `inline-flex align-middle ${className}`.trim()}>
|
|
146
|
+
{trigger({ open, props: { ...popover.getReferenceProps(), 'aria-pressed': undefined } })}
|
|
147
|
+
</span>
|
|
148
|
+
)}
|
|
149
|
+
{open && (
|
|
150
|
+
<PopoverPanel popover={popover} panel={false} focus={false}
|
|
151
|
+
className={`kol-menu-panel${fused ? ' kol-menu-panel--fused' : ' w-max'} ${panelClassName}`.trim()}
|
|
152
|
+
style={{ ...ambient, ...(minWidth ? { minWidth } : null), ...panelStyle }}>
|
|
153
|
+
{/* a row's click closes the menu (it bubbles from `[data-menu-item]`); a flyout row only toggles */}
|
|
154
|
+
<div role="none" className="flex flex-col min-h-0" onClick={(e) => { if (closeOnSelect && e.target.closest('[data-menu-item]')) setOpen(false) }}>
|
|
155
|
+
{search && <div className="pb-1"><SearchInput variant="outline" size="sm" value={q} onChange={(e) => setQ(e.target?.value ?? e)} onClear={() => setQ('')} placeholder={search.placeholder || 'Search'} /></div>}
|
|
156
|
+
{typeof children === 'function' ? children({ close: () => setOpen(false) }) : children}
|
|
157
|
+
{rows.length > 0 && <Rows items={rows} />}
|
|
158
|
+
</div>
|
|
159
|
+
</PopoverPanel>
|
|
160
|
+
)}
|
|
122
161
|
</>
|
|
123
162
|
)
|
|
124
163
|
}
|
|
@@ -179,7 +218,7 @@ export function MenuDatePicker({ groups = [], value, onChange, label, icon = 'ca
|
|
|
179
218
|
const items = [
|
|
180
219
|
...groups.flatMap((g, i) => [
|
|
181
220
|
...(i > 0 ? [{ divider: true }] : []),
|
|
182
|
-
...g.map((r) => ({ key: r.key, label: r.label, current: r.key === value,
|
|
221
|
+
...g.map((r) => ({ key: r.key, label: r.label, current: r.key === value, indicator: r.key === value ? 'dot' : undefined, kbd: r.kbd, onClick: () => onChange?.(r.key) })),
|
|
183
222
|
]),
|
|
184
223
|
...(compare ? [{ divider: true }, { key: 'compare', label: compare.label, kbd: compare.kbd, onClick: compare.onClick }] : []),
|
|
185
224
|
]
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { useLayoutEffect, useRef, useState } from 'react'
|
|
2
2
|
import { Icon } from '@kolkrabbi/kol-icons'
|
|
3
|
-
import {
|
|
3
|
+
import { Menu } from './Menu.jsx'
|
|
4
|
+
import Kbd from '../atoms/Kbd.jsx'
|
|
5
|
+
import { indicatorSize } from '../hooks/glyphLadders.js'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* MenuItem — top-level menu entry. Trigger button + popover panel.
|
|
7
9
|
*
|
|
8
10
|
* <MenuItem label="File">
|
|
9
|
-
* <
|
|
10
|
-
* <
|
|
11
|
+
* <MenuRow onClick={…} kbd="⌘S">Save</MenuRow>
|
|
12
|
+
* <MenuRow onClick={…}>Export…</MenuRow>
|
|
11
13
|
* </MenuItem>
|
|
12
14
|
*
|
|
13
|
-
* Built on `usePopover` (`@floating-ui/react`): portal-rendered panel
|
|
15
|
+
* Built on `Menu` (the one engine, 2026-10-31), which is `usePopover` (`@floating-ui/react`): portal-rendered panel
|
|
14
16
|
* (escapes overflow), auto-flip + viewport shift, click-outside / Escape
|
|
15
17
|
* dismiss, focus management. `align="end"` switches the placement to
|
|
16
18
|
* `bottom-end` for right-aligned panels (Templates menu).
|
|
@@ -47,54 +49,34 @@ export function MenuItem({
|
|
|
47
49
|
* the panel's top lands on the bar's own line (MenuItemOffset, kol-fxr 2026-10-13) */
|
|
48
50
|
offset = 4,
|
|
49
51
|
}) {
|
|
50
|
-
|
|
51
|
-
const popover = usePopover({
|
|
52
|
-
open,
|
|
53
|
-
onOpenChange: setOpen,
|
|
54
|
-
placement: align === 'end' ? 'bottom-end' : 'bottom-start',
|
|
55
|
-
offset,
|
|
56
|
-
role: 'menu',
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
const close = () => setOpen(false)
|
|
60
|
-
|
|
52
|
+
/* `Menu` is the engine (plan-2026-10-31-menu-engine W1.4): this is a menubar trigger on it, the panel is the menu panel */
|
|
61
53
|
return (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
size={10}
|
|
75
|
-
style={{ transform: open ? 'rotate(180deg)' : 'rotate(0deg)', transition: 'transform 200ms' }}
|
|
76
|
-
/>
|
|
77
|
-
)}
|
|
78
|
-
</button>
|
|
79
|
-
{/* w-max: floats size to CONTENT, never to the containing block —
|
|
80
|
-
* same family law as ShapeDropdown's panel (2026-08-09 review). */}
|
|
81
|
-
<PopoverPanel
|
|
82
|
-
popover={popover}
|
|
83
|
-
panel={false}
|
|
84
|
-
focus={false}
|
|
85
|
-
className={`w-max bg-surface-secondary rounded ${panelClassName}`}
|
|
86
|
-
style={panelStyle}
|
|
87
|
-
>
|
|
88
|
-
<div
|
|
89
|
-
onClick={(e) => {
|
|
90
|
-
/* close on item click — items inside fire their handler then bubble. */
|
|
91
|
-
if (e.target.closest('[data-menu-item]')) close()
|
|
92
|
-
}}
|
|
54
|
+
<Menu
|
|
55
|
+
align={align}
|
|
56
|
+
offset={offset}
|
|
57
|
+
defaultOpen={defaultOpen}
|
|
58
|
+
panelClassName={panelClassName}
|
|
59
|
+
panelStyle={panelStyle}
|
|
60
|
+
trigger={({ open, props }) => (
|
|
61
|
+
<button
|
|
62
|
+
{...props}
|
|
63
|
+
type="button"
|
|
64
|
+
className={`kol-menu-btn ${TRIGGER_BY_SIZE[size] ?? TRIGGER_BY_SIZE.md} inline-flex items-center gap-2 rounded text-body hover:text-emphasis transition-colors ${buttonClassName}`}
|
|
65
|
+
style={{ height: TRIGGER_H[size] ?? TRIGGER_H.md }}
|
|
93
66
|
>
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
67
|
+
<span>{label}</span>
|
|
68
|
+
{caret && (
|
|
69
|
+
<Icon
|
|
70
|
+
name="chevron-down"
|
|
71
|
+
size={10}
|
|
72
|
+
style={{ transform: open ? 'rotate(180deg)' : 'rotate(0deg)', transition: 'transform 200ms' }}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
</button>
|
|
76
|
+
)}
|
|
77
|
+
>
|
|
78
|
+
{children}
|
|
79
|
+
</Menu>
|
|
98
80
|
)
|
|
99
81
|
}
|
|
100
82
|
|
|
@@ -119,7 +101,11 @@ export function MenuItem({
|
|
|
119
101
|
* strip). Use for visuals wider than a single icon.
|
|
120
102
|
* - iconLeft — leading icon, fixed 16px width column (rows align).
|
|
121
103
|
* - children — main label, flex-1.
|
|
122
|
-
* -
|
|
104
|
+
* - indicator — the row's state mark, ALWAYS a kol-icon (plan-2026-10-31-menu-engine W2, user: *"its mainly about
|
|
105
|
+
* using real icons, not typed symbols"*): `dot` the current pick of a single choice (*"• replaces ✓ for
|
|
106
|
+
* single picks, definitely"*), `check` a row that is on in a many-of-N, `chevron` a row that opens more.
|
|
107
|
+
* - kbd — a key, drawn as `Kbd`. Nothing trails a row unless the caller passes one of these.
|
|
108
|
+
* - shortcut — @deprecated: the free trailing node the typed ✓ › ⌘S came through. A string renders as `Kbd`.
|
|
123
109
|
*/
|
|
124
110
|
/* the row follows the trigger's rung (DropdownXsList, kol-monitor 2026-09-01):
|
|
125
111
|
* at xs the list kept sm rows — kol-helper-12 in a 32px pitch — inside a panel
|
|
@@ -134,7 +120,9 @@ const ROW_BY_SIZE = { xs: 'kol-mono-8 px-2 h-5', sm: 'kol-helper-12 px-2 h-8', m
|
|
|
134
120
|
/* `flex`, not `inline-flex` (MenuDropdownItemBlockRow, kol-fxr 2026-10-13): as bare children of a
|
|
135
121
|
* content-sized (`w-max`) panel, inline rows measured as ONE line — five starters ≈ 795px. A block
|
|
136
122
|
* row still fills a fixed panel through `w-full` and lets a content-sized one hug its longest label. */
|
|
137
|
-
|
|
123
|
+
const INDICATOR = { dot: 'ascii-dot', check: 'check', chevron: 'chevron-right' }
|
|
124
|
+
|
|
125
|
+
export function MenuRow({ href, onClick, onPointerEnter, onPointerLeave, disabled, prefix, iconLeft, indicator, kbd, shortcut, hover = true, height, size = 'sm', rowClass, children }) {
|
|
138
126
|
/* `href` makes the row a real link — cmd/ctrl-click and middle-click open a new tab (DocumentHeader, 2026-10-31);
|
|
139
127
|
* a plain click still runs `onClick` (the app's router), which may preventDefault */
|
|
140
128
|
const Row = href && !disabled ? 'a' : 'button'
|
|
@@ -156,7 +144,17 @@ export function MenuRow({ href, onClick, onPointerEnter, onPointerLeave, disable
|
|
|
156
144
|
* loses its g). The h-8 centered row absorbs the taller line box —
|
|
157
145
|
* zero layout shift (MenuItemDescenderClip, 2026-08-12). */}
|
|
158
146
|
<span className="flex-1 truncate leading-normal">{children}</span>
|
|
159
|
-
{
|
|
147
|
+
{(indicator || kbd != null || shortcut) && (
|
|
148
|
+
<span className="shrink-0 inline-flex items-center gap-2 text-oq-88">
|
|
149
|
+
{/* the dot is kol-icons `ascii-dot` drawn at twice the slot and pulled back into it: at the slot's own size its
|
|
150
|
+
* 2.25/24 circle is a 2.6px speck; at 24 it is the rail's • (≈4.5px) and still takes the check's 14px column */}
|
|
151
|
+
{indicator === 'dot'
|
|
152
|
+
? <Icon name="ascii-dot" size={size === 'xs' ? 16 : 24} style={{ margin: size === 'xs' ? -4 : -5 }} />
|
|
153
|
+
: indicator && <Icon name={INDICATOR[indicator] ?? indicator} size={size === 'xs' ? indicatorSize('xs') : 14} />}
|
|
154
|
+
{kbd != null && <Kbd size="md" className="kol-menu-kbd">{kbd}</Kbd>}
|
|
155
|
+
{typeof shortcut === 'string' ? <Kbd size="md" className="kol-menu-kbd">{shortcut}</Kbd> : shortcut}
|
|
156
|
+
</span>
|
|
157
|
+
)}
|
|
160
158
|
</Row>
|
|
161
159
|
)
|
|
162
160
|
}
|