@kolkrabbi/kol-component 0.387.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 +1 -1
- package/src/index.js +1 -1
- 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 +8 -24
- package/src/utilities/Popover.jsx +8 -4
package/package.json
CHANGED
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'
|
|
@@ -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. */
|
package/src/molecules/Menu.jsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import { IconLoader } from '@kolkrabbi/kol-icons'
|
|
3
3
|
import Button from '../atoms/Button.jsx'
|
|
4
4
|
import KolboxGlyph from '../utilities/kolboxGlyph.jsx'
|
|
5
5
|
import { MenuRow, MenuDivider } from './MenuItem.jsx'
|
|
6
6
|
import { MenuList, MenuLabel } from './MenuList.jsx'
|
|
7
|
-
import { PopoverPanel,
|
|
7
|
+
import { PopoverPanel, usePopover, spend } from '../utilities/Popover.jsx'
|
|
8
8
|
import { TONE_VARS } from '../utilities/tone.js'
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -53,53 +53,12 @@ export const MenuPanel = ({ className = '', children, ...rest }) => (
|
|
|
53
53
|
export { MenuLabel }
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
/* ── the kolbox look (plan-2026-11-18-kolbox-system W31.2 batch 4, 2026-11-18) ──
|
|
57
|
-
* kolbox's Menu carried line for line, the chrome in kol-theme `.kol-menu--kolbox` and its rows. Its own API, which no
|
|
58
|
-
* other look shares: an `anchor` (an element, a ref, or anything with getBoundingClientRect), controlled `open` with
|
|
59
|
-
* `onClose`, `onSelect(row)`, and `groups` `[[row, ...], { title, rows: [...] }]` with a rule between groups; a row is
|
|
60
|
-
* `{ label, value, icon, check, shortcut, tag, submenu, disabled, highlighted, inset }`; `highlighted` marks the chosen row
|
|
61
|
-
* (where the keys start, the row an `over` list lays on its field), never a lit row: a menu opens with none lit. KOL's words where they are the
|
|
62
|
-
* same thing: `aria-label`, `minWidth`, `panelClassName` (the panel's class), `children` (a node above the rows: the
|
|
63
|
-
* zoom menu's field). A row's `icon` is the set's name. `placement` is the layer's (`PopoverLayer`): bottom-start, left-start, right-start, beside, over
|
|
64
|
-
* (a Dropdown's list lying over its field). */
|
|
65
|
-
|
|
66
|
-
/* One row: a leading check or icon, the label, then a shortcut, a tag or a submenu chevron. The active row (the pointer's
|
|
67
|
-
or the keys') is solid accent with on-accent ink. The pointer lights a row when it moves on it, so a list that opens
|
|
68
|
-
under a resting pointer (a dropdown laid over its field) opens with no row lit.
|
|
69
|
-
`inset`: a row with no glyph held in the glyph's column. */
|
|
70
|
-
function MenuRowKolbox({ row, index, lead, active, onEnter, onPick }) {
|
|
71
|
-
const { label, icon, check, shortcut, tag, submenu, disabled, inset } = row
|
|
72
|
-
return (
|
|
73
|
-
<div
|
|
74
|
-
role={check === undefined ? 'menuitem' : 'menuitemcheckbox'}
|
|
75
|
-
aria-checked={check === undefined ? undefined : !!check}
|
|
76
|
-
aria-disabled={disabled || undefined}
|
|
77
|
-
aria-haspopup={submenu ? 'menu' : undefined}
|
|
78
|
-
data-menu-row={index}
|
|
79
|
-
data-active={active || undefined}
|
|
80
|
-
data-chosen={row.highlighted || undefined}
|
|
81
|
-
onPointerMove={disabled || active ? undefined : onEnter}
|
|
82
|
-
onClick={disabled ? undefined : onPick}
|
|
83
|
-
className={`kol-menu-row--kolbox${disabled ? ' is-disabled' : active ? ' is-active' : ''} flex h-6 shrink-0 cursor-default items-center gap-2 px-2 whitespace-nowrap${disabled ? ' opacity-50' : ''}`}
|
|
84
|
-
>
|
|
85
|
-
{lead ? (
|
|
86
|
-
<span className="flex size-4 shrink-0 items-center justify-center">
|
|
87
|
-
{check ? <KolboxGlyph name="check" size={12} /> : icon ? <KolboxGlyph name={icon} /> : null}
|
|
88
|
-
</span>
|
|
89
|
-
) : icon ? <KolboxGlyph name={icon} /> : inset && <span className="size-4 shrink-0" />}
|
|
90
|
-
<span className="flex-1">{label}</span>
|
|
91
|
-
{shortcut && <span className={`shrink-0 ${active ? '' : 'kol-menu-sub--kolbox'}`}>{shortcut}</span>}
|
|
92
|
-
{tag && <span className={`kol-menu-tag--kolbox${active ? ' is-active' : ''} px-1`}>{tag}</span>}
|
|
93
|
-
{submenu && <KolboxGlyph name="chevron-right" className={active ? '' : 'kol-menu-sub--kolbox'} />}
|
|
94
|
-
</div>
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
56
|
/**
|
|
99
|
-
* MenuScroll — the foot of a
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
57
|
+
* MenuScroll — the foot of a menu taller than the window (Menu family, W31.2 batch 4; Figma 288:8017): the full panel
|
|
58
|
+
* width, 24 high, the 12 chevron-down centred in oq-64. While the pointer is on it the panel scrolls down, 4 px a frame,
|
|
59
|
+
* until the end or the pointer leaves. It sits sticky on the menu's own fill so the rows pass under it. `Menu` draws it on
|
|
60
|
+
* its own when its panel scrolls (the theme gives the panel a height cap: kolbox's, the window less 16); `panel` is the
|
|
61
|
+
* scrolling panel's ref.
|
|
103
62
|
*/
|
|
104
63
|
export function MenuScroll({ panel }) {
|
|
105
64
|
const run = useRef(0)
|
|
@@ -113,224 +72,126 @@ export function MenuScroll({ panel }) {
|
|
|
113
72
|
useEffect(() => stop, [])
|
|
114
73
|
return (
|
|
115
74
|
<div data-menu-more="" aria-hidden onPointerEnter={go} onPointerLeave={stop}
|
|
116
|
-
className="kol-menu-scroll
|
|
75
|
+
className="kol-menu-scroll sticky flex h-6 shrink-0 items-center justify-center">
|
|
117
76
|
<KolboxGlyph name="chevron-down" />
|
|
118
77
|
</div>
|
|
119
78
|
)
|
|
120
79
|
}
|
|
121
80
|
|
|
122
|
-
/*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
/* focus once, when the panel mounts: a flyout takes the keys while it is open */
|
|
141
|
-
const panel = useRef(null)
|
|
142
|
-
const [more, setMore] = useState(false)
|
|
143
|
-
const measure = useCallback(() => { const p = panel.current; if (p) setMore(p.scrollHeight - p.scrollTop - p.clientHeight > 1) }, [])
|
|
144
|
-
const mount = useCallback((node) => { panel.current = node; node?.focus({ preventScroll: true }); if (node) requestAnimationFrame(measure) }, [measure])
|
|
145
|
-
const refocus = () => panel.current?.focus({ preventScroll: true })
|
|
146
|
-
/* the keys move the lit row; a long list follows it */
|
|
147
|
-
useEffect(() => { panel.current?.querySelector(`[data-menu-row="${active}"]`)?.scrollIntoView({ block: 'nearest' }) }, [active])
|
|
148
|
-
|
|
149
|
-
const pick = (row) => { onSelect?.(row); onClose?.() }
|
|
150
|
-
const show = (i) => { if (flyout !== null && flyout !== i) refocus(); setFlyout(i !== null && rows[i]?.submenu && !rows[i].disabled ? i : null) }
|
|
151
|
-
const press = (i) => (rows[i].submenu ? show(i) : pick(rows[i]))
|
|
152
|
-
const key = (e) => {
|
|
153
|
-
/* the page's own shortcuts never see a key meant for the menu; Escape goes on to the layer's listener */
|
|
154
|
-
if (e.key !== 'Escape') e.stopPropagation()
|
|
155
|
-
if (e.key === 'ArrowLeft' && nested) { e.preventDefault(); onClose?.(); return }
|
|
156
|
-
const live = rows.map((r, i) => (r.disabled ? -1 : i)).filter((i) => i >= 0)
|
|
157
|
-
if (!live.length) return
|
|
158
|
-
const at = live.indexOf(active)
|
|
159
|
-
if (e.key === 'ArrowDown') { e.preventDefault(); show(null); setActive(at < 0 && live.includes(chosen) ? chosen : live[(at + 1) % live.length]) }
|
|
160
|
-
if (e.key === 'ArrowUp') { e.preventDefault(); show(null); setActive(live[at < 0 ? live.length - 1 : (at - 1 + live.length) % live.length]) }
|
|
161
|
-
if (e.key === 'ArrowRight' && rows[active]?.submenu) { e.preventDefault(); show(active) }
|
|
162
|
-
/* preventDefault: else the Enter's keypress lands on the trigger that takes focus back, and opens it again */
|
|
163
|
-
if (e.key === 'Enter' && rows[active] && !rows[active].disabled) { e.preventDefault(); press(active) }
|
|
164
|
-
/* a letter jumps to the next live row that starts with it */
|
|
165
|
-
if (e.key.length === 1 && /\S/.test(e.key) && !e.metaKey && !e.ctrlKey && !e.altKey && e.target.tagName !== 'INPUT') {
|
|
166
|
-
const k = e.key.toLowerCase()
|
|
167
|
-
const next = [...live.slice(at + 1), ...live.slice(0, at + 1)].find((i) => String(rows[i].label).toLowerCase().startsWith(k))
|
|
168
|
-
if (next !== undefined) { show(null); setActive(next) }
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let n = -1
|
|
173
|
-
const sub = flyout !== null ? rows[flyout] : null
|
|
174
|
-
return (
|
|
175
|
-
<>
|
|
176
|
-
<PopoverLayer anchor={anchor} open={open} onClose={onClose} placement={placement} kind="menu">
|
|
177
|
-
<div
|
|
178
|
-
data-accent={accent === 'secondary' ? accent : undefined}
|
|
179
|
-
role="menu"
|
|
180
|
-
aria-label={label}
|
|
181
|
-
tabIndex={-1}
|
|
182
|
-
ref={mount}
|
|
183
|
-
onKeyDown={key}
|
|
184
|
-
onScroll={measure}
|
|
185
|
-
data-kolbox-menu=""
|
|
186
|
-
style={minWidth != null ? { minWidth } : undefined}
|
|
187
|
-
className={`kol-menu--kolbox kol-kolbox-surface flex min-w-40 flex-col overflow-y-auto p-2 outline-none ${panelClassName}`}
|
|
188
|
-
>
|
|
189
|
-
{children}
|
|
190
|
-
{all.map((g, gi) => (
|
|
191
|
-
<Fragment key={gi}>
|
|
192
|
-
{gi > 0 && <div role="separator" className="kol-menu-rule--kolbox -mx-2 my-1 h-px shrink-0" />}
|
|
193
|
-
{g.title && <div className="kol-menu-heading--kolbox flex h-6 shrink-0 items-center px-2">{g.title}</div>}
|
|
194
|
-
{g.rows.map((row) => {
|
|
195
|
-
const i = ++n
|
|
196
|
-
return <MenuRowKolbox key={i} row={row} index={i} lead={lead} active={i === active || i === flyout} onEnter={() => { setActive(i); show(i) }} onPick={() => press(i)} />
|
|
197
|
-
})}
|
|
198
|
-
</Fragment>
|
|
199
|
-
))}
|
|
200
|
-
{more && <MenuScroll panel={panel} />}
|
|
201
|
-
</div>
|
|
202
|
-
</PopoverLayer>
|
|
203
|
-
{sub?.submenu && (
|
|
204
|
-
<MenuKolbox
|
|
205
|
-
key={flyout}
|
|
206
|
-
nested
|
|
207
|
-
anchor={panel.current}
|
|
208
|
-
open={open}
|
|
209
|
-
placement="beside"
|
|
210
|
-
aria-label={sub.label}
|
|
211
|
-
groups={sub.submenu}
|
|
212
|
-
accent={accent}
|
|
213
|
-
onSelect={pick}
|
|
214
|
-
onClose={() => { setFlyout(null); refocus() }}
|
|
215
|
-
/>
|
|
216
|
-
)}
|
|
217
|
-
</>
|
|
218
|
-
)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/* Menu's own rows under the kolbox look (Folio on kolbox, 2026-11-22), so a host that passes `items` switches by the
|
|
222
|
-
variant alone: `{ label, onClick, kbd, checked, disabled, icon, items }`, `{ divider: true }` (a new group) and
|
|
223
|
-
`{ heading }` (a titled group) become kolbox's groups; a row's `onClick` runs as it is picked. `anchor` may also be a
|
|
224
|
-
point `{ x, y }` (a right-click list): the list opens at it. */
|
|
225
|
-
const kolboxGroupsOf = (items) => {
|
|
226
|
-
const groups = [{ rows: [] }]
|
|
227
|
-
for (const it of items) {
|
|
228
|
-
if (it.divider || it.heading) { if (groups.at(-1).rows.length || groups.at(-1).title) groups.push({ rows: [] }); if (it.heading) groups.at(-1).title = it.heading; continue }
|
|
229
|
-
groups.at(-1).rows.push({ label: it.label, check: it.checked, shortcut: it.kbd || undefined, disabled: it.disabled, icon: typeof it.icon === 'string' ? it.icon : undefined, submenu: it.items?.length ? kolboxGroupsOf(it.items) : undefined, run: it.onClick })
|
|
230
|
-
}
|
|
231
|
-
return groups.filter((g) => g.rows.length)
|
|
232
|
-
}
|
|
233
|
-
function MenuKolboxItems({ items, anchor, onSelect, ...props }) {
|
|
234
|
-
const point = anchor != null && !('current' in anchor) && typeof anchor.getBoundingClientRect !== 'function' && anchor.x != null
|
|
235
|
-
const { x, y } = point ? anchor : {}
|
|
236
|
-
const at = useMemo(() => (point ? { getBoundingClientRect: () => ({ x, y, left: x, right: x, top: y, bottom: y, width: 0, height: 0 }) } : anchor), [point, x, y, point ? null : anchor]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
237
|
-
return <MenuKolbox {...props} anchor={at} groups={kolboxGroupsOf(items)} onSelect={(row) => { onSelect?.(row); row.run?.() }} />
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/* ── the folio look (Folio migration batch B, 2026-11-22) ──
|
|
241
|
-
* Folio's menu list (apps/folio EditorChrome `Items`) carried class for class, the chrome in kol-theme `.kol-menu--folio`.
|
|
242
|
-
* The host owns the trigger, as kolbox's does; the list is drawn in place, never portalled, so it keeps the frame's
|
|
243
|
-
* `data-folio-*` switches. KOL's words: `open`, `onClose`, `items` (`{ label, onClick, kbd, checked, disabled }` or
|
|
244
|
-
* `{ divider: true }`), `aria-label`, `minWidth`, `panelClassName` (where the list sits: the host's `absolute ...`).
|
|
245
|
-
* `anchor` a point `{ x, y }`: a right-click list, fixed at the point and kept on screen, closed by any press, a scroll or
|
|
246
|
-
* the window's blur. Without one a press outside the host's wrapper (the list's parent) closes it. Escape closes either.
|
|
247
|
-
* The check column is drawn when any row says `checked`; the key column when a row says `kbd`. A row's click closes
|
|
248
|
-
* the list, then runs. */
|
|
249
|
-
function MenuFolioCheck({ checked }) {
|
|
250
|
-
return <span aria-hidden className="kol-menu-check--folio inline-flex size-[16px] shrink-0 items-center justify-center">{checked ? '✓' : ''}</span>
|
|
251
|
-
}
|
|
252
|
-
function MenuFolio({ open, onClose, items = [], anchor, 'aria-label': label, minWidth, panelClassName = '', accent }) {
|
|
253
|
-
const panel = useRef(null)
|
|
254
|
-
useEffect(() => {
|
|
255
|
-
if (!open) return undefined
|
|
256
|
-
const esc = (e) => e.key === 'Escape' && onClose?.()
|
|
257
|
-
if (anchor) {
|
|
258
|
-
const shut = () => onClose?.()
|
|
259
|
-
addEventListener('mousedown', shut); addEventListener('keydown', esc); addEventListener('scroll', shut, true); addEventListener('blur', shut)
|
|
260
|
-
return () => { removeEventListener('mousedown', shut); removeEventListener('keydown', esc); removeEventListener('scroll', shut, true); removeEventListener('blur', shut) }
|
|
261
|
-
}
|
|
262
|
-
const off = (e) => { if (!panel.current?.parentElement?.contains(e.target)) onClose?.() }
|
|
263
|
-
addEventListener('mousedown', off); addEventListener('keydown', esc)
|
|
264
|
-
return () => { removeEventListener('mousedown', off); removeEventListener('keydown', esc) }
|
|
265
|
-
}, [open, onClose, anchor])
|
|
266
|
-
if (!open) return null
|
|
267
|
-
const lead = items.some((it) => it.checked !== undefined)
|
|
268
|
-
const rows = items.filter((it) => !it.divider).length, seps = items.length - rows
|
|
269
|
-
const at = anchor ? { left: Math.min(anchor.x, innerWidth - 260), top: Math.max(8, Math.min(anchor.y, innerHeight - (rows * 32 + seps * 13 + 16) - 8)) } : null
|
|
270
|
-
return (
|
|
271
|
-
<span data-accent={accent === 'secondary' ? accent : undefined} ref={panel} role="menu" aria-label={label} style={{ ...at, ...(minWidth != null ? { minWidth } : null) }} onMouseDown={(e) => e.stopPropagation()}
|
|
272
|
-
className={`kol-menu--folio z-50 flex min-w-[240px] flex-col rounded-[4px] border py-[6px] ${anchor ? 'fixed' : ''} ${panelClassName}`}>
|
|
273
|
-
{items.map((it, i) => (it.divider ? <span key={i} className="kol-menu-rule--folio my-[6px] h-px" /> : (
|
|
274
|
-
<button key={`${it.label}${i}`} type="button" role="menuitem" disabled={it.disabled} onMouseDown={(e) => e.preventDefault()} onClick={() => { onClose?.(); it.onClick?.() }}
|
|
275
|
-
className="kol-menu-row--folio flex h-[32px] items-center gap-[16px] px-[14px] text-left">
|
|
276
|
-
{lead && <MenuFolioCheck checked={it.checked} />}{it.label}{it.kbd !== undefined && <span className="kol-menu-kbd--folio ml-auto">{it.kbd}</span>}
|
|
277
|
-
</button>
|
|
278
|
-
)))}
|
|
279
|
-
</span>
|
|
280
|
-
)
|
|
281
|
-
}
|
|
81
|
+
/* `groups` (kolbox's word, kept): `[[row, ...], { title, rows: [...] }]`, a rule between groups, a title a heading; a row
|
|
82
|
+
`{ label, value, icon, check, shortcut, tag, submenu, disabled, highlighted, inset }` becomes a Menu row (`shortcut` the
|
|
83
|
+
key cap, `submenu` a flyout of the same groups), and a pick hands `onSelect` the row as it was given */
|
|
84
|
+
const itemsOfGroups = (groups) => groups.flatMap((g, gi) => {
|
|
85
|
+
const { title, rows = [] } = Array.isArray(g) ? { rows: g } : g
|
|
86
|
+
return [
|
|
87
|
+
...(gi > 0 ? [{ divider: true, key: `d${gi}` }] : []),
|
|
88
|
+
...(title ? [{ heading: title, key: `h${gi}` }] : []),
|
|
89
|
+
...rows.map((r, ri) => ({ key: `${gi}.${ri}`, label: r.label, icon: r.icon, check: r.check, kbd: r.shortcut || undefined, tag: r.tag, disabled: r.disabled, highlighted: r.highlighted, inset: r.inset, items: r.submenu ? itemsOfGroups(r.submenu) : undefined, row: r })),
|
|
90
|
+
]
|
|
91
|
+
})
|
|
92
|
+
const anchorOf = (anchor) => (anchor && typeof anchor === 'object' && 'current' in anchor ? anchor.current : anchor)
|
|
93
|
+
const pointRect = (x, y) => ({ getBoundingClientRect: () => ({ x, y, left: x, right: x, top: y, bottom: y, width: 0, height: 0 }) })
|
|
94
|
+
const later = (a, b) => !!(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
95
|
+
/* a number the theme sets on the panel (`--kol-menu-flyout-*`), or the default */
|
|
96
|
+
const themeNum = (el, name, d) => { const v = parseFloat(getComputedStyle(el).getPropertyValue(name)); return Number.isFinite(v) ? v : d }
|
|
97
|
+
const PLACE = { 'bottom-start': 'bottom-start', 'bottom-end': 'bottom-end', 'left-start': 'left-start', 'right-start': 'right-start', over: 'bottom-start', flyout: 'right-start' }
|
|
98
|
+
const GAP = { 'left-start': 8, 'right-start': 8 }
|
|
282
99
|
|
|
283
100
|
/**
|
|
284
|
-
* Menu — THE menu
|
|
285
|
-
* menus, Dropdown (a `fused` select
|
|
101
|
+
* Menu — THE menu (plan-2026-10-31-menu-engine W1; one menu since plan-2026-11-29-one-set-fold W3). Every list that floats
|
|
102
|
+
* over a trigger or an anchor is this: the Menu* menus, Dropdown (a `fused` select, and its field's list), MultiSelect
|
|
103
|
+
* (columns), MenuItem (a menubar entry), ContextMenu (a point), MenuBar, the kolbox menus. Its look is the theme's
|
|
104
|
+
* (`--kol-menu-*`, kol-theme `.kol-menu-panel` and its rows): the default theme draws KOL's panel, `data-theme-variant=
|
|
105
|
+
* "kolbox"` kolbox's (rows 24 touching, the lit row solid accent, the check in the leading column, plain shortcuts).
|
|
286
106
|
*
|
|
287
107
|
* trigger render prop `({ open, props })` — any trigger: MenuTrigger chip, a select, the ⋮, a menubar button
|
|
288
|
-
* anchor
|
|
289
|
-
*
|
|
108
|
+
* anchor instead of a trigger: an element, a ref, anything with getBoundingClientRect, or a point `{ x, y }` (a
|
|
109
|
+
* right-click). With neither, the panel hangs under the element it is rendered in (Folio's in-place list)
|
|
110
|
+
* placement anchored: bottom-start (unset), bottom-end, left-start, right-start, over (the list over its field, the
|
|
111
|
+
* `highlighted` row lying on it). With a trigger: `align` 'start' | 'end', the panel's edge flush with it
|
|
112
|
+
* items rows as data (MenuList's keys); or `groups` (kolbox's: `[[row], { title, rows }]`, rows `{ label, value,
|
|
113
|
+
* icon, check, shortcut, tag, submenu, disabled, highlighted, inset }`); `onSelect(row)` on any pick
|
|
290
114
|
* fused the panel continues the trigger: no gap, its width, top corners squared, never flips
|
|
291
|
-
* tone nothing to pass: the trigger's resolved `--kol-tone-*` ride onto the portalled panel
|
|
292
|
-
* `kol-tone-*` wrapper floats on that tone's surface
|
|
115
|
+
* tone nothing to pass: the trigger's resolved `--kol-tone-*` ride onto the portalled panel
|
|
293
116
|
* closeOnSelect false keeps the panel open while rows toggle (a multiselect)
|
|
294
|
-
* open / onOpenChange controlled
|
|
295
|
-
* offset the gap
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
* variant 'folio'
|
|
117
|
+
* open / defaultOpen / onOpenChange / onClose controlled or not; `onClose` runs on every close
|
|
118
|
+
* offset the gap (default 4; a fused panel -1, a point anchor 4, beside 8)
|
|
119
|
+
* search · minWidth · panelClassName (the panel's class) · panelStyle · aria-label · accent · children (above the rows;
|
|
120
|
+
* a function gets `{ close }`)
|
|
121
|
+
* variant 'kolbox' | 'folio' are accepted and do nothing: the theme draws the look (on the retirement ledger)
|
|
122
|
+
*
|
|
123
|
+
* The keys, every menu (kolbox's): the panel takes focus on open; the arrows move the lit row, Enter picks (or opens a
|
|
124
|
+
* flyout), ArrowRight opens and ArrowLeft closes a flyout, a letter jumps to the next row that starts with it, Escape
|
|
125
|
+
* closes the topmost menu only. No row is lit on open; the pointer lights the row it moves on. Closed from a trigger, the
|
|
126
|
+
* focus goes back to it. A press outside closes, except one inside a menu or layer opened later (a child, a field's
|
|
127
|
+
* list); a press on the canvas (`[data-canvas]`) that closes it is spent there.
|
|
299
128
|
*/
|
|
300
|
-
export function Menu(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
function MenuOn({
|
|
307
|
-
items, trigger, anchor, align = 'start', minWidth, offset, defaultOpen = false, open: openProp, onOpenChange,
|
|
308
|
-
stayOpen = false, closeOnSelect = true, fused = false, search, role = 'menu',
|
|
309
|
-
panelClassName = '', panelStyle, rootClassName, className = '', accent, children,
|
|
129
|
+
export function Menu({
|
|
130
|
+
items, groups, onSelect, trigger, anchor, placement, align = 'start', minWidth, offset, defaultOpen = false,
|
|
131
|
+
open: openProp, onOpenChange, onClose, stayOpen = false, closeOnSelect = true, fused = false, search, role = 'menu',
|
|
132
|
+
panelClassName = '', panelStyle, rootClassName, className = '', accent, 'aria-label': ariaLabel, nested = false,
|
|
133
|
+
variant, children, // eslint-disable-line no-unused-vars
|
|
310
134
|
}) {
|
|
311
135
|
const [own, setOwn] = useState(defaultOpen)
|
|
312
136
|
const controlled = openProp !== undefined
|
|
313
137
|
const open = controlled ? openProp : own
|
|
314
|
-
const setOpen = (v) => { if (!controlled) setOwn(v); onOpenChange?.(v) }
|
|
138
|
+
const setOpen = (v) => { if (!controlled) setOwn(v); onOpenChange?.(v); if (!v) onClose?.() }
|
|
139
|
+
const rows = useMemo(() => (groups ? itemsOfGroups(groups) : items), [groups, items])
|
|
140
|
+
|
|
141
|
+
const a = anchorOf(anchor)
|
|
142
|
+
const point = !trigger && a && typeof a === 'object' && !(a instanceof Element) && typeof a.getBoundingClientRect !== 'function' && a.x != null
|
|
143
|
+
const where = trigger ? (align === 'end' ? 'bottom-end' : 'bottom-start') : placement ?? 'bottom-start'
|
|
144
|
+
const panel = useRef(null)
|
|
315
145
|
const popover = usePopover({
|
|
316
146
|
open,
|
|
317
147
|
onOpenChange: setOpen,
|
|
318
|
-
placement:
|
|
319
|
-
offset:
|
|
320
|
-
|
|
148
|
+
placement: PLACE[where] ?? where,
|
|
149
|
+
offset: where === 'over' ? (({ rects, elements }) => {
|
|
150
|
+
/* the list over its field: the chosen row's middle on the field's middle, or the list's top on the field's top */
|
|
151
|
+
const row = elements.floating.querySelector('[data-chosen]')
|
|
152
|
+
if (!row) return -rects.reference.height
|
|
153
|
+
const top = row.getBoundingClientRect().top - elements.floating.getBoundingClientRect().top
|
|
154
|
+
return -rects.reference.height / 2 - (top + row.offsetHeight / 2)
|
|
155
|
+
}) : where === 'flyout' ? (({ placement: side }) => {
|
|
156
|
+
/* a child menu beside its parent's PANEL, `--kol-menu-flyout-gap` off its edge; its top on the row less
|
|
157
|
+
`--kol-menu-flyout-dy` (`--kol-menu-flyout-on-row` 1), or level with the panel's top (0) */
|
|
158
|
+
const p = a?.closest?.('[data-menu-panel]')
|
|
159
|
+
if (!p) return 4
|
|
160
|
+
const pr = p.getBoundingClientRect(), rr = a.getBoundingClientRect()
|
|
161
|
+
const onRow = themeNum(p, '--kol-menu-flyout-on-row', 1)
|
|
162
|
+
return {
|
|
163
|
+
mainAxis: (side.startsWith('right') ? pr.right - rr.right : rr.left - pr.left) + themeNum(p, '--kol-menu-flyout-gap', 0),
|
|
164
|
+
crossAxis: (onRow ? 0 : pr.top - rr.top) + themeNum(p, '--kol-menu-flyout-dy', -5),
|
|
165
|
+
}
|
|
166
|
+
}) : offset ?? (fused ? -1 : GAP[where] ?? 4),
|
|
167
|
+
flip: !fused && where !== 'over',
|
|
321
168
|
matchReferenceWidth: fused,
|
|
322
|
-
click:
|
|
169
|
+
click: !!trigger,
|
|
323
170
|
role,
|
|
324
|
-
|
|
171
|
+
/* Escape is ours (below); the press outside skips a menu or layer opened after this one, and spends a canvas press */
|
|
172
|
+
dismiss: {
|
|
173
|
+
escapeKey: false,
|
|
174
|
+
outsidePress: stayOpen ? false : (e) => {
|
|
175
|
+
const me = panel.current, t = e.target
|
|
176
|
+
const hit = t?.closest?.('[data-kolbox-overlay]')
|
|
177
|
+
if (me && hit && hit !== me && later(me, hit)) return false
|
|
178
|
+
if (t?.closest?.('[data-canvas]')) spend(e)
|
|
179
|
+
return true
|
|
180
|
+
},
|
|
181
|
+
},
|
|
325
182
|
})
|
|
326
183
|
|
|
327
|
-
/*
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
184
|
+
/* the anchor: an element is the reference (a press on it is the caller's toggle, never outside); a point or a box is
|
|
185
|
+
a virtual one; with neither, the element the Menu is rendered in */
|
|
186
|
+
const { setReference, setPositionReference } = popover.refs
|
|
187
|
+
const here = useRef(null)
|
|
188
|
+
useLayoutEffect(() => {
|
|
189
|
+
if (trigger || !open) return
|
|
190
|
+
if (!a) { const host = here.current?.parentElement; if (host) setReference(host); return }
|
|
191
|
+
if (a instanceof Element) setReference(a)
|
|
192
|
+
else if (point) setPositionReference(pointRect(a.x, a.y))
|
|
193
|
+
else setPositionReference(a)
|
|
194
|
+
}, [open, trigger, a, point ? a.x : null, point ? a.y : null]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
334
195
|
|
|
335
196
|
/* THE PANEL IS PORTALLED, so a tone the trigger inherits never reaches it through the cascade — copy it on open */
|
|
336
197
|
const rootRef = useRef(null)
|
|
@@ -345,24 +206,93 @@ function MenuOn({
|
|
|
345
206
|
setAmbient(vars)
|
|
346
207
|
}, [open])
|
|
347
208
|
|
|
209
|
+
/* closed from a trigger, the focus goes back to it when it was in the panel */
|
|
210
|
+
const wasOpen = useRef(open)
|
|
211
|
+
useLayoutEffect(() => {
|
|
212
|
+
if (wasOpen.current && !open && trigger) {
|
|
213
|
+
const f = document.activeElement
|
|
214
|
+
if (!f || f === document.body) rootRef.current?.querySelector('button, [href], [tabindex]:not([tabindex="-1"])')?.focus({ preventScroll: true })
|
|
215
|
+
}
|
|
216
|
+
wasOpen.current = open
|
|
217
|
+
}, [open, trigger])
|
|
218
|
+
|
|
219
|
+
/* Escape closes the topmost menu or layer only */
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
if (!open) return undefined
|
|
222
|
+
const esc = (e) => {
|
|
223
|
+
if (e.key !== 'Escape' || !panel.current) return
|
|
224
|
+
const all = document.querySelectorAll('[data-kolbox-overlay]')
|
|
225
|
+
if (all[all.length - 1] === panel.current) setOpen(false)
|
|
226
|
+
}
|
|
227
|
+
document.addEventListener('keydown', esc)
|
|
228
|
+
return () => document.removeEventListener('keydown', esc)
|
|
229
|
+
}) // eslint-disable-line react-hooks/exhaustive-deps
|
|
230
|
+
|
|
231
|
+
/* the panel's scroll foot, when it scrolls */
|
|
232
|
+
const [more, setMore] = useState(false)
|
|
233
|
+
const measure = useCallback(() => { const p = panel.current; if (p) setMore(p.scrollHeight - p.scrollTop - p.clientHeight > 1) }, [])
|
|
234
|
+
const mount = useCallback((node) => { panel.current = node; if (node) { node.focus({ preventScroll: true }); requestAnimationFrame(measure) } }, [measure])
|
|
235
|
+
|
|
236
|
+
/* the lit row: the pointer's or the keys' (`data-active`, on the DOM, so composed rows light too) */
|
|
237
|
+
const lit = useRef(null)
|
|
238
|
+
const light = (el, keys) => {
|
|
239
|
+
if (lit.current && lit.current !== el) lit.current.removeAttribute('data-active')
|
|
240
|
+
lit.current = el
|
|
241
|
+
if (el) { el.setAttribute('data-active', ''); if (keys) el.scrollIntoView({ block: 'nearest' }) }
|
|
242
|
+
panel.current?.toggleAttribute('data-keys', !!keys)
|
|
243
|
+
}
|
|
244
|
+
const liveRows = () => [...(panel.current?.querySelectorAll('[data-menu-row]') ?? [])].filter((el) => !el.disabled && el.getAttribute('aria-disabled') !== 'true' && el.closest('[data-menu-panel]') === panel.current)
|
|
245
|
+
const onPointerMove = (e) => {
|
|
246
|
+
const row = e.target.closest?.('[data-menu-row]')
|
|
247
|
+
if (row && row !== lit.current && liveRows().includes(row)) light(row, false)
|
|
248
|
+
}
|
|
249
|
+
const onKeyDown = (e) => {
|
|
250
|
+
/* the page's own shortcuts never see a key meant for the menu; Escape goes on to the listener above */
|
|
251
|
+
if (e.key === 'Escape') return
|
|
252
|
+
e.stopPropagation()
|
|
253
|
+
if (e.key === 'ArrowLeft' && nested) { e.preventDefault(); setOpen(false); return }
|
|
254
|
+
const live = liveRows()
|
|
255
|
+
if (!live.length) return
|
|
256
|
+
const at = live.indexOf(lit.current)
|
|
257
|
+
const chosen = live.find((el) => el.hasAttribute('data-chosen'))
|
|
258
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); light(at < 0 && chosen ? chosen : live[(at + 1) % live.length], true) }
|
|
259
|
+
if (e.key === 'ArrowUp') { e.preventDefault(); light(live[at < 0 ? live.length - 1 : (at - 1 + live.length) % live.length], true) }
|
|
260
|
+
const row = live[at]
|
|
261
|
+
if (row && e.key === 'ArrowRight' && row.getAttribute('aria-haspopup')) { e.preventDefault(); if (row.getAttribute('aria-expanded') !== 'true') row.click() }
|
|
262
|
+
/* preventDefault: else the Enter's keypress lands on the trigger that takes focus back, and opens it again */
|
|
263
|
+
if (row && e.key === 'Enter' && e.target.tagName !== 'INPUT') { e.preventDefault(); if (row.getAttribute('aria-expanded') !== 'true') row.click() }
|
|
264
|
+
/* a letter jumps to the next live row that starts with it */
|
|
265
|
+
if (e.key.length === 1 && /\S/.test(e.key) && !e.metaKey && !e.ctrlKey && !e.altKey && e.target.tagName !== 'INPUT') {
|
|
266
|
+
const k = e.key.toLowerCase()
|
|
267
|
+
const next = [...live.slice(at + 1), ...live.slice(0, at + 1)].find((el) => el.textContent.trim().toLowerCase().startsWith(k))
|
|
268
|
+
if (next) light(next, true)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const close = () => setOpen(false)
|
|
348
273
|
/* the wrapper takes the ref (a Button need not forward one); the trigger takes the handlers and the aria —
|
|
349
274
|
* `aria-pressed` cleared, an open menu is `aria-expanded`, its fill is the trigger's `pressed` */
|
|
350
275
|
return (
|
|
351
276
|
<>
|
|
352
|
-
{trigger
|
|
277
|
+
{trigger ? (
|
|
353
278
|
<span data-accent={accent === 'secondary' ? accent : undefined} ref={(el) => { rootRef.current = el; popover.refs.setReference(el) }} className={rootClassName ?? `inline-flex align-middle ${className}`.trim()}>
|
|
354
279
|
{trigger({ open, props: { ...popover.getReferenceProps(), 'aria-pressed': undefined } })}
|
|
355
280
|
</span>
|
|
356
|
-
)}
|
|
281
|
+
) : !a && <span ref={here} hidden />}
|
|
357
282
|
{open && (
|
|
358
|
-
<PopoverPanel popover={popover} panel={false} focus={false}
|
|
359
|
-
className={`kol-menu-panel${fused ? ' kol-menu-panel--fused' : ' w-max'} ${panelClassName}`.replace(/\s+/g, ' ').trim()}
|
|
360
|
-
style={{ ...ambient, ...(minWidth ? { minWidth } : null), ...panelStyle }}
|
|
361
|
-
{
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
283
|
+
<PopoverPanel popover={popover} panel={false} focus={false} panelRef={mount}
|
|
284
|
+
className={`kol-menu-panel${fused ? ' kol-menu-panel--fused' : ' w-max'} outline-none ${panelClassName}`.replace(/\s+/g, ' ').trim()}
|
|
285
|
+
style={{ ...ambient, ...(minWidth ? { minWidth } : null), ...panelStyle }}
|
|
286
|
+
floatingProps={{
|
|
287
|
+
tabIndex: -1, 'aria-label': ariaLabel, 'data-menu-panel': '', 'data-kolbox-overlay': 'menu', 'data-kolbox-menu': '',
|
|
288
|
+
'data-accent': accent === 'secondary' ? accent : undefined, onKeyDown, onPointerMove, onScroll: measure,
|
|
289
|
+
}}>
|
|
290
|
+
{/* a row's click closes the menu (it bubbles from `[data-menu-item]`, a child menu's too); a flyout row only opens */}
|
|
291
|
+
<div data-accent={accent === 'secondary' ? accent : undefined} role="none" className="flex flex-col gap-[var(--kol-menu-gap,var(--kol-spacing-0-5))] min-h-0" onClick={(e) => { if (closeOnSelect && e.target.closest('[data-menu-item]')) close() }}>
|
|
292
|
+
<MenuList items={rows} search={search} onSelect={onSelect}>
|
|
293
|
+
{typeof children === 'function' ? children({ close }) : children}
|
|
365
294
|
</MenuList>
|
|
295
|
+
{more && <MenuScroll panel={panel} />}
|
|
366
296
|
</div>
|
|
367
297
|
</PopoverPanel>
|
|
368
298
|
)}
|
|
@@ -393,7 +323,7 @@ export function MenuFilter({ groups = [], onPick, active = [], onRemove, onClear
|
|
|
393
323
|
})
|
|
394
324
|
const rowCls = 'kol-menu-row kol-helper-12'
|
|
395
325
|
return (
|
|
396
|
-
<Menu align={align} minWidth={minWidth} offset={8} items={items}
|
|
326
|
+
<Menu align={align} minWidth={minWidth} offset={8} items={items}
|
|
397
327
|
trigger={({ open, props }) => <MenuTrigger open={open || active.length > 0} icon={icon} variant={variant} {...props}>{label}</MenuTrigger>}>
|
|
398
328
|
{active.length > 0 && (
|
|
399
329
|
<>
|
|
@@ -431,7 +361,7 @@ export function MenuDatePicker({ groups = [], value, onChange, label, icon = 'ca
|
|
|
431
361
|
...(compare ? [{ divider: true }, { key: 'compare', label: compare.label, kbd: compare.kbd, onClick: compare.onClick }] : []),
|
|
432
362
|
]
|
|
433
363
|
return (
|
|
434
|
-
<Menu align={align} minWidth={minWidth} offset={8} items={items}
|
|
364
|
+
<Menu align={align} minWidth={minWidth} offset={8} items={items}
|
|
435
365
|
trigger={({ open, props }) => <MenuTrigger open={open} icon={icon} iconComponent={iconComponent} variant={variant} {...props}>{label}</MenuTrigger>} />
|
|
436
366
|
)
|
|
437
367
|
}
|
|
@@ -439,7 +369,12 @@ export function MenuDatePicker({ groups = [], value, onChange, label, icon = 'ca
|
|
|
439
369
|
/** MenuMore — the ⋮ chip and its rows (`items`, as `Menu`'s); `label` names it for a screen reader. */
|
|
440
370
|
export function MenuMore({ label, items = [], align = 'end', minWidth = 224, defaultOpen, stayOpen, variant }) {
|
|
441
371
|
return (
|
|
442
|
-
<Menu align={align} minWidth={minWidth} offset={8} items={items} defaultOpen={defaultOpen} stayOpen={stayOpen}
|
|
372
|
+
<Menu align={align} minWidth={minWidth} offset={8} items={items} defaultOpen={defaultOpen} stayOpen={stayOpen}
|
|
443
373
|
trigger={({ open, props }) => <MenuTrigger open={open} iconOnly aria-label={label} variant={variant} {...props} />} />
|
|
444
374
|
)
|
|
445
375
|
}
|
|
376
|
+
|
|
377
|
+
/** @deprecated 2026-11-29 → Menu (plan-2026-11-29-one-set-fold W3): kolbox's menu is the one Menu, its look the theme's */
|
|
378
|
+
export const MenuKolbox = Menu
|
|
379
|
+
/** @deprecated 2026-11-29 → Menu (plan-2026-11-29-one-set-fold W3): Folio wears the kolbox theme */
|
|
380
|
+
export const MenuFolio = Menu
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useLayoutEffect, useRef, useState } from 'react'
|
|
2
2
|
import { IconLoader } from '@kolkrabbi/kol-icons'
|
|
3
3
|
import { Menu } from './Menu.jsx'
|
|
4
|
-
import Kbd from '../atoms/Kbd.jsx'
|
|
5
4
|
import Divider from '../atoms/Divider.jsx'
|
|
6
5
|
import { indicatorSize } from '../hooks/glyphLadders.js'
|
|
7
6
|
|
|
@@ -125,47 +124,81 @@ const ROW_BY_SIZE = { xs: 'kol-mono-8 px-2 h-5', sm: 'kol-helper-12 px-2 h-8', m
|
|
|
125
124
|
* row still fills a fixed panel through `w-full` and lets a content-sized one hug its longest label. */
|
|
126
125
|
const INDICATOR = { dot: 'ascii-dot', check: 'check', chevron: 'chevron-right' }
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
/* ONE ROW, ITS LOOK THE THEME'S (plan-2026-11-29-one-set-fold W3): kolbox's row keys are MenuRow's too.
|
|
128
|
+
* check true | false: a check mark, `menuitemcheckbox`. Where it sits is the theme's (`.kol-menu-check`): after the
|
|
129
|
+
* label in the default theme, the leading column in the kolbox theme. `lead` (the list's: a row in it has a
|
|
130
|
+
* check) keeps the column on every row, empty where the row is not checked.
|
|
131
|
+
* tag a small mono chip after the shortcut (`.kol-menu-tag`)
|
|
132
|
+
* flyout the row opens a child menu: no pick, `aria-haspopup`, `expanded` while it is open, the chevron last
|
|
133
|
+
* chosen the chosen row (`data-chosen`): where the keys start, what a list laid over its field puts on the field
|
|
134
|
+
* rowRef · onPointerMove for the list that holds it (MenuList's flyouts)
|
|
135
|
+
* The lit row (the pointer's or the keys') is `data-active`, set by the Menu that holds it, never by React. */
|
|
136
|
+
export function MenuRow({ href, onClick, onPointerEnter, onPointerLeave, onPointerMove, disabled, prefix, iconLeft, indicator, kbd, shortcut, hover = true, height, size = 'sm', rowClass, tone, accent, check, lead = false, tag, flyout = false, expanded, chosen, rowRef, children }) {
|
|
129
137
|
/* `href` makes the row a real link — cmd/ctrl-click and middle-click open a new tab (DocumentHeader, 2026-10-31);
|
|
130
138
|
* a plain click still runs `onClick` (the app's router), which may preventDefault */
|
|
131
139
|
const Row = href && !disabled ? 'a' : 'button'
|
|
140
|
+
const caps = kbd != null || typeof shortcut === 'string'
|
|
132
141
|
return (
|
|
133
142
|
<Row
|
|
143
|
+
ref={rowRef}
|
|
134
144
|
{...(Row === 'a' ? { href, onClick: (e) => { if (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1) return; onClick?.(e) } } : { type: 'button', onClick })}
|
|
135
|
-
data-menu-item
|
|
145
|
+
/* a flyout row only opens its child: the menu closes on a click from `[data-menu-item]`, never on this one */
|
|
146
|
+
data-menu-item={flyout ? undefined : ''}
|
|
147
|
+
data-menu-row=""
|
|
148
|
+
data-chosen={chosen || undefined}
|
|
136
149
|
data-accent={accent === 'secondary' ? accent : undefined}
|
|
137
150
|
onPointerEnter={onPointerEnter}
|
|
138
151
|
onPointerLeave={onPointerLeave}
|
|
152
|
+
onPointerMove={onPointerMove}
|
|
139
153
|
disabled={Row === 'button' ? disabled : undefined}
|
|
140
|
-
role=
|
|
154
|
+
role={check === undefined ? 'menuitem' : 'menuitemcheckbox'}
|
|
155
|
+
aria-checked={check === undefined ? undefined : !!check}
|
|
156
|
+
aria-haspopup={flyout ? 'menu' : undefined}
|
|
157
|
+
aria-expanded={flyout ? !!expanded : undefined}
|
|
141
158
|
style={height != null ? { height } : undefined}
|
|
142
|
-
className={`kol-menu-btn w-full ${rowClass ?? ROW_BY_SIZE[size] ?? ROW_BY_SIZE.sm} shrink-0 flex items-center gap-2 text-body ${hover ? 'hover:text-emphasis' : ''} ${tone === 'danger' ? 'kol-menu-row--danger' : ''} disabled:opacity-
|
|
159
|
+
className={`kol-menu-btn w-full ${rowClass ?? ROW_BY_SIZE[size] ?? ROW_BY_SIZE.sm} shrink-0 flex items-center gap-2 text-body ${hover ? 'hover:text-emphasis' : ''} ${tone === 'danger' ? 'kol-menu-row--danger' : ''} disabled:opacity-[var(--kol-menu-row-disabled-opacity,0.4)] disabled:cursor-not-allowed text-left`.replace(/\s+/g, ' ')}
|
|
143
160
|
>
|
|
144
161
|
{prefix && <span className="shrink-0 inline-flex items-center">{prefix}</span>}
|
|
145
|
-
{iconLeft && <span className="shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
|
|
162
|
+
{iconLeft && <span className="kol-menu-lead-icon shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
|
|
146
163
|
{/* leading-normal: kol-helper-12 is line-height 1, and truncate's
|
|
147
164
|
* overflow clip cuts mono descenders on a 1-em line box ("Show grid"
|
|
148
165
|
* loses its g). The h-8 centered row absorbs the taller line box —
|
|
149
166
|
* zero layout shift (MenuItemDescenderClip, 2026-08-12). */}
|
|
150
167
|
<span className="flex-1 truncate leading-normal">{children}</span>
|
|
151
|
-
{
|
|
168
|
+
{lead && <span className="kol-menu-check">{check ? <IconLoader name="check" size={size === 'xs' ? indicatorSize('xs') : 14} /> : null}</span>}
|
|
169
|
+
{(indicator || caps || (shortcut && typeof shortcut !== 'string')) && (
|
|
152
170
|
<span className="shrink-0 inline-flex items-center gap-2 text-oq-88">
|
|
153
171
|
{/* the dot is kol-icons `ascii-dot` drawn at twice the slot and pulled back into it: at the slot's own size its
|
|
154
172
|
* 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 */}
|
|
155
173
|
{indicator === 'dot'
|
|
156
174
|
? <IconLoader name="ascii-dot" size={size === 'xs' ? 16 : 24} style={{ margin: size === 'xs' ? -4 : -5 }} />
|
|
157
175
|
: indicator && <IconLoader name={INDICATOR[indicator] ?? indicator} size={size === 'xs' ? indicatorSize('xs') : 14} />}
|
|
158
|
-
{
|
|
159
|
-
{
|
|
160
|
-
? <Kbd size="md" icon="command" className="kol-menu-kbd">{kbd.slice(1)}</Kbd>
|
|
161
|
-
: <Kbd size="md" className="kol-menu-kbd">{kbd}</Kbd>)}
|
|
162
|
-
{typeof shortcut === 'string' ? <Kbd size="md" className="kol-menu-kbd">{shortcut}</Kbd> : shortcut}
|
|
176
|
+
{kbd != null && <MenuKbd keys={kbd} />}
|
|
177
|
+
{typeof shortcut === 'string' ? <MenuKbd keys={shortcut} plain /> : shortcut}
|
|
163
178
|
</span>
|
|
164
179
|
)}
|
|
180
|
+
{tag && <span className="kol-menu-tag shrink-0 px-1">{tag}</span>}
|
|
181
|
+
{flyout && <IconLoader name="chevron-right" size={10} className="kol-menu-chevron text-emphasis shrink-0" />}
|
|
165
182
|
</Row>
|
|
166
183
|
)
|
|
167
184
|
}
|
|
168
185
|
|
|
186
|
+
/* a row's key cap: the Kbd's plate and type (`.kol-kbd .kol-kbd-md`), its box in `.kol-menu-kbd` so the theme can draw
|
|
187
|
+
* it as plain text (kolbox: the muted ink, no plate, as Figma's menus). ⌘ is drawn, never typed — the Kbd's `command`
|
|
188
|
+
* glyph (W2 row 27, 2026-11-04) — and kolbox writes it as text: both are here, the theme shows one. `plain`: no ⌘ glyph
|
|
189
|
+
* (the old free `shortcut` string was a cap as written). */
|
|
190
|
+
function MenuKbd({ keys, plain = false }) {
|
|
191
|
+
const s = keys
|
|
192
|
+
const cmd = !plain && typeof s === 'string' && s.startsWith('⌘')
|
|
193
|
+
return (
|
|
194
|
+
<kbd aria-hidden="true" className="kol-kbd kol-kbd-md kol-menu-kbd">
|
|
195
|
+
{cmd && <span className="kol-menu-kbd-glyph"><IconLoader name="command" size={12} className="kol-kbd-icon shrink-0" /></span>}
|
|
196
|
+
{cmd && <span className="kol-menu-kbd-char">⌘</span>}
|
|
197
|
+
{cmd ? s.slice(1) : s}
|
|
198
|
+
</kbd>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
169
202
|
/* `className` — the rule's spacing, whole (MetricDashboardUpstream, kol-website 2026-10-31); `kol-menu-rule` is the
|
|
170
203
|
* panel's edge-to-edge rule, its ink set by the panel (oq-16, float oq-08). */
|
|
171
204
|
/* MenuDivider — a rule between a menu's groups: the Divider atom on the oq ramp, oq-08 (plan-2026-11-07-menu-system
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
2
|
import { IconLoader } from '@kolkrabbi/kol-icons'
|
|
3
3
|
import SearchInput from './SearchInput.jsx'
|
|
4
|
-
import { MenuRow, MenuDivider
|
|
4
|
+
import { MenuRow, MenuDivider } from './MenuItem.jsx'
|
|
5
|
+
import { Menu } from './Menu.jsx'
|
|
5
6
|
import { Tooltip } from '../utilities/Popover.jsx'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -16,30 +17,43 @@ import { Tooltip } from '../utilities/Popover.jsx'
|
|
|
16
17
|
* ]} />
|
|
17
18
|
*
|
|
18
19
|
* items rows as data — the row keys `Menu` documents: `label` · `icon` · `trailing` (+ `trailingSize`) · `current`
|
|
19
|
-
* · `indicator` 'dot' | 'check' | 'chevron' · `checked`
|
|
20
|
-
* · `
|
|
21
|
-
* · `
|
|
20
|
+
* · `indicator` 'dot' | 'check' | 'chevron' · `checked` (or `check`) · `kbd` · `tag` · `inset`
|
|
21
|
+
* · `highlighted` · `disabled` + `tooltip` · `tone: 'danger'` · `href` · `onClick` · `items` (a flyout) · `key`.
|
|
22
|
+
* A row may also carry MenuRow's own `rowClass` · `hover` · `size` · `height` · `prefix` · `onPointerEnter` /
|
|
23
|
+
* `onPointerLeave` (Dropdown's rows do).
|
|
22
24
|
* search `{ placeholder, empty }` — a search field above the rows that filters them by label
|
|
25
|
+
* onSelect `(row)` on a pick, before the row's own `onClick` (Menu passes its own; a flyout's pick is its parent's)
|
|
23
26
|
* children sit above the rows (under the search)
|
|
24
27
|
* dividerClassName the rule's class, whole (default `kol-menu-rule` — the panel's edge-to-edge rule)
|
|
25
28
|
* headingClassName the heading's class, whole (default the MenuLabel's)
|
|
29
|
+
*
|
|
30
|
+
* ONE LIST (plan-2026-11-29-one-set-fold W3): kolbox's rows are these rows. A flyout is a child `Menu` beside the panel,
|
|
31
|
+
* opened by the pointer moving on its row, a click, ArrowRight or Enter, closed by the pointer moving on another row,
|
|
32
|
+
* ArrowLeft or Escape in it; where it stands is the theme's (`--kol-menu-flyout-*`).
|
|
26
33
|
*/
|
|
27
34
|
|
|
28
35
|
export const MenuLabel = ({ className = 'kol-menu-label kol-helper-12', children }) => <div className={className}>{children}</div>
|
|
29
36
|
|
|
30
37
|
const glyph = (icon, size) => (typeof icon === 'string' ? <IconLoader name={icon} size={size} /> : icon)
|
|
31
|
-
/* a row's trailing marks — real icons and Kbd only (W2): `indicator` 'dot' | 'check' | 'chevron', `
|
|
32
|
-
* `
|
|
33
|
-
const
|
|
38
|
+
/* a row's trailing marks — real icons and Kbd only (W2): `indicator` 'dot' | 'check' | 'chevron', `kbd` a key cap,
|
|
39
|
+
* `trailing` an icon name for an action (download). `checked` is the check (MenuRow's `check`). */
|
|
40
|
+
const checkOf = (it) => it.check ?? it.checked
|
|
41
|
+
const focusPanel = (el) => el?.closest('[data-menu-panel]')?.focus({ preventScroll: true })
|
|
34
42
|
|
|
35
|
-
export function MenuList({ items = [], search, dividerClassName = 'kol-menu-rule', headingClassName, children }) {
|
|
43
|
+
export function MenuList({ items = [], search, onSelect, dividerClassName = 'kol-menu-rule', headingClassName, children }) {
|
|
36
44
|
const [q, setQ] = useState('')
|
|
45
|
+
const [flyout, setFlyout] = useState(null)
|
|
46
|
+
const [rowEl, setRowEl] = useState(null)
|
|
37
47
|
let rows = items
|
|
38
48
|
if (search) {
|
|
39
49
|
const s = q.toLowerCase()
|
|
40
50
|
rows = rows.filter((it) => it.label == null || String(it.label).toLowerCase().includes(s))
|
|
41
51
|
if (!rows.some((it) => it.label != null)) rows = [...rows, { key: 'empty', label: search.empty || 'Nothing matches', disabled: true }]
|
|
42
52
|
}
|
|
53
|
+
/* the check column is the list's: kept on every row once one row can be checked */
|
|
54
|
+
const lead = items.some((it) => !it.divider && !it.heading && checkOf(it) !== undefined)
|
|
55
|
+
/* a pointer on another row closes the open child and gives the keys back to this panel */
|
|
56
|
+
const shut = (el) => { if (flyout !== null) { setFlyout(null); focusPanel(el) } }
|
|
43
57
|
return (
|
|
44
58
|
<>
|
|
45
59
|
{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>}
|
|
@@ -47,21 +61,38 @@ export function MenuList({ items = [], search, dividerClassName = 'kol-menu-rule
|
|
|
47
61
|
{rows.map((it, i) => {
|
|
48
62
|
if (it.divider) return <MenuDivider key={it.key ?? `d${i}`} className={dividerClassName} />
|
|
49
63
|
if (it.heading) return <MenuLabel key={it.key ?? `h${i}`} className={headingClassName}>{it.heading}</MenuLabel>
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
const key = it.key ?? `r${i}`
|
|
65
|
+
const icon = it.icon ? <span className="kol-menu-icon inline-flex">{glyph(it.icon, 16)}</span> : it.inset ? <span className="size-4" /> : null
|
|
66
|
+
/* `kol-menu-row--kolbox` rides along as a hook for kol-fxr's own rules (on the retirement ledger) */
|
|
67
|
+
const cls = it.rowClass ?? `kol-menu-row kol-menu-row--kolbox kol-helper-12${it.current ? ' kol-menu-row--current' : ''}${it.tone === 'danger' ? ' kol-menu-row--danger' : ''}`
|
|
68
|
+
const common = {
|
|
69
|
+
rowClass: cls, iconLeft: icon, prefix: it.prefix, disabled: it.disabled, check: checkOf(it), lead, tag: it.tag,
|
|
70
|
+
chosen: it.highlighted, hover: it.hover, size: it.size, height: it.height, kbd: it.kbd,
|
|
71
|
+
}
|
|
72
|
+
const opens = it.items?.length && !it.disabled
|
|
73
|
+
const open = opens && flyout === key
|
|
74
|
+
const row = opens ? (
|
|
75
|
+
<>
|
|
76
|
+
<MenuRow {...common} flyout expanded={open} rowRef={open ? setRowEl : undefined}
|
|
77
|
+
onPointerMove={(e) => { if (flyout !== key) { if (flyout !== null) focusPanel(e.currentTarget); setRowEl(e.currentTarget); setFlyout(key) } }}
|
|
78
|
+
onClick={(e) => { setRowEl(e.currentTarget); setFlyout(open ? null : key) }}>
|
|
79
|
+
{it.label}
|
|
80
|
+
</MenuRow>
|
|
81
|
+
{open && rowEl && (
|
|
82
|
+
<Menu nested anchor={rowEl} open placement="flyout" aria-label={typeof it.label === 'string' ? it.label : undefined}
|
|
83
|
+
items={it.items} onSelect={onSelect} panelClassName="kol-menu-flyout"
|
|
84
|
+
onClose={() => { setFlyout(null); focusPanel(rowEl) }} />
|
|
85
|
+
)}
|
|
86
|
+
</>
|
|
56
87
|
) : (
|
|
57
|
-
<MenuRow
|
|
58
|
-
|
|
88
|
+
<MenuRow {...common} href={it.href} indicator={it.indicator}
|
|
89
|
+
onClick={onSelect ? (e) => { onSelect(it.row ?? it); it.onClick?.(e) } : it.onClick}
|
|
59
90
|
onPointerEnter={it.onPointerEnter} onPointerLeave={it.onPointerLeave}
|
|
91
|
+
onPointerMove={flyout !== null ? (e) => shut(e.currentTarget) : undefined}
|
|
60
92
|
shortcut={it.shortcut ?? (it.trailing ? <span className="text-oq-88 inline-flex">{glyph(it.trailing, it.trailingSize ?? 14)}</span> : undefined)}>
|
|
61
93
|
{it.label}
|
|
62
94
|
</MenuRow>
|
|
63
95
|
)
|
|
64
|
-
const key = it.key ?? `r${i}`
|
|
65
96
|
return it.tooltip
|
|
66
97
|
? <Tooltip key={key} label={it.tooltip} placement="left" triggerClassName="block w-full">{row}</Tooltip>
|
|
67
98
|
: <div key={key}>{row}</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef
|
|
1
|
+
import { forwardRef } from 'react'
|
|
2
2
|
import { Menu } from './Menu.jsx'
|
|
3
3
|
import { Tooltip } from '../utilities/Popover.jsx'
|
|
4
4
|
|
|
@@ -37,13 +37,14 @@ import { Tooltip } from '../utilities/Popover.jsx'
|
|
|
37
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
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
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
|
|
41
|
-
* Menu
|
|
40
|
+
* `items` (kolbox's `{ label, checked, onClick }` rows are Menu rows; the kolbox theme draws them as kolbox's menu). The
|
|
41
|
+
* kolbox Menu bridge left with the Menu fold (W3): `variant="kolbox"` and `"folio"` are accepted, open the one Menu and
|
|
42
|
+
* keep kolbox's place for it, under the dot from its left edge (`align` unset reads `start`). The bridge is in
|
|
43
|
+
* `_tmp/2026-11-29-one-set-fold/ParamBindDot.pre-menu.jsx`.
|
|
42
44
|
*/
|
|
43
45
|
const THEME_WORDS = ['kolbox', 'folio']
|
|
44
|
-
export default function ParamBindDot({ variant, ...props }) {
|
|
45
|
-
|
|
46
|
-
return THEME_WORDS.includes(variant) ? <ParamBindDotMenuBridge {...props} /> : <ParamBindDotMenu {...props} />
|
|
46
|
+
export default function ParamBindDot({ variant, align, ...props }) {
|
|
47
|
+
return <ParamBindDotMenu {...props} align={align ?? (THEME_WORDS.includes(variant) ? 'start' : 'end')} />
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
/* the dot itself, the same button for both menus */
|
|
@@ -62,23 +63,6 @@ const Dot = forwardRef(function Dot({ bound, className = '', size = 'sm', accent
|
|
|
62
63
|
)
|
|
63
64
|
})
|
|
64
65
|
|
|
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
66
|
function ParamBindDotMenu({
|
|
83
67
|
bound = false,
|
|
84
68
|
mode,
|
|
@@ -96,7 +80,7 @@ function ParamBindDotMenu({
|
|
|
96
80
|
return (
|
|
97
81
|
<Menu align={align} minWidth={minWidth} items={items} trigger={({ open, props }) => (
|
|
98
82
|
<Tooltip label={open ? null : tip}>
|
|
99
|
-
<Dot aria-label={name} bound={bound} size={size} className={className} accent={accent} open={open} {...props} />
|
|
83
|
+
<Dot data-bind-dot aria-label={name} bound={bound} size={size} className={className} accent={accent} open={open} {...props} />
|
|
100
84
|
</Tooltip>
|
|
101
85
|
)} />
|
|
102
86
|
)
|
|
@@ -163,8 +163,9 @@ export function usePopover({
|
|
|
163
163
|
const anchorEl = (anchor) => (anchor && 'current' in anchor ? anchor.current : anchor)
|
|
164
164
|
const later = (a, b) => !!(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
165
165
|
/* spend a press: stop it here, and swallow the mouse events and the click it raises until the press ends. Several
|
|
166
|
-
layers may close on one press; the first spends it, the rest find it stopped and do nothing more.
|
|
167
|
-
|
|
166
|
+
layers may close on one press; the first spends it, the rest find it stopped and do nothing more. Menu's press outside
|
|
167
|
+
spends a press on the canvas the same way (plan-2026-11-29-one-set-fold W3). */
|
|
168
|
+
export function spend(e) {
|
|
168
169
|
if (e.cancelBubble) return
|
|
169
170
|
e.stopPropagation(); e.preventDefault()
|
|
170
171
|
const stop = (ev) => { ev.stopPropagation(); ev.preventDefault() }
|
|
@@ -555,6 +556,9 @@ function PopoverPanelOn({
|
|
|
555
556
|
motion,
|
|
556
557
|
className = '',
|
|
557
558
|
style: extraStyle,
|
|
559
|
+
/* Menu's panel (plan-2026-11-29-one-set-fold W3): its own attributes and handlers on the floating node, and its ref */
|
|
560
|
+
floatingProps,
|
|
561
|
+
panelRef,
|
|
558
562
|
}) {
|
|
559
563
|
const depth = useContext(FloatDepth)
|
|
560
564
|
const fm = motion == null ? null : floatMotion(motion)
|
|
@@ -577,13 +581,13 @@ function PopoverPanelOn({
|
|
|
577
581
|
* for non-editor consumers since they ignore the attr. */
|
|
578
582
|
const node = (
|
|
579
583
|
<div
|
|
580
|
-
ref={refs.setFloating}
|
|
584
|
+
ref={panelRef ? (n) => { refs.setFloating(n); panelRef(n) } : refs.setFloating}
|
|
581
585
|
style={{ ...floatingStyles, ...(depth ? { '--kol-float-depth': depth } : null), ...fm?.style, ...extraStyle }}
|
|
582
586
|
className={cls}
|
|
583
587
|
data-editor-keep-selection
|
|
584
588
|
data-side={fm ? popover.placement?.split('-')[0] : undefined}
|
|
585
589
|
data-exit={fm && presence.exiting ? '' : undefined}
|
|
586
|
-
{...getFloatingProps()}
|
|
590
|
+
{...getFloatingProps(floatingProps)}
|
|
587
591
|
>
|
|
588
592
|
<FloatDepth.Provider value={depth + 1}>{children}</FloatDepth.Provider>
|
|
589
593
|
</div>
|