@justanarthur/modo-ui 2.3.0 → 2.5.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/components/data-display/diff/index.tsx +19 -3
- package/components/inputs/choice-list/index.tsx +4 -3
- package/components/navigation/sidebar/index.tsx +48 -1
- package/components/navigation/sidebar/menu-scope.tsx +142 -53
- package/components/navigation/sidebar/sidebar-menu-actions.tsx +5 -5
- package/components/navigation/sidebar/sidebar-menu-button.tsx +4 -7
- package/components/navigation/sidebar/sidebar-menu-item.tsx +39 -36
- package/components/navigation/sidebar/sidebar-menu-sub.tsx +3 -2
- package/components/overlays/command/index.tsx +70 -12
- package/components/overlays/dropdown/menu-popup.tsx +11 -2
- package/components/overlays/tooltip/index.tsx +9 -1
- package/dist/blocks/desktop-shell/index.js +11 -11
- package/dist/blocks/sidebar-app/index.js +14 -14
- package/dist/components/actions/copy/index.js +3 -3
- package/dist/components/containers/accordion/index.js +5 -5
- package/dist/components/containers/card/index.js +4 -4
- package/dist/components/data-display/diff/index.d.ts +1 -1
- package/dist/components/data-display/diff/index.js +2 -2
- package/dist/components/data-display/markdown/index.js +7 -7
- package/dist/components/data-display/table/index.js +4 -4
- package/dist/components/inputs/checkbox/index.js +6 -6
- package/dist/components/inputs/choice-list/index.js +5 -5
- package/dist/components/inputs/color-picker/index.js +7 -7
- package/dist/components/inputs/combobox/index.js +7 -7
- package/dist/components/inputs/date-time/calendar/index.js +5 -5
- package/dist/components/inputs/date-time/date-picker/index.js +12 -12
- package/dist/components/inputs/date-time/date-range-picker/index.js +12 -12
- package/dist/components/inputs/date-time/duration-picker/index.js +11 -11
- package/dist/components/inputs/date-time/month-picker/index.js +10 -10
- package/dist/components/inputs/date-time/time-picker/index.js +11 -11
- package/dist/components/inputs/input/index.js +2 -2
- package/dist/components/inputs/key-value/index.js +3 -3
- package/dist/components/inputs/number-input/index.js +3 -3
- package/dist/components/inputs/radio/index.js +5 -5
- package/dist/components/inputs/search/index.js +8 -8
- package/dist/components/inputs/select/index.js +7 -7
- package/dist/components/inputs/switch/index.js +4 -4
- package/dist/components/navigation/breadcrumb/index.js +9 -9
- package/dist/components/navigation/navigation-menu/index.js +6 -6
- package/dist/components/navigation/pagination/index.js +5 -5
- package/dist/components/navigation/sidebar/index.js +10 -10
- package/dist/components/navigation/tabs/index.js +4 -4
- package/dist/components/navigation/tree/index.js +5 -5
- package/dist/components/overlays/alert-dialog/index.js +3 -3
- package/dist/components/overlays/command/index.d.ts +6 -3
- package/dist/components/overlays/command/index.js +7 -7
- package/dist/components/overlays/context-menu/index.js +9 -9
- package/dist/components/overlays/dialog/index.js +2 -2
- package/dist/components/overlays/dropdown/index.js +8 -8
- package/dist/components/overlays/popover/index.js +2 -2
- package/dist/components/overlays/preview-card/index.js +2 -2
- package/dist/components/overlays/sheet/index.js +3 -3
- package/dist/components/overlays/tooltip/index.js +2 -2
- package/dist/docs/index.js +11 -11
- package/dist/index.d.ts +12 -6
- package/dist/index.js +55 -55
- package/dist/lib/fluid-hover-highlight.js +3 -2
- package/dist/lib/focus-ring.d.ts +5 -2
- package/dist/lib/focus-ring.js +2 -1
- package/dist/lib/goo-indicator.d.ts +5 -2
- package/dist/lib/goo-indicator.js +2 -1
- package/dist/lib/overlay.d.ts +8 -1
- package/dist/lib/overlay.js +3 -1
- package/dist/lib/scroll-column.js +4 -4
- package/dist/lib/use-fluid-hover.d.ts +3 -1
- package/dist/lib/use-fluid-hover.js +3 -1
- package/dist/lib/use-merge-split.js +3 -2
- package/dist/primitives/content/code/index.js +2 -2
- package/dist/primitives/layout/scroll-area/index.js +1 -1
- package/dist/primitives/systems/fluid-hover/index.js +4 -4
- package/dist/shared/{components-7xc2dne4.js → components-0ep66sg9.js} +5 -5
- package/dist/shared/{components-agjpst9b.js → components-0v4jxw7z.js} +1 -1
- package/dist/shared/{components-a3brpprb.js → components-1qw8hqwq.js} +7 -7
- package/dist/shared/{components-7c4a0egq.js → components-21hcwp85.js} +78 -43
- package/dist/shared/{components-fjg4j430.js → components-2c22zpm2.js} +2 -2
- package/dist/shared/{components-kz6ak6kj.js → components-3qcgeay1.js} +2 -2
- package/dist/shared/{components-8ybvpebx.js → components-4d0v8nzm.js} +59 -19
- package/dist/shared/{components-e52xgvd9.js → components-4fay97sm.js} +7 -7
- package/dist/shared/{components-fxw1122w.js → components-4fhjk3jz.js} +2 -2
- package/dist/shared/{components-czvraaw9.js → components-4m9stj7d.js} +10 -10
- package/dist/shared/{components-y4gsk1jt.js → components-5w7hxa1n.js} +1 -1
- package/dist/shared/{components-c515d6xr.js → components-5wykqxph.js} +6 -1
- package/dist/shared/{components-7g2q2ccp.js → components-66aw235e.js} +6 -6
- package/dist/shared/{components-z87sanbc.js → components-766w1xcw.js} +4 -4
- package/dist/shared/{components-8e0fjgm9.js → components-7rn454aq.js} +11 -2
- package/dist/shared/{components-2tw25pk6.js → components-895m1f3s.js} +7 -7
- package/dist/shared/{components-h8v9nh5r.js → components-8dgrpegd.js} +16 -4
- package/dist/shared/{components-m7d7r3r8.js → components-8hzwz162.js} +2 -2
- package/dist/shared/{components-b7p1pjcm.js → components-8m5e493q.js} +1 -1
- package/dist/shared/{components-rzy6h7s4.js → components-8nnhzeb3.js} +5 -5
- package/dist/shared/{components-1hga6pkn.js → components-8xe4h118.js} +5 -5
- package/dist/shared/{components-83jn0raj.js → components-9am5511q.js} +3 -3
- package/dist/shared/{components-g35n8tzm.js → components-9b2m90st.js} +1 -1
- package/dist/shared/{components-2bq4ng4d.js → components-9yrajpy0.js} +1 -1
- package/dist/shared/{components-mvwf8ckh.js → components-ac0x7zpq.js} +2 -2
- package/dist/shared/{components-q7zk70tx.js → components-af44r4y9.js} +1 -1
- package/dist/shared/{components-2v4mmw1s.js → components-b2fag579.js} +212 -121
- package/dist/shared/{components-ex2xtqv7.js → components-br6t88cb.js} +1 -1
- package/dist/shared/{components-z0kz9rxj.js → components-bxqmbcz2.js} +6 -2
- package/dist/shared/{components-e7zxwja1.js → components-d4gkhy26.js} +1 -1
- package/dist/shared/{components-w1ysefg1.js → components-eawe4nxm.js} +1 -1
- package/dist/shared/{components-1sbnbq6a.js → components-fpgfs01m.js} +1 -1
- package/dist/shared/{components-tcm3k3wj.js → components-ft5dgjg6.js} +9 -2
- package/dist/shared/{components-6g8a5nrs.js → components-fymenepq.js} +7 -7
- package/dist/shared/{components-k2gg1agj.js → components-gzve0nkp.js} +4 -4
- package/dist/shared/{components-k25zw9g8.js → components-hjk6dwsp.js} +1 -1
- package/dist/shared/{components-6xtntksc.js → components-jnjw9j2z.js} +9 -9
- package/dist/shared/{components-9rebr89j.js → components-k8awpmbn.js} +2 -2
- package/dist/shared/{components-4fswe4kh.js → components-mb80a9wg.js} +1 -1
- package/dist/shared/{components-nh05qz8b.js → components-mzdbtgvz.js} +8 -8
- package/dist/shared/{components-x5v7e0fz.js → components-nmbcfwx8.js} +7 -7
- package/dist/shared/{components-01e24999.js → components-pfwjhxd8.js} +21 -11
- package/dist/shared/{components-nred2e6g.js → components-q28xct6t.js} +2 -2
- package/dist/shared/{components-etgpz4zk.js → components-qrtcc8aw.js} +3 -3
- package/dist/shared/{components-esy5nsvc.js → components-resqc2d2.js} +12 -0
- package/dist/shared/{components-gnsvnejm.js → components-rtwfh1gc.js} +2 -2
- package/dist/shared/{components-vykcfb5r.js → components-v1zzr668.js} +3 -3
- package/dist/shared/{components-5vezp3e5.js → components-vcmky8ns.js} +6 -6
- package/dist/shared/{components-27fatggq.js → components-y9se9mx5.js} +3 -3
- package/dist/shared/{components-9ca0c92a.js → components-yfx0skxc.js} +1 -1
- package/dist/shared/{components-eebf7f9c.js → components-z14s3avn.js} +9 -9
- package/dist/shared/{components-ta4e10mx.js → components-zckgawt6.js} +5 -5
- package/dist/styles.css +2 -1
- package/lib/focus-ring.tsx +15 -8
- package/lib/goo-indicator.tsx +20 -8
- package/lib/overlay.tsx +22 -1
- package/lib/use-fluid-hover.ts +96 -72
- package/package.json +1 -1
- package/primitives/layout/scroll-area/index.tsx +20 -0
|
@@ -37,16 +37,32 @@ const SIGN: Record<DiffLineKind, string> = {
|
|
|
37
37
|
}
|
|
38
38
|
const SIGN_CHAR: Record<DiffLineKind, string> = { add: '+', remove: '−', context: ' ', hunk: '' }
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
// What git prints above a file's hunks: never code.
|
|
41
|
+
const GIT_HEADER =
|
|
42
|
+
/^(diff --git |index |(new|deleted) file mode |(old|new) mode |(dis)?similarity index |rename (from|to) |copy (from|to) |Binary files )/
|
|
43
|
+
|
|
44
|
+
/** Reads a unified diff (`@@ -a,b +c,d @@` hunks, `+`/`-`/space lines); file headers (`git diff`'s too) are skipped. */
|
|
41
45
|
function parsePatch(patch: string): DiffLine[] {
|
|
42
46
|
const lines: DiffLine[] = []
|
|
43
47
|
let oldNo = 0
|
|
44
48
|
let newNo = 0
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
// Between a file's first header line and its first hunk; a patch may also start straight with lines.
|
|
50
|
+
let header = true
|
|
51
|
+
const raws = patch.replace(/^\n+|\n+$/g, '').split('\n')
|
|
52
|
+
for (const [i, raw] of raws.entries()) {
|
|
53
|
+
if (raw.startsWith('diff --git ')) header = true
|
|
54
|
+
if (header && (GIT_HEADER.test(raw) || raw.startsWith('---') || raw.startsWith('+++'))) continue
|
|
55
|
+
// Inside hunks, a `---` / `+++` pair starts the next file (`diff -u` of several); alone it is a line that began with `--` or `++`.
|
|
56
|
+
if (raw.startsWith('--- ') && raws[i + 1]?.startsWith('+++ ')) {
|
|
57
|
+
header = true
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
// "" annotates the line above it.
|
|
61
|
+
if (raw.startsWith('\\')) continue
|
|
47
62
|
|
|
48
63
|
const hunk = raw.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/)
|
|
49
64
|
if (hunk) {
|
|
65
|
+
header = false
|
|
50
66
|
oldNo = Number(hunk[1])
|
|
51
67
|
newNo = Number(hunk[2])
|
|
52
68
|
lines.push({ kind: 'hunk', text: raw })
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
'use client'
|
|
11
11
|
|
|
12
|
-
import { forwardRef, type ReactNode, useRef } from 'react'
|
|
12
|
+
import { forwardRef, memo, type ReactNode, useRef } from 'react'
|
|
13
13
|
import { FluidHoverHighlight } from '../../../lib/fluid-hover-highlight'
|
|
14
14
|
import { FocusRing } from '../../../lib/focus-ring'
|
|
15
15
|
import { GooIndicator } from '../../../lib/goo-indicator'
|
|
@@ -48,7 +48,8 @@ interface RowProps {
|
|
|
48
48
|
rowClassName?: string
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
// Memoized: the list re-renders on every hover and resize step; a row only when its own props change.
|
|
52
|
+
const Row = memo(function Row({ option, index, selected, tabbable, register, onPick, rowClassName }: RowProps) {
|
|
52
53
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
53
54
|
const shape = useShape()
|
|
54
55
|
const size = useSize()
|
|
@@ -98,7 +99,7 @@ function Row({ option, index, selected, tabbable, register, onPick, rowClassName
|
|
|
98
99
|
</div>
|
|
99
100
|
</div>
|
|
100
101
|
)
|
|
101
|
-
}
|
|
102
|
+
})
|
|
102
103
|
|
|
103
104
|
interface ChoiceListProps {
|
|
104
105
|
/** The rows, in order. */
|
|
@@ -14,9 +14,12 @@ import {
|
|
|
14
14
|
type HTMLAttributes,
|
|
15
15
|
type ReactNode,
|
|
16
16
|
type RefAttributes,
|
|
17
|
+
type RefObject,
|
|
17
18
|
useEffect,
|
|
18
19
|
useMemo,
|
|
20
|
+
useRef,
|
|
19
21
|
} from 'react'
|
|
22
|
+
import { useMergeRefs } from '../../../lib/merge-refs'
|
|
20
23
|
import { useControllableState } from '../../../lib/use-controllable-state'
|
|
21
24
|
import { cn } from '../../../lib/utils'
|
|
22
25
|
import { ScrollArea } from '../../../primitives/layout/scroll-area'
|
|
@@ -271,6 +274,41 @@ const Sidebar = forwardRef<HTMLDivElement, SidebarProps>(
|
|
|
271
274
|
) as SidebarComponent
|
|
272
275
|
Sidebar.displayName = 'Sidebar'
|
|
273
276
|
|
|
277
|
+
/**
|
|
278
|
+
* While the list scrolls under a resting pointer, its rows stop taking the
|
|
279
|
+
* pointer: every row passing under it would hover (the highlight, revealed
|
|
280
|
+
* actions, a row's lazy tooltips), a style change and often a commit per row.
|
|
281
|
+
* Moving the pointer, or 150 ms without a scroll, hands it back.
|
|
282
|
+
*/
|
|
283
|
+
function usePauseHoverWhileScrolling(ref: RefObject<HTMLDivElement | null>, enabled: boolean) {
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
const content = enabled ? ref.current : null
|
|
286
|
+
const scroller = content?.closest('[data-slot="scroll-area-viewport"]')
|
|
287
|
+
if (!content || !scroller) return
|
|
288
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
289
|
+
const resume = () => {
|
|
290
|
+
clearTimeout(timer)
|
|
291
|
+
content.removeAttribute('data-scrolling')
|
|
292
|
+
}
|
|
293
|
+
const onScroll = () => {
|
|
294
|
+
if (!content.hasAttribute('data-scrolling')) content.setAttribute('data-scrolling', '')
|
|
295
|
+
clearTimeout(timer)
|
|
296
|
+
timer = setTimeout(resume, 150)
|
|
297
|
+
}
|
|
298
|
+
const onPointerMove = (e: Event) => {
|
|
299
|
+
const { movementX, movementY } = e as PointerEvent
|
|
300
|
+
if ((movementX || movementY) && content.hasAttribute('data-scrolling')) resume()
|
|
301
|
+
}
|
|
302
|
+
scroller.addEventListener('scroll', onScroll, { passive: true })
|
|
303
|
+
scroller.addEventListener('pointermove', onPointerMove, { passive: true })
|
|
304
|
+
return () => {
|
|
305
|
+
resume()
|
|
306
|
+
scroller.removeEventListener('scroll', onScroll)
|
|
307
|
+
scroller.removeEventListener('pointermove', onPointerMove)
|
|
308
|
+
}
|
|
309
|
+
}, [ref, enabled])
|
|
310
|
+
}
|
|
311
|
+
|
|
274
312
|
export interface SidebarContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
275
313
|
viewportClassName?: string
|
|
276
314
|
}
|
|
@@ -278,6 +316,10 @@ export interface SidebarContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
278
316
|
const SidebarContent = forwardRef<HTMLDivElement, SidebarContentProps>(
|
|
279
317
|
({ className, viewportClassName, children, ...props }, ref) => {
|
|
280
318
|
const { isMobile } = useSidebar()
|
|
319
|
+
const contentRef = useRef<HTMLDivElement>(null)
|
|
320
|
+
const mergedRef = useMergeRefs(ref, contentRef)
|
|
321
|
+
// The sheet is touch, which has no hover to pause.
|
|
322
|
+
usePauseHoverWhileScrolling(contentRef, !isMobile)
|
|
281
323
|
|
|
282
324
|
// In the sheet this region scrolls natively (a ScrollArea would
|
|
283
325
|
// double-scroll). The hairline can't sit on the scroller, whose fade mask
|
|
@@ -304,7 +346,12 @@ const SidebarContent = forwardRef<HTMLDivElement, SidebarContentProps>(
|
|
|
304
346
|
className={cn('scroll-divider min-h-0 w-full flex-1', className)}
|
|
305
347
|
viewportClassName={cn('scroll-fade [&>div]:!block [&>div]:!min-w-0', viewportClassName)}
|
|
306
348
|
>
|
|
307
|
-
<div
|
|
349
|
+
<div
|
|
350
|
+
ref={mergedRef}
|
|
351
|
+
data-sidebar="content"
|
|
352
|
+
className="flex w-full min-w-0 flex-col data-[scrolling]:pointer-events-none"
|
|
353
|
+
{...props}
|
|
354
|
+
>
|
|
308
355
|
{children}
|
|
309
356
|
</div>
|
|
310
357
|
</ScrollArea>
|
|
@@ -14,19 +14,22 @@ import {
|
|
|
14
14
|
type KeyboardEvent,
|
|
15
15
|
type MouseEvent,
|
|
16
16
|
type MutableRefObject,
|
|
17
|
+
memo,
|
|
17
18
|
type ReactNode,
|
|
18
19
|
type RefObject,
|
|
19
20
|
useCallback,
|
|
21
|
+
useContext,
|
|
20
22
|
useMemo,
|
|
21
23
|
useRef,
|
|
22
24
|
useState,
|
|
25
|
+
useSyncExternalStore,
|
|
23
26
|
} from 'react'
|
|
24
27
|
import { FluidHoverHighlight } from '../../../lib/fluid-hover-highlight'
|
|
25
28
|
import { FocusRing } from '../../../lib/focus-ring'
|
|
26
29
|
import { GooIndicator } from '../../../lib/goo-indicator'
|
|
27
30
|
import { useShape } from '../../../lib/shape-context'
|
|
28
31
|
import { spring } from '../../../lib/springs'
|
|
29
|
-
import { type ItemRect, useFluidHover } from '../../../lib/use-fluid-hover'
|
|
32
|
+
import { type ItemRect, sameRect, useFluidHover } from '../../../lib/use-fluid-hover'
|
|
30
33
|
import { useIsoLayoutEffect } from '../../../lib/use-iso-layout-effect'
|
|
31
34
|
import { cn } from '../../../lib/utils'
|
|
32
35
|
|
|
@@ -36,17 +39,24 @@ import { cn } from '../../../lib/utils'
|
|
|
36
39
|
// as one piece. The active background stays one per level, so a current
|
|
37
40
|
// section and the current page inside it can both be lit.
|
|
38
41
|
|
|
42
|
+
/** What rows read from the scope: the hovered row, every visible active row (DOM order) and the first row. */
|
|
43
|
+
interface MenuScopeSnapshot {
|
|
44
|
+
hovered: HTMLElement | null
|
|
45
|
+
active: HTMLElement[]
|
|
46
|
+
first: HTMLElement | null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Stable for the scope's life: rows subscribe to the snapshot instead of
|
|
50
|
+
// reading it from context, so a hover re-renders the two rows it moves
|
|
51
|
+
// between, not every row.
|
|
39
52
|
interface MenuScopeValue {
|
|
40
53
|
registerRow: (el: HTMLElement) => () => void
|
|
41
54
|
setRowButton: (row: HTMLElement, button: HTMLElement | null) => void
|
|
42
55
|
setRowActive: (row: HTMLElement, active: boolean) => void
|
|
43
|
-
hoveredRowEl: HTMLElement | null
|
|
44
|
-
/** Every visible active row, in DOM order. */
|
|
45
|
-
activeRows: HTMLElement[]
|
|
46
|
-
firstRowEl: HTMLElement | null
|
|
47
|
-
hasActive: boolean
|
|
48
56
|
/** A sub-menu toggled: re-read what is visible. */
|
|
49
57
|
refreshVisibility: () => void
|
|
58
|
+
subscribe: (listener: () => void) => () => void
|
|
59
|
+
getSnapshot: () => MenuScopeSnapshot
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
export const MenuScopeContext = createContext<MenuScopeValue | null>(null)
|
|
@@ -63,8 +73,6 @@ export interface MenuItemContextValue {
|
|
|
63
73
|
rowRef: MutableRefObject<HTMLLIElement | null>
|
|
64
74
|
/** The row's `<li>` ref callback; replays its active flag to the scope. */
|
|
65
75
|
attachRow: (node: HTMLLIElement | null) => void
|
|
66
|
-
isHovered: boolean
|
|
67
|
-
isActiveRow: boolean
|
|
68
76
|
/** Inside `SidebarMenuSubItem`: actions centre on the shorter row. */
|
|
69
77
|
isSubRow: boolean
|
|
70
78
|
setActive: (active: boolean) => void
|
|
@@ -82,9 +90,42 @@ export interface MenuItemContextValue {
|
|
|
82
90
|
|
|
83
91
|
export const MenuItemContext = createContext<MenuItemContextValue | null>(null)
|
|
84
92
|
|
|
93
|
+
/** The row's stable part, for the actions and the badge: they re-render with neither the gutter nor the sub-menu. */
|
|
94
|
+
export type MenuRowContextValue = Pick<MenuItemContextValue, 'rowRef' | 'isSubRow' | 'setActions' | 'setHasBadge'>
|
|
95
|
+
|
|
96
|
+
export const MenuRowContext = createContext<MenuRowContextValue | null>(null)
|
|
97
|
+
|
|
85
98
|
/** True inside a SidebarMenuActions cluster, where each action flows in the row. */
|
|
86
99
|
export const MenuActionsClusterContext = createContext(false)
|
|
87
100
|
|
|
101
|
+
const NO_SUBSCRIPTION = () => () => {}
|
|
102
|
+
const HOVERED = 1
|
|
103
|
+
const ACTIVE = 2
|
|
104
|
+
const TAB_STOP = 4
|
|
105
|
+
|
|
106
|
+
/** The row's hover, active and tab-stop flags, re-rendering only when one of its own flips. */
|
|
107
|
+
export function useRowState(rowRef: MutableRefObject<HTMLElement | null> | undefined) {
|
|
108
|
+
const scope = useContext(MenuScopeContext)
|
|
109
|
+
const flags = useSyncExternalStore(
|
|
110
|
+
scope?.subscribe ?? NO_SUBSCRIPTION,
|
|
111
|
+
() => {
|
|
112
|
+
const row = rowRef?.current
|
|
113
|
+
if (!scope || !row) return 0
|
|
114
|
+
const { hovered, active, first } = scope.getSnapshot()
|
|
115
|
+
const isActive = active.includes(row)
|
|
116
|
+
// Roving tabindex: the active rows are the tab stops, else the first row.
|
|
117
|
+
const tabStop = active.length > 0 ? isActive : row === first
|
|
118
|
+
return (row === hovered ? HOVERED : 0) | (isActive ? ACTIVE : 0) | (tabStop ? TAB_STOP : 0)
|
|
119
|
+
},
|
|
120
|
+
() => 0,
|
|
121
|
+
)
|
|
122
|
+
return {
|
|
123
|
+
isHovered: (flags & HOVERED) !== 0,
|
|
124
|
+
isActiveRow: (flags & ACTIVE) !== 0,
|
|
125
|
+
isTabStop: (flags & TAB_STOP) !== 0,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
88
129
|
/** Inside a collapsed sub-tree. Such rows stay registered: unregistering on every toggle would churn the measurements and blink the overlays. */
|
|
89
130
|
function rowHidden(el: HTMLElement) {
|
|
90
131
|
return el.closest('[data-sidebar="menu-sub"][data-state="closed"]') !== null
|
|
@@ -153,6 +194,41 @@ export function gutterVars(item: MenuItemContextValue | null) {
|
|
|
153
194
|
return { '--row-gutter': `${rest}px`, '--row-gutter-hover': `${hover}px` }
|
|
154
195
|
}
|
|
155
196
|
|
|
197
|
+
interface ActiveBackground {
|
|
198
|
+
key: string
|
|
199
|
+
rect: ItemRect
|
|
200
|
+
rowChanged: boolean
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function sameBackgrounds(a: ActiveBackground[], b: ActiveBackground[]) {
|
|
204
|
+
return (
|
|
205
|
+
a.length === b.length &&
|
|
206
|
+
a.every((x, i) => x.key === b[i]?.key && x.rowChanged === b[i]?.rowChanged && sameRect(x.rect, b[i]?.rect))
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The active rows' backgrounds. The menu re-renders on every hover; these skip it unless a selection moved. */
|
|
211
|
+
const ActiveBackgrounds = memo(
|
|
212
|
+
function ActiveBackgrounds({ items, className }: { items: ActiveBackground[]; className: string }) {
|
|
213
|
+
return (
|
|
214
|
+
<AnimatePresence>
|
|
215
|
+
{items.map(({ key, rect, rowChanged }) => (
|
|
216
|
+
<motion.div
|
|
217
|
+
key={key}
|
|
218
|
+
className="pointer-events-none absolute top-0 left-0"
|
|
219
|
+
initial={false}
|
|
220
|
+
animate={{ opacity: 1 }}
|
|
221
|
+
exit={{ opacity: 0, transition: spring.moderate.exit }}
|
|
222
|
+
>
|
|
223
|
+
<GooIndicator rect={rect} className={className} transition={rowChanged ? spring.moderate : false} />
|
|
224
|
+
</motion.div>
|
|
225
|
+
))}
|
|
226
|
+
</AnimatePresence>
|
|
227
|
+
)
|
|
228
|
+
},
|
|
229
|
+
(a, b) => a.className === b.className && sameBackgrounds(a.items, b.items),
|
|
230
|
+
)
|
|
231
|
+
|
|
156
232
|
interface MenuScopeOptions {
|
|
157
233
|
/** Draw the travelling keyboard focus ring. Off, keyboard focus moves the hover only (a settings dialog's section list). Defaults to `true`. */
|
|
158
234
|
focusRing?: boolean
|
|
@@ -169,16 +245,10 @@ export function useMenuScope(containerRef: RefObject<HTMLElement | null>, { focu
|
|
|
169
245
|
const activeMapRef = useRef<Map<HTMLElement, boolean>>(new Map())
|
|
170
246
|
const [orderedRows, setOrderedRows] = useState<HTMLElement[]>([])
|
|
171
247
|
const orderedRowsRef = useRef(orderedRows)
|
|
172
|
-
orderedRowsRef.current = orderedRows
|
|
173
248
|
const registeredCountRef = useRef(0)
|
|
174
249
|
const [activeRows, setActiveRows] = useState<HTMLElement[]>([])
|
|
175
250
|
const [focusedRowEl, setFocusedRowEl] = useState<HTMLElement | null>(null)
|
|
176
251
|
|
|
177
|
-
const recomputeActive = useCallback(() => {
|
|
178
|
-
const next = orderedRowsRef.current.filter(el => activeMapRef.current.get(el) && !rowSkipped(el))
|
|
179
|
-
setActiveRows(prev => (sameElements(prev, next) ? prev : next))
|
|
180
|
-
}, [])
|
|
181
|
-
|
|
182
252
|
const rowButton = useCallback(
|
|
183
253
|
(row: HTMLElement) =>
|
|
184
254
|
rowButtonsRef.current.get(row) ??
|
|
@@ -191,55 +261,78 @@ export function useMenuScope(containerRef: RefObject<HTMLElement | null>, { focu
|
|
|
191
261
|
// Indexes come from DOM order, so rows take no index and conditional rows
|
|
192
262
|
// just work. The hover measures the row's button, not the `<li>`: a row
|
|
193
263
|
// hosting an expanded sub-tree is tall, and its gaps would go to the parent.
|
|
264
|
+
// Every change only marks the order stale; one sort runs per batch (a
|
|
265
|
+
// microtask after the commit that mounted a list of rows), or at once when
|
|
266
|
+
// something reads the order first.
|
|
267
|
+
const staleRef = useRef(false)
|
|
194
268
|
const syncRows = useCallback(() => {
|
|
269
|
+
staleRef.current = false
|
|
195
270
|
const sorted = [...rowsRef.current].sort(byDomOrder)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
271
|
+
if (!sameElements(orderedRowsRef.current, sorted)) {
|
|
272
|
+
orderedRowsRef.current = sorted
|
|
273
|
+
setOrderedRows(sorted)
|
|
274
|
+
}
|
|
199
275
|
for (const [i, el] of sorted.entries()) registerItem(i, rowButton(el) ?? el)
|
|
200
276
|
for (let i = sorted.length; i < registeredCountRef.current; i++) registerItem(i, null)
|
|
201
277
|
registeredCountRef.current = sorted.length
|
|
202
|
-
|
|
203
|
-
|
|
278
|
+
const active = sorted.filter(el => activeMapRef.current.get(el) && !rowSkipped(el))
|
|
279
|
+
setActiveRows(prev => (sameElements(prev, active) ? prev : active))
|
|
280
|
+
}, [registerItem, rowButton])
|
|
281
|
+
|
|
282
|
+
const rows = useCallback(() => {
|
|
283
|
+
if (staleRef.current) syncRows()
|
|
284
|
+
return orderedRowsRef.current
|
|
285
|
+
}, [syncRows])
|
|
286
|
+
|
|
287
|
+
const invalidate = useCallback(() => {
|
|
288
|
+
if (staleRef.current) return
|
|
289
|
+
staleRef.current = true
|
|
290
|
+
queueMicrotask(() => {
|
|
291
|
+
if (staleRef.current) syncRows()
|
|
292
|
+
})
|
|
293
|
+
}, [syncRows])
|
|
204
294
|
|
|
205
295
|
const registerRow = useCallback(
|
|
206
296
|
(el: HTMLElement) => {
|
|
207
297
|
rowsRef.current.add(el)
|
|
208
|
-
|
|
298
|
+
invalidate()
|
|
209
299
|
return () => {
|
|
210
300
|
rowsRef.current.delete(el)
|
|
211
301
|
rowButtonsRef.current.delete(el)
|
|
212
302
|
activeMapRef.current.delete(el)
|
|
213
|
-
|
|
303
|
+
invalidate()
|
|
214
304
|
}
|
|
215
305
|
},
|
|
216
|
-
[
|
|
306
|
+
[invalidate],
|
|
217
307
|
)
|
|
218
308
|
|
|
219
309
|
const setRowButton = useCallback(
|
|
220
310
|
(row: HTMLElement, button: HTMLElement | null) => {
|
|
221
311
|
if (button) rowButtonsRef.current.set(row, button)
|
|
222
312
|
else rowButtonsRef.current.delete(row)
|
|
223
|
-
|
|
313
|
+
invalidate()
|
|
224
314
|
},
|
|
225
|
-
[
|
|
315
|
+
[invalidate],
|
|
226
316
|
)
|
|
227
317
|
|
|
228
318
|
const setRowActive = useCallback(
|
|
229
319
|
(row: HTMLElement, active: boolean) => {
|
|
320
|
+
if (activeMapRef.current.get(row) === active) return
|
|
230
321
|
activeMapRef.current.set(row, active)
|
|
231
|
-
|
|
322
|
+
invalidate()
|
|
232
323
|
},
|
|
233
|
-
[
|
|
324
|
+
[invalidate],
|
|
234
325
|
)
|
|
235
326
|
|
|
236
327
|
const refreshVisibility = useCallback(() => {
|
|
237
|
-
|
|
328
|
+
const ordered = rows()
|
|
329
|
+
const active = ordered.filter(el => activeMapRef.current.get(el) && !rowSkipped(el))
|
|
330
|
+
setActiveRows(prev => (sameElements(prev, active) ? prev : active))
|
|
238
331
|
setActiveIndex(prev => {
|
|
239
|
-
const row = prev !== null ?
|
|
332
|
+
const row = prev !== null ? ordered[prev] : undefined
|
|
240
333
|
return row && rowSkipped(row) ? null : prev
|
|
241
334
|
})
|
|
242
|
-
}, [
|
|
335
|
+
}, [rows, setActiveIndex])
|
|
243
336
|
|
|
244
337
|
// A row's rect spans its `<li>`, which grows with an expanded sub-menu: the
|
|
245
338
|
// overlays clamp to the button (32px, the tallest row, if it isn't found).
|
|
@@ -282,12 +375,12 @@ export function useMenuScope(containerRef: RefObject<HTMLElement | null>, { focu
|
|
|
282
375
|
if (!target.closest(ROW_BUTTON)) return
|
|
283
376
|
const row = target.closest<HTMLElement>('[data-sidebar="menu-item"],[data-sidebar="menu-sub-item"]')
|
|
284
377
|
if (!row) return
|
|
285
|
-
const idx =
|
|
378
|
+
const idx = rows().indexOf(row)
|
|
286
379
|
if (idx === -1) return
|
|
287
380
|
setActiveIndex(idx)
|
|
288
381
|
setFocusedRowEl(target.matches(':focus-visible') ? row : null)
|
|
289
382
|
},
|
|
290
|
-
[setActiveIndex],
|
|
383
|
+
[rows, setActiveIndex],
|
|
291
384
|
)
|
|
292
385
|
|
|
293
386
|
const onBlur = useCallback(
|
|
@@ -325,18 +418,30 @@ export function useMenuScope(containerRef: RefObject<HTMLElement | null>, { focu
|
|
|
325
418
|
|
|
326
419
|
const hoveredRowEl = activeIndex !== null ? (orderedRows[activeIndex] ?? null) : null
|
|
327
420
|
|
|
421
|
+
// The snapshot rows read, published after each commit that changed it.
|
|
422
|
+
const snapshotRef = useRef<MenuScopeSnapshot>({ hovered: null, active: [], first: null })
|
|
423
|
+
const listenersRef = useRef(new Set<() => void>())
|
|
424
|
+
const firstRowEl = orderedRows[0] ?? null
|
|
425
|
+
useIsoLayoutEffect(() => {
|
|
426
|
+
const prev = snapshotRef.current
|
|
427
|
+
if (prev.hovered === hoveredRowEl && prev.active === activeRows && prev.first === firstRowEl) return
|
|
428
|
+
snapshotRef.current = { hovered: hoveredRowEl, active: activeRows, first: firstRowEl }
|
|
429
|
+
for (const listener of listenersRef.current) listener()
|
|
430
|
+
}, [hoveredRowEl, activeRows, firstRowEl])
|
|
431
|
+
|
|
328
432
|
const value = useMemo<MenuScopeValue>(
|
|
329
433
|
() => ({
|
|
330
434
|
registerRow,
|
|
331
435
|
setRowButton,
|
|
332
436
|
setRowActive,
|
|
333
|
-
hoveredRowEl,
|
|
334
|
-
activeRows,
|
|
335
|
-
firstRowEl: orderedRows[0] ?? null,
|
|
336
|
-
hasActive: activeRows.length > 0,
|
|
337
437
|
refreshVisibility,
|
|
438
|
+
subscribe: listener => {
|
|
439
|
+
listenersRef.current.add(listener)
|
|
440
|
+
return () => listenersRef.current.delete(listener)
|
|
441
|
+
},
|
|
442
|
+
getSnapshot: () => snapshotRef.current,
|
|
338
443
|
}),
|
|
339
|
-
[registerRow, setRowButton, setRowActive,
|
|
444
|
+
[registerRow, setRowButton, setRowActive, refreshVisibility],
|
|
340
445
|
)
|
|
341
446
|
|
|
342
447
|
const shape = useShape()
|
|
@@ -393,23 +498,7 @@ export function useMenuScope(containerRef: RefObject<HTMLElement | null>, { focu
|
|
|
393
498
|
|
|
394
499
|
const overlays: ReactNode = isMeasured ? (
|
|
395
500
|
<>
|
|
396
|
-
<
|
|
397
|
-
{activeRects.map(({ key, rect, rowChanged }) => (
|
|
398
|
-
<motion.div
|
|
399
|
-
key={key}
|
|
400
|
-
className="pointer-events-none absolute top-0 left-0"
|
|
401
|
-
initial={false}
|
|
402
|
-
animate={{ opacity: 1 }}
|
|
403
|
-
exit={{ opacity: 0, transition: spring.moderate.exit }}
|
|
404
|
-
>
|
|
405
|
-
<GooIndicator
|
|
406
|
-
rect={rect}
|
|
407
|
-
className={cn('bg-active', shape.bg)}
|
|
408
|
-
transition={rowChanged ? spring.moderate : false}
|
|
409
|
-
/>
|
|
410
|
-
</motion.div>
|
|
411
|
-
))}
|
|
412
|
-
</AnimatePresence>
|
|
501
|
+
<ActiveBackgrounds items={activeRects} className={cn('bg-active', shape.bg)} />
|
|
413
502
|
<FluidHoverHighlight
|
|
414
503
|
rect={hoverRect}
|
|
415
504
|
session={sessionRef.current}
|
|
@@ -24,7 +24,7 @@ import { useSize } from '../../../lib/size-context'
|
|
|
24
24
|
import { resolveSlotTemplate, slotElement } from '../../../lib/slot'
|
|
25
25
|
import { useIsoLayoutEffect } from '../../../lib/use-iso-layout-effect'
|
|
26
26
|
import { cn } from '../../../lib/utils'
|
|
27
|
-
import { MenuActionsClusterContext,
|
|
27
|
+
import { MenuActionsClusterContext, MenuRowContext, useRowState } from './menu-scope'
|
|
28
28
|
|
|
29
29
|
export interface SidebarMenuActionProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
30
30
|
/** Hidden until the row is hovered or focused, so the label keeps the room at rest. Defaults to `false`. */
|
|
@@ -39,7 +39,7 @@ const SidebarMenuAction = forwardRef<HTMLButtonElement, SidebarMenuActionProps>(
|
|
|
39
39
|
({ className, showOnHover = false, render, asChild, children, onClick, style, ...props }, ref) => {
|
|
40
40
|
const shape = useShape()
|
|
41
41
|
const size = useSize()
|
|
42
|
-
const item = useContext(
|
|
42
|
+
const item = useContext(MenuRowContext)
|
|
43
43
|
const inCluster = useContext(MenuActionsClusterContext)
|
|
44
44
|
const { template, content } = resolveSlotTemplate(render, asChild, children)
|
|
45
45
|
|
|
@@ -106,7 +106,7 @@ export interface SidebarMenuActionsProps extends HTMLAttributes<HTMLDivElement>
|
|
|
106
106
|
/** A row's cluster of `SidebarMenuAction`s: it positions them and reports the count, so the button reserves the exact gutter. */
|
|
107
107
|
const SidebarMenuActions = forwardRef<HTMLDivElement, SidebarMenuActionsProps>(
|
|
108
108
|
({ className, showOnHover = false, children, ...props }, ref) => {
|
|
109
|
-
const item = useContext(
|
|
109
|
+
const item = useContext(MenuRowContext)
|
|
110
110
|
const size = useSize()
|
|
111
111
|
const count = Children.count(children)
|
|
112
112
|
|
|
@@ -144,9 +144,9 @@ SidebarMenuActions.displayName = 'SidebarMenuActions'
|
|
|
144
144
|
export type SidebarMenuBadgeProps = HTMLAttributes<HTMLDivElement>
|
|
145
145
|
|
|
146
146
|
const SidebarMenuBadge = forwardRef<HTMLDivElement, SidebarMenuBadgeProps>(({ className, ...props }, ref) => {
|
|
147
|
-
const item = useContext(
|
|
147
|
+
const item = useContext(MenuRowContext)
|
|
148
148
|
const size = useSize()
|
|
149
|
-
const lit = item?.isActiveRow
|
|
149
|
+
const lit = useRowState(item?.rowRef).isActiveRow
|
|
150
150
|
|
|
151
151
|
const setHasBadge = item?.setHasBadge
|
|
152
152
|
useIsoLayoutEffect(() => {
|
|
@@ -26,7 +26,7 @@ import { resolveSlotTemplate, slotElement } from '../../../lib/slot'
|
|
|
26
26
|
import { spring } from '../../../lib/springs'
|
|
27
27
|
import { useIsoLayoutEffect } from '../../../lib/use-iso-layout-effect'
|
|
28
28
|
import { cn } from '../../../lib/utils'
|
|
29
|
-
import { gutterVars, MenuItemContext,
|
|
29
|
+
import { gutterVars, MenuItemContext, SidebarSelection, useRowState } from './menu-scope'
|
|
30
30
|
import { MenuRowLabel } from './row-label'
|
|
31
31
|
|
|
32
32
|
export const sidebarMenuButtonVariants = cva(
|
|
@@ -87,7 +87,6 @@ const SidebarMenuButton = forwardRef<HTMLButtonElement, SidebarMenuButtonProps>(
|
|
|
87
87
|
},
|
|
88
88
|
ref,
|
|
89
89
|
) => {
|
|
90
|
-
const scope = useContext(MenuScopeContext)
|
|
91
90
|
const item = useContext(MenuItemContext)
|
|
92
91
|
const selection = useContext(SidebarSelection)
|
|
93
92
|
const shape = useShape()
|
|
@@ -111,11 +110,9 @@ const SidebarMenuButton = forwardRef<HTMLButtonElement, SidebarMenuButtonProps>(
|
|
|
111
110
|
return () => setButtonEl?.(null)
|
|
112
111
|
}, [setButtonEl])
|
|
113
112
|
const resolvedDot = dot ?? (status ? (status === 'idle' ? 'ring' : 'filled') : undefined)
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const row = item?.rowRef.current ?? null
|
|
118
|
-
const tabIdx = effectiveActive ? 0 : scope?.hasActive ? -1 : row !== null && row === scope?.firstRowEl ? 0 : -1
|
|
113
|
+
const row = useRowState(item?.rowRef)
|
|
114
|
+
const lit = effectiveActive || row.isHovered
|
|
115
|
+
const tabIdx = effectiveActive || row.isTabStop ? 0 : -1
|
|
119
116
|
|
|
120
117
|
const { template, content } = resolveSlotTemplate(render, asChild, children)
|
|
121
118
|
|
|
@@ -24,7 +24,14 @@ import { useControllableState } from '../../../lib/use-controllable-state'
|
|
|
24
24
|
import { useIsoLayoutEffect } from '../../../lib/use-iso-layout-effect'
|
|
25
25
|
import { cn } from '../../../lib/utils'
|
|
26
26
|
import { SizeScope } from '../../../primitives/systems/sizes'
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
MenuItemContext,
|
|
29
|
+
type MenuItemContextValue,
|
|
30
|
+
MenuRowContext,
|
|
31
|
+
type MenuRowContextValue,
|
|
32
|
+
MenuScopeContext,
|
|
33
|
+
useMenuScope,
|
|
34
|
+
} from './menu-scope'
|
|
28
35
|
|
|
29
36
|
export interface SidebarMenuProps extends HTMLAttributes<HTMLUListElement> {
|
|
30
37
|
/** Pins the menu's rows to one step of the size ladder. Omitted, they follow the surrounding SizeProvider. */
|
|
@@ -74,7 +81,7 @@ function useMenuRow(
|
|
|
74
81
|
rowRef: MutableRefObject<HTMLLIElement | null>,
|
|
75
82
|
isSubRow: boolean,
|
|
76
83
|
sub?: Pick<SidebarMenuItemProps, 'collapsible' | 'open' | 'defaultOpen' | 'onOpenChange'>,
|
|
77
|
-
): MenuItemContextValue {
|
|
84
|
+
): { item: MenuItemContextValue; row: MenuRowContextValue } {
|
|
78
85
|
const scope = useContext(MenuScopeContext)
|
|
79
86
|
const registerRow = scope?.registerRow
|
|
80
87
|
const setRowButton = scope?.setRowButton
|
|
@@ -115,9 +122,6 @@ function useMenuRow(
|
|
|
115
122
|
[setRowButton, rowRef],
|
|
116
123
|
)
|
|
117
124
|
|
|
118
|
-
const isHovered = rowRef.current !== null && scope?.hoveredRowEl === rowRef.current
|
|
119
|
-
const isActiveRow = rowRef.current !== null && (scope?.activeRows.includes(rowRef.current) ?? false)
|
|
120
|
-
|
|
121
125
|
const [trailing, setTrailing] = useState({ actionCount: 0, actionsShowOnHover: false, hasBadge: false })
|
|
122
126
|
const setActions = useCallback(
|
|
123
127
|
(count: number, showOnHover: boolean) =>
|
|
@@ -137,12 +141,14 @@ function useMenuRow(
|
|
|
137
141
|
const subOpen = sub?.collapsible ? open : undefined
|
|
138
142
|
const toggleSub = useCallback(() => setOpen(prev => !prev), [setOpen])
|
|
139
143
|
|
|
140
|
-
|
|
144
|
+
const row = useMemo(
|
|
145
|
+
() => ({ rowRef, isSubRow, setActions, setHasBadge }),
|
|
146
|
+
[rowRef, isSubRow, setActions, setHasBadge],
|
|
147
|
+
)
|
|
148
|
+
const item = useMemo(
|
|
141
149
|
() => ({
|
|
142
150
|
rowRef,
|
|
143
151
|
attachRow,
|
|
144
|
-
isHovered,
|
|
145
|
-
isActiveRow,
|
|
146
152
|
isSubRow,
|
|
147
153
|
setActive,
|
|
148
154
|
setButtonEl,
|
|
@@ -152,35 +158,25 @@ function useMenuRow(
|
|
|
152
158
|
subOpen,
|
|
153
159
|
toggleSub,
|
|
154
160
|
}),
|
|
155
|
-
[
|
|
156
|
-
rowRef,
|
|
157
|
-
attachRow,
|
|
158
|
-
isHovered,
|
|
159
|
-
isActiveRow,
|
|
160
|
-
isSubRow,
|
|
161
|
-
setActive,
|
|
162
|
-
setButtonEl,
|
|
163
|
-
trailing,
|
|
164
|
-
setActions,
|
|
165
|
-
setHasBadge,
|
|
166
|
-
subOpen,
|
|
167
|
-
toggleSub,
|
|
168
|
-
],
|
|
161
|
+
[rowRef, attachRow, isSubRow, setActive, setButtonEl, trailing, setActions, setHasBadge, subOpen, toggleSub],
|
|
169
162
|
)
|
|
163
|
+
return { item, row }
|
|
170
164
|
}
|
|
171
165
|
|
|
172
166
|
const SidebarMenuItem = forwardRef<HTMLLIElement, SidebarMenuItemProps>(
|
|
173
167
|
({ collapsible, open, defaultOpen, onOpenChange, className, children, ...props }, ref) => {
|
|
174
168
|
const rowRef = useRef<HTMLLIElement | null>(null)
|
|
175
|
-
const item = useMenuRow(rowRef, false, { collapsible, open, defaultOpen, onOpenChange })
|
|
169
|
+
const { item, row } = useMenuRow(rowRef, false, { collapsible, open, defaultOpen, onOpenChange })
|
|
176
170
|
// Stable: an inline ref is detached around every re-render, and child layout effects fire in that window.
|
|
177
|
-
const
|
|
171
|
+
const attach = useMergeRefs(item.attachRow, ref)
|
|
178
172
|
return (
|
|
179
|
-
<
|
|
180
|
-
<
|
|
181
|
-
{
|
|
182
|
-
|
|
183
|
-
|
|
173
|
+
<MenuRowContext.Provider value={row}>
|
|
174
|
+
<MenuItemContext.Provider value={item}>
|
|
175
|
+
<li ref={attach} data-sidebar="menu-item" className={cn('group/menu-item relative', className)} {...props}>
|
|
176
|
+
{children}
|
|
177
|
+
</li>
|
|
178
|
+
</MenuItemContext.Provider>
|
|
179
|
+
</MenuRowContext.Provider>
|
|
184
180
|
)
|
|
185
181
|
},
|
|
186
182
|
)
|
|
@@ -191,14 +187,21 @@ export type SidebarMenuSubItemProps = LiHTMLAttributes<HTMLLIElement>
|
|
|
191
187
|
const SidebarMenuSubItem = forwardRef<HTMLLIElement, SidebarMenuSubItemProps>(
|
|
192
188
|
({ className, children, ...props }, ref) => {
|
|
193
189
|
const rowRef = useRef<HTMLLIElement | null>(null)
|
|
194
|
-
const item = useMenuRow(rowRef, true)
|
|
195
|
-
const
|
|
190
|
+
const { item, row } = useMenuRow(rowRef, true)
|
|
191
|
+
const attach = useMergeRefs(item.attachRow, ref)
|
|
196
192
|
return (
|
|
197
|
-
<
|
|
198
|
-
<
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
193
|
+
<MenuRowContext.Provider value={row}>
|
|
194
|
+
<MenuItemContext.Provider value={item}>
|
|
195
|
+
<li
|
|
196
|
+
ref={attach}
|
|
197
|
+
data-sidebar="menu-sub-item"
|
|
198
|
+
className={cn('group/menu-sub-item relative', className)}
|
|
199
|
+
{...props}
|
|
200
|
+
>
|
|
201
|
+
{children}
|
|
202
|
+
</li>
|
|
203
|
+
</MenuItemContext.Provider>
|
|
204
|
+
</MenuRowContext.Provider>
|
|
202
205
|
)
|
|
203
206
|
},
|
|
204
207
|
)
|