@mrpelz/uikit-ish 7.9.0 → 7.11.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/components/action-sheet/main.d.ts +1 -2
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +12 -12
- package/dist/components/action-sheet/main.js.map +1 -1
- package/dist/components/action-sheet/props.d.ts +2 -2
- package/dist/components/action-sheet/props.d.ts.map +1 -1
- package/dist/components/action-sheet/style.css +10 -1
- package/dist/components/activity-view/main.d.ts +1 -1
- package/dist/components/activity-view/main.d.ts.map +1 -1
- package/dist/components/activity-view/main.js +9 -11
- package/dist/components/activity-view/main.js.map +1 -1
- package/dist/components/activity-view/style.css +21 -21
- package/dist/components/alert/main.d.ts +2 -3
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +12 -15
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +3 -3
- package/dist/components/alert/style.css +23 -23
- package/dist/components/avatar/main.d.ts.map +1 -1
- package/dist/components/avatar/main.js +7 -8
- package/dist/components/avatar/main.js.map +1 -1
- package/dist/components/avatar/style.css +1 -1
- package/dist/components/badge/main.d.ts +1 -1
- package/dist/components/badge/main.js +4 -4
- package/dist/components/badge/main.js.map +1 -1
- package/dist/components/badge/style.css +7 -2
- package/dist/components/button/main.d.ts.map +1 -1
- package/dist/components/button/main.js +9 -9
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/props.d.ts +8 -8
- package/dist/components/button/props.d.ts.map +1 -1
- package/dist/components/button/style.css +27 -29
- package/dist/components/checkbox/main.d.ts.map +1 -1
- package/dist/components/checkbox/main.js +5 -7
- package/dist/components/checkbox/main.js.map +1 -1
- package/dist/components/checkbox/style.css +3 -3
- package/dist/components/color-picker/color.d.ts +23 -0
- package/dist/components/color-picker/color.d.ts.map +1 -0
- package/dist/components/color-picker/color.js +150 -0
- package/dist/components/color-picker/color.js.map +1 -0
- package/dist/components/color-picker/main.d.ts +41 -5
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +633 -99
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/named-colors.d.ts +3 -0
- package/dist/components/color-picker/named-colors.d.ts.map +1 -0
- package/dist/components/color-picker/named-colors.js +152 -0
- package/dist/components/color-picker/named-colors.js.map +1 -0
- package/dist/components/color-picker/props.d.ts +97 -14
- package/dist/components/color-picker/props.d.ts.map +1 -1
- package/dist/components/color-picker/style.css +316 -50
- package/dist/components/contextual-menu/main.d.ts.map +1 -1
- package/dist/components/contextual-menu/main.js +189 -236
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +10 -33
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +60 -34
- package/dist/components/date-picker/main.d.ts.map +1 -1
- package/dist/components/date-picker/main.js +100 -66
- package/dist/components/date-picker/main.js.map +1 -1
- package/dist/components/date-picker/props.d.ts +10 -10
- package/dist/components/date-picker/props.d.ts.map +1 -1
- package/dist/components/date-picker/style.css +51 -47
- package/dist/components/drawer/main.d.ts.map +1 -1
- package/dist/components/drawer/main.js +52 -7
- package/dist/components/drawer/main.js.map +1 -1
- package/dist/components/drawer/style.css +1 -1
- package/dist/components/edit-menu/main.d.ts.map +1 -1
- package/dist/components/edit-menu/main.js +41 -30
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/edit-menu/props.d.ts +4 -4
- package/dist/components/edit-menu/props.d.ts.map +1 -1
- package/dist/components/edit-menu/style.css +27 -1
- package/dist/components/form/main.js +3 -3
- package/dist/components/form/main.js.map +1 -1
- package/dist/components/glass/main.d.ts +1 -1
- package/dist/components/glass/main.js +4 -4
- package/dist/components/glass/main.js.map +1 -1
- package/dist/components/glass/props.d.ts +5 -5
- package/dist/components/glass/props.d.ts.map +1 -1
- package/dist/components/glass/style.css +157 -157
- package/dist/components/header/main.d.ts.map +1 -1
- package/dist/components/header/main.js +27 -26
- package/dist/components/header/main.js.map +1 -1
- package/dist/components/header/style.css +13 -52
- package/dist/components/index.d.ts +6 -6
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/layout/main.js +5 -5
- package/dist/components/layout/main.js.map +1 -1
- package/dist/components/layout/style.css +2 -2
- package/dist/components/list/main.d.ts +11 -3
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +296 -300
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +49 -16
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/reorder.d.ts +146 -0
- package/dist/components/list/reorder.d.ts.map +1 -0
- package/dist/components/list/reorder.js +819 -0
- package/dist/components/list/reorder.js.map +1 -0
- package/dist/components/list/select.d.ts +6 -0
- package/dist/components/list/select.d.ts.map +1 -0
- package/dist/components/list/select.js +141 -0
- package/dist/components/list/select.js.map +1 -0
- package/dist/components/list/style.css +206 -158
- package/dist/components/menu/main.d.ts +81 -30
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +568 -93
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +3 -4
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +30 -12
- package/dist/components/navigation/main.d.ts +5 -2
- package/dist/components/navigation/main.d.ts.map +1 -1
- package/dist/components/navigation/main.js +287 -57
- package/dist/components/navigation/main.js.map +1 -1
- package/dist/components/navigation/props.d.ts +37 -4
- package/dist/components/navigation/props.d.ts.map +1 -1
- package/dist/components/navigation/style.css +32 -2
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +12 -7
- package/dist/components/page/main.js.map +1 -1
- package/dist/components/page/props.d.ts +1 -1
- package/dist/components/page/style.css +3 -6
- package/dist/components/page-control/main.d.ts +1 -1
- package/dist/components/page-control/main.js +9 -9
- package/dist/components/page-control/main.js.map +1 -1
- package/dist/components/page-control/style.css +2 -2
- package/dist/components/popover/main.d.ts +1 -1
- package/dist/components/popover/main.d.ts.map +1 -1
- package/dist/components/popover/main.js +41 -17
- package/dist/components/popover/main.js.map +1 -1
- package/dist/components/popover/props.d.ts +2 -2
- package/dist/components/popover/style.css +10 -1
- package/dist/components/progress/main.d.ts +1 -2
- package/dist/components/progress/main.d.ts.map +1 -1
- package/dist/components/progress/main.js +45 -19
- package/dist/components/progress/main.js.map +1 -1
- package/dist/components/progress/props.d.ts +22 -8
- package/dist/components/progress/props.d.ts.map +1 -1
- package/dist/components/progress/style.css +15 -15
- package/dist/components/roll/main.js +10 -10
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/roll/props.d.ts +1 -1
- package/dist/components/roll/style.css +11 -11
- package/dist/components/segmented/main.d.ts.map +1 -1
- package/dist/components/segmented/main.js +183 -31
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/props.d.ts +7 -0
- package/dist/components/segmented/props.d.ts.map +1 -1
- package/dist/components/segmented/style.css +148 -14
- package/dist/components/sheet/main.d.ts +6 -5
- package/dist/components/sheet/main.d.ts.map +1 -1
- package/dist/components/sheet/main.js +53 -27
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +29 -1
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/style.css +138 -33
- package/dist/components/sidebar/main.d.ts.map +1 -1
- package/dist/components/sidebar/main.js +9 -13
- package/dist/components/sidebar/main.js.map +1 -1
- package/dist/components/sidebar/style.css +8 -8
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +19 -19
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/props.d.ts +1 -2
- package/dist/components/slider/props.d.ts.map +1 -1
- package/dist/components/slider/style.css +25 -25
- package/dist/components/stepper/main.d.ts.map +1 -1
- package/dist/components/stepper/main.js +13 -15
- package/dist/components/stepper/main.js.map +1 -1
- package/dist/components/stepper/style.css +8 -8
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +25 -18
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/switch/props.d.ts +5 -3
- package/dist/components/switch/props.d.ts.map +1 -1
- package/dist/components/switch/style.css +13 -17
- package/dist/components/symbol/main.d.ts +1 -1
- package/dist/components/symbol/main.d.ts.map +1 -1
- package/dist/components/symbol/main.js +6 -5
- package/dist/components/symbol/main.js.map +1 -1
- package/dist/components/symbol/props.d.ts +3 -3
- package/dist/components/symbol/style.css +1 -1
- package/dist/components/tab-bar/main.d.ts +2 -2
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +78 -59
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +3 -3
- package/dist/components/tab-bar/style.css +92 -56
- package/dist/components/text-field/main.d.ts +3 -2
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +26 -28
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/props.d.ts +16 -1
- package/dist/components/text-field/props.d.ts.map +1 -1
- package/dist/components/text-field/style.css +105 -31
- package/dist/components/toolbar/main.d.ts.map +1 -1
- package/dist/components/toolbar/main.js +18 -20
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/props.d.ts +10 -4
- package/dist/components/toolbar/props.d.ts.map +1 -1
- package/dist/components/toolbar/style.css +13 -13
- package/dist/components/tooltip/main.js +4 -4
- package/dist/components/tooltip/main.js.map +1 -1
- package/dist/components/tooltip/style.css +5 -5
- package/dist/components/typography/main.d.ts +2 -2
- package/dist/components/typography/main.d.ts.map +1 -1
- package/dist/components/typography/main.js +10 -12
- package/dist/components/typography/main.js.map +1 -1
- package/dist/components/typography/props.d.ts +9 -9
- package/dist/components/typography/props.d.ts.map +1 -1
- package/dist/components/typography/style.css +503 -503
- package/dist/components/utils/main.d.ts +52 -6
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +163 -6
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/utils/props.d.ts +24 -3
- package/dist/components/utils/props.d.ts.map +1 -1
- package/dist/components/utils/style.css +4 -4
- package/dist/components/viewport/edge-effect.d.ts +10 -0
- package/dist/components/viewport/edge-effect.d.ts.map +1 -0
- package/dist/components/viewport/edge-effect.js +100 -0
- package/dist/components/viewport/edge-effect.js.map +1 -0
- package/dist/components/viewport/edge.d.ts +39 -0
- package/dist/components/viewport/edge.d.ts.map +1 -0
- package/dist/components/viewport/edge.js +151 -0
- package/dist/components/viewport/edge.js.map +1 -0
- package/dist/components/viewport/input.d.ts +19 -3
- package/dist/components/viewport/input.d.ts.map +1 -1
- package/dist/components/viewport/input.js +197 -12
- package/dist/components/viewport/input.js.map +1 -1
- package/dist/components/viewport/main.d.ts +10 -5
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +327 -90
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +31 -3
- package/dist/components/viewport/padding.d.ts.map +1 -1
- package/dist/components/viewport/padding.js +116 -17
- package/dist/components/viewport/padding.js.map +1 -1
- package/dist/components/viewport/props.d.ts +69 -8
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/style.css +230 -6
- package/dist/styles.css +285 -302
- package/package.json +4 -4
|
@@ -3,51 +3,47 @@ import '../glass/style.css';
|
|
|
3
3
|
import './style.css';
|
|
4
4
|
import { Menu as BaseMenu } from '@base-ui/react/menu';
|
|
5
5
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
6
|
-
import { cn, draggingAttribute, edgeScrollDelta, frameElapsed, MovingHighlight, positionerSide, useCollision, useForwardedRef, usePortalContainer, useSecondaryClick, } from '../utils/main.js';
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// `glass/main.tsx` (`glassMedium`).
|
|
6
|
+
import { Checkmark, cn, draggingAttribute, edgeScrollDelta, frameElapsed, MovingHighlight, positionerSide, useCollision, useForwardedRef, useGrowAvoidance, usePortalContainer, useSecondaryClick, } from '../utils/main.js';
|
|
7
|
+
// Menus (compact and regular): items, section titles, separators, quick
|
|
8
|
+
// actions and shortcuts, light and dark, with the destructive color mapped
|
|
9
|
+
// to `systemRed`; the “Medium” glass material and the vibrant content
|
|
10
|
+
// colors are tokens in `styles.css`, used via `glass/main.tsx`
|
|
11
|
+
// (`glassMedium`).
|
|
13
12
|
//
|
|
14
|
-
// Menus close when their anchor or popup leaves the viewport
|
|
15
|
-
// the
|
|
16
|
-
//
|
|
13
|
+
// Menus close when their anchor or popup leaves the viewport; popups taller
|
|
14
|
+
// than the space beside their trigger grow over it (see
|
|
15
|
+
// `useGrowAvoidance`), scrolling only taller than the screen (Framework7
|
|
16
|
+
// `popover.less`: `.popover-inner`).
|
|
17
17
|
//
|
|
18
18
|
// Symbols are in the Body (compact) and Subheadline (regular) text styles;
|
|
19
|
-
//
|
|
20
|
-
// differ from the text styles in line height or tracking
|
|
19
|
+
// labels, subtitles, section titles, shortcuts and quick action labels
|
|
20
|
+
// differ from the text styles in line height or tracking.
|
|
21
21
|
//
|
|
22
|
-
//
|
|
23
|
-
// - The root's `size` (
|
|
24
|
-
// (`compact`) and the
|
|
22
|
+
// Also:
|
|
23
|
+
// - The root's `size` (a size class) switches between the phone
|
|
24
|
+
// (`compact`) and the tablet (`regular`) menu, for all its popups:
|
|
25
25
|
// - `compact`: 40px items with 17px labels; submenus open over their
|
|
26
|
-
// trigger (which stays visible, its chevron turned down
|
|
27
|
-
//
|
|
28
|
-
// 8px from the popup's edge
|
|
29
|
-
// items).
|
|
26
|
+
// trigger (which stays visible, its chevron turned down; without room
|
|
27
|
+
// below it, covered), covering the items below it; a press outside one
|
|
28
|
+
// closes it alone. Items are inset 8px from the popup's edge.
|
|
30
29
|
// - `regular`: 36px items with 15px labels; submenus open beside their
|
|
31
30
|
// trigger, which shows the selection while open.
|
|
32
|
-
// - Popups are at least 238px wide
|
|
31
|
+
// - Popups are at least 238px wide.
|
|
33
32
|
// - A checkmark column is reserved in all items of a popup containing
|
|
34
|
-
// checkbox or radio items
|
|
33
|
+
// checkbox or radio items.
|
|
35
34
|
// - Highlighted items and quick actions (pointer, keyboard) show the
|
|
36
|
-
// selection
|
|
37
|
-
// - The popup's corners are concentric with the item selections (pills
|
|
38
|
-
//
|
|
39
|
-
// (
|
|
40
|
-
// quick actions 10px less (Figma: 20px).
|
|
35
|
+
// selection.
|
|
36
|
+
// - The popup's corners are concentric with the item selections (pills):
|
|
37
|
+
// the pill's radius plus the insets, 28px/30px (compact) and 26px/28px
|
|
38
|
+
// (regular) on the inline/block axes; quick actions 10px less.
|
|
41
39
|
// - While a compact submenu covers its parent, the parent's items but the
|
|
42
|
-
// trigger fade
|
|
43
|
-
//
|
|
44
|
-
// - Quick action symbols are 17px (compact) and 15px (regular)
|
|
45
|
-
//
|
|
46
|
-
// - The checkmark and chevrons are drawn as SVG strokes (Figma: SF Symbols
|
|
47
|
-
// glyphs , , ).
|
|
40
|
+
// trigger fade, and the submenu has no background of its own (it's on its
|
|
41
|
+
// parent's glass, whose background it would compound).
|
|
42
|
+
// - Quick action symbols are 17px (compact) and 15px (regular).
|
|
43
|
+
// - The checkmark and chevrons are drawn as SVG strokes.
|
|
48
44
|
// - The popup is Framework7's popover glass (background, backdrop blur and
|
|
49
|
-
// glass effect, see `glassMedium`),
|
|
50
|
-
//
|
|
45
|
+
// glass effect, see `glassMedium`), and scales in and out as a Framework7
|
|
46
|
+
// popover.
|
|
51
47
|
/** Shared by `Menu` and `EditMenu` (internal). */
|
|
52
48
|
export const MenuContext = createContext({
|
|
53
49
|
orientation: 'vertical',
|
|
@@ -61,28 +57,144 @@ export const useRootActions = (actionsRef) => {
|
|
|
61
57
|
const ownActionsRef = useRef(null);
|
|
62
58
|
return actionsRef ?? ownActionsRef;
|
|
63
59
|
};
|
|
60
|
+
/** Sets a (forwarded) ref, a callback or an object. */
|
|
61
|
+
const assignRef = (ref, value) => {
|
|
62
|
+
if (typeof ref === 'function')
|
|
63
|
+
ref(value);
|
|
64
|
+
else if (ref)
|
|
65
|
+
ref.current = value;
|
|
66
|
+
};
|
|
67
|
+
/** Whether `event` is `decided`'s press (itself, or its `mousedown`). */
|
|
68
|
+
const isSamePress = (decided, event) => decided === event ||
|
|
69
|
+
(decided.type === 'pointerdown' &&
|
|
70
|
+
event.type === 'mousedown' &&
|
|
71
|
+
decided.target === event.target);
|
|
72
|
+
export const createOpenSubmenus = (all = false) => {
|
|
73
|
+
let open = [];
|
|
74
|
+
let decided;
|
|
75
|
+
return {
|
|
76
|
+
add: (submenu) => {
|
|
77
|
+
open = [...open.filter(({ close }) => close !== submenu.close), submenu];
|
|
78
|
+
},
|
|
79
|
+
all,
|
|
80
|
+
closing: (event) => {
|
|
81
|
+
if (!decided || !isSamePress(decided.event, event)) {
|
|
82
|
+
const innermost = open.at(-1);
|
|
83
|
+
const { target } = event;
|
|
84
|
+
decided = {
|
|
85
|
+
event,
|
|
86
|
+
submenu: innermost && target instanceof Node && !innermost.contains(target)
|
|
87
|
+
? innermost
|
|
88
|
+
: undefined,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return decided.submenu;
|
|
92
|
+
},
|
|
93
|
+
innermost: () => open.at(-1),
|
|
94
|
+
remove: (close) => {
|
|
95
|
+
open = open.filter((submenu) => submenu.close !== close);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
/** The root's open submenus (internal; Menu's, EditMenu's). */
|
|
100
|
+
export const OpenSubmenusContext = createContext(undefined);
|
|
101
|
+
/** How long after a stopped press its following events are too (ms). */
|
|
102
|
+
const pressTail = 600;
|
|
103
|
+
/**
|
|
104
|
+
* An open submenu (see `OpenSubmenus`), a press outside it (on the menus
|
|
105
|
+
* it covers, the page, or a modal menu's backdrop) closes it alone, as the
|
|
106
|
+
* pointer is released, doing nothing else: the whole press stopped and its
|
|
107
|
+
* defaults prevented (e.g. a mouse's keeping the page's selection), at the
|
|
108
|
+
* window, capturing: before Base UI's own listeners, which close menus by
|
|
109
|
+
* pointer type, iOS' taps on a backdrop differently (it sends them no
|
|
110
|
+
* mouse events), and before the page's (internal, see `Root`).
|
|
111
|
+
*/
|
|
112
|
+
export const useSubmenuOutsidePress = (submenus) => {
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
// The press stopped (its pointer), and when it ended: its mouse events,
|
|
115
|
+
// touches and click follow (each browser in its order).
|
|
116
|
+
let pointerId;
|
|
117
|
+
let endedAt = Number.NEGATIVE_INFINITY;
|
|
118
|
+
const stop = (event) => {
|
|
119
|
+
if (event.cancelable)
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
event.stopPropagation();
|
|
122
|
+
};
|
|
123
|
+
const onPointerDown = (event) => {
|
|
124
|
+
const open = submenus.innermost();
|
|
125
|
+
const { target } = event;
|
|
126
|
+
pointerId =
|
|
127
|
+
open && target instanceof Node && !open.contains(target)
|
|
128
|
+
? event.pointerId
|
|
129
|
+
: undefined;
|
|
130
|
+
if (pointerId !== undefined)
|
|
131
|
+
stop(event);
|
|
132
|
+
};
|
|
133
|
+
const onPointerUp = (event) => {
|
|
134
|
+
if (event.pointerId !== pointerId)
|
|
135
|
+
return;
|
|
136
|
+
pointerId = undefined;
|
|
137
|
+
endedAt = event.timeStamp;
|
|
138
|
+
stop(event);
|
|
139
|
+
submenus.innermost()?.close();
|
|
140
|
+
};
|
|
141
|
+
const onPointerCancel = (event) => {
|
|
142
|
+
if (event.pointerId === pointerId)
|
|
143
|
+
pointerId = undefined;
|
|
144
|
+
};
|
|
145
|
+
const onFollowing = (event) => {
|
|
146
|
+
if (pointerId !== undefined || event.timeStamp - endedAt < pressTail) {
|
|
147
|
+
stop(event);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const listeners = [
|
|
151
|
+
['pointerdown', onPointerDown],
|
|
152
|
+
['pointerup', onPointerUp],
|
|
153
|
+
['pointercancel', onPointerCancel],
|
|
154
|
+
...['mousedown', 'mouseup', 'click', 'touchstart', 'touchend'].map((type) => [type, onFollowing]),
|
|
155
|
+
];
|
|
156
|
+
for (const [type, listener] of listeners) {
|
|
157
|
+
addEventListener(type, listener, { capture: true, passive: false });
|
|
158
|
+
}
|
|
159
|
+
return () => {
|
|
160
|
+
for (const [type, listener] of listeners) {
|
|
161
|
+
removeEventListener(type, listener, { capture: true });
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}, [submenus]);
|
|
165
|
+
};
|
|
64
166
|
/**
|
|
65
167
|
* A root menu's `onOpenChange`, not closing it for a press in one of its
|
|
66
168
|
* submenus (in portals): Base UI tells those from presses outside by React's
|
|
67
169
|
* event bubbling through portals, which Preact's portals lack, so it'd close
|
|
68
170
|
* the whole menu, e.g. as a submenu's checkbox item is toggled (internal;
|
|
69
|
-
* Menu's, EditMenu's).
|
|
171
|
+
* Menu's, EditMenu's). A compact submenu open, a press outside it (on its
|
|
172
|
+
* parent's items, or outside the menu) closes it alone (its trigger's own,
|
|
173
|
+
* see `useSubmenuToggle`).
|
|
70
174
|
*/
|
|
71
|
-
export const useKeepOpenInSubmenus = (onOpenChange) => useCallback((isOpen, details) => {
|
|
175
|
+
export const useKeepOpenInSubmenus = (onOpenChange, submenus) => useCallback((isOpen, details) => {
|
|
72
176
|
const { event, reason } = details;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
177
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
178
|
+
if (!isOpen && reason === 'outside-press' && target) {
|
|
179
|
+
const closing = submenus?.closing(event);
|
|
180
|
+
if (closing) {
|
|
181
|
+
details.cancel();
|
|
182
|
+
closing.close();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (target.closest('[role="menu"]') !== null) {
|
|
186
|
+
details.cancel();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
79
189
|
}
|
|
80
190
|
onOpenChange?.(isOpen, details);
|
|
81
|
-
}, [onOpenChange]);
|
|
191
|
+
}, [submenus, onOpenChange]);
|
|
82
192
|
const Root = ({ onOpenChange, size = 'compact', ...props }) => {
|
|
83
193
|
const actionsRef = useRootActions(props.actionsRef);
|
|
84
|
-
const
|
|
85
|
-
|
|
194
|
+
const [submenus] = useState(() => createOpenSubmenus());
|
|
195
|
+
useSubmenuOutsidePress(submenus);
|
|
196
|
+
const onRootOpenChange = useKeepOpenInSubmenus(onOpenChange, submenus);
|
|
197
|
+
return (_jsx(MenuContext.Provider, { value: { actionsRef, orientation: 'vertical', size }, children: _jsx(OpenSubmenusContext.Provider, { value: submenus, children: _jsx(BaseMenu.Root, { ...props, actionsRef: actionsRef, onOpenChange: onRootOpenChange }) }) }));
|
|
86
198
|
};
|
|
87
199
|
// A click this soon (ms) after hovering opened a submenu means to open it
|
|
88
200
|
// (it was on its way), not to close it.
|
|
@@ -90,17 +202,28 @@ const hoverConfirm = 400;
|
|
|
90
202
|
const SubmenuToggleContext = createContext(undefined);
|
|
91
203
|
const SubmenuRoot = ({ actionsRef: actionsRefProp, onOpenChange, ...props }) => {
|
|
92
204
|
const { actionsRef, orientation, size } = useContext(MenuContext);
|
|
205
|
+
const submenus = useContext(OpenSubmenusContext);
|
|
93
206
|
const submenuActionsRef = useRootActions(actionsRefProp);
|
|
94
207
|
// When hovering opened it (ms, the event's time base), if it did.
|
|
95
208
|
const hoveredOpen = useRef(undefined);
|
|
96
209
|
const pressed = useRef(undefined);
|
|
210
|
+
const popupRef = useRef(null);
|
|
211
|
+
const triggerRef = useRef(null);
|
|
97
212
|
const toggle = useMemo(() => ({
|
|
98
213
|
close: () => submenuActionsRef.current?.close(),
|
|
214
|
+
contains: (target) => (popupRef.current?.contains(target) ?? false) ||
|
|
215
|
+
(triggerRef.current?.contains(target) ?? false),
|
|
99
216
|
isJustHovered: () => hoveredOpen.current !== undefined &&
|
|
100
217
|
performance.now() - hoveredOpen.current < hoverConfirm,
|
|
101
218
|
press: (press) => {
|
|
102
219
|
pressed.current = press;
|
|
103
220
|
},
|
|
221
|
+
setPopup: (popup) => {
|
|
222
|
+
popupRef.current = popup;
|
|
223
|
+
},
|
|
224
|
+
setTrigger: (trigger) => {
|
|
225
|
+
triggerRef.current = trigger;
|
|
226
|
+
},
|
|
104
227
|
takePress: () => {
|
|
105
228
|
const press = pressed.current;
|
|
106
229
|
pressed.current = undefined;
|
|
@@ -118,6 +241,29 @@ const SubmenuRoot = ({ actionsRef: actionsRefProp, onOpenChange, ...props }) =>
|
|
|
118
241
|
isOpen && details.reason === 'trigger-hover'
|
|
119
242
|
? performance.now()
|
|
120
243
|
: undefined;
|
|
244
|
+
// Open, the innermost (see `OpenSubmenus`): compact ones
|
|
245
|
+
// (covering their parent), or all (an edit menu's); a press
|
|
246
|
+
// outside closes the innermost alone.
|
|
247
|
+
const isCompact = size === 'compact' && orientation === 'vertical';
|
|
248
|
+
const isTracked = submenus && (submenus.all || isCompact);
|
|
249
|
+
if (isTracked &&
|
|
250
|
+
!isOpen &&
|
|
251
|
+
details.reason === 'outside-press' &&
|
|
252
|
+
submenus.closing(details.event)?.close !== toggle.close) {
|
|
253
|
+
details.cancel();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (isTracked) {
|
|
257
|
+
if (isOpen) {
|
|
258
|
+
submenus.add({
|
|
259
|
+
close: toggle.close,
|
|
260
|
+
contains: toggle.contains,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
submenus.remove(toggle.close);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
121
267
|
onOpenChange?.(isOpen, details);
|
|
122
268
|
} }) }) }));
|
|
123
269
|
};
|
|
@@ -172,6 +318,159 @@ const menuAt = (x, y) => document
|
|
|
172
318
|
.map((element) => element.closest('[role="menu"]'))
|
|
173
319
|
.find(Boolean);
|
|
174
320
|
const pixels = (value) => Number.parseFloat(value) || 0;
|
|
321
|
+
// How far (px) a finger moves before it's dragging (see `dragOverItems`).
|
|
322
|
+
const dragSlop = 10;
|
|
323
|
+
// Panning a scroller (see `dragOverItems`' `pan`): how soon (ms) and how far
|
|
324
|
+
// (px) a finger moves to pan instead of dragging over its items (as the
|
|
325
|
+
// segmented control's lens and scroll; see `Segmented`), how fast a fling
|
|
326
|
+
// slows (per ms, as UIKit's normal deceleration), and how recent (ms) the
|
|
327
|
+
// moves its speed is taken from.
|
|
328
|
+
const panDelay = 120;
|
|
329
|
+
const panSlop = 8;
|
|
330
|
+
const flingDecay = 0.998;
|
|
331
|
+
const flingWindow = 100;
|
|
332
|
+
// Marks a scroller scrolled by a drag (panned, flung, or near its ends):
|
|
333
|
+
// not snapped (back) each frame, until settled (see `settle`).
|
|
334
|
+
const unsnappedAttribute = 'data-unsnapped';
|
|
335
|
+
// Scrollers settling, their frames (a touch stops them, see
|
|
336
|
+
// `dragOverItems`).
|
|
337
|
+
const settling = new Map();
|
|
338
|
+
// How long (ms) a scroller settles (see `settle`): at most, at least, and
|
|
339
|
+
// unflung; and how much of a scroll padding (its peek) a hint shows at least.
|
|
340
|
+
const settleLongest = 900;
|
|
341
|
+
const settleShortest = 200;
|
|
342
|
+
const settleUnflung = 300;
|
|
343
|
+
const hintShare = 0.75;
|
|
344
|
+
/**
|
|
345
|
+
* Where a sideways scroller rests nearest to `natural` (a `scrollLeft`): its
|
|
346
|
+
* snap positions (its children's starts, beside its scroll padding; its
|
|
347
|
+
* ends), those hinting at the items beyond its ends first (a peek of them,
|
|
348
|
+
* most of its scroll padding wide); as a `scrollLeft`.
|
|
349
|
+
*/
|
|
350
|
+
const restingPosition = (scroller, natural) => {
|
|
351
|
+
const style = getComputedStyle(scroller);
|
|
352
|
+
const isRtl = style.direction === 'rtl';
|
|
353
|
+
const sign = isRtl ? -1 : 1;
|
|
354
|
+
const shown = scroller.getBoundingClientRect();
|
|
355
|
+
const width = scroller.clientWidth;
|
|
356
|
+
const max = scroller.scrollWidth - width;
|
|
357
|
+
// (Logical: from its start, RTL too.)
|
|
358
|
+
const scrolled = Math.abs(scroller.scrollLeft);
|
|
359
|
+
const left = pixels(style.scrollPaddingLeft);
|
|
360
|
+
const right = pixels(style.scrollPaddingRight);
|
|
361
|
+
const [paddingStart, paddingEnd] = isRtl ? [right, left] : [left, right];
|
|
362
|
+
const items = [...scroller.children]
|
|
363
|
+
.filter((child) => getComputedStyle(child).scrollSnapAlign === 'start')
|
|
364
|
+
.map((child) => {
|
|
365
|
+
const rect = child.getBoundingClientRect();
|
|
366
|
+
const start = scrolled + (isRtl ? shown.right - rect.right : rect.left - shown.left);
|
|
367
|
+
return { end: start + rect.width, start };
|
|
368
|
+
});
|
|
369
|
+
const clamp = (at) => Math.min(max, Math.max(0, at));
|
|
370
|
+
if (items.length === 0)
|
|
371
|
+
return sign * clamp(sign * natural);
|
|
372
|
+
// How much of the item across an edge shows (none across it: none).
|
|
373
|
+
const crossing = (edge) => items.find((item) => item.start < edge && item.end > edge);
|
|
374
|
+
const isHinting = (at) => {
|
|
375
|
+
const before = crossing(at);
|
|
376
|
+
const after = crossing(at + width);
|
|
377
|
+
return ((at < 0.5 ||
|
|
378
|
+
(before !== undefined &&
|
|
379
|
+
before.end - at >= paddingStart * hintShare)) &&
|
|
380
|
+
(at > max - 0.5 ||
|
|
381
|
+
(after !== undefined &&
|
|
382
|
+
at + width - after.start >= paddingEnd * hintShare)));
|
|
383
|
+
};
|
|
384
|
+
// (Its ends always: as far as it goes.)
|
|
385
|
+
const snaps = [
|
|
386
|
+
0,
|
|
387
|
+
max,
|
|
388
|
+
...items.map(({ start }) => start - paddingStart),
|
|
389
|
+
].filter((at) => at >= 0 && at <= max);
|
|
390
|
+
const hinting = snaps.filter((at) => at < 0.5 || at > max - 0.5 || isHinting(at));
|
|
391
|
+
const target = clamp(sign * natural);
|
|
392
|
+
let nearest;
|
|
393
|
+
for (const at of hinting.length > 0 ? hinting : snaps) {
|
|
394
|
+
if (nearest === undefined ||
|
|
395
|
+
Math.abs(at - target) < Math.abs(nearest - target)) {
|
|
396
|
+
nearest = at;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return sign * (nearest ?? target);
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Scrolls a sideways scroller on (`velocity`, px per ms, as its
|
|
403
|
+
* `scrollLeft`), to rest where it'd stop flung (see `restingPosition`),
|
|
404
|
+
* easing out from that speed (within `settleShortest` and `settleLongest`);
|
|
405
|
+
* then it snaps again.
|
|
406
|
+
*/
|
|
407
|
+
const settle = (scroller, velocity = 0) => {
|
|
408
|
+
const from = scroller.scrollLeft;
|
|
409
|
+
const rate = -Math.log(flingDecay);
|
|
410
|
+
const distance = restingPosition(scroller, from + velocity / rate) - from;
|
|
411
|
+
// (An ease-out cubic starts at three times its average speed.)
|
|
412
|
+
const isFlung = velocity !== 0 && Math.sign(velocity) === Math.sign(distance);
|
|
413
|
+
const duration = isFlung
|
|
414
|
+
? Math.min(settleLongest, Math.max(settleShortest, (3 * Math.abs(distance)) / Math.abs(velocity)))
|
|
415
|
+
: settleUnflung;
|
|
416
|
+
let startedAt;
|
|
417
|
+
const step = (time) => {
|
|
418
|
+
startedAt ??= time;
|
|
419
|
+
const progress = Math.min(1, (time - startedAt) / duration);
|
|
420
|
+
scroller.scrollLeft = from + distance * (1 - (1 - progress) ** 3);
|
|
421
|
+
if (progress < 1) {
|
|
422
|
+
settling.set(scroller, requestAnimationFrame(step));
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
settling.delete(scroller);
|
|
426
|
+
scroller.removeAttribute(unsnappedAttribute);
|
|
427
|
+
};
|
|
428
|
+
scroller.setAttribute(unsnappedAttribute, '');
|
|
429
|
+
settling.set(scroller, requestAnimationFrame(step));
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* A touch in a sideways scroller, from `start`: moving sideways first (past
|
|
433
|
+
* `panSlop`, within `panDelay`), it pans it (`track`: `start` as it begins,
|
|
434
|
+
* `pan` after), unless held or moved otherwise first (`undefined`). Its
|
|
435
|
+
* speed (px per ms, as its `scrollLeft`), from its recent moves.
|
|
436
|
+
*/
|
|
437
|
+
const createPan = (scroller, start) => {
|
|
438
|
+
const startedAt = performance.now();
|
|
439
|
+
let isPannable = true;
|
|
440
|
+
let from;
|
|
441
|
+
let moves = [];
|
|
442
|
+
const track = (x, y, time) => {
|
|
443
|
+
if (from) {
|
|
444
|
+
scroller.scrollLeft = from.scrollLeft - (x - from.x);
|
|
445
|
+
moves = [...moves, { time, x }];
|
|
446
|
+
return 'pan';
|
|
447
|
+
}
|
|
448
|
+
if (!isPannable)
|
|
449
|
+
return undefined;
|
|
450
|
+
if (time - startedAt > panDelay) {
|
|
451
|
+
isPannable = false;
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
if (Math.hypot(x - start.x, y - start.y) <= panSlop)
|
|
455
|
+
return undefined;
|
|
456
|
+
isPannable = false;
|
|
457
|
+
if (Math.abs(x - start.x) < Math.abs(y - start.y))
|
|
458
|
+
return undefined;
|
|
459
|
+
scroller.setAttribute(unsnappedAttribute, '');
|
|
460
|
+
from = { scrollLeft: scroller.scrollLeft, x };
|
|
461
|
+
moves = [{ time, x }];
|
|
462
|
+
return 'start';
|
|
463
|
+
};
|
|
464
|
+
const velocity = (time) => {
|
|
465
|
+
const recent = moves.filter((move) => time - move.time <= flingWindow);
|
|
466
|
+
const [first] = recent;
|
|
467
|
+
const last = recent.at(-1);
|
|
468
|
+
return first && last && last.time > first.time
|
|
469
|
+
? -(last.x - first.x) / (last.time - first.time)
|
|
470
|
+
: 0;
|
|
471
|
+
};
|
|
472
|
+
return { isPanning: () => from !== undefined, track, velocity };
|
|
473
|
+
};
|
|
175
474
|
// Keeps a touch from scrolling (dragging over menus).
|
|
176
475
|
const keepScroll = (event) => {
|
|
177
476
|
if (event.cancelable)
|
|
@@ -188,21 +487,50 @@ const keepTrustedMouse = (event) => {
|
|
|
188
487
|
event.preventDefault();
|
|
189
488
|
event.stopPropagation();
|
|
190
489
|
};
|
|
490
|
+
/**
|
|
491
|
+
* How long (ms) a finger rests on a submenu's item before it opens (see
|
|
492
|
+
* `dragOverItems`): longer than Base UI's hover delay, so a submenu that
|
|
493
|
+
* opens on hover (regular) has by then.
|
|
494
|
+
*/
|
|
495
|
+
const submenuDwell = 300;
|
|
496
|
+
/** A press's click (see `dragOverItems`). */
|
|
497
|
+
const pressClick = (item) => {
|
|
498
|
+
// (Not `click()`'s: Base UI takes a click without a click count for a
|
|
499
|
+
// screen reader's, highlighting a submenu's first item as it opens.)
|
|
500
|
+
item.dispatchEvent(new MouseEvent('click', {
|
|
501
|
+
bubbles: true,
|
|
502
|
+
cancelable: true,
|
|
503
|
+
composed: true,
|
|
504
|
+
detail: 1,
|
|
505
|
+
view: item.ownerDocument.defaultView,
|
|
506
|
+
}));
|
|
507
|
+
};
|
|
191
508
|
/** A menu's element scrolling its items (itself, unless it marks one). */
|
|
192
509
|
const scrollerOf = (menu) => menu.querySelector('[data-menu-part=scroller]') ?? menu;
|
|
193
510
|
/**
|
|
194
511
|
* Drags a touch (`pointerId`) over menus' items, from `start` (if given, it
|
|
195
512
|
* hovers the item there right away): the finger hovers the items as a mouse
|
|
196
513
|
* would (see `hover`), so only the item under it is highlighted, and resting
|
|
197
|
-
* on a submenu's item opens the submenu
|
|
514
|
+
* on a submenu's item opens the submenu (by hover, or else pressed after
|
|
515
|
+
* `submenuDwell`), to drag on into; released, the item
|
|
198
516
|
* there is clicked. Held near an end of a menu that scrolls (either way), the
|
|
199
517
|
* finger scrolls it (as the tab bar's lens does). The touch's own clicks are
|
|
200
|
-
* kept from the items (internal; Menu's trigger, EditMenu).
|
|
518
|
+
* kept from the items (internal; Menu's trigger, EditMenu). Released outside
|
|
519
|
+
* every menu after dragging (moved past `dragSlop`, or over a menu), it calls
|
|
520
|
+
* `onReleaseOutside` (e.g. closing the menu, as Base UI does for a mouse
|
|
521
|
+
* pressed on the trigger and released elsewhere). Begun in `pan` (a
|
|
522
|
+
* scroller, sideways, overflowing; e.g. EditMenu's actions), a finger moving
|
|
523
|
+
* sideways first (past `panSlop`, within `panDelay`) pans it instead,
|
|
524
|
+
* flung on release, nothing chosen (its touches don't scroll natively, see
|
|
525
|
+
* EditMenu).
|
|
201
526
|
*/
|
|
202
|
-
export const dragOverItems = (document, pointerId, start) => {
|
|
527
|
+
export const dragOverItems = (document, pointerId, start, onReleaseOutside, pan) => {
|
|
203
528
|
let item;
|
|
204
529
|
// The open submenu's item the touch began on, if any (see below).
|
|
205
530
|
let openAtStart;
|
|
531
|
+
// Resting on a submenu's item that hover doesn't open (compact): opening
|
|
532
|
+
// it (see `submenuDwell`).
|
|
533
|
+
let dwell;
|
|
206
534
|
let isFirst = true;
|
|
207
535
|
const types = ['pointermove', 'pointerup', 'pointercancel'];
|
|
208
536
|
// The touch's boundary events, kept from Base UI as its moves are.
|
|
@@ -213,8 +541,21 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
213
541
|
'pointerleave',
|
|
214
542
|
];
|
|
215
543
|
let finger;
|
|
544
|
+
// Where the finger first moved, and whether it has dragged since.
|
|
545
|
+
let origin;
|
|
546
|
+
let hasDragged = false;
|
|
216
547
|
// The menu the finger was last over, which it scrolls beyond its ends.
|
|
217
548
|
let menu;
|
|
549
|
+
// Panning `pan` (see `createPan`), and the scrollers the drag scrolled
|
|
550
|
+
// sideways (each settled as it ends; those settling stopped, too).
|
|
551
|
+
const panning = start && pan && pan.scrollWidth > pan.clientWidth
|
|
552
|
+
? createPan(pan, start)
|
|
553
|
+
: undefined;
|
|
554
|
+
const scrolled = new Set(settling.keys());
|
|
555
|
+
for (const [scroller, frame] of settling) {
|
|
556
|
+
cancelAnimationFrame(frame);
|
|
557
|
+
settling.delete(scroller);
|
|
558
|
+
}
|
|
218
559
|
document.documentElement.setAttribute(draggingAttribute, '');
|
|
219
560
|
// No scrolling while dragging (e.g. from a trigger held: see `Trigger`).
|
|
220
561
|
document.addEventListener('touchmove', keepScroll, {
|
|
@@ -225,6 +566,10 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
225
566
|
if (!finger)
|
|
226
567
|
return;
|
|
227
568
|
menu = menuAt(finger.x, finger.y) ?? menu;
|
|
569
|
+
origin ??= { x: finger.x, y: finger.y };
|
|
570
|
+
hasDragged ||=
|
|
571
|
+
menu !== undefined ||
|
|
572
|
+
Math.hypot(finger.x - origin.x, finger.y - origin.y) > dragSlop;
|
|
228
573
|
const next = menuItemAt(finger.x, finger.y);
|
|
229
574
|
if (isFirst) {
|
|
230
575
|
isFirst = false;
|
|
@@ -240,22 +585,43 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
240
585
|
hover(item, false, finger);
|
|
241
586
|
}
|
|
242
587
|
item = next;
|
|
243
|
-
|
|
244
|
-
|
|
588
|
+
clearTimeout(dwell);
|
|
589
|
+
if (!item)
|
|
590
|
+
return;
|
|
591
|
+
hover(item, true, finger);
|
|
592
|
+
if (isSubmenuTrigger(item) && !isExpanded(item)) {
|
|
593
|
+
const rested = item;
|
|
594
|
+
dwell = setTimeout(() => {
|
|
595
|
+
if (rested === item && !isExpanded(rested))
|
|
596
|
+
pressClick(rested);
|
|
597
|
+
}, submenuDwell);
|
|
598
|
+
}
|
|
245
599
|
};
|
|
246
600
|
const elapsedOf = frameElapsed();
|
|
247
601
|
let frame = requestAnimationFrame(function scroll(time) {
|
|
248
602
|
frame = requestAnimationFrame(scroll);
|
|
249
603
|
const elapsed = elapsedOf(time);
|
|
250
|
-
if (!finger || !menu?.isConnected)
|
|
604
|
+
if (!finger || panning?.isPanning() || !menu?.isConnected)
|
|
251
605
|
return;
|
|
252
|
-
// Its ends are inside its scroll padding (e.g. EditMenu's
|
|
606
|
+
// Its ends are inside its scroll padding (e.g. EditMenu's peeks: held
|
|
607
|
+
// over the actions peeking beyond them).
|
|
253
608
|
const scroller = scrollerOf(menu);
|
|
254
609
|
const { bottom, left, right, top } = scroller.getBoundingClientRect();
|
|
255
610
|
const style = getComputedStyle(scroller);
|
|
256
611
|
const { scrollLeft, scrollTop } = scroller;
|
|
257
612
|
if (scroller.scrollWidth > scroller.clientWidth) {
|
|
258
|
-
|
|
613
|
+
const delta = edgeScrollDelta(finger.x, left + pixels(style.scrollPaddingLeft), right - pixels(style.scrollPaddingRight), elapsed);
|
|
614
|
+
if (delta !== 0) {
|
|
615
|
+
const before = scroller.scrollLeft;
|
|
616
|
+
scroller.setAttribute(unsnappedAttribute, '');
|
|
617
|
+
scroller.scrollLeft += delta;
|
|
618
|
+
// (Already at that end: not scrolled, nothing to settle.)
|
|
619
|
+
if (scroller.scrollLeft !== before)
|
|
620
|
+
scrolled.add(scroller);
|
|
621
|
+
else if (!scrolled.has(scroller)) {
|
|
622
|
+
scroller.removeAttribute(unsnappedAttribute);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
259
625
|
}
|
|
260
626
|
if (scroller.scrollHeight > scroller.clientHeight) {
|
|
261
627
|
scroller.scrollTop += edgeScrollDelta(finger.y, top + pixels(style.scrollPaddingTop), bottom - pixels(style.scrollPaddingBottom), elapsed);
|
|
@@ -266,6 +632,42 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
266
632
|
update();
|
|
267
633
|
}
|
|
268
634
|
});
|
|
635
|
+
// Released: the item there clicked; dragged out of the menus and released
|
|
636
|
+
// there, nothing chosen.
|
|
637
|
+
const release = ({ clientX: x, clientY: y }) => {
|
|
638
|
+
if (panning?.isPanning())
|
|
639
|
+
return;
|
|
640
|
+
if (!item) {
|
|
641
|
+
if (hasDragged && !menuAt(x, y))
|
|
642
|
+
onReleaseOutside?.(x, y);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
// An open submenu stays open (clicking its item would close it), unless
|
|
646
|
+
// it was already open as the touch began on its item: pressed again, it
|
|
647
|
+
// closes (see `SubmenuTrigger`).
|
|
648
|
+
if (!isSubmenuTrigger(item) || !isExpanded(item) || item === openAtStart) {
|
|
649
|
+
pressClick(item);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
// Panning (see `createPan`): its items no longer hovered.
|
|
653
|
+
const panTo = (x, y, time) => {
|
|
654
|
+
const panned = panning?.track(x, y, time);
|
|
655
|
+
if (panned === 'start') {
|
|
656
|
+
clearTimeout(dwell);
|
|
657
|
+
if (item && finger)
|
|
658
|
+
hover(item, false, finger);
|
|
659
|
+
item = undefined;
|
|
660
|
+
}
|
|
661
|
+
return panned !== undefined;
|
|
662
|
+
};
|
|
663
|
+
// The scrollers it scrolled come to rest, snapping again (panned: flung).
|
|
664
|
+
const rest = (time) => {
|
|
665
|
+
if (pan && panning?.isPanning())
|
|
666
|
+
scrolled.add(pan);
|
|
667
|
+
for (const scroller of scrolled) {
|
|
668
|
+
settle(scroller, scroller === pan ? panning?.velocity(time) : 0);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
269
671
|
const listener = (pointerEvent) => {
|
|
270
672
|
// Not the drag's own (synthetic) hovering.
|
|
271
673
|
if (!pointerEvent.isTrusted)
|
|
@@ -281,6 +683,8 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
281
683
|
return;
|
|
282
684
|
const x = pointerEvent.clientX;
|
|
283
685
|
const y = pointerEvent.clientY;
|
|
686
|
+
if (panTo(x, y, pointerEvent.timeStamp))
|
|
687
|
+
return;
|
|
284
688
|
finger = {
|
|
285
689
|
// At least a pixel, also when only scrolling moves the items.
|
|
286
690
|
movementX: x - (finger?.x ?? x) || 1,
|
|
@@ -292,11 +696,13 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
292
696
|
return;
|
|
293
697
|
}
|
|
294
698
|
cancelAnimationFrame(frame);
|
|
699
|
+
clearTimeout(dwell);
|
|
295
700
|
for (const type of [...types, ...boundaryTypes]) {
|
|
296
701
|
document.removeEventListener(type, listener, { capture: true });
|
|
297
702
|
}
|
|
298
703
|
document.documentElement.removeAttribute(draggingAttribute);
|
|
299
704
|
document.removeEventListener('touchmove', keepScroll, { capture: true });
|
|
705
|
+
rest(pointerEvent.timeStamp);
|
|
300
706
|
if (pointerEvent.type !== 'pointerup')
|
|
301
707
|
return;
|
|
302
708
|
// The touch's own click (on the element touched, if released there) is
|
|
@@ -311,13 +717,7 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
311
717
|
});
|
|
312
718
|
}
|
|
313
719
|
}, 500);
|
|
314
|
-
|
|
315
|
-
// it was already open as the touch began on its item: pressed again, it
|
|
316
|
-
// closes (see `SubmenuTrigger`).
|
|
317
|
-
if (item &&
|
|
318
|
-
(!isSubmenuTrigger(item) || !isExpanded(item) || item === openAtStart)) {
|
|
319
|
-
item.click();
|
|
320
|
-
}
|
|
720
|
+
release(pointerEvent);
|
|
321
721
|
};
|
|
322
722
|
for (const type of [...types, ...boundaryTypes]) {
|
|
323
723
|
document.addEventListener(type, listener, { capture: true });
|
|
@@ -327,20 +727,29 @@ export const dragOverItems = (document, pointerId, start) => {
|
|
|
327
727
|
update();
|
|
328
728
|
}
|
|
329
729
|
};
|
|
730
|
+
/**
|
|
731
|
+
* Presses a menu's trigger as a mouse does (Base UI opens, or closes, its
|
|
732
|
+
* menu on a mouse down).
|
|
733
|
+
*/
|
|
734
|
+
const pressTrigger = (trigger) => {
|
|
735
|
+
trigger.dispatchEvent(new MouseEvent('mousedown', {
|
|
736
|
+
bubbles: true,
|
|
737
|
+
button: 0,
|
|
738
|
+
cancelable: true,
|
|
739
|
+
// (A press, not a screen reader's: Base UI takes a mouse down
|
|
740
|
+
// without a click count for one, highlighting the first item.)
|
|
741
|
+
detail: 1,
|
|
742
|
+
view: trigger.ownerDocument.defaultView,
|
|
743
|
+
}));
|
|
744
|
+
};
|
|
330
745
|
/**
|
|
331
746
|
* Opens a menu by its trigger (`trigger`) as Base UI does on a mouse down;
|
|
332
747
|
* a touch (`pointerId`) then drags over its items (see `dragOverItems`).
|
|
333
748
|
*/
|
|
334
749
|
const openByTrigger = (trigger, pointerId) => {
|
|
335
750
|
const document = trigger.ownerDocument;
|
|
336
|
-
if (trigger.getAttribute('aria-expanded') !== 'true')
|
|
337
|
-
trigger
|
|
338
|
-
bubbles: true,
|
|
339
|
-
button: 0,
|
|
340
|
-
cancelable: true,
|
|
341
|
-
view: document.defaultView,
|
|
342
|
-
}));
|
|
343
|
-
}
|
|
751
|
+
if (trigger.getAttribute('aria-expanded') !== 'true')
|
|
752
|
+
pressTrigger(trigger);
|
|
344
753
|
if (pointerId === undefined)
|
|
345
754
|
return;
|
|
346
755
|
// Touch captures the pointer to the trigger; the menu's items are
|
|
@@ -348,13 +757,18 @@ const openByTrigger = (trigger, pointerId) => {
|
|
|
348
757
|
if (trigger.hasPointerCapture(pointerId)) {
|
|
349
758
|
trigger.releasePointerCapture(pointerId);
|
|
350
759
|
}
|
|
351
|
-
|
|
760
|
+
// Dragged out and released elsewhere (also back on the trigger): closed,
|
|
761
|
+
// as Base UI closes it for a mouse.
|
|
762
|
+
dragOverItems(document, pointerId, undefined, () => {
|
|
763
|
+
if (trigger.getAttribute('aria-expanded') === 'true')
|
|
764
|
+
pressTrigger(trigger);
|
|
765
|
+
});
|
|
352
766
|
};
|
|
353
767
|
/** Opening by a secondary click: the trigger's own mouse down (internal). */
|
|
354
768
|
let isOpeningBySecondaryClick = false;
|
|
355
769
|
/**
|
|
356
770
|
* Opens the menu as Base UI's trigger does, but on touch already on touch
|
|
357
|
-
* down
|
|
771
|
+
* down; dragging on, the item under the finger is highlighted
|
|
358
772
|
* and chosen where it's released, as Base UI does for the mouse (pressing
|
|
359
773
|
* the trigger, releasing on an item): the finger hovers the items as a
|
|
360
774
|
* mouse would, so only the item under it is highlighted, and resting on a
|
|
@@ -363,6 +777,10 @@ let isOpeningBySecondaryClick = false;
|
|
|
363
777
|
*/
|
|
364
778
|
const Trigger = forwardRef(({ onClick, onMouseDown, openOn, ...props }, ref) => {
|
|
365
779
|
const isSecondary = openOn === 'secondaryClick';
|
|
780
|
+
// Pressed by a touch (opened or closed on its touch down, see below):
|
|
781
|
+
// its emulated mouse down and click aren't Base UI's (which would open
|
|
782
|
+
// the menu again; iOS emulates them after a tap, not after a drag).
|
|
783
|
+
const isTouchPress = useRef(false);
|
|
366
784
|
// A secondary click (or a handler for it) opens the menu.
|
|
367
785
|
const triggerProps = useSecondaryClick({
|
|
368
786
|
...props,
|
|
@@ -396,32 +814,49 @@ const Trigger = forwardRef(({ onClick, onMouseDown, openOn, ...props }, ref) =>
|
|
|
396
814
|
// a click by keys).
|
|
397
815
|
onClick: (event) => {
|
|
398
816
|
onClick?.(event);
|
|
399
|
-
if (isSecondary)
|
|
817
|
+
if (isSecondary || isTouchPress.current)
|
|
400
818
|
event.preventBaseUIHandler();
|
|
819
|
+
isTouchPress.current = false;
|
|
401
820
|
}, onMouseDown: (event) => {
|
|
402
821
|
onMouseDown?.(event);
|
|
403
|
-
if (isSecondary && !isOpeningBySecondaryClick)
|
|
822
|
+
if ((isSecondary && !isOpeningBySecondaryClick) ||
|
|
823
|
+
(isTouchPress.current && event.isTrusted)) {
|
|
404
824
|
event.preventBaseUIHandler();
|
|
405
825
|
}
|
|
406
826
|
}, onPointerDown: (event) => {
|
|
407
827
|
// Its own, and the secondary click's.
|
|
408
828
|
triggerProps
|
|
409
829
|
.onPointerDown?.(event);
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
830
|
+
isTouchPress.current = false;
|
|
831
|
+
if (event.pointerType !== 'touch')
|
|
832
|
+
return;
|
|
833
|
+
// (Not Base UI's own: iOS' touches have no size, which it takes
|
|
834
|
+
// for a screen reader's, highlighting the first item.)
|
|
835
|
+
event.preventBaseUIHandler();
|
|
836
|
+
if (isSecondary || event.defaultPrevented)
|
|
413
837
|
return;
|
|
414
|
-
}
|
|
415
838
|
// No emulated mouse events after the touch: Base UI opens and
|
|
416
|
-
// closes a menu on mouse down. Opens on touch down,
|
|
839
|
+
// closes a menu on mouse down. Opens on touch down; open, closes
|
|
840
|
+
// (as Base UI's mouse down does).
|
|
417
841
|
event.preventDefault();
|
|
842
|
+
isTouchPress.current = true;
|
|
843
|
+
if (event.currentTarget.getAttribute('aria-expanded') === 'true') {
|
|
844
|
+
pressTrigger(event.currentTarget);
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
418
847
|
openByTrigger(event.currentTarget, event.pointerId);
|
|
848
|
+
}, onPointerEnter: (event) => {
|
|
849
|
+
triggerProps
|
|
850
|
+
.onPointerEnter?.(event);
|
|
851
|
+
// (Not Base UI's own on touch, see below.)
|
|
852
|
+
if (event.pointerType === 'touch')
|
|
853
|
+
event.preventBaseUIHandler();
|
|
419
854
|
} }));
|
|
420
855
|
});
|
|
421
856
|
/**
|
|
422
857
|
* Closes the root menu when an open positioner's anchor (Base UI:
|
|
423
858
|
* `data-anchor-hidden`) or the positioner itself leaves the viewport, as
|
|
424
|
-
*
|
|
859
|
+
* Menus close when their source view scrolls away (internal).
|
|
425
860
|
*/
|
|
426
861
|
export const useCloseOutOfView = (positionerRef) => {
|
|
427
862
|
const { actionsRef } = useContext(MenuContext);
|
|
@@ -469,8 +904,8 @@ const Positioner = forwardRef(({ className, collisionBoundary, collisionPadding,
|
|
|
469
904
|
sideOffset: 12,
|
|
470
905
|
};
|
|
471
906
|
}
|
|
472
|
-
// (Over its parent's items, below its trigger
|
|
473
|
-
//
|
|
907
|
+
// (Over its parent's items, below its trigger: not flipped above it;
|
|
908
|
+
// without room, shifted up over it, see `useGrowAvoidance`.)
|
|
474
909
|
if (submenu && size === 'compact') {
|
|
475
910
|
return {
|
|
476
911
|
align: 'start',
|
|
@@ -484,22 +919,37 @@ const Positioner = forwardRef(({ className, collisionBoundary, collisionPadding,
|
|
|
484
919
|
sideOffset: 0,
|
|
485
920
|
};
|
|
486
921
|
}
|
|
922
|
+
// (On its axis: flipped at most, else shifted, not beside its trigger
|
|
923
|
+
// instead, see `useGrowAvoidance`.)
|
|
487
924
|
if (submenu) {
|
|
488
925
|
return {
|
|
489
926
|
align: 'start',
|
|
490
927
|
alignOffset: -10,
|
|
928
|
+
collisionAvoidance: { fallbackAxisSide: 'none' },
|
|
491
929
|
side: 'inline-end',
|
|
492
930
|
sideOffset: 8,
|
|
493
931
|
};
|
|
494
932
|
}
|
|
495
|
-
return {
|
|
933
|
+
return {
|
|
934
|
+
collisionAvoidance: { fallbackAxisSide: 'none' },
|
|
935
|
+
sideOffset: 8,
|
|
936
|
+
};
|
|
496
937
|
})();
|
|
497
|
-
|
|
938
|
+
// Growing rather than scrolling (unless its own is given).
|
|
939
|
+
const [grow, growRef] = useGrowAvoidance(defaults.collisionAvoidance, ref);
|
|
940
|
+
return (_jsx(BaseMenu.Positioner, { ref: growRef, ...collision, ...props, align: props.align ?? defaults.align, alignOffset: props.alignOffset ?? defaults.alignOffset, className: cn('uikit-menu-positioner', className), collisionAvoidance: props.collisionAvoidance ?? grow, "data-menu-part": "positioner", side: positionerSide(side ?? defaults.side), sideOffset: props.sideOffset ?? defaults.sideOffset }));
|
|
498
941
|
});
|
|
499
942
|
const highlightSelectors = ['[data-highlighted]', '[data-popup-open]'];
|
|
500
|
-
/** The menu's glass popup (
|
|
943
|
+
/** The menu's glass popup (the medium glass). */
|
|
501
944
|
const Popup = forwardRef(({ className, children, ...props }, ref) => {
|
|
502
945
|
const { size, submenu } = useContext(MenuContext);
|
|
946
|
+
// A submenu's: its element, for presses outside it (see `OpenSubmenus`).
|
|
947
|
+
const toggle = useContext(SubmenuToggleContext);
|
|
948
|
+
const popupRef = useCallback((element) => {
|
|
949
|
+
if (submenu)
|
|
950
|
+
toggle?.setPopup(element);
|
|
951
|
+
assignRef(ref, element);
|
|
952
|
+
}, [ref, submenu, toggle]);
|
|
503
953
|
// Closed by keys, focus returns to its trigger; otherwise (a pointer:
|
|
504
954
|
// an item, outside) it doesn't (Chrome would ring it: the popup took
|
|
505
955
|
// focus by script, e.g. opened through a list row). Submenus: as Base
|
|
@@ -509,17 +959,16 @@ const Popup = forwardRef(({ className, children, ...props }, ref) => {
|
|
|
509
959
|
: (closeType) => closeType === 'keyboard';
|
|
510
960
|
// Compact submenus cover their parent's items: as wide as its popup.
|
|
511
961
|
const isOverlay = submenu === 'vertical' && size === 'compact';
|
|
512
|
-
return (_jsxs(BaseMenu.Popup, { ref:
|
|
962
|
+
return (_jsxs(BaseMenu.Popup, { ref: popupRef, "data-overlay": isOverlay ? '' : undefined, "data-size": size, ...props, "data-menu-part": "popup", finalFocus: props.finalFocus ?? finalFocus, className: cn('uikit-menu-popup uikit-glass-medium uikit-popup-transition', className), children: [children, _jsx(MovingHighlight, { selectors: size === 'compact'
|
|
513
963
|
? highlightSelectors.slice(0, 1)
|
|
514
964
|
: highlightSelectors })] }));
|
|
515
965
|
});
|
|
516
|
-
//
|
|
966
|
+
// An item: [checkmark] [symbol] label/subtitle [shortcut | chevron]
|
|
517
967
|
// (see style.css).
|
|
518
968
|
const Item = forwardRef(({ className, destructive, ...props }, ref) => (_jsx(BaseMenu.Item, { ref: ref, "data-clickable": props.onClick ? '' : undefined, "data-destructive": destructive ? '' : undefined, ...props, className: cn('uikit-menu-item uikit-menu-action-cursor', className), "data-menu-part": "item" })));
|
|
519
969
|
const LinkItem = forwardRef(({ className, destructive, ...props }, ref) => (_jsx(BaseMenu.LinkItem, { ref: ref, "data-destructive": destructive ? '' : undefined, ...props, "data-menu-part": "item", className: cn('uikit-menu-item uikit-menu-toggle-cursor uikit-menu-link-item', className) })));
|
|
520
970
|
const CheckboxItem = forwardRef(({ className, destructive, ...props }, ref) => (_jsx(BaseMenu.CheckboxItem, { ref: ref, "data-destructive": destructive ? '' : undefined, ...props, className: cn('uikit-menu-item uikit-menu-toggle-cursor', className), "data-menu-part": "item" })));
|
|
521
971
|
const RadioItem = forwardRef(({ className, destructive, ...props }, ref) => (_jsx(BaseMenu.RadioItem, { ref: ref, "data-destructive": destructive ? '' : undefined, ...props, className: cn('uikit-menu-item uikit-menu-toggle-cursor', className), "data-menu-part": "item" })));
|
|
522
|
-
const Checkmark = () => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "0.8em", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2.2", viewBox: "0 0 16 16", width: "0.8em", children: _jsx("path", { d: "M2.5 8.5l3.8 3.8L13.5 3.5" }) }));
|
|
523
972
|
const CheckboxItemIndicator = forwardRef(({ className, children, ...props }, ref) => (_jsx(BaseMenu.CheckboxItemIndicator, { ref: ref, ...props, className: cn('uikit-menu-checkbox-item-indicator', className), "data-menu-part": "checkbox-item-indicator", children: children ?? _jsx(Checkmark, {}) })));
|
|
524
973
|
const RadioItemIndicator = forwardRef(({ className, children, ...props }, ref) => (_jsx(BaseMenu.RadioItemIndicator, { ref: ref, ...props, className: cn('uikit-menu-radio-item-indicator', className), "data-menu-part": "radio-item-indicator", children: children ?? _jsx(Checkmark, {}) })));
|
|
525
974
|
/**
|
|
@@ -528,9 +977,15 @@ const RadioItemIndicator = forwardRef(({ className, children, ...props }, ref) =
|
|
|
528
977
|
* as hovering opened it keeps it open (internal; `SubmenuTrigger`'s,
|
|
529
978
|
* EditMenu's `More`'s).
|
|
530
979
|
*/
|
|
531
|
-
export const useSubmenuToggle = ({ onClick, onPointerDown, }) => {
|
|
980
|
+
export const useSubmenuToggle = ({ onClick, onPointerDown, onPointerEnter, ref, }) => {
|
|
532
981
|
const toggle = useContext(SubmenuToggleContext);
|
|
982
|
+
// Its element, for presses outside its submenu (see `OpenSubmenus`).
|
|
983
|
+
const triggerRef = useCallback((element) => {
|
|
984
|
+
toggle?.setTrigger(element);
|
|
985
|
+
assignRef(ref, element);
|
|
986
|
+
}, [ref, toggle]);
|
|
533
987
|
return {
|
|
988
|
+
ref: triggerRef,
|
|
534
989
|
onClick: (event) => {
|
|
535
990
|
onClick?.(event);
|
|
536
991
|
if (!toggle)
|
|
@@ -548,27 +1003,47 @@ export const useSubmenuToggle = ({ onClick, onPointerDown, }) => {
|
|
|
548
1003
|
},
|
|
549
1004
|
onPointerDown: (event) => {
|
|
550
1005
|
onPointerDown?.(event);
|
|
1006
|
+
// (Not Base UI's own on touch: iOS' touches have no size, which it
|
|
1007
|
+
// takes for a screen reader's, highlighting the first item.)
|
|
1008
|
+
if (event.pointerType === 'touch')
|
|
1009
|
+
event.preventBaseUIHandler();
|
|
551
1010
|
toggle?.press({
|
|
552
1011
|
isOpen: event.currentTarget.getAttribute('aria-expanded') === 'true',
|
|
553
1012
|
pointerType: event.pointerType,
|
|
554
1013
|
});
|
|
555
1014
|
},
|
|
1015
|
+
onPointerEnter: (event) => {
|
|
1016
|
+
onPointerEnter?.(event);
|
|
1017
|
+
// (Not Base UI's own on touch, see above.)
|
|
1018
|
+
if (event.pointerType === 'touch')
|
|
1019
|
+
event.preventBaseUIHandler();
|
|
1020
|
+
},
|
|
556
1021
|
};
|
|
557
1022
|
};
|
|
558
1023
|
/** An item opening a submenu, with a chevron (see `useSubmenuToggle`). */
|
|
559
|
-
const SubmenuTrigger = forwardRef(({ className, children, destructive, onClick, onPointerDown, ...props }, ref) => {
|
|
1024
|
+
const SubmenuTrigger = forwardRef(({ className, children, destructive, onClick, onPointerDown, onPointerEnter, openOnHover, ...props }, ref) => {
|
|
560
1025
|
const { orientation, size } = useContext(MenuContext);
|
|
561
|
-
const
|
|
562
|
-
|
|
1026
|
+
const isOverlay = size === 'compact' && orientation === 'vertical';
|
|
1027
|
+
const handlers = useSubmenuToggle({
|
|
1028
|
+
onClick,
|
|
1029
|
+
onPointerDown,
|
|
1030
|
+
onPointerEnter,
|
|
1031
|
+
ref,
|
|
1032
|
+
});
|
|
1033
|
+
return (_jsxs(BaseMenu.SubmenuTrigger, { "data-destructive": destructive ? '' : undefined, ...handlers, "data-submenu-overlay": isOverlay ? '' : undefined,
|
|
1034
|
+
// Covering, pressed, not hovered, by default (a compact menu: no
|
|
1035
|
+
// hover; Base UI ignores clicks on a hover-opened one, so leaving it
|
|
1036
|
+
// would close it); otherwise Base UI's.
|
|
1037
|
+
openOnHover: openOnHover ?? (isOverlay ? false : undefined), ...props, className: cn('uikit-menu-item uikit-menu-toggle-cursor', className), "data-menu-part": "item", children: [children, _jsx("span", { "aria-hidden": "true", className: "uikit-menu-chevron", "data-menu-part": "chevron", children: _jsx("svg", { fill: "none", height: "15", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2.4", viewBox: "0 0 10 16", width: "10", children: _jsx("path", { d: "M2.5 2.5L8 8l-5.5 5.5" }) }) })] }));
|
|
563
1038
|
});
|
|
564
1039
|
const Shortcut = forwardRef(({ className, children, ...props }, ref) => (_jsx("kbd", { ref: ref, ...props, className: cn('uikit-menu-shortcut', className), "data-menu-part": "shortcut", children: typeof children === 'string'
|
|
565
1040
|
? Array.from(children, (glyph, index) => (_jsx("span", { children: glyph }, index)))
|
|
566
1041
|
: children })));
|
|
567
|
-
//
|
|
568
|
-
//
|
|
1042
|
+
// A separator: a hairline, inset 8px; regular, 16px high, 17px before a
|
|
1043
|
+
// section, 21px after quick actions (compact: 21px).
|
|
569
1044
|
const StyledSeparator = forwardRef(({ className, ...props }, ref) => (_jsx(BaseMenu.Separator, { ref: ref, className: cn('uikit-menu-separator', className), "data-menu-part": "separator", ...props })));
|
|
570
1045
|
const Separator = StyledSeparator;
|
|
571
|
-
//
|
|
1046
|
+
// A section title.
|
|
572
1047
|
const GroupLabel = forwardRef(({ className, ...props }, ref) => (_jsx(BaseMenu.GroupLabel, { ref: ref, className: cn('uikit-menu-group-label', className), "data-menu-part": "group-label", ...props })));
|
|
573
1048
|
const QuickActions = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, "data-menu-part": "quick-actions", ...props, className: cn('uikit-menu-quick-actions', className) })));
|
|
574
1049
|
const QuickAction = forwardRef(({ className, destructive, ...props }, ref) => (_jsx(BaseMenu.Item, { ref: ref, "data-clickable": props.onClick ? '' : undefined, "data-destructive": destructive ? '' : undefined, ...props, "data-menu-part": "quick-action", className: cn('uikit-menu-quick-action uikit-menu-action-cursor', className) })));
|