@duro-app/ui 5.12.0 → 5.13.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/dist/Table-Bms2ftt3.js +1694 -0
- package/dist/Table-Bms2ftt3.js.map +1 -0
- package/dist/components/AppShell/native.css.d.ts +53 -0
- package/dist/components/AppShell/native.css.d.ts.map +1 -0
- package/dist/components/Drawer/Drawer.d.ts +7 -35
- package/dist/components/Drawer/Drawer.d.ts.map +1 -1
- package/dist/components/Drawer/Drawer.meta.d.ts.map +1 -1
- package/dist/components/Drawer/DrawerScroll.stories.d.ts.map +1 -1
- package/dist/components/Drawer/DrawerSnap.stories.d.ts +20 -0
- package/dist/components/Drawer/DrawerSnap.stories.d.ts.map +1 -0
- package/dist/components/Drawer/native.css.d.ts +55 -0
- package/dist/components/Drawer/native.css.d.ts.map +1 -0
- package/dist/components/Drawer/parts.css.d.ts +96 -0
- package/dist/components/Drawer/parts.css.d.ts.map +1 -0
- package/dist/components/Drawer/parts.d.ts +56 -0
- package/dist/components/Drawer/parts.d.ts.map +1 -0
- package/dist/components/Drawer/sheetPhysics.d.ts +56 -0
- package/dist/components/Drawer/sheetPhysics.d.ts.map +1 -0
- package/dist/components/Drawer/styles.css.d.ts +13 -58
- package/dist/components/Drawer/styles.css.d.ts.map +1 -1
- package/dist/components/Drawer/touchInput.d.ts +35 -0
- package/dist/components/Drawer/touchInput.d.ts.map +1 -0
- package/dist/components/Drawer/useDrawerRoot.d.ts +33 -0
- package/dist/components/Drawer/useDrawerRoot.d.ts.map +1 -0
- package/dist/components/Drawer/useSheetHeights.d.ts +7 -0
- package/dist/components/Drawer/useSheetHeights.d.ts.map +1 -0
- package/dist/components/Drawer/useSwipeDismiss.d.ts +13 -2
- package/dist/components/Drawer/useSwipeDismiss.d.ts.map +1 -1
- package/dist/components/Menu/Menu.d.ts +7 -1
- package/dist/components/Menu/Menu.d.ts.map +1 -1
- package/dist/components/Menu/native.css.d.ts +14 -0
- package/dist/components/Menu/native.css.d.ts.map +1 -0
- package/dist/components/Menu/useMenuOpen.d.ts +16 -0
- package/dist/components/Menu/useMenuOpen.d.ts.map +1 -0
- package/dist/components/Menu/useMenuRoot.d.ts +3 -6
- package/dist/components/Menu/useMenuRoot.d.ts.map +1 -1
- package/dist/components/Popover/native.css.d.ts +11 -0
- package/dist/components/Popover/native.css.d.ts.map +1 -0
- package/dist/components/SideNav/Chevron.d.ts +4 -0
- package/dist/components/SideNav/Chevron.d.ts.map +1 -0
- package/dist/components/SideNav/SideNav.d.ts.map +1 -1
- package/dist/components/SideNav/styles.css.d.ts +6 -0
- package/dist/components/SideNav/styles.css.d.ts.map +1 -1
- package/dist/components/SideNav/types.d.ts +6 -0
- package/dist/components/SideNav/types.d.ts.map +1 -0
- package/dist/components/SplitPane/SplitPane.d.ts +38 -0
- package/dist/components/SplitPane/SplitPane.d.ts.map +1 -0
- package/dist/components/SplitPane/SplitPane.meta.d.ts +3 -0
- package/dist/components/SplitPane/SplitPane.meta.d.ts.map +1 -0
- package/dist/components/SplitPane/SplitPane.stories.d.ts +17 -0
- package/dist/components/SplitPane/SplitPane.stories.d.ts.map +1 -0
- package/dist/components/SplitPane/styles.css.d.ts +78 -0
- package/dist/components/SplitPane/styles.css.d.ts.map +1 -0
- package/dist/components/Tabs/TabLayout.d.ts +7 -0
- package/dist/components/Tabs/TabLayout.d.ts.map +1 -0
- package/dist/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/components/Tabs/indicator.d.ts +28 -0
- package/dist/components/Tabs/indicator.d.ts.map +1 -0
- package/dist/components/Tabs/styles.css.d.ts +4 -0
- package/dist/components/Tabs/styles.css.d.ts.map +1 -1
- package/dist/components/Tabs/useTabIndicator.d.ts +4 -0
- package/dist/components/Tabs/useTabIndicator.d.ts.map +1 -0
- package/dist/components/Tabs/useTabKeys.d.ts +13 -0
- package/dist/components/Tabs/useTabKeys.d.ts.map +1 -0
- package/dist/components/Tag/RemoveGlyph.d.ts +4 -0
- package/dist/components/Tag/RemoveGlyph.d.ts.map +1 -0
- package/dist/components/Tag/Tag.d.ts +2 -24
- package/dist/components/Tag/Tag.d.ts.map +1 -1
- package/dist/components/Tag/styles.css.d.ts +8 -0
- package/dist/components/Tag/styles.css.d.ts.map +1 -1
- package/dist/components/Tag/types.d.ts +39 -0
- package/dist/components/Tag/types.d.ts.map +1 -0
- package/dist/components/Toast/ToastProvider.d.ts +2 -21
- package/dist/components/Toast/ToastProvider.d.ts.map +1 -1
- package/dist/components/Toast/native.css.d.ts +81 -0
- package/dist/components/Toast/native.css.d.ts.map +1 -0
- package/dist/components/Toast/store.d.ts +47 -0
- package/dist/components/Toast/store.d.ts.map +1 -0
- package/dist/components/Tooltip/TooltipHint.d.ts +9 -0
- package/dist/components/Tooltip/TooltipHint.d.ts.map +1 -0
- package/dist/components/Tree/Tree.d.ts.map +1 -1
- package/dist/components/Tree/styles.css.d.ts +6 -0
- package/dist/components/Tree/styles.css.d.ts.map +1 -1
- package/dist/components/Tree/useTreeKeyboard.d.ts +19 -0
- package/dist/components/Tree/useTreeKeyboard.d.ts.map +1 -0
- package/dist/components/VirtualList/VirtualList.d.ts +33 -0
- package/dist/components/VirtualList/VirtualList.d.ts.map +1 -0
- package/dist/components/VirtualList/VirtualList.meta.d.ts +3 -0
- package/dist/components/VirtualList/VirtualList.meta.d.ts.map +1 -0
- package/dist/components/VirtualList/VirtualList.stories.d.ts +15 -0
- package/dist/components/VirtualList/VirtualList.stories.d.ts.map +1 -0
- package/dist/components/VirtualList/styles.css.d.ts +28 -0
- package/dist/components/VirtualList/styles.css.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4935 -4260
- package/dist/index.js.map +1 -1
- package/dist/shared/ButtonHost.d.ts +11 -0
- package/dist/shared/ButtonHost.d.ts.map +1 -0
- package/dist/shared/pressableChild.d.ts +14 -0
- package/dist/shared/pressableChild.d.ts.map +1 -0
- package/dist/table.js +1 -1
- package/package.json +2 -2
- package/src/components/AppShell/AppShell.meta.ts +1 -1
- package/src/components/AppShell/AppShell.native.tsx +174 -0
- package/src/components/AppShell/native.css.ts +56 -0
- package/src/components/Button/Button.tsx +3 -3
- package/src/components/Drawer/Drawer.meta.ts +2 -1
- package/src/components/Drawer/Drawer.native.tsx +469 -0
- package/src/components/Drawer/Drawer.tsx +58 -145
- package/src/components/Drawer/DrawerScroll.stories.tsx +4 -54
- package/src/components/Drawer/DrawerSnap.stories.tsx +205 -0
- package/src/components/Drawer/native.css.ts +58 -0
- package/src/components/Drawer/parts.css.ts +125 -0
- package/src/components/Drawer/parts.tsx +110 -0
- package/src/components/Drawer/sheetPhysics.ts +103 -0
- package/src/components/Drawer/styles.css.ts +15 -74
- package/src/components/Drawer/touchInput.ts +81 -0
- package/src/components/Drawer/useDrawerRoot.ts +90 -0
- package/src/components/Drawer/useSheetHeights.ts +42 -0
- package/src/components/Drawer/useSwipeDismiss.ts +146 -23
- package/src/components/Menu/Menu.meta.ts +1 -1
- package/src/components/Menu/Menu.native.tsx +268 -0
- package/src/components/Menu/Menu.tsx +11 -2
- package/src/components/Menu/native.css.ts +18 -0
- package/src/components/Menu/useMenuOpen.ts +33 -0
- package/src/components/Menu/useMenuRoot.ts +7 -26
- package/src/components/Popover/Popover.meta.ts +1 -1
- package/src/components/Popover/Popover.native.tsx +205 -0
- package/src/components/Popover/native.css.ts +13 -0
- package/src/components/SideNav/Chevron.native.tsx +20 -0
- package/src/components/SideNav/Chevron.tsx +20 -0
- package/src/components/SideNav/SideNav.meta.ts +1 -1
- package/src/components/SideNav/SideNav.tsx +57 -41
- package/src/components/SideNav/styles.css.ts +8 -0
- package/src/components/SideNav/types.ts +6 -0
- package/src/components/SplitPane/SplitPane.meta.ts +40 -0
- package/src/components/SplitPane/SplitPane.native.tsx +47 -0
- package/src/components/SplitPane/SplitPane.stories.tsx +148 -0
- package/src/components/SplitPane/SplitPane.tsx +218 -0
- package/src/components/SplitPane/styles.css.ts +81 -0
- package/src/components/Tabs/TabLayout.native.tsx +9 -0
- package/src/components/Tabs/TabLayout.tsx +6 -0
- package/src/components/Tabs/Tabs.meta.ts +1 -1
- package/src/components/Tabs/Tabs.tsx +38 -136
- package/src/components/Tabs/indicator.ts +36 -0
- package/src/components/Tabs/styles.css.ts +7 -0
- package/src/components/Tabs/useTabIndicator.native.ts +35 -0
- package/src/components/Tabs/useTabIndicator.ts +49 -0
- package/src/components/Tabs/useTabKeys.native.ts +2 -0
- package/src/components/Tabs/useTabKeys.ts +99 -0
- package/src/components/Tag/RemoveGlyph.native.tsx +17 -0
- package/src/components/Tag/RemoveGlyph.tsx +10 -0
- package/src/components/Tag/Tag.meta.ts +1 -1
- package/src/components/Tag/Tag.native.tsx +70 -0
- package/src/components/Tag/Tag.tsx +9 -37
- package/src/components/Tag/styles.css.ts +9 -0
- package/src/components/Tag/types.ts +43 -0
- package/src/components/Toast/Toast.meta.ts +1 -1
- package/src/components/Toast/ToastProvider.native.tsx +226 -0
- package/src/components/Toast/ToastProvider.tsx +22 -84
- package/src/components/Toast/native.css.ts +78 -0
- package/src/components/Toast/store.ts +96 -0
- package/src/components/Toggle/Toggle.tsx +3 -3
- package/src/components/Tooltip/Tooltip.meta.ts +1 -1
- package/src/components/Tooltip/Tooltip.native.tsx +36 -0
- package/src/components/Tooltip/TooltipHint.ts +13 -0
- package/src/components/Tree/Tree.meta.ts +1 -1
- package/src/components/Tree/Tree.tsx +23 -135
- package/src/components/Tree/styles.css.ts +6 -0
- package/src/components/Tree/useTreeKeyboard.native.ts +5 -0
- package/src/components/Tree/useTreeKeyboard.ts +152 -0
- package/src/components/VirtualList/VirtualList.meta.ts +39 -0
- package/src/components/VirtualList/VirtualList.stories.tsx +95 -0
- package/src/components/VirtualList/VirtualList.tsx +103 -0
- package/src/components/VirtualList/styles.css.ts +31 -0
- package/src/hooks/useContainerBelow.native.ts +30 -0
- package/src/index.native.ts +33 -0
- package/src/index.ts +8 -1
- package/src/shared/ButtonHost.native.tsx +70 -0
- package/src/shared/ButtonHost.tsx +12 -0
- package/src/shared/portal/AnchoredOverlay.native.tsx +117 -0
- package/src/shared/pressableChild.ts +33 -0
- package/src/shared/useKeyboardHeight.native.ts +18 -0
- package/src/shared/useScreenReaderEnabled.native.ts +19 -0
- package/dist/Table-ColfpgKV.js +0 -1552
- package/dist/Table-ColfpgKV.js.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {useRef, useCallback, useEffect} from 'react'
|
|
2
|
-
import type {DrawerAnchor} from './
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import type {DrawerAnchor} from './parts'
|
|
3
|
+
import {
|
|
4
|
+
DISMISS_DURATION,
|
|
5
|
+
DRAG_SLOP,
|
|
6
|
+
SNAP_DURATION,
|
|
7
|
+
SNAP_MAX_OVERSHOOT,
|
|
8
|
+
rubberBand,
|
|
9
|
+
settleDetent,
|
|
10
|
+
shouldDismissEdge,
|
|
11
|
+
} from './sheetPhysics'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Max pixels the panel visually "grows" when dragged in the opposite direction.
|
|
@@ -17,6 +17,16 @@ const DISMISS_DURATION = 160
|
|
|
17
17
|
*/
|
|
18
18
|
const OPPOSITE_MAX_OVERSCROLL = 12
|
|
19
19
|
|
|
20
|
+
/** A bottom sheet's detents: the drag moves between them before it dismisses. */
|
|
21
|
+
export interface SwipeSnap {
|
|
22
|
+
/** Each detent's height in px, ascending */
|
|
23
|
+
heights: readonly number[]
|
|
24
|
+
/** The detent the sheet rests at */
|
|
25
|
+
index: number
|
|
26
|
+
/** A drag settled on another detent */
|
|
27
|
+
onSnap: (index: number) => void
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
interface UseSwipeDismissOptions {
|
|
21
31
|
anchor: DrawerAnchor
|
|
22
32
|
enabled: boolean
|
|
@@ -27,6 +37,8 @@ interface UseSwipeDismissOptions {
|
|
|
27
37
|
* exists, and listeners must follow the element that is actually shown.
|
|
28
38
|
*/
|
|
29
39
|
panel: HTMLDivElement | null
|
|
40
|
+
/** Bottom anchor with snapPoints: drag between detents, dismiss below the lowest */
|
|
41
|
+
snap?: SwipeSnap | null
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
interface SwipeState {
|
|
@@ -39,6 +51,8 @@ interface SwipeState {
|
|
|
39
51
|
panelSize: number
|
|
40
52
|
/** Inner Duro scroll viewport the gesture started in; capture is deferred until the axis is decided */
|
|
41
53
|
deferredScroll: HTMLElement | null
|
|
54
|
+
/** Started on a snap sheet's grabber: a tap stays its click, a drag moves the sheet */
|
|
55
|
+
fromGrabber: boolean
|
|
42
56
|
pointerId: number
|
|
43
57
|
}
|
|
44
58
|
|
|
@@ -49,7 +63,13 @@ interface SwipeState {
|
|
|
49
63
|
* Opposite direction: iOS-style — panel stays anchored, shows subtle
|
|
50
64
|
* overscroll feedback (box-shadow intensifies), then snaps back.
|
|
51
65
|
*/
|
|
52
|
-
export function useSwipeDismiss({
|
|
66
|
+
export function useSwipeDismiss({
|
|
67
|
+
anchor,
|
|
68
|
+
enabled,
|
|
69
|
+
onDismiss,
|
|
70
|
+
panel,
|
|
71
|
+
snap = null,
|
|
72
|
+
}: UseSwipeDismissOptions) {
|
|
53
73
|
const stateRef = useRef<SwipeState>({
|
|
54
74
|
startX: 0,
|
|
55
75
|
startY: 0,
|
|
@@ -59,8 +79,13 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
59
79
|
swiping: false,
|
|
60
80
|
panelSize: 0,
|
|
61
81
|
deferredScroll: null,
|
|
82
|
+
fromGrabber: false,
|
|
62
83
|
pointerId: 0,
|
|
63
84
|
})
|
|
85
|
+
// Read at event time, so a settle that re-renders mid-gesture is never stale.
|
|
86
|
+
const snapRef = useRef(snap)
|
|
87
|
+
snapRef.current = snap
|
|
88
|
+
const snapping = snap !== null
|
|
64
89
|
|
|
65
90
|
const isHorizontal = anchor === 'left' || anchor === 'right'
|
|
66
91
|
|
|
@@ -117,6 +142,8 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
117
142
|
const resetStyles = useCallback((panelEl: HTMLDivElement) => {
|
|
118
143
|
panelEl.style.transform = ''
|
|
119
144
|
panelEl.style.boxShadow = ''
|
|
145
|
+
panelEl.style.height = ''
|
|
146
|
+
panelEl.style.transition = ''
|
|
120
147
|
|
|
121
148
|
const backdrop = panelEl.closest('[data-drawer-viewport]')
|
|
122
149
|
?.previousElementSibling as HTMLElement | null
|
|
@@ -178,19 +205,79 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
178
205
|
setTimeout(cleanup, 250)
|
|
179
206
|
}, [])
|
|
180
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Snap sheet drag: the visible height follows the finger. Between the lowest
|
|
210
|
+
* and the largest detent the panel resizes; past the largest it resists;
|
|
211
|
+
* below the lowest it slides down and the backdrop fades.
|
|
212
|
+
*/
|
|
213
|
+
const applySnapDrag = useCallback((movement: number, panelEl: HTMLDivElement) => {
|
|
214
|
+
const current = snapRef.current
|
|
215
|
+
if (!current) return
|
|
216
|
+
const {heights, index} = current
|
|
217
|
+
const low = heights[0]
|
|
218
|
+
const high = heights[heights.length - 1]
|
|
219
|
+
const visible = heights[index] - movement
|
|
220
|
+
const backdrop = backdropOf(panelEl)
|
|
221
|
+
if (visible > high) {
|
|
222
|
+
panelEl.style.height = `${high + rubberBand(visible - high, SNAP_MAX_OVERSHOOT)}px`
|
|
223
|
+
panelEl.style.transform = ''
|
|
224
|
+
} else if (visible >= low) {
|
|
225
|
+
panelEl.style.height = `${visible}px`
|
|
226
|
+
panelEl.style.transform = ''
|
|
227
|
+
} else {
|
|
228
|
+
panelEl.style.height = `${low}px`
|
|
229
|
+
panelEl.style.transform = `translateY(${low - visible}px)`
|
|
230
|
+
}
|
|
231
|
+
if (backdrop) backdrop.style.opacity = String(Math.min(1, Math.max(0, visible / low)))
|
|
232
|
+
}, [])
|
|
233
|
+
|
|
234
|
+
/** Settle a snap sheet on a detent, then hand the height back to React */
|
|
235
|
+
const animateToDetent = useCallback((panelEl: HTMLDivElement, target: number) => {
|
|
236
|
+
const current = snapRef.current
|
|
237
|
+
if (!current) return
|
|
238
|
+
const ease = `${SNAP_DURATION}ms cubic-bezier(0.25, 1, 0.5, 1)`
|
|
239
|
+
panelEl.style.transition = `height ${ease}, transform ${ease}`
|
|
240
|
+
panelEl.style.height = `${current.heights[target]}px`
|
|
241
|
+
panelEl.style.transform = ''
|
|
242
|
+
const backdrop = backdropOf(panelEl)
|
|
243
|
+
if (backdrop) {
|
|
244
|
+
backdrop.style.transition = `opacity ${ease}`
|
|
245
|
+
backdrop.style.opacity = ''
|
|
246
|
+
}
|
|
247
|
+
let settled = false
|
|
248
|
+
const done = () => {
|
|
249
|
+
if (settled) return
|
|
250
|
+
settled = true
|
|
251
|
+
current.onSnap(target)
|
|
252
|
+
// React now sizes the panel at this detent: drop the inline copy.
|
|
253
|
+
requestAnimationFrame(() => {
|
|
254
|
+
panelEl.style.transition = ''
|
|
255
|
+
panelEl.style.height = ''
|
|
256
|
+
if (backdrop) backdrop.style.transition = ''
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
panelEl.addEventListener('transitionend', done, {once: true})
|
|
260
|
+
setTimeout(done, SNAP_DURATION + 50)
|
|
261
|
+
}, [])
|
|
262
|
+
|
|
181
263
|
useEffect(() => {
|
|
182
264
|
if (!enabled || !panel) return
|
|
183
265
|
|
|
184
266
|
function handlePointerDown(e: PointerEvent) {
|
|
185
267
|
if (e.button !== 0) return
|
|
186
268
|
const target = e.target as HTMLElement
|
|
187
|
-
const
|
|
269
|
+
const fromGrabber = snapping && target.closest('[data-drawer-grabber]') !== null
|
|
270
|
+
const scrollEl = fromGrabber ? null : target.closest<HTMLElement>('[data-duro-scroll]')
|
|
188
271
|
// Outside a ScrollArea a control keeps its press. Inside one the gesture
|
|
189
272
|
// is decided on the first move even from a control: a list of toggles is
|
|
190
273
|
// all buttons, and touch adjustment snaps a finger onto one. A tap
|
|
191
274
|
// (under the 8px slop) still presses it; a drag never captures before
|
|
192
275
|
// the decision, so the release lands on the panel, not the control.
|
|
193
|
-
if (
|
|
276
|
+
if (
|
|
277
|
+
!fromGrabber &&
|
|
278
|
+
!scrollEl &&
|
|
279
|
+
target.closest('button, a, input, textarea, select, [role="button"]')
|
|
280
|
+
) {
|
|
194
281
|
return
|
|
195
282
|
}
|
|
196
283
|
|
|
@@ -206,11 +293,13 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
206
293
|
|
|
207
294
|
state.pointerId = e.pointerId
|
|
208
295
|
state.deferredScroll = scrollEl
|
|
296
|
+
state.fromGrabber = fromGrabber
|
|
209
297
|
|
|
210
298
|
panel!.dataset.panelSize = String(state.panelSize)
|
|
211
299
|
|
|
212
|
-
// Inside a Duro ScrollArea the scroll may own the gesture
|
|
213
|
-
|
|
300
|
+
// Inside a Duro ScrollArea the scroll may own the gesture, and a press on
|
|
301
|
+
// the grabber may be a tap: wait for the first move.
|
|
302
|
+
if (!state.deferredScroll && !fromGrabber) beginCapture(e.pointerId)
|
|
214
303
|
}
|
|
215
304
|
|
|
216
305
|
function beginCapture(pointerId: number) {
|
|
@@ -219,6 +308,14 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
219
308
|
// Freeze CSS animation — we take over positioning.
|
|
220
309
|
// Never restore it; the panel is already at its final resting position.
|
|
221
310
|
panel!.style.animation = 'none'
|
|
311
|
+
// A snap sheet animates its height between detents; the finger drives it now.
|
|
312
|
+
if (snapping) panel!.style.transition = 'none'
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** A snap sheet below its largest detent grows when dragged up from its content */
|
|
316
|
+
function canGrow() {
|
|
317
|
+
const current = snapRef.current
|
|
318
|
+
return current !== null && current.index < current.heights.length - 1
|
|
222
319
|
}
|
|
223
320
|
|
|
224
321
|
/** True when the viewport can't scroll further against the dismiss direction */
|
|
@@ -240,7 +337,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
240
337
|
|
|
241
338
|
if (!state.swiping) {
|
|
242
339
|
const totalMovement = Math.sqrt(dx * dx + dy * dy)
|
|
243
|
-
if (totalMovement <
|
|
340
|
+
if (totalMovement < DRAG_SLOP) return
|
|
244
341
|
|
|
245
342
|
if (isHorizontal && dx > dy) {
|
|
246
343
|
state.swiping = true
|
|
@@ -250,13 +347,19 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
250
347
|
// Wrong axis — abort gesture
|
|
251
348
|
state.startTime = 0
|
|
252
349
|
state.deferredScroll = null
|
|
350
|
+
state.fromGrabber = false
|
|
253
351
|
return
|
|
254
352
|
}
|
|
255
353
|
|
|
256
354
|
const scrollEl = state.deferredScroll
|
|
257
|
-
if (
|
|
355
|
+
if (state.fromGrabber) {
|
|
356
|
+
beginCapture(state.pointerId)
|
|
357
|
+
} else if (scrollEl) {
|
|
258
358
|
state.deferredScroll = null
|
|
259
|
-
|
|
359
|
+
const movement = getMovement(state)
|
|
360
|
+
const sheetOwns =
|
|
361
|
+
movement > 0 ? isAtDismissEdge(scrollEl) : snapping && movement < 0 && canGrow()
|
|
362
|
+
if (!sheetOwns) {
|
|
260
363
|
// The scroll owns this gesture: no swiping, no capture, no preventDefault
|
|
261
364
|
state.swiping = false
|
|
262
365
|
state.startTime = 0
|
|
@@ -269,7 +372,8 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
269
372
|
if (state.swiping) {
|
|
270
373
|
e.preventDefault()
|
|
271
374
|
const movement = getMovement(state)
|
|
272
|
-
|
|
375
|
+
if (snapping) applySnapDrag(movement, panel!)
|
|
376
|
+
else applyTransform(movement, panel!)
|
|
273
377
|
}
|
|
274
378
|
}
|
|
275
379
|
|
|
@@ -283,6 +387,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
283
387
|
|
|
284
388
|
state.startTime = 0
|
|
285
389
|
state.deferredScroll = null
|
|
390
|
+
state.fromGrabber = false
|
|
286
391
|
|
|
287
392
|
if (!state.swiping) {
|
|
288
393
|
return
|
|
@@ -290,16 +395,26 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
290
395
|
|
|
291
396
|
state.swiping = false
|
|
292
397
|
|
|
398
|
+
const current = snapRef.current
|
|
399
|
+
if (current) {
|
|
400
|
+
const settled = settleDetent({
|
|
401
|
+
heights: current.heights,
|
|
402
|
+
from: current.index,
|
|
403
|
+
height: current.heights[current.index] - movement,
|
|
404
|
+
velocity,
|
|
405
|
+
})
|
|
406
|
+
if (settled === 'dismiss') animateDismiss(panel!)
|
|
407
|
+
else animateToDetent(panel!, settled)
|
|
408
|
+
return
|
|
409
|
+
}
|
|
410
|
+
|
|
293
411
|
if (movement <= 0) {
|
|
294
412
|
// Was dragging in opposite direction — just reset (no translate was applied)
|
|
295
413
|
resetStyles(panel!)
|
|
296
414
|
return
|
|
297
415
|
}
|
|
298
416
|
|
|
299
|
-
|
|
300
|
-
const shouldDismiss = fraction > DISMISS_THRESHOLD || velocity > VELOCITY_THRESHOLD
|
|
301
|
-
|
|
302
|
-
if (shouldDismiss) {
|
|
417
|
+
if (shouldDismissEdge(movement, state.panelSize, velocity)) {
|
|
303
418
|
animateDismiss(panel!)
|
|
304
419
|
} else {
|
|
305
420
|
animateSnapBack(panel!)
|
|
@@ -311,6 +426,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
311
426
|
state.startTime = 0
|
|
312
427
|
state.swiping = false
|
|
313
428
|
state.deferredScroll = null
|
|
429
|
+
state.fromGrabber = false
|
|
314
430
|
resetStyles(panel!)
|
|
315
431
|
}
|
|
316
432
|
|
|
@@ -340,8 +456,15 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
340
456
|
isHorizontal,
|
|
341
457
|
getMovement,
|
|
342
458
|
applyTransform,
|
|
459
|
+
applySnapDrag,
|
|
460
|
+
animateToDetent,
|
|
343
461
|
resetStyles,
|
|
344
462
|
animateSnapBack,
|
|
345
463
|
animateDismiss,
|
|
464
|
+
snapping,
|
|
346
465
|
])
|
|
347
466
|
}
|
|
467
|
+
|
|
468
|
+
function backdropOf(panelEl: HTMLDivElement) {
|
|
469
|
+
return panelEl.closest('[data-drawer-viewport]')?.previousElementSibling as HTMLElement | null
|
|
470
|
+
}
|
|
@@ -2,7 +2,7 @@ import type {ComponentMeta} from '../component-meta'
|
|
|
2
2
|
|
|
3
3
|
export const meta: ComponentMeta = {
|
|
4
4
|
description:
|
|
5
|
-
'Dropdown action menu. Triggers actions (not value selection). Compound component — Root is required (throws without it). Menu.Trigger renders the button itself: give it the label (text, an Icon), never a Button; an icon-only trigger takes aria-label, and variant="ghost" suits toolbars; size="small" matches small Toggles and Buttons (a small ghost trigger is iconButtonSm). The popup is portalled and placed against the trigger (never clipped by a sticky or overflow ancestor), capped at sizes.listMaxH with scrolling, and takes focus on open (WAI-ARIA menu button); Escape closes only the menu, not an enclosing Popover or Dialog.',
|
|
5
|
+
'Dropdown action menu. Triggers actions (not value selection). Compound component — Root is required (throws without it). Menu.Trigger renders the button itself: give it the label (text, an Icon), never a Button; an icon-only trigger takes aria-label, and variant="ghost" suits toolbars; size="small" matches small Toggles and Buttons (a small ghost trigger is iconButtonSm). The popup is portalled and placed against the trigger (never clipped by a sticky or overflow ancestor), capped at sizes.listMaxH with scrolling, and takes focus on open (WAI-ARIA menu button); Escape closes only the menu, not an enclosing Popover or Dialog. On React Native the popup is placed against the trigger in a modal overlay; a press outside or the Android back button closes it, and an item runs its onClick after the menu has gone (so an item can open a Dialog). Menu.LinkItem takes onNavigate(href, event) on both platforms (ADR-0002); on native, without it or without preventDefault, the link opens with the system. Native has no arrow keys: each item is its own screen-reader stop.',
|
|
6
6
|
whenToUse: [
|
|
7
7
|
'Context menu or "more actions" dropdown',
|
|
8
8
|
'Navigation links in a dropdown',
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
type ReactNode,
|
|
4
|
+
type Ref,
|
|
5
|
+
type RefObject,
|
|
6
|
+
useCallback,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect,
|
|
9
|
+
useId,
|
|
10
|
+
useRef,
|
|
11
|
+
} from 'react'
|
|
12
|
+
import {Linking, Platform, Pressable, ScrollView, StyleSheet} from 'react-native'
|
|
13
|
+
import {html} from 'react-strict-dom'
|
|
14
|
+
import {SIZES_PX} from '@duro-app/tokens/keys'
|
|
15
|
+
import {styles} from './styles.css'
|
|
16
|
+
import {nativeStyles} from './native.css'
|
|
17
|
+
import {useMenuOpen} from './useMenuOpen'
|
|
18
|
+
import {AnchoredOverlay} from '../../shared/portal/AnchoredOverlay'
|
|
19
|
+
import {focusForAccessibility} from '../../shared/accessibilityFocus'
|
|
20
|
+
import {mergeRefs} from '../../shared/mergeRefs'
|
|
21
|
+
import type {LinkClickEvent, OnNavigate} from '../../shared/navigate'
|
|
22
|
+
import type {ControlSize} from '../../shared/types'
|
|
23
|
+
import {useTooltipHint} from '../Tooltip/TooltipHint'
|
|
24
|
+
import {ControlContextBoundary} from '../Toolbar/ControlContextBoundary'
|
|
25
|
+
|
|
26
|
+
interface NativeMenuContextValue {
|
|
27
|
+
open: boolean
|
|
28
|
+
toggle: () => void
|
|
29
|
+
/**
|
|
30
|
+
* Close, then run `after` once the menu's Modal is gone: an item that opens
|
|
31
|
+
* a Dialog would otherwise present during a dismissal, which iOS drops.
|
|
32
|
+
*/
|
|
33
|
+
closeThen: (after?: () => void) => void
|
|
34
|
+
menuId: string
|
|
35
|
+
triggerRef: RefObject<unknown>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const MenuContext = createContext<NativeMenuContextValue | null>(null)
|
|
39
|
+
|
|
40
|
+
function useMenu() {
|
|
41
|
+
const ctx = useContext(MenuContext)
|
|
42
|
+
if (!ctx) throw new Error('Menu compound components must be used within Menu.Root')
|
|
43
|
+
return ctx
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface RootProps {
|
|
47
|
+
children: ReactNode
|
|
48
|
+
/** Controlled open state. */
|
|
49
|
+
open?: boolean
|
|
50
|
+
/** Initial open state (uncontrolled). */
|
|
51
|
+
defaultOpen?: boolean
|
|
52
|
+
/** Called when the menu opens or closes. */
|
|
53
|
+
onOpenChange?: (open: boolean) => void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Native Menu (plan N0, Slice B): the same compound API, its popup placed
|
|
58
|
+
* against the trigger in an OverlayModal. A press outside or Android's back
|
|
59
|
+
* button closes it; an item runs its action after the menu has gone. Native
|
|
60
|
+
* has no arrow keys or active descendant (Decision 6): each item is its own
|
|
61
|
+
* screen-reader stop.
|
|
62
|
+
*/
|
|
63
|
+
function Root({children, ...options}: RootProps) {
|
|
64
|
+
const {open, setOpen} = useMenuOpen(options)
|
|
65
|
+
const menuId = useId()
|
|
66
|
+
const triggerRef = useRef<unknown>(null)
|
|
67
|
+
const pendingRef = useRef<(() => void) | null>(null)
|
|
68
|
+
|
|
69
|
+
const runPending = useCallback(() => {
|
|
70
|
+
const pending = pendingRef.current
|
|
71
|
+
pendingRef.current = null
|
|
72
|
+
pending?.()
|
|
73
|
+
}, [])
|
|
74
|
+
|
|
75
|
+
const closeThen = useCallback(
|
|
76
|
+
(after?: () => void) => {
|
|
77
|
+
pendingRef.current = after ?? null
|
|
78
|
+
setOpen(false)
|
|
79
|
+
},
|
|
80
|
+
[setOpen],
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
// Focus back on the trigger once the menu is gone; Android has no Modal
|
|
84
|
+
// onDismiss, so a pending action runs on the next frame there.
|
|
85
|
+
const wasOpen = useRef(open)
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (wasOpen.current && !open) {
|
|
88
|
+
focusForAccessibility(triggerRef.current, 'Menu')
|
|
89
|
+
if (Platform.OS !== 'ios') requestAnimationFrame(runPending)
|
|
90
|
+
}
|
|
91
|
+
wasOpen.current = open
|
|
92
|
+
}, [open, runPending])
|
|
93
|
+
|
|
94
|
+
const toggle = useCallback(() => setOpen(!open), [open, setOpen])
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<MenuContext.Provider value={{open, toggle, closeThen, menuId, triggerRef}}>
|
|
98
|
+
<PendingContext.Provider value={runPending}>
|
|
99
|
+
<html.div style={[styles.root, nativeStyles.nativeFlex]}>{children}</html.div>
|
|
100
|
+
</PendingContext.Provider>
|
|
101
|
+
</MenuContext.Provider>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** iOS: run the pending item action once the Modal has dismissed. */
|
|
106
|
+
const PendingContext = createContext<() => void>(() => {})
|
|
107
|
+
|
|
108
|
+
export type MenuTriggerVariant = 'default' | 'ghost'
|
|
109
|
+
|
|
110
|
+
interface TriggerProps {
|
|
111
|
+
children: ReactNode
|
|
112
|
+
/** Accessible name — required when the label is an icon only. */
|
|
113
|
+
'aria-label'?: string
|
|
114
|
+
/** `ghost`: no border or fill until hover, for toolbars. Default: `default`. */
|
|
115
|
+
variant?: MenuTriggerVariant
|
|
116
|
+
/** `small` matches a small Toggle or Button beside it. Default: `default`. */
|
|
117
|
+
size?: ControlSize
|
|
118
|
+
ref?: Ref<unknown>
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The trigger is an RN Pressable host, so it carries an enclosing Tooltip's
|
|
123
|
+
* text as its own accessibility hint (RSD drops `accessibilityHint` on html.*).
|
|
124
|
+
*
|
|
125
|
+
* holds-until: react-strict-dom maps aria-description to accessibilityHint
|
|
126
|
+
* (https://github.com/react/react-strict-dom/issues/524).
|
|
127
|
+
*/
|
|
128
|
+
function Trigger({
|
|
129
|
+
children,
|
|
130
|
+
'aria-label': ariaLabel,
|
|
131
|
+
variant = 'default',
|
|
132
|
+
size = 'default',
|
|
133
|
+
ref,
|
|
134
|
+
}: TriggerProps) {
|
|
135
|
+
const {open, toggle, triggerRef} = useMenu()
|
|
136
|
+
const hint = useTooltipHint()
|
|
137
|
+
return (
|
|
138
|
+
<Pressable
|
|
139
|
+
ref={mergeRefs(triggerRef, ref) as Ref<never>}
|
|
140
|
+
onPress={toggle}
|
|
141
|
+
accessibilityRole="button"
|
|
142
|
+
accessibilityLabel={ariaLabel}
|
|
143
|
+
accessibilityHint={hint}
|
|
144
|
+
accessibilityState={{expanded: open}}
|
|
145
|
+
>
|
|
146
|
+
<html.div
|
|
147
|
+
style={[
|
|
148
|
+
styles.trigger,
|
|
149
|
+
nativeStyles.nativeFlex,
|
|
150
|
+
variant === 'ghost'
|
|
151
|
+
? [styles.triggerGhost, size === 'small' && styles.triggerGhostSmall]
|
|
152
|
+
: size === 'small' && styles.triggerSmall,
|
|
153
|
+
]}
|
|
154
|
+
>
|
|
155
|
+
{children}
|
|
156
|
+
</html.div>
|
|
157
|
+
</Pressable>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface PopupProps {
|
|
162
|
+
children: ReactNode
|
|
163
|
+
align?: 'start' | 'end'
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function Popup({children, align = 'start'}: PopupProps) {
|
|
167
|
+
const {open, closeThen, menuId, triggerRef} = useMenu()
|
|
168
|
+
const runPending = useContext(PendingContext)
|
|
169
|
+
const popupRef = useRef<HTMLDivElement>(null)
|
|
170
|
+
return (
|
|
171
|
+
<AnchoredOverlay
|
|
172
|
+
visible={open}
|
|
173
|
+
anchorRef={triggerRef}
|
|
174
|
+
side="bottom"
|
|
175
|
+
align={align}
|
|
176
|
+
onRequestClose={() => closeThen()}
|
|
177
|
+
onShow={() => focusForAccessibility(popupRef.current, 'Menu')}
|
|
178
|
+
onDismiss={runPending}
|
|
179
|
+
>
|
|
180
|
+
<html.div
|
|
181
|
+
ref={popupRef}
|
|
182
|
+
id={menuId}
|
|
183
|
+
role="menu"
|
|
184
|
+
style={[styles.popup, nativeStyles.popupInPlace]}
|
|
185
|
+
>
|
|
186
|
+
<ScrollView style={layout.scroll} bounces={false}>
|
|
187
|
+
<ControlContextBoundary>{children}</ControlContextBoundary>
|
|
188
|
+
</ScrollView>
|
|
189
|
+
</html.div>
|
|
190
|
+
</AnchoredOverlay>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The popup's height cap, `sizes.listMaxH`, on the view that scrolls.
|
|
195
|
+
const layout = StyleSheet.create({scroll: {maxHeight: SIZES_PX.listMaxH, flexGrow: 0}})
|
|
196
|
+
|
|
197
|
+
interface ItemProps {
|
|
198
|
+
onClick?: () => void
|
|
199
|
+
children: ReactNode
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function Item({onClick, children}: ItemProps) {
|
|
203
|
+
const {closeThen} = useMenu()
|
|
204
|
+
return (
|
|
205
|
+
<Pressable accessibilityRole="menuitem" onPress={() => closeThen(onClick)}>
|
|
206
|
+
{({pressed}) => (
|
|
207
|
+
<html.div style={[styles.item, pressed && nativeStyles.itemPressed]}>{children}</html.div>
|
|
208
|
+
)}
|
|
209
|
+
</Pressable>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
interface LinkItemProps {
|
|
214
|
+
href: string
|
|
215
|
+
/**
|
|
216
|
+
* Called with the href when the item is pressed (ADR-0002). Call
|
|
217
|
+
* `event.preventDefault()` to navigate in-app; otherwise, and without it,
|
|
218
|
+
* the URL opens with the system (`Linking.openURL`).
|
|
219
|
+
*/
|
|
220
|
+
onNavigate?: OnNavigate
|
|
221
|
+
children: ReactNode
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function LinkItem({href, onNavigate, children}: LinkItemProps) {
|
|
225
|
+
const {closeThen} = useMenu()
|
|
226
|
+
const follow = () => {
|
|
227
|
+
let prevented = false
|
|
228
|
+
const event: LinkClickEvent = {
|
|
229
|
+
button: 0,
|
|
230
|
+
metaKey: false,
|
|
231
|
+
ctrlKey: false,
|
|
232
|
+
shiftKey: false,
|
|
233
|
+
altKey: false,
|
|
234
|
+
get defaultPrevented() {
|
|
235
|
+
return prevented
|
|
236
|
+
},
|
|
237
|
+
preventDefault() {
|
|
238
|
+
prevented = true
|
|
239
|
+
},
|
|
240
|
+
}
|
|
241
|
+
onNavigate?.(href, event)
|
|
242
|
+
if (!prevented) {
|
|
243
|
+
Linking.openURL(href).catch((error: unknown) => {
|
|
244
|
+
console.warn(`[duro] Menu.LinkItem: could not open ${href}: ${String(error)}`)
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return (
|
|
249
|
+
<Pressable accessibilityRole="link" onPress={() => closeThen(follow)}>
|
|
250
|
+
{({pressed}) => (
|
|
251
|
+
<html.div style={[styles.item, pressed && nativeStyles.itemPressed]}>{children}</html.div>
|
|
252
|
+
)}
|
|
253
|
+
</Pressable>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function Separator() {
|
|
258
|
+
return <html.div role="separator" aria-orientation="horizontal" style={styles.separator} />
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export const Menu = {
|
|
262
|
+
Root,
|
|
263
|
+
Trigger,
|
|
264
|
+
Popup,
|
|
265
|
+
Item,
|
|
266
|
+
LinkItem,
|
|
267
|
+
Separator,
|
|
268
|
+
}
|
|
@@ -15,6 +15,7 @@ import {styles} from './styles.css'
|
|
|
15
15
|
import {MenuContext, useMenu} from './MenuContext'
|
|
16
16
|
import {useMenuRoot} from './useMenuRoot'
|
|
17
17
|
import {devWarnOnce} from '../../shared/devWarnOnce'
|
|
18
|
+
import {isPlainClick, type LinkClickEvent, type OnNavigate} from '../../shared/navigate'
|
|
18
19
|
import type {ControlSize} from '../../shared/types'
|
|
19
20
|
import {usePortalMount} from '../ThemeProvider/ThemeProvider'
|
|
20
21
|
import {computePopoverPosition} from '../Popover/position'
|
|
@@ -222,10 +223,15 @@ function Item({onClick, children}: ItemProps) {
|
|
|
222
223
|
// --- LinkItem ---
|
|
223
224
|
interface LinkItemProps {
|
|
224
225
|
href: string
|
|
226
|
+
/**
|
|
227
|
+
* Called for a plain primary click (ADR-0002): call `event.preventDefault()`,
|
|
228
|
+
* then your router's navigate. Without it the browser follows the link.
|
|
229
|
+
*/
|
|
230
|
+
onNavigate?: OnNavigate
|
|
225
231
|
children: ReactNode
|
|
226
232
|
}
|
|
227
233
|
|
|
228
|
-
function LinkItem({href, children}: LinkItemProps) {
|
|
234
|
+
function LinkItem({href, onNavigate, children}: LinkItemProps) {
|
|
229
235
|
const {close, highlightedId, setHighlightedId, registerItem} = useMenu()
|
|
230
236
|
const id = useId()
|
|
231
237
|
const ref = useRef<HTMLAnchorElement>(null)
|
|
@@ -242,7 +248,10 @@ function LinkItem({href, children}: LinkItemProps) {
|
|
|
242
248
|
ref={ref}
|
|
243
249
|
id={id}
|
|
244
250
|
href={href}
|
|
245
|
-
onClick={() =>
|
|
251
|
+
onClick={(event: LinkClickEvent) => {
|
|
252
|
+
if (onNavigate && isPlainClick(event)) onNavigate(href, event)
|
|
253
|
+
close()
|
|
254
|
+
}}
|
|
246
255
|
role="menuitem"
|
|
247
256
|
onPointerEnter={() => setHighlightedId(id)}
|
|
248
257
|
style={[styles.item, styles.linkItem, isHighlighted && styles.itemHighlighted]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {css} from 'react-strict-dom'
|
|
2
|
+
import {colors} from '@duro-app/tokens/tokens/colors.css'
|
|
3
|
+
|
|
4
|
+
/** Native Menu additions to the shared styles. */
|
|
5
|
+
export const nativeStyles = css.create({
|
|
6
|
+
// The AnchoredOverlay's view places the popup; it flows inside it.
|
|
7
|
+
// RSD on native lays out only display: flex, not the web's inline-flex.
|
|
8
|
+
nativeFlex: {
|
|
9
|
+
display: 'flex',
|
|
10
|
+
},
|
|
11
|
+
popupInPlace: {
|
|
12
|
+
position: 'relative',
|
|
13
|
+
},
|
|
14
|
+
// A press shows the highlight that hover and the arrow keys show on the web.
|
|
15
|
+
itemPressed: {
|
|
16
|
+
backgroundColor: colors.bgCardHover,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {useCallback, useRef, useState} from 'react'
|
|
2
|
+
|
|
3
|
+
export interface MenuOpenOptions {
|
|
4
|
+
open?: boolean
|
|
5
|
+
defaultOpen?: boolean
|
|
6
|
+
onOpenChange?: (open: boolean) => void
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The menu's open state, controlled or not, shared by both platforms (plan
|
|
11
|
+
* N0, Decision 10). Focus, highlight and keys are each platform's adapter:
|
|
12
|
+
* `useMenuRoot` on the web, Menu.native on native.
|
|
13
|
+
*/
|
|
14
|
+
export function useMenuOpen({open: openProp, defaultOpen = false, onOpenChange}: MenuOpenOptions) {
|
|
15
|
+
const [inner, setInner] = useState(defaultOpen)
|
|
16
|
+
const controlled = openProp !== undefined
|
|
17
|
+
const open = controlled ? openProp : inner
|
|
18
|
+
const openRef = useRef(open)
|
|
19
|
+
openRef.current = open
|
|
20
|
+
const onOpenChangeRef = useRef(onOpenChange)
|
|
21
|
+
onOpenChangeRef.current = onOpenChange
|
|
22
|
+
|
|
23
|
+
const setOpen = useCallback(
|
|
24
|
+
(next: boolean) => {
|
|
25
|
+
if (next === openRef.current) return
|
|
26
|
+
if (!controlled) setInner(next)
|
|
27
|
+
onOpenChangeRef.current?.(next)
|
|
28
|
+
},
|
|
29
|
+
[controlled],
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return {open, openRef, setOpen}
|
|
33
|
+
}
|