@kolkrabbi/kol-shell 0.97.0 → 0.98.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/AppFloatNav.jsx +30 -11
- package/src/AppHub.jsx +1 -1
- package/src/AppShell.jsx +12 -2
- package/src/MoreSheet.jsx +99 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.98.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The application shell",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"react-dom": "^18.3.0 || ^19.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@kolkrabbi/kol-theme": "^0.207.0",
|
|
25
|
-
"@kolkrabbi/kol-icons": "^0.55.0",
|
|
26
24
|
"@kolkrabbi/kol-framework": "^0.67.0",
|
|
27
|
-
"@kolkrabbi/kol-
|
|
25
|
+
"@kolkrabbi/kol-icons": "^0.56.0",
|
|
26
|
+
"@kolkrabbi/kol-component": "^0.323.0",
|
|
27
|
+
"@kolkrabbi/kol-theme": "^0.207.0"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"src",
|
package/src/AppFloatNav.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react'
|
|
2
2
|
import { TabsRow, TABBAR_H, TABBAR_PILL_H, TABBAR_PILL_INSET, tabbarPillWidth, tabbarPillSlot, floatSurfaceClass, usePopover, PopoverPanel } from '@kolkrabbi/kol-component'
|
|
3
|
-
import MoreRows from './MoreSheet.jsx'
|
|
3
|
+
import MoreRows, { FloatMenu } from './MoreSheet.jsx'
|
|
4
4
|
|
|
5
5
|
/* taxonomy-ok: molecule — TabsRow's pill + MoreRows sheets of Buttons */
|
|
6
6
|
|
|
@@ -69,8 +69,13 @@ import MoreRows from './MoreSheet.jsx'
|
|
|
69
69
|
* `--kol-oq-04` ground and `--kol-surface-on-primary` ink (`.kol-btn-nav`'s hover tokens).
|
|
70
70
|
*
|
|
71
71
|
* THE FLOAT (AppFloatNav, 2026-10-30):
|
|
72
|
-
* @param {Array} items[].sub `[{ label, icon?, onPress }]` — a row that opens its own rows above its slot instead of
|
|
73
|
-
* routing (fxr: Randomiser → Generate, Effects); lit while they are open
|
|
72
|
+
* @param {Array} items[].sub `[{ label, icon?, onPress?, path?, sub? }]` — a row that opens its own rows above its slot instead of
|
|
73
|
+
* routing (fxr: Randomiser → Generate, Effects); lit while they are open. A row without
|
|
74
|
+
* `onPress` routes to its `path`
|
|
75
|
+
* NESTED LEVELS (FloatsOwnItems, kol-fxr 2026-10-31): a sub row with its own `sub` opens a level, the same row shape to any
|
|
76
|
+
* depth — `sub`, the More's `actions` and the transport's `sheetFor` rows alike (MoreSheet's `FloatMenu`). On the `dock` a
|
|
77
|
+
* level opens BESIDE its row (the + menu's popover); on every phone variant it REPLACES the card's rows under a Back row. A
|
|
78
|
+
* leaf runs and closes every level; Escape and an outside press close all; ↑ ↓ move, → / Enter open a level, ← goes back one.
|
|
74
79
|
* Its menus are the floating style B (`variant="float"` on the rows, `.kol-more-sheet-float`) — the board's.
|
|
75
80
|
* @param {boolean} menuBorder the sheets' 1px hairline (`.kol-more-sheet-bordered`) — off by default, the board's menus have none
|
|
76
81
|
* THE FOUR VARIANTS (user ruling 2026-10-30): `mobile` · `dock` · `panel` · `transport` — nothing else.
|
|
@@ -120,7 +125,8 @@ function FloatNav({ items = [], currentPath = '/', onNavigate, actions = [], sha
|
|
|
120
125
|
const [moreEl, setMoreEl] = useState(null)
|
|
121
126
|
const findMore = useCallback((n) => setMoreEl(n?.querySelector('button[aria-label="More"]') ?? null), [])
|
|
122
127
|
/* offset: 12 off the pill — the slot sits 4 inside it; crossAxis drops the card's bottom to the pill's */
|
|
123
|
-
|
|
128
|
+
/* an outside press closes it — except one on a nested level, which hangs beside it in its own portal (FloatMenu) */
|
|
129
|
+
const morePop = usePopover({ open: dock && open, onOpenChange: setOpen, placement: 'right-end', offset: { mainAxis: 16, crossAxis: 4 }, click: false, referenceElement: moreEl, dismiss: { outsidePress: (e) => !e.target?.closest?.('.kol-float-level') } })
|
|
124
130
|
/* the row whose `sub` rows are open */
|
|
125
131
|
const [sub, setSub] = useState(null)
|
|
126
132
|
useEffect(() => { setOpen(false); setSub(null) }, [currentPath])
|
|
@@ -184,6 +190,11 @@ function FloatNav({ items = [], currentPath = '/', onNavigate, actions = [], sha
|
|
|
184
190
|
: { bottom: pill ? `calc(env(safe-area-inset-bottom, 0px) + ${TABBAR_PILL_INSET}px)` : 'env(safe-area-inset-bottom, 0px)' }),
|
|
185
191
|
width: 'max-content', minWidth: 220, maxWidth: `calc(100vw - ${(pill ? TABBAR_PILL_H : TABBAR_H) + 36}px)`,
|
|
186
192
|
}
|
|
193
|
+
const card = `kol-more-sheet kol-more-sheet-float ${floatSurfaceClass(surface, true)}${menuBorder ? ' kol-more-sheet-bordered' : ''}`
|
|
194
|
+
/* a sub row (any level) picked: close everything; its `onPress` has run, else it routes */
|
|
195
|
+
const pickSub = (x) => { setSub(null); if (!x.onPress && x.path) onNavigate?.(x.path) }
|
|
196
|
+
/* a nested leaf in More: close it; its `onPress` has run, else it routes */
|
|
197
|
+
const pickMoreLeaf = (x) => { setOpen(false); if (!x.onPress && x.path) onNavigate?.(x.path) }
|
|
187
198
|
const press = (v) => {
|
|
188
199
|
if (v === MORE) { setSub(null); setOpen((o) => !o); return }
|
|
189
200
|
const item = inBar.find((i) => key(i) === v)
|
|
@@ -199,8 +210,10 @@ function FloatNav({ items = [], currentPath = '/', onNavigate, actions = [], sha
|
|
|
199
210
|
<button type="button" aria-label="Close" className="kol-phone-nav-scrim" onClick={() => setSub(null)} />
|
|
200
211
|
)}
|
|
201
212
|
{sub && (
|
|
202
|
-
<div className={`kol-phone-nav-more
|
|
203
|
-
<
|
|
213
|
+
<div className={`kol-phone-nav-more ${card}`} role="menu" aria-label={inBar.find((i) => key(i) === sub)?.label} style={overSlot(inBar.findIndex((i) => key(i) === sub))}>
|
|
214
|
+
<FloatMenu beside={dock} cardClass={card} onLeaf={pickSub}>
|
|
215
|
+
<MoreRows variant="float" actions={inBar.find((i) => key(i) === sub)?.sub} onPick={pickSub} />
|
|
216
|
+
</FloatMenu>
|
|
204
217
|
</div>
|
|
205
218
|
)}
|
|
206
219
|
{open && !dock && (
|
|
@@ -209,16 +222,20 @@ function FloatNav({ items = [], currentPath = '/', onNavigate, actions = [], sha
|
|
|
209
222
|
<button type="button" aria-label="Close more" className={`kol-phone-nav-scrim${moreKeepsOpen ? '' : ' kol-overlay-scrim'}`} onClick={() => setOpen(false)} />
|
|
210
223
|
)}
|
|
211
224
|
{open && !dock && (
|
|
212
|
-
<div className={`kol-phone-nav-more
|
|
225
|
+
<div className={`kol-phone-nav-more ${card}`} role="menu" aria-label="More" style={sheetStyle}>
|
|
213
226
|
{/* the nav, the page's actions, then the pinned foot (frame A2) */}
|
|
227
|
+
<FloatMenu cardClass={card} onLeaf={pickMoreLeaf}>
|
|
214
228
|
<MoreRows variant="float" actions={actions} items={before} itemsFirst active={active} onPick={(x) => { setOpen(false); if (x.onPress && !actions.includes(x)) { x.onPress(); return } if (x.path) onNavigate?.(x.path) }} />
|
|
215
229
|
{after.length > 0 && <MoreRows variant="float" items={after} active={active} onPick={(x) => { setOpen(false); if (x.onPress) { x.onPress(); return } if (x.path) onNavigate?.(x.path) }} />}
|
|
230
|
+
</FloatMenu>
|
|
216
231
|
</div>
|
|
217
232
|
)}
|
|
218
233
|
{dock && (
|
|
219
|
-
<PopoverPanel popover={morePop} panel={false} focus={false} className={
|
|
234
|
+
<PopoverPanel popover={morePop} panel={false} focus={false} className={card} style={{ minWidth: 220, maxWidth: 'calc(100vw - 24px)' }}>
|
|
235
|
+
<FloatMenu beside cardClass={card} onLeaf={pickMoreLeaf}>
|
|
220
236
|
<MoreRows variant="float" actions={actions} items={before} itemsFirst active={active} onPick={(x) => { setOpen(false); if (x.onPress && !actions.includes(x)) { x.onPress(); return } if (x.path) onNavigate?.(x.path) }} />
|
|
221
237
|
{after.length > 0 && <MoreRows variant="float" items={after} active={active} onPick={(x) => { setOpen(false); if (x.onPress) { x.onPress(); return } if (x.path) onNavigate?.(x.path) }} />}
|
|
238
|
+
</FloatMenu>
|
|
222
239
|
</PopoverPanel>
|
|
223
240
|
)}
|
|
224
241
|
{/* `contents` — no box; it only hands the ··· slot to the popover */}
|
|
@@ -260,8 +277,8 @@ function FloatNav({ items = [], currentPath = '/', onNavigate, actions = [], sha
|
|
|
260
277
|
* `onPress` and closes the sheet.
|
|
261
278
|
*
|
|
262
279
|
* @param {Array} items `[{ id, icon, label, onPress?, selected? }]` in pill order
|
|
263
|
-
* @param {Object} sheetFor `{ [id]: [{ label, icon?, onPress, checked? }] }` — rows for a slot that opens a sheet;
|
|
264
|
-
* `checked` marks the current pick with the 22px check (MoreRows)
|
|
280
|
+
* @param {Object} sheetFor `{ [id]: [{ label, icon?, onPress, checked?, sub? }] }` — rows for a slot that opens a sheet;
|
|
281
|
+
* `checked` marks the current pick with the 22px check (MoreRows); `sub` opens a level in place
|
|
265
282
|
* @param {'bottom'|'top'} placement the pill's edge (default bottom)
|
|
266
283
|
* @param {boolean} foldable a sideways swipe folds it into the right edge tab
|
|
267
284
|
* @param {boolean} folded · {Function} onFoldChange the folded state, controlled (else the pill holds it)
|
|
@@ -303,7 +320,9 @@ function Transport({ items = [], sheetFor = {}, placement = 'bottom', foldable =
|
|
|
303
320
|
)}
|
|
304
321
|
{sheet && (
|
|
305
322
|
<div className={`kol-phone-nav-more kol-more-sheet kol-more-sheet-float ${floatSurfaceClass(surface, true)}${menuBorder ? ' kol-more-sheet-bordered' : ''}`} role="menu" aria-label={items[at]?.label} style={sheetStyle}>
|
|
306
|
-
<
|
|
323
|
+
<FloatMenu onLeaf={() => setSheet(null)}>
|
|
324
|
+
<MoreRows variant="float" actions={sheetFor[sheet]} onPick={() => setSheet(null)} />
|
|
325
|
+
</FloatMenu>
|
|
307
326
|
</div>
|
|
308
327
|
)}
|
|
309
328
|
<TabsRow
|
package/src/AppHub.jsx
CHANGED
|
@@ -413,7 +413,7 @@ function HubFrame({
|
|
|
413
413
|
<AppShell
|
|
414
414
|
items={rows}
|
|
415
415
|
bottomItems={bottom}
|
|
416
|
-
barItems={signedOutHome && home.chromes?.length ? home.chromes.map((c) => ({ id: c.label, label: c.label, icon: c.icon, onPress: c.onPress })) : barItems}
|
|
416
|
+
barItems={signedOutHome && home.chromes?.length ? home.chromes.map((c) => ({ id: c.label, label: c.label, icon: c.icon, onPress: c.onPress, sub: c.sub })) : barItems}
|
|
417
417
|
barActions={homeActions}
|
|
418
418
|
phoneNav={(() => {
|
|
419
419
|
const sheet = [...rows, ...bottom.map((r) => ({ ...r, icon: r.icon === ACCOUNT_GLYPH ? 'user' : r.icon, foot: true }))]
|
package/src/AppShell.jsx
CHANGED
|
@@ -84,7 +84,14 @@ import { TABBAR_H, TABBAR_PILL_H, TABBAR_PILL_INSET, MastheadContext, RAIL_PRESE
|
|
|
84
84
|
* them the stage (children) and a bottom Rail. `{ transport: { items, sheetFor, … },
|
|
85
85
|
* rail: node, railHeight = '50dvh' }`. The stage starts under the top float and the Rail's
|
|
86
86
|
* rows scroll clear of the transport — both insets are `TABBAR_PILL_INSET + TABBAR_PILL_H +
|
|
87
|
-
* TABBAR_PILL_INSET` plus the safe area; the Rail rises on `--kol-shadow-rail-up`, no rule
|
|
87
|
+
* TABBAR_PILL_INSET` plus the safe area; the Rail rises on `--kol-shadow-rail-up`, no rule.
|
|
88
|
+
* THE PAGE'S OWN ROWS (FloatsOwnItems, kol-fxr 2026-10-31 — *"keep it as flexible as possible"*):
|
|
89
|
+
* `floats.items` (AppFloatNav items — `{ path | id, icon, label, onPress?, selected?, sub? }`)
|
|
90
|
+
* take the top float's slots and `floats.actions` (`[{ label, icon?, onPress, sub? }]`) its
|
|
91
|
+
* More's actions, wherever the app passes them — the page's route, typically. THE ONE RULE:
|
|
92
|
+
* the More keeps the app's whole nav (`barItems`, else items + bottomItems) — the page's
|
|
93
|
+
* rows replace the slots, never the way back (a `phoneNav.sheetItems` still wins). Unset,
|
|
94
|
+
* the top float is the app's nav and `barActions`, as 0.97.0
|
|
88
95
|
* @param {Array} [props.barActions] `[{ label, icon?, onPress }]` — the page's buttons in the bar's More sheet, under the nav (PhoneNav `actions`)
|
|
89
96
|
* @param {'mobile'|'panel'|'transport'} [props.navVariant='mobile'] THE PHONE PILL'S PRESET (PhoneNavVariants, kol-fxr 2026-10-28 —
|
|
90
97
|
* the Home pill kept its hairline while Labs tuned its own by hand): `mobile` (was `nav`) is no hairline,
|
|
@@ -213,6 +220,9 @@ export default function AppShell({
|
|
|
213
220
|
/* THE TWO FLOATS: the bar is the top float, and the page is a column — the stage, then the Rail */
|
|
214
221
|
const floats = bar && touch === 'floats'
|
|
215
222
|
const floatClear = `${TABBAR_PILL_INSET + TABBAR_PILL_H + TABBAR_PILL_INSET}px`
|
|
223
|
+
/* the app's nav, and the page's own rows when it passes them — the app's nav then lives in the top float's More */
|
|
224
|
+
const appNav = barItems ?? [...(items ?? []), ...(bottomItems ?? [])]
|
|
225
|
+
const pageRows = floats && floatsProp?.items?.length ? floatsProp.items : null
|
|
216
226
|
const [drawerOpen, setDrawerOpen] = useState(false)
|
|
217
227
|
useEffect(() => { if (!drawer) setDrawerOpen(false) }, [drawer])
|
|
218
228
|
useEffect(() => {
|
|
@@ -414,7 +424,7 @@ export default function AppShell({
|
|
|
414
424
|
onClick={() => setDrawerOpen(false)}
|
|
415
425
|
/>
|
|
416
426
|
)}
|
|
417
|
-
{bar && <AppFloatNav items={
|
|
427
|
+
{bar && <AppFloatNav items={pageRows ?? appNav} actions={floats && floatsProp?.actions ? floatsProp.actions : barActions} shape={touch === 'bar' ? 'bar' : 'pill'} variant={floats ? 'panel' : navVariant} moreItems={moreItems} {...(pageRows && { sheetItems: appNav })} {...phoneNav} currentPath={currentPath} onNavigate={navigate} />}
|
|
418
428
|
{floats && floatsProp?.transport?.items?.length > 0 && <AppFloatNav variant="transport" foldable {...floatsProp.transport} />}
|
|
419
429
|
{!navHidden && !bar && !barAside && (
|
|
420
430
|
<Rail
|
package/src/MoreSheet.jsx
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createContext, useContext, useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { Avatar, Button, usePopover, PopoverPanel } from '@kolkrabbi/kol-component'
|
|
2
3
|
import { Icon } from '@kolkrabbi/kol-icons'
|
|
3
4
|
|
|
5
|
+
/* the open level a row sits in (FloatMenu); null outside one, where a row's `sub` is ignored as before */
|
|
6
|
+
const Level = createContext(null)
|
|
7
|
+
const FLOAT_ROW = 'w-full justify-start kol-btn-float'
|
|
8
|
+
|
|
4
9
|
/* taxonomy-ok: molecule — a column of nav Buttons */
|
|
5
10
|
|
|
6
11
|
/**
|
|
@@ -25,19 +30,28 @@ export default function MoreRows({ actions = [], items = [], active, onPick, ite
|
|
|
25
30
|
/* the float row's height, inset and gap are the theme's (`.kol-more-sheet-float`, round 3) — no h-11 / gap-3 utility,
|
|
26
31
|
* which would outrank the components layer */
|
|
27
32
|
const float = variant === 'float'
|
|
28
|
-
const rowCls = float ?
|
|
33
|
+
const rowCls = float ? FLOAT_ROW : 'w-full justify-start h-11 gap-3'
|
|
34
|
+
const level = useContext(Level)
|
|
29
35
|
const glyph = float ? 'var(--kol-float-ic)' : 22
|
|
30
36
|
const acts = (
|
|
31
37
|
<>
|
|
32
|
-
{actions.map((a) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
{actions.map((a) => {
|
|
39
|
+
/* a row with `sub` inside a FloatMenu opens its level instead of picking — the chevron at the row's end */
|
|
40
|
+
const nests = level && a.sub?.length > 0
|
|
41
|
+
return (
|
|
42
|
+
/* a nesting row draws its own glyph so the label can take the room between it and the chevron; 8 apart, as Button's */
|
|
43
|
+
<Button key={a.label} variant="nav" size="lg" iconLeft={a.checked === undefined && !a.avatar && !nests ? a.icon : undefined} iconSize={glyph}
|
|
44
|
+
className={rowCls} style={nests ? { gap: 8 } : undefined}
|
|
45
|
+
aria-haspopup={nests ? 'menu' : undefined} aria-expanded={nests ? level.isOpen(a) : undefined}
|
|
46
|
+
onClick={(e) => { if (nests) { level.open(a, e.currentTarget); return } onPick?.(a); a.onPress?.() }}>
|
|
47
|
+
{a.avatar && <Avatar src={a.avatar} alt="" size="xs" />}
|
|
48
|
+
{a.checked !== undefined && (
|
|
49
|
+
<span className="inline-flex items-center justify-center shrink-0" style={{ width: float ? 'var(--kol-float-ic)' : 22, height: float ? 'var(--kol-float-ic)' : 22 }}>{a.checked && <Icon name="check" size={22} />}</span>
|
|
50
|
+
)}
|
|
51
|
+
{nests ? <>{a.icon && <Icon name={a.icon} size={glyph} />}<span className="flex-1 text-left">{a.label}</span><Icon name="chevron-right" size={glyph} className="shrink-0 text-oq-48" /></> : a.label}
|
|
52
|
+
</Button>
|
|
53
|
+
)
|
|
54
|
+
})}
|
|
41
55
|
</>
|
|
42
56
|
)
|
|
43
57
|
const dests = (
|
|
@@ -60,3 +74,77 @@ export default function MoreRows({ actions = [], items = [], active, onPick, ite
|
|
|
60
74
|
)
|
|
61
75
|
return itemsFirst ? <>{dests}{acts}</> : <>{acts}{dests}</>
|
|
62
76
|
}
|
|
77
|
+
|
|
78
|
+
const rowKey = (r) => r.id ?? r.path ?? r.label
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* FloatMenu — A float's card with NESTED LEVELS (FloatsOwnItems, kol-fxr 2026-10-31 — *"does the float nav offer nested
|
|
82
|
+
* menus"*). Wraps the card's first level (`children`, MoreRows); a MoreRows action with `sub` opens the next level, the same
|
|
83
|
+
* row shape to any depth (`sub[].sub[].sub…`). How a level opens is one rule, by room:
|
|
84
|
+
* - `beside` (the desk's `dock`) — a card of the same chrome beside its parent row, right of it, the bottom edges on one
|
|
85
|
+
* line, through the existing popover (`usePopover` + `PopoverPanel`, flips and shifts at the window's edge);
|
|
86
|
+
* - else (every phone variant) — the level REPLACES the card's rows, under a Back row naming the parent.
|
|
87
|
+
* A leaf runs its `onPress`, then `onLeaf(row)` closes every level (the caller closes the card — Escape and an outside press
|
|
88
|
+
* are the card's, and closing it closes everything). Keys: ↑ ↓ move, → or Enter opens a level, ← goes back one.
|
|
89
|
+
*
|
|
90
|
+
* @param {boolean} beside levels open beside their row (else they replace the card's rows)
|
|
91
|
+
* @param {string} cardClass a beside level's chrome — the first card's classes
|
|
92
|
+
* @param {Function} onLeaf `(row) => void` — a nested leaf was picked (its `onPress` has run); close everything here
|
|
93
|
+
*/
|
|
94
|
+
export function FloatMenu({ beside = false, cardClass = '', onLeaf, children }) {
|
|
95
|
+
/* the open rows, outermost first — `{ row, el }`, `el` the row a beside level hangs off.
|
|
96
|
+
* ponytail: the row object is kept as opened; a consumer that rebuilds its rows mid-open sees the old `sub` until reopened */
|
|
97
|
+
const [trail, setTrail] = useState([])
|
|
98
|
+
const at = (depth) => ({
|
|
99
|
+
open: (row, el) => setTrail((t) => (t[depth] && rowKey(t[depth].row) === rowKey(row) ? t.slice(0, depth) : [...t.slice(0, depth), { row, el }])),
|
|
100
|
+
isOpen: (row) => !!trail[depth] && rowKey(trail[depth].row) === rowKey(row),
|
|
101
|
+
})
|
|
102
|
+
const back = (depth) => { const parent = trail[depth - 1]?.el; setTrail((t) => t.slice(0, depth - 1)); if (beside) parent?.focus({ preventScroll: true }) }
|
|
103
|
+
const keys = (depth) => (e) => {
|
|
104
|
+
const rows = [...e.currentTarget.querySelectorAll('button')]
|
|
105
|
+
const i = rows.indexOf(document.activeElement)
|
|
106
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') rows[(i + (e.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length]?.focus()
|
|
107
|
+
else if (e.key === 'ArrowRight' && e.target.getAttribute?.('aria-haspopup')) { if (e.target.getAttribute('aria-expanded') !== 'true') e.target.click() }
|
|
108
|
+
else if (e.key === 'ArrowLeft' && depth > 0) back(depth)
|
|
109
|
+
else return
|
|
110
|
+
e.preventDefault()
|
|
111
|
+
e.stopPropagation()
|
|
112
|
+
}
|
|
113
|
+
const level = (depth, rows, lead) => (
|
|
114
|
+
<Level.Provider value={at(depth)}>
|
|
115
|
+
<LevelRows key={`${depth}:${rowKey(trail[depth - 1].row)}`} onKeyDown={keys(depth)}>
|
|
116
|
+
{lead}
|
|
117
|
+
<MoreRows variant="float" actions={rows} onPick={onLeaf} />
|
|
118
|
+
</LevelRows>
|
|
119
|
+
</Level.Provider>
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
if (!beside && trail.length) {
|
|
123
|
+
const d = trail.length
|
|
124
|
+
return level(d, trail[d - 1].row.sub, (
|
|
125
|
+
<Button variant="nav" size="lg" iconLeft="chevron-left" iconSize="var(--kol-float-ic)" className={FLOAT_ROW} onClick={() => back(d)}>{trail[d - 1].row.label}</Button>
|
|
126
|
+
))
|
|
127
|
+
}
|
|
128
|
+
return (
|
|
129
|
+
<Level.Provider value={at(0)}>
|
|
130
|
+
<div className="contents" onKeyDown={keys(0)}>{children}</div>
|
|
131
|
+
{beside && trail.map((s, i) => (
|
|
132
|
+
<Beside key={i} anchor={s.el} cardClass={cardClass}>{level(i + 1, s.row.sub)}</Beside>
|
|
133
|
+
))}
|
|
134
|
+
</Level.Provider>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* a nested level's rows — its first row takes the focus when it opens, so the keys carry on in it */
|
|
139
|
+
function LevelRows({ onKeyDown, children }) {
|
|
140
|
+
const ref = useRef(null)
|
|
141
|
+
useEffect(() => { ref.current?.querySelector('button')?.focus({ preventScroll: true }) }, [])
|
|
142
|
+
return <div ref={ref} className="contents" onKeyDown={onKeyDown}>{children}</div>
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* a level beside its row — the + menu's popover: right of the row, 12 off the card (the row sits 6 in), the bottom edges on
|
|
146
|
+
* one line. `kol-float-level` marks it so a parent popover's outside press lets it be */
|
|
147
|
+
function Beside({ anchor, cardClass, children }) {
|
|
148
|
+
const pop = usePopover({ open: true, placement: 'right-end', offset: { mainAxis: 18, crossAxis: 6 }, click: false, dismiss: false, role: 'menu', referenceElement: anchor })
|
|
149
|
+
return <PopoverPanel popover={pop} panel={false} focus={false} className={`kol-float-level ${cardClass}`} style={{ minWidth: 220, maxWidth: 'calc(100vw - 24px)' }}>{children}</PopoverPanel>
|
|
150
|
+
}
|