@kolkrabbi/kol-component 0.250.0 → 0.252.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.250.0",
3
+ "version": "0.252.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "embla-carousel-react": "^8.6.0",
27
27
  "pdfjs-dist": "^6.3.289",
28
28
  "react-syntax-highlighter": "^16.1.1",
29
- "@kolkrabbi/kol-search": "^0.3.0",
30
- "@kolkrabbi/kol-markdown": "^0.1.3"
29
+ "@kolkrabbi/kol-markdown": "^0.1.3",
30
+ "@kolkrabbi/kol-search": "^0.3.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@kolkrabbi/kol-icons": ">=0.22.0",
@@ -38,7 +38,7 @@
38
38
  "react-dom": "^18.3.0 || ^19.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@kolkrabbi/kol-icons": "^0.36.0"
41
+ "@kolkrabbi/kol-icons": "^0.37.0"
42
42
  },
43
43
  "files": [
44
44
  "src",
@@ -113,6 +113,11 @@ const Dropdown = ({
113
113
  * the showcase's preview, with its toolbar pickers beside it (user 2026-10-02: *"can we
114
114
  * disclude the preview from that behaviour?"*). */
115
115
  stayOpen = false,
116
+ /* `ariaLabel` — what the dropdown CHOOSES (DropdownAriaLabel, kol-fxr 2026-10-13: a Color pane's
117
+ * Hue · Wheel · HSL · RGB picker read as "Hue, popup button", no word for what it picks). Same name
118
+ * as SegmentedToggle's. An aria-label replaces the button's text, so the current value rides along
119
+ * after it — "Color view, Hue" — and is still announced. */
120
+ ariaLabel,
116
121
  className = ''
117
122
  }) => {
118
123
  const [isOpen, setIsOpen] = useState(defaultOpen)
@@ -239,6 +244,7 @@ const Dropdown = ({
239
244
  className={triggerCls}
240
245
  aria-haspopup="listbox"
241
246
  aria-expanded={isOpen}
247
+ aria-label={ariaLabel ? [ariaLabel, currentOption?.label].filter((t) => typeof t === 'string' && t).join(', ') : undefined}
242
248
  data-state={isOpen ? 'open' : 'closed'}
243
249
  >
244
250
  {iconOnly ? (
@@ -1,4 +1,4 @@
1
- import { useState } from 'react'
1
+ import { useLayoutEffect, useRef, useState } from 'react'
2
2
  import { Icon } from '@kolkrabbi/kol-icons'
3
3
  import { PopoverPanel, usePopover } from '../utilities/Popover.jsx'
4
4
 
@@ -125,6 +125,9 @@ const ROW_BY_SIZE = { xs: 'kol-mono-8 px-2 h-5', sm: 'kol-helper-12 px-3 h-8', m
125
125
  /* `rowClass` — the row's type, side padding and height, whole, in place of the size's own
126
126
  * (Dropdown passes it, 2026-10-02: its rows wear the trigger's face and sit on the trigger's
127
127
  * text edge; a menu's rows keep `ROW_BY_SIZE`). */
128
+ /* `flex`, not `inline-flex` (MenuDropdownItemBlockRow, kol-fxr 2026-10-13): as bare children of a
129
+ * content-sized (`w-max`) panel, inline rows measured as ONE line — five starters ≈ 795px. A block
130
+ * row still fills a fixed panel through `w-full` and lets a content-sized one hug its longest label. */
128
131
  export function MenuDropdownItem({ onClick, onPointerEnter, onPointerLeave, disabled, prefix, iconLeft, shortcut, hover = true, height, size = 'sm', rowClass, children }) {
129
132
  return (
130
133
  <button
@@ -136,7 +139,7 @@ export function MenuDropdownItem({ onClick, onPointerEnter, onPointerLeave, disa
136
139
  disabled={disabled}
137
140
  role="menuitem"
138
141
  style={height != null ? { height } : undefined}
139
- className={`kol-menu-btn w-full ${rowClass ?? ROW_BY_SIZE[size] ?? ROW_BY_SIZE.sm} shrink-0 inline-flex items-center gap-2 text-body ${hover ? 'hover:text-emphasis' : ''} disabled:opacity-40 disabled:cursor-not-allowed text-left`}
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' : ''} disabled:opacity-40 disabled:cursor-not-allowed text-left`}
140
143
  >
141
144
  {prefix && <span className="shrink-0 inline-flex items-center">{prefix}</span>}
142
145
  {iconLeft && <span className="shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
@@ -155,16 +158,48 @@ export function MenuDropdownDivider() {
155
158
  }
156
159
 
157
160
  /**
158
- * MenuDropdownNest — accordion-style row inside a dropdown panel. Click
159
- * the row to expand/collapse its children inline (below the row, in the
160
- * same panel). The trailing chevron rotates 90° to indicate state.
161
+ * MenuDropdownNest — a row inside a dropdown panel that holds a submenu.
161
162
  *
162
- * Same visual shape as MenuDropdownItem at rest. Clicking a leaf
163
- * MenuDropdownItem inside an open nest still closes the entire menu via
164
- * the standard data-menu-item bubble. Clicking the nest row itself only
165
- * toggles its own expansion.
163
+ * Default — ACCORDION: click the row to expand/collapse its children inline
164
+ * (below the row, in the same panel); the trailing chevron rotates 90°.
165
+ *
166
+ * `flyout` — the submenu opens BESIDE the row, the way a desktop menu bar does
167
+ * (MenuDropdownNestFlyout, kol-fxr 2026-10-13 — the editor's Affinity-style
168
+ * bar: Tools › Generative › Loops › Field › preset). Hover opens, leaving the
169
+ * row and its panel closes, a click toggles (touch), → opens and ← closes from
170
+ * the keyboard. The panel is a DOM CHILD of the row, never a portal: MenuItem
171
+ * closes on a click bubbling from `[data-menu-item]` and dismisses on an outside
172
+ * press, so a portalled panel would read as "outside" and close the menu under
173
+ * the pointer. One measure on open keeps it on screen — lifted to end above the
174
+ * window's foot (never past its head), flipped to the row's left when it would
175
+ * cross the right edge. Flyouts nest to any depth.
176
+ *
177
+ * `scroll` (flyout only) — caps the panel at 60vh and scrolls it, for long leaf
178
+ * lists. A scrolling panel clips its own flyouts, so give it to a panel with no
179
+ * flyouts inside.
180
+ *
181
+ * Either way, a leaf MenuDropdownItem inside still closes the whole menu via the
182
+ * standard data-menu-item bubble; the nest row itself only toggles.
166
183
  */
167
- export function MenuDropdownNest({ prefix, iconLeft, label, children }) {
184
+ export function MenuDropdownNest({ prefix, iconLeft, label, disabled, flyout = false, scroll = false, children }) {
185
+ if (flyout) return <MenuFlyoutNest prefix={prefix} iconLeft={iconLeft} label={label} disabled={disabled} scroll={scroll}>{children}</MenuFlyoutNest>
186
+ return <MenuAccordionNest prefix={prefix} iconLeft={iconLeft} label={label} disabled={disabled}>{children}</MenuAccordionNest>
187
+ }
188
+
189
+ const NEST_ROW = 'kol-menu-btn w-full kol-helper-12 px-3 h-8 shrink-0 flex items-center gap-2 text-left disabled:opacity-40 disabled:cursor-not-allowed'
190
+
191
+ function NestRowBody({ prefix, iconLeft, label }) {
192
+ return (
193
+ <>
194
+ {prefix && <span className="shrink-0 inline-flex items-center">{prefix}</span>}
195
+ {iconLeft && <span className="shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
196
+ {/* leading-normal — same descender fix as MenuDropdownItem above. */}
197
+ <span className="flex-1 truncate leading-normal">{label}</span>
198
+ </>
199
+ )
200
+ }
201
+
202
+ function MenuAccordionNest({ prefix, iconLeft, label, disabled, children }) {
168
203
  const [open, setOpen] = useState(false)
169
204
  return (
170
205
  <>
@@ -172,12 +207,10 @@ export function MenuDropdownNest({ prefix, iconLeft, label, children }) {
172
207
  type="button"
173
208
  onClick={() => setOpen((v) => !v)}
174
209
  aria-expanded={open}
175
- className="kol-menu-btn w-full kol-helper-12 px-3 h-8 inline-flex items-center gap-2 text-body hover:text-emphasis text-left"
210
+ disabled={disabled}
211
+ className={`${NEST_ROW} text-body hover:text-emphasis`}
176
212
  >
177
- {prefix && <span className="shrink-0 inline-flex items-center">{prefix}</span>}
178
- {iconLeft && <span className="shrink-0 w-4 inline-flex items-center justify-center">{iconLeft}</span>}
179
- {/* leading-normal — same descender fix as MenuDropdownItem above. */}
180
- <span className="flex-1 truncate leading-normal">{label}</span>
213
+ <NestRowBody prefix={prefix} iconLeft={iconLeft} label={label} />
181
214
  <Icon
182
215
  name="chevron-down"
183
216
  size={10}
@@ -193,3 +226,61 @@ export function MenuDropdownNest({ prefix, iconLeft, label, children }) {
193
226
  </>
194
227
  )
195
228
  }
229
+
230
+ function MenuFlyoutNest({ prefix, iconLeft, label, disabled, scroll, children }) {
231
+ const [open, setOpen] = useState(false)
232
+ const [fit, setFit] = useState({ dy: 0, flip: false })
233
+ const row = useRef(null)
234
+ const panel = useRef(null)
235
+
236
+ useLayoutEffect(() => {
237
+ if (!open) { setFit({ dy: 0, flip: false }); return }
238
+ const r = panel.current?.getBoundingClientRect()
239
+ /* lift it to end above the window's foot, never past its head — a panel taller than the
240
+ * window keeps its top rows (`scroll` is the answer for a long one) */
241
+ if (r) setFit({ dy: Math.max(8 - r.top, Math.min(0, window.innerHeight - 8 - r.bottom)), flip: r.right > window.innerWidth - 8 })
242
+ }, [open])
243
+
244
+ return (
245
+ <div
246
+ className="relative"
247
+ onPointerEnter={() => !disabled && setOpen(true)}
248
+ onPointerLeave={() => setOpen(false)}
249
+ onKeyDown={(e) => {
250
+ if (e.key === 'ArrowLeft' && open) { e.stopPropagation(); setOpen(false); row.current?.focus() }
251
+ }}
252
+ >
253
+ <button
254
+ ref={row}
255
+ type="button"
256
+ role="menuitem"
257
+ aria-haspopup="menu"
258
+ aria-expanded={open}
259
+ disabled={disabled}
260
+ onClick={() => setOpen((v) => !v)}
261
+ onKeyDown={(e) => {
262
+ if (e.key === 'ArrowRight') {
263
+ e.preventDefault()
264
+ setOpen(true)
265
+ requestAnimationFrame(() => panel.current?.querySelector('button:not(:disabled)')?.focus())
266
+ }
267
+ }}
268
+ className={`${NEST_ROW} ${open ? 'text-emphasis' : 'text-body hover:text-emphasis'}`}
269
+ >
270
+ <NestRowBody prefix={prefix} iconLeft={iconLeft} label={label} />
271
+ <Icon name="chevron-right" size={10} className="text-emphasis shrink-0" />
272
+ </button>
273
+ {open && (
274
+ /* top -5 = the panel's 1px border + 4px pad, so its first row sits on the trigger row */
275
+ <div
276
+ ref={panel}
277
+ role="menu"
278
+ className={`absolute ${fit.flip ? 'right-full' : 'left-full'} flex flex-col w-max min-w-[180px] max-w-[320px] py-1 bg-surface-secondary rounded border border-oq-08 shadow-lg z-10 ${scroll ? 'max-h-[60vh] overflow-y-auto' : ''}`}
279
+ style={{ top: -5 + fit.dy }}
280
+ >
281
+ {children}
282
+ </div>
283
+ )}
284
+ </div>
285
+ )
286
+ }
@@ -2,6 +2,7 @@ import { createContext, useContext, useEffect, useMemo, useState } from 'react'
2
2
  import { Icon } from '@kolkrabbi/kol-icons'
3
3
  import ActionButton from '../molecules/ActionButton.jsx'
4
4
  import Button from '../atoms/Button.jsx'
5
+ import CloseButton from '../atoms/CloseButton.jsx'
5
6
  import Divider from '../atoms/Divider.jsx'
6
7
  import Dropdown from '../molecules/Dropdown.jsx'
7
8
  import Input from '../atoms/Input.jsx'
@@ -1084,7 +1085,10 @@ function PickerBrowse({ client, accept, onClose, onSelect, title = 'MEDIA', ...b
1084
1085
  onClose?.()
1085
1086
  }
1086
1087
  return (
1087
- <FullscreenOverlay open scrim onClose={onClose}>
1088
+ /* THE X SITS ON THE HEADER ROW (MediaPickerCloseOnTheHeaderRow, kol-fxr 2026-10-10 — user: *"x
1089
+ * close is in a weird place, align better"*). The overlay's corner close floated ~100px above
1090
+ * the header and lined up with nothing; it rides `headerTrailing`, after the gear, instead. */
1091
+ <FullscreenOverlay open scrim onClose={onClose} closeButton={false}>
1088
1092
  <div className="kol-media-picker gap-4">
1089
1093
  <MediaLibraryBrowse
1090
1094
  {...browseProps}
@@ -1095,6 +1099,7 @@ function PickerBrowse({ client, accept, onClose, onSelect, title = 'MEDIA', ...b
1095
1099
  settings={settings}
1096
1100
  onSettingsChange={setSettings}
1097
1101
  onPickFile={setFile}
1102
+ headerTrailing={<>{browseProps.headerTrailing}<CloseButton onClick={onClose} /></>}
1098
1103
  />
1099
1104
  <div className="mt-auto flex items-center justify-end gap-4">
1100
1105
  <span className="kol-mono-12 text-fg-48 truncate mr-auto">{file ? file.key : 'Select a file'}</span>
@@ -81,7 +81,8 @@ export function HighlightMatch({ label, query, ranges }) {
81
81
  * the search modal opens on somewhere to go, not a blank box
82
82
  * @param {string} query controlled query (drives the highlight slice)
83
83
  * @param {Function} onQueryChange (string) => void — input change
84
- * @param {Function} onSelect (item) => void — row click / Enter; consumer navigates
84
+ * @param {Function} onSelect (item) => void — row click / Enter; consumer navigates. A row
85
+ * with `keepOpen` or `action` selects and the modal stays open
85
86
  * @param {string} placeholder input placeholder
86
87
  * @param {string} [enterLabel] what Enter does when no row is picked — shown as
87
88
  * the panel's last line, so Enter is never a surprise
@@ -137,8 +138,12 @@ export default function ShellSearchOverlay({
137
138
  return () => { if (prev instanceof HTMLElement) prev.focus() }
138
139
  }, [open])
139
140
 
140
- /* Roving row resets to the top on every query change / reopen. */
141
- useEffect(() => { setActiveIndex(0); setNavigated(false) }, [query, open])
141
+ /* Roving row resets to the top on every query change / reopen — and when the ROWS change under an
142
+ * unchanged query (ShellSearchOverlayActionKeepsOpen, kol-fxr 2026-10-13: a drill-in swaps the
143
+ * suggestions for a category's presets). Keyed on the row ids, not the array's identity, so a
144
+ * consumer passing a fresh array every render does not snap the highlight back to the top. */
145
+ const rowsKey = results.map((r) => r.id).join('\u0000')
146
+ useEffect(() => { setActiveIndex(0); setNavigated(false) }, [query, open, rowsKey])
142
147
 
143
148
  /* Keep the active row visible inside the scrolling list. */
144
149
  useEffect(() => {
@@ -148,9 +153,13 @@ export default function ShellSearchOverlay({
148
153
 
149
154
  if (!open) return null
150
155
 
156
+ /* A row that KEEPS THE MODAL OPEN — `keepOpen`, or an `action` row (the contract below always said
157
+ * so; until 0.252.0 every pick closed — ShellSearchOverlayActionKeepsOpen, kol-fxr 2026-10-13). It
158
+ * still reaches `onSelect`, and the closure stays the consumer's to run there: the overlay running
159
+ * it too would fire it twice in every shell that already does (workshop's tag rows). */
151
160
  const select = (item) => {
152
161
  onSelect?.(item)
153
- onClose?.()
162
+ if (!(item?.keepOpen || typeof item?.action === 'function')) onClose?.()
154
163
  }
155
164
 
156
165
  const optionId = (item) => `${listId}-${item.id}`
@@ -248,7 +257,9 @@ export default function ShellSearchOverlay({
248
257
  * icon optional leading glyph (kol-icons name)
249
258
  * hint subtext shown when the LABEL was not what matched
250
259
  * href a destination; dismisses the search modal
251
- * action a closure; runs and KEEPS the search modal open (tag rows)
260
+ * action a closure, run by the consumer's `onSelect`; the search modal STAYS OPEN (tag rows)
261
+ * keepOpen the row selects and the search modal STAYS OPEN — a drill-in (category →
262
+ * its items, a "← All" row back); the consumer swaps `suggestions`/`results`
252
263
  * Built by `buildShellSearchItems` (showcase/src/nav/shell-nav.js). */}
253
264
  {expanded ? (
254
265
  <div className="border-t border-fg-08 max-h-[70vh] overflow-y-auto">{children}</div>