@dxos/react-ui-stack 0.7.5-main.9d2a38b → 0.7.5-main.ff8607b
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/lib/browser/index.mjs +80 -55
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +81 -55
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +80 -55
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Stack.d.ts +3 -0
- package/dist/types/src/components/Stack.d.ts.map +1 -1
- package/dist/types/src/components/StackItem.d.ts +2 -0
- package/dist/types/src/components/StackItem.d.ts.map +1 -1
- package/dist/types/src/components/StackItemResizeHandle.d.ts.map +1 -1
- package/dist/types/src/components/StackItemSigil.d.ts.map +1 -1
- package/package.json +28 -27
- package/src/components/Stack.tsx +45 -30
- package/src/components/StackItem.tsx +42 -10
- package/src/components/StackItemHeading.tsx +1 -1
- package/src/components/StackItemResizeHandle.tsx +20 -9
- package/src/components/StackItemSigil.tsx +90 -103
package/src/components/Stack.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
|
+
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
4
5
|
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
6
|
+
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
5
7
|
import { attachClosestEdge, extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
|
|
6
8
|
import { useArrowNavigationGroup } from '@fluentui/react-tabster';
|
|
7
9
|
import { composeRefs } from '@radix-ui/react-compose-refs';
|
|
@@ -29,6 +31,8 @@ export const railGridHorizontal = 'grid-rows-[[rail-start]_var(--rail-size)_[con
|
|
|
29
31
|
|
|
30
32
|
export const railGridVertical = 'grid-cols-[[rail-start]_var(--rail-size)_[content-start]_1fr_[content-end]]';
|
|
31
33
|
|
|
34
|
+
export const autoScrollRootAttributes = { 'data-drag-autoscroll': 'idle' };
|
|
35
|
+
|
|
32
36
|
export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
33
37
|
(
|
|
34
38
|
{
|
|
@@ -62,33 +66,36 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
|
62
66
|
return;
|
|
63
67
|
}
|
|
64
68
|
const acceptSourceType = orientation === 'horizontal' ? 'column' : 'card';
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
69
|
+
return combine(
|
|
70
|
+
dropTargetForElements({
|
|
71
|
+
element: stackElement,
|
|
72
|
+
getData: ({ input, element }) => {
|
|
73
|
+
return attachClosestEdge(
|
|
74
|
+
{ id: props.id, type: orientation === 'horizontal' ? 'card' : 'column' },
|
|
75
|
+
{ input, element, allowedEdges: [orientation === 'horizontal' ? 'left' : 'top'] },
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
onDragEnter: ({ source }) => {
|
|
79
|
+
if (source.data.type === acceptSourceType) {
|
|
80
|
+
setDropping(true);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
onDrag: ({ source }) => {
|
|
84
|
+
if (source.data.type === acceptSourceType) {
|
|
85
|
+
setDropping(true);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
onDragLeave: () => setDropping(false),
|
|
89
|
+
onDrop: ({ self, source }) => {
|
|
90
|
+
setDropping(false);
|
|
91
|
+
if (source.data.type === acceptSourceType && selfDroppable) {
|
|
92
|
+
onRearrange(source.data as StackItemData, self.data as StackItemData, extractClosestEdge(self.data));
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
autoScrollForElements({ element: stackElement, getAllowedAxis: () => orientation }),
|
|
97
|
+
);
|
|
98
|
+
}, [stackElement, selfDroppable, orientation]);
|
|
92
99
|
|
|
93
100
|
return (
|
|
94
101
|
<StackContext.Provider value={{ orientation, rail, size, onRearrange }}>
|
|
@@ -102,20 +109,28 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
|
102
109
|
? railGridHorizontal
|
|
103
110
|
: railGridVertical
|
|
104
111
|
: orientation === 'horizontal'
|
|
105
|
-
? 'grid-rows-1'
|
|
106
|
-
: 'grid-cols-1',
|
|
112
|
+
? 'grid-rows-1 pli-1'
|
|
113
|
+
: 'grid-cols-1 plb-1',
|
|
107
114
|
size === 'contain' &&
|
|
108
115
|
(orientation === 'horizontal'
|
|
109
116
|
? 'overflow-x-auto min-bs-0 bs-full max-bs-full'
|
|
110
117
|
: 'overflow-y-auto min-is-0 is-full max-is-full'),
|
|
111
118
|
classNames,
|
|
112
119
|
)}
|
|
120
|
+
data-rail={rail}
|
|
113
121
|
aria-orientation={orientation}
|
|
114
122
|
style={styles}
|
|
115
123
|
ref={composedItemRef}
|
|
116
124
|
>
|
|
117
125
|
{children}
|
|
118
|
-
{selfDroppable && dropping &&
|
|
126
|
+
{selfDroppable && dropping && (
|
|
127
|
+
<ListItem.DropIndicator
|
|
128
|
+
lineInset={8}
|
|
129
|
+
terminalInset={-8}
|
|
130
|
+
gap={-8}
|
|
131
|
+
edge={orientation === 'horizontal' ? 'left' : 'top'}
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
119
134
|
</div>
|
|
120
135
|
</StackContext.Provider>
|
|
121
136
|
);
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
6
6
|
import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { preserveOffsetOnSource } from '@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source';
|
|
8
|
+
import { scrollJustEnoughIntoView } from '@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view';
|
|
9
9
|
import {
|
|
10
10
|
attachClosestEdge,
|
|
11
11
|
extractClosestEdge,
|
|
@@ -46,10 +46,27 @@ export type StackItemRootProps = ThemedClassName<ComponentPropsWithRef<'div'>> &
|
|
|
46
46
|
size?: StackItemSize;
|
|
47
47
|
onSizeChange?: (nextSize: StackItemSize) => void;
|
|
48
48
|
role?: 'article' | 'section';
|
|
49
|
+
disableRearrange?: boolean;
|
|
50
|
+
focusIndicatorVariant?: 'over-all' | 'group';
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
const StackItemRoot = forwardRef<HTMLDivElement, StackItemRootProps>(
|
|
52
|
-
(
|
|
54
|
+
(
|
|
55
|
+
{
|
|
56
|
+
item,
|
|
57
|
+
children,
|
|
58
|
+
classNames,
|
|
59
|
+
size: propsSize,
|
|
60
|
+
onSizeChange,
|
|
61
|
+
role,
|
|
62
|
+
order,
|
|
63
|
+
style,
|
|
64
|
+
disableRearrange,
|
|
65
|
+
focusIndicatorVariant = 'over-all',
|
|
66
|
+
...props
|
|
67
|
+
},
|
|
68
|
+
forwardedRef,
|
|
69
|
+
) => {
|
|
53
70
|
const [itemElement, itemRef] = useState<HTMLDivElement | null>(null);
|
|
54
71
|
const [selfDragHandleElement, selfDragHandleRef] = useState<HTMLDivElement | null>(null);
|
|
55
72
|
const [closestEdge, setEdge] = useState<Edge | null>(null);
|
|
@@ -74,7 +91,7 @@ const StackItemRoot = forwardRef<HTMLDivElement, StackItemRootProps>(
|
|
|
74
91
|
const type = orientation === 'horizontal' ? 'column' : 'card';
|
|
75
92
|
|
|
76
93
|
useLayoutEffect(() => {
|
|
77
|
-
if (!itemElement || !onRearrange) {
|
|
94
|
+
if (!itemElement || !onRearrange || disableRearrange) {
|
|
78
95
|
return;
|
|
79
96
|
}
|
|
80
97
|
return combine(
|
|
@@ -82,10 +99,20 @@ const StackItemRoot = forwardRef<HTMLDivElement, StackItemRootProps>(
|
|
|
82
99
|
element: itemElement,
|
|
83
100
|
...(selfDragHandleElement && { dragHandle: selfDragHandleElement }),
|
|
84
101
|
getInitialData: () => ({ id: item.id, type }),
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
onGenerateDragPreview: ({ nativeSetDragImage, source, location }) => {
|
|
103
|
+
document.body.setAttribute('data-drag-preview', 'true');
|
|
104
|
+
scrollJustEnoughIntoView({ element: source.element });
|
|
105
|
+
const { x, y } = preserveOffsetOnSource({ element: source.element, input: location.current.input })({
|
|
106
|
+
container: (source.element.offsetParent ?? document.body) as HTMLElement,
|
|
107
|
+
});
|
|
108
|
+
nativeSetDragImage?.(source.element, x, y);
|
|
109
|
+
},
|
|
110
|
+
onDragStart: () => {
|
|
111
|
+
document.body.removeAttribute('data-drag-preview');
|
|
112
|
+
itemElement?.closest('[data-drag-autoscroll]')?.setAttribute('data-drag-autoscroll', 'active');
|
|
113
|
+
},
|
|
114
|
+
onDrop: () => {
|
|
115
|
+
itemElement?.closest('[data-drag-autoscroll]')?.setAttribute('data-drag-autoscroll', 'idle');
|
|
89
116
|
},
|
|
90
117
|
}),
|
|
91
118
|
dropTargetForElements({
|
|
@@ -126,7 +153,12 @@ const StackItemRoot = forwardRef<HTMLDivElement, StackItemRootProps>(
|
|
|
126
153
|
tabIndex={0}
|
|
127
154
|
{...focusGroupAttrs}
|
|
128
155
|
className={mx(
|
|
129
|
-
'group/stack-item grid relative
|
|
156
|
+
'group/stack-item grid relative',
|
|
157
|
+
focusIndicatorVariant === 'over-all'
|
|
158
|
+
? 'dx-focus-ring-inset-over-all'
|
|
159
|
+
: orientation === 'horizontal'
|
|
160
|
+
? 'dx-focus-ring-group-x'
|
|
161
|
+
: 'dx-focus-ring-group-y',
|
|
130
162
|
size === 'min-content' && (orientation === 'horizontal' ? 'is-min' : 'bs-min'),
|
|
131
163
|
orientation === 'horizontal' ? 'grid-rows-subgrid' : 'grid-cols-subgrid',
|
|
132
164
|
rail && (orientation === 'horizontal' ? 'row-span-2' : 'col-span-2'),
|
|
@@ -145,7 +177,7 @@ const StackItemRoot = forwardRef<HTMLDivElement, StackItemRootProps>(
|
|
|
145
177
|
ref={composedItemRef}
|
|
146
178
|
>
|
|
147
179
|
{children}
|
|
148
|
-
{closestEdge && <ListItem.DropIndicator edge={closestEdge} />}
|
|
180
|
+
{closestEdge && <ListItem.DropIndicator lineInset={8} terminalInset={-8} edge={closestEdge} />}
|
|
149
181
|
</Root>
|
|
150
182
|
</StackItemContext.Provider>
|
|
151
183
|
);
|
|
@@ -23,7 +23,7 @@ export const StackItemHeading = ({ children, classNames, ...props }: StackItemHe
|
|
|
23
23
|
tabIndex={0}
|
|
24
24
|
{...focusableGroupAttrs}
|
|
25
25
|
className={mx(
|
|
26
|
-
'flex items-center
|
|
26
|
+
'flex items-center dx-focus-ring-inset-over-all relative !border-is-0',
|
|
27
27
|
orientation === 'horizontal' ? 'bs-[--rail-size]' : 'is-[--rail-size] flex-col',
|
|
28
28
|
classNames,
|
|
29
29
|
)}
|
|
@@ -15,7 +15,8 @@ import { DEFAULT_EXTRINSIC_SIZE } from './StackItem';
|
|
|
15
15
|
|
|
16
16
|
const REM = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const MIN_WIDTH = 20;
|
|
19
|
+
const MIN_HEIGHT = 3;
|
|
19
20
|
|
|
20
21
|
const measureStackItem = (element: HTMLButtonElement): { width: number; height: number } => {
|
|
21
22
|
const stackItemElement = element.closest('[data-dx-stack-item]');
|
|
@@ -23,7 +24,10 @@ const measureStackItem = (element: HTMLButtonElement): { width: number; height:
|
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
const getNextSize = (startSize: number, location: DragLocationHistory, client: 'clientX' | 'clientY') => {
|
|
26
|
-
return Math.max(
|
|
27
|
+
return Math.max(
|
|
28
|
+
client === 'clientX' ? MIN_WIDTH : MIN_HEIGHT,
|
|
29
|
+
startSize + (location.current.input[client] - location.initial.input[client]) / REM,
|
|
30
|
+
);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
export type StackItemResizeHandleProps = {};
|
|
@@ -81,29 +85,36 @@ export const StackItemResizeHandle = () => {
|
|
|
81
85
|
<button
|
|
82
86
|
ref={buttonRef}
|
|
83
87
|
className={mx(
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
'group absolute',
|
|
89
|
+
orientation === 'horizontal'
|
|
90
|
+
? 'cursor-col-resize is-3 bs-full inline-end-[-1px] !border-lb-0 before:inset-block-0 before:inline-end-0 before:is-1'
|
|
91
|
+
: 'cursor-row-resize bs-3 is-full block-end-[-1px] !border-li-0 before:inset-inline-0 before:block-end-0 before:bs-1',
|
|
86
92
|
'before:transition-opacity before:duration-100 before:ease-in-out before:opacity-0 hover:before:opacity-100 focus-visible:before:opacity-100 active:before:opacity-100',
|
|
87
|
-
'before:absolute before:block before:
|
|
93
|
+
'before:absolute before:block before:bg-accentFocusIndicator',
|
|
88
94
|
)}
|
|
89
95
|
>
|
|
90
96
|
<div
|
|
91
97
|
role='none'
|
|
92
|
-
className=
|
|
98
|
+
className={mx(
|
|
99
|
+
'absolute flex items-center group-hover:opacity-0 group-focus-visible:opacity-0 group-active:opacity-0',
|
|
100
|
+
orientation === 'horizontal'
|
|
101
|
+
? 'block-start-0 inline-end-px bs-[--rail-size]'
|
|
102
|
+
: 'inline-start-0 block-end-px is-[--rail-size] flex justify-center',
|
|
103
|
+
)}
|
|
93
104
|
>
|
|
94
|
-
<DragHandleSignifier />
|
|
105
|
+
<DragHandleSignifier orientation={orientation} />
|
|
95
106
|
</div>
|
|
96
107
|
</button>
|
|
97
108
|
);
|
|
98
109
|
};
|
|
99
110
|
|
|
100
|
-
const DragHandleSignifier = () => {
|
|
111
|
+
const DragHandleSignifier = ({ orientation }: { orientation: 'horizontal' | 'vertical' }) => {
|
|
101
112
|
return (
|
|
102
113
|
<svg
|
|
103
114
|
xmlns='http://www.w3.org/2000/svg'
|
|
104
115
|
viewBox='0 0 256 256'
|
|
105
116
|
fill='currentColor'
|
|
106
|
-
className='shrink-0 bs-[1em] is-[1em] text-unAccent'
|
|
117
|
+
className={mx('shrink-0 bs-[1em] is-[1em] text-unAccent', orientation === 'vertical' && 'rotate-90')}
|
|
107
118
|
>
|
|
108
119
|
{/* two pips: <path d='M256,120c-8.8,0-16-7.2-16-16v-56c0-8.8,7.2-16,16-16v88Z' />
|
|
109
120
|
<path d='M256,232c-8.8,0-16-7.2-16-16v-56c0-8.8,7.2-16,16-16v88Z' /> */}
|
|
@@ -6,15 +6,7 @@ import React, { Fragment, type PropsWithChildren, forwardRef, useRef, useState }
|
|
|
6
6
|
|
|
7
7
|
import { type ActionLike } from '@dxos/app-graph';
|
|
8
8
|
import { keySymbols } from '@dxos/keyboard';
|
|
9
|
-
import {
|
|
10
|
-
Button,
|
|
11
|
-
type ButtonProps,
|
|
12
|
-
DropdownMenu,
|
|
13
|
-
Icon,
|
|
14
|
-
toLocalizedString,
|
|
15
|
-
Tooltip,
|
|
16
|
-
useTranslation,
|
|
17
|
-
} from '@dxos/react-ui';
|
|
9
|
+
import { Button, type ButtonProps, DropdownMenu, Icon, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
18
10
|
import { type AttendableId, type Related, useAttention } from '@dxos/react-ui-attention';
|
|
19
11
|
import { descriptionText, mx } from '@dxos/react-ui-theme';
|
|
20
12
|
import { getHostPlatform } from '@dxos/util';
|
|
@@ -42,7 +34,7 @@ export const StackItemSigilButton = forwardRef<HTMLButtonElement, StackItemSigil
|
|
|
42
34
|
<Button
|
|
43
35
|
{...props}
|
|
44
36
|
variant={variant}
|
|
45
|
-
classNames={['shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative', classNames]}
|
|
37
|
+
classNames={['shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative app-no-drag', classNames]}
|
|
46
38
|
ref={forwardedRef}
|
|
47
39
|
>
|
|
48
40
|
<MenuSignifierHorizontal />
|
|
@@ -68,103 +60,98 @@ export const StackItemSigil = forwardRef<HTMLButtonElement, StackItemSigilProps>
|
|
|
68
60
|
const suppressNextTooltip = useRef(false);
|
|
69
61
|
|
|
70
62
|
const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
|
|
71
|
-
|
|
63
|
+
|
|
64
|
+
const hasActions = actionGroups && actionGroups.length > 0;
|
|
65
|
+
|
|
66
|
+
const button = (
|
|
67
|
+
<StackItemSigilButton
|
|
68
|
+
attendableId={attendableId}
|
|
69
|
+
related={related}
|
|
70
|
+
// TODO(wittjosiah): Better disabling of interactive styles when no action are available.
|
|
71
|
+
// Remove underscore icon when no actions are available?
|
|
72
|
+
classNames={!hasActions && 'cursor-default'}
|
|
73
|
+
>
|
|
74
|
+
<span className='sr-only'>{triggerLabel}</span>
|
|
75
|
+
<Icon icon={icon} size={5} />
|
|
76
|
+
</StackItemSigilButton>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (!hasActions) {
|
|
80
|
+
return button;
|
|
81
|
+
}
|
|
72
82
|
|
|
73
83
|
return (
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
84
|
+
<DropdownMenu.Root
|
|
85
|
+
{...{
|
|
86
|
+
open: optionsMenuOpen,
|
|
87
|
+
onOpenChange: (nextOpen: boolean) => {
|
|
88
|
+
if (!nextOpen) {
|
|
89
|
+
suppressNextTooltip.current = true;
|
|
90
|
+
}
|
|
91
|
+
return setOptionsMenuOpen(nextOpen);
|
|
92
|
+
},
|
|
83
93
|
}}
|
|
84
94
|
>
|
|
85
|
-
<DropdownMenu.
|
|
86
|
-
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
)}
|
|
146
|
-
{shortcut && (
|
|
147
|
-
<span className={mx('shrink-0', descriptionText)}>{keySymbols(shortcut).join('')}</span>
|
|
148
|
-
)}
|
|
149
|
-
</Root>
|
|
150
|
-
);
|
|
151
|
-
})}
|
|
152
|
-
</Fragment>
|
|
153
|
-
);
|
|
154
|
-
})}
|
|
155
|
-
{children}
|
|
156
|
-
</DropdownMenu.Viewport>
|
|
157
|
-
<DropdownMenu.Arrow />
|
|
158
|
-
</DropdownMenu.Content>
|
|
159
|
-
</DropdownMenu.Portal>
|
|
160
|
-
</DropdownMenu.Root>
|
|
161
|
-
<Tooltip.Portal>
|
|
162
|
-
<Tooltip.Content side='bottom'>
|
|
163
|
-
{triggerLabel}
|
|
164
|
-
<Tooltip.Arrow />
|
|
165
|
-
</Tooltip.Content>
|
|
166
|
-
</Tooltip.Portal>
|
|
167
|
-
</Tooltip.Root>
|
|
95
|
+
<DropdownMenu.Trigger asChild ref={forwardedRef}>
|
|
96
|
+
{button}
|
|
97
|
+
</DropdownMenu.Trigger>
|
|
98
|
+
<DropdownMenu.Portal>
|
|
99
|
+
<DropdownMenu.Content classNames='z-[31]'>
|
|
100
|
+
<DropdownMenu.Viewport>
|
|
101
|
+
{actionGroups?.map((actions, index) => {
|
|
102
|
+
const separator = index > 0 ? <DropdownMenu.Separator /> : null;
|
|
103
|
+
return (
|
|
104
|
+
<Fragment key={index}>
|
|
105
|
+
{separator}
|
|
106
|
+
{actions.map((action) => {
|
|
107
|
+
const shortcut =
|
|
108
|
+
typeof action.properties.keyBinding === 'string'
|
|
109
|
+
? action.properties.keyBinding
|
|
110
|
+
: action.properties.keyBinding?.[getHostPlatform()];
|
|
111
|
+
|
|
112
|
+
const menuItemType = action.properties.menuItemType;
|
|
113
|
+
const Root = menuItemType === 'toggle' ? DropdownMenu.CheckboxItem : DropdownMenu.Item;
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<Root
|
|
117
|
+
key={action.id}
|
|
118
|
+
onClick={(event) => {
|
|
119
|
+
if (action.properties.disabled) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
event.stopPropagation();
|
|
123
|
+
// TODO(thure): Why does Dialog’s modal-ness cause issues if we don’t explicitly close the menu here?
|
|
124
|
+
suppressNextTooltip.current = true;
|
|
125
|
+
setOptionsMenuOpen(false);
|
|
126
|
+
onAction?.(action);
|
|
127
|
+
}}
|
|
128
|
+
classNames='gap-2'
|
|
129
|
+
disabled={action.properties.disabled}
|
|
130
|
+
checked={menuItemType === 'toggle' ? action.properties.isChecked : undefined}
|
|
131
|
+
{...(action.properties?.testId && { 'data-testid': action.properties.testId })}
|
|
132
|
+
>
|
|
133
|
+
<Icon icon={action.properties.icon ?? 'ph--placeholder--regular'} size={4} />
|
|
134
|
+
<span className='grow truncate'>{toLocalizedString(action.properties.label ?? '', t)}</span>
|
|
135
|
+
{menuItemType === 'toggle' && (
|
|
136
|
+
<DropdownMenu.ItemIndicator asChild>
|
|
137
|
+
<Icon icon='ph--check--regular' size={4} />
|
|
138
|
+
</DropdownMenu.ItemIndicator>
|
|
139
|
+
)}
|
|
140
|
+
{shortcut && (
|
|
141
|
+
<span className={mx('shrink-0', descriptionText)}>{keySymbols(shortcut).join('')}</span>
|
|
142
|
+
)}
|
|
143
|
+
</Root>
|
|
144
|
+
);
|
|
145
|
+
})}
|
|
146
|
+
</Fragment>
|
|
147
|
+
);
|
|
148
|
+
})}
|
|
149
|
+
{children}
|
|
150
|
+
</DropdownMenu.Viewport>
|
|
151
|
+
<DropdownMenu.Arrow />
|
|
152
|
+
</DropdownMenu.Content>
|
|
153
|
+
</DropdownMenu.Portal>
|
|
154
|
+
</DropdownMenu.Root>
|
|
168
155
|
);
|
|
169
156
|
},
|
|
170
157
|
);
|