@dxos/react-ui-stack 0.7.5-labs.e27f9b9 → 0.7.5-main.2567c87

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.
@@ -15,12 +15,10 @@ export type StackItemContentProps = ThemedClassName<ComponentPropsWithoutRef<'di
15
15
  * (`row-span-2`) or was buggy. See the description of the StackItem.Content component itself for more information.
16
16
  */
17
17
  toolbar: boolean;
18
-
19
18
  /**
20
19
  * Whether to provide for the layout of a statusbar after the content.
21
20
  */
22
21
  statusbar?: boolean;
23
-
24
22
  /**
25
23
  * Whether to set a certain aspect ratio on the content, including the toolbar and statusbar. This is provided for
26
24
  * convenience and consistency; it can instead be specified by the `classNames` or `style` props as needed.
@@ -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 dx-focus-ring-inset-over-all relative !border-is-0',
26
+ 'flex items-center ch-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,8 +15,7 @@ import { DEFAULT_EXTRINSIC_SIZE } from './StackItem';
15
15
 
16
16
  const REM = parseFloat(getComputedStyle(document.documentElement).fontSize);
17
17
 
18
- const MIN_WIDTH = 20;
19
- const MIN_HEIGHT = 3;
18
+ const MIN_SIZE = 20;
20
19
 
21
20
  const measureStackItem = (element: HTMLButtonElement): { width: number; height: number } => {
22
21
  const stackItemElement = element.closest('[data-dx-stack-item]');
@@ -24,10 +23,7 @@ const measureStackItem = (element: HTMLButtonElement): { width: number; height:
24
23
  };
25
24
 
26
25
  const getNextSize = (startSize: number, location: DragLocationHistory, client: 'clientX' | 'clientY') => {
27
- return Math.max(
28
- client === 'clientX' ? MIN_WIDTH : MIN_HEIGHT,
29
- startSize + (location.current.input[client] - location.initial.input[client]) / REM,
30
- );
26
+ return Math.max(MIN_SIZE, startSize + (location.current.input[client] - location.initial.input[client]) / REM);
31
27
  };
32
28
 
33
29
  export type StackItemResizeHandleProps = {};
@@ -85,36 +81,29 @@ export const StackItemResizeHandle = () => {
85
81
  <button
86
82
  ref={buttonRef}
87
83
  className={mx(
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',
84
+ orientation === 'horizontal' ? 'cursor-col-resize' : 'cursor-row-resize',
85
+ 'group absolute is-3 bs-full inline-end-[-1px] !border-lb-0',
92
86
  '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',
93
- 'before:absolute before:block before:bg-accentFocusIndicator',
87
+ 'before:absolute before:block before:inset-block-0 before:inline-end-0 before:is-1 before:bg-accentFocusIndicator',
94
88
  )}
95
89
  >
96
90
  <div
97
91
  role='none'
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
- )}
92
+ className='absolute block-start-0 inline-end-[1px] bs-[--rail-size] flex items-center group-hover:opacity-0 group-focus-visible:opacity-0 group-active:opacity-0'
104
93
  >
105
- <DragHandleSignifier orientation={orientation} />
94
+ <DragHandleSignifier />
106
95
  </div>
107
96
  </button>
108
97
  );
109
98
  };
110
99
 
111
- const DragHandleSignifier = ({ orientation }: { orientation: 'horizontal' | 'vertical' }) => {
100
+ const DragHandleSignifier = () => {
112
101
  return (
113
102
  <svg
114
103
  xmlns='http://www.w3.org/2000/svg'
115
104
  viewBox='0 0 256 256'
116
105
  fill='currentColor'
117
- className={mx('shrink-0 bs-[1em] is-[1em] text-unAccent', orientation === 'vertical' && 'rotate-90')}
106
+ className='shrink-0 bs-[1em] is-[1em] text-unAccent'
118
107
  >
119
108
  {/* two pips: <path d='M256,120c-8.8,0-16-7.2-16-16v-56c0-8.8,7.2-16,16-16v88Z' />
120
109
  <path d='M256,232c-8.8,0-16-7.2-16-16v-56c0-8.8,7.2-16,16-16v88Z' /> */}
@@ -6,7 +6,15 @@ 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 { Button, type ButtonProps, DropdownMenu, Icon, toLocalizedString, useTranslation } from '@dxos/react-ui';
9
+ import {
10
+ Button,
11
+ type ButtonProps,
12
+ DropdownMenu,
13
+ Icon,
14
+ toLocalizedString,
15
+ Tooltip,
16
+ useTranslation,
17
+ } from '@dxos/react-ui';
10
18
  import { type AttendableId, type Related, useAttention } from '@dxos/react-ui-attention';
11
19
  import { descriptionText, mx } from '@dxos/react-ui-theme';
12
20
  import { getHostPlatform } from '@dxos/util';
@@ -34,7 +42,7 @@ export const StackItemSigilButton = forwardRef<HTMLButtonElement, StackItemSigil
34
42
  <Button
35
43
  {...props}
36
44
  variant={variant}
37
- classNames={['shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative app-no-drag', classNames]}
45
+ classNames={['shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative', classNames]}
38
46
  ref={forwardedRef}
39
47
  >
40
48
  <MenuSignifierHorizontal />
@@ -60,98 +68,103 @@ export const StackItemSigil = forwardRef<HTMLButtonElement, StackItemSigilProps>
60
68
  const suppressNextTooltip = useRef(false);
61
69
 
62
70
  const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
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
- }
71
+ const [triggerTooltipOpen, setTriggerTooltipOpen] = useState(false);
82
72
 
83
73
  return (
84
- <DropdownMenu.Root
85
- {...{
86
- open: optionsMenuOpen,
87
- onOpenChange: (nextOpen: boolean) => {
88
- if (!nextOpen) {
89
- suppressNextTooltip.current = true;
90
- }
91
- return setOptionsMenuOpen(nextOpen);
92
- },
74
+ <Tooltip.Root
75
+ open={triggerTooltipOpen}
76
+ onOpenChange={(nextOpen) => {
77
+ if (suppressNextTooltip.current) {
78
+ setTriggerTooltipOpen(false);
79
+ suppressNextTooltip.current = false;
80
+ } else {
81
+ setTriggerTooltipOpen(nextOpen);
82
+ }
93
83
  }}
94
84
  >
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>
85
+ <DropdownMenu.Root
86
+ {...{
87
+ open: optionsMenuOpen,
88
+ onOpenChange: (nextOpen: boolean) => {
89
+ if (!nextOpen) {
90
+ suppressNextTooltip.current = true;
91
+ }
92
+ return setOptionsMenuOpen(nextOpen);
93
+ },
94
+ }}
95
+ >
96
+ <Tooltip.Trigger asChild>
97
+ <DropdownMenu.Trigger asChild ref={forwardedRef}>
98
+ <StackItemSigilButton attendableId={attendableId} related={related}>
99
+ <span className='sr-only'>{triggerLabel}</span>
100
+ <Icon icon={icon} size={5} />
101
+ </StackItemSigilButton>
102
+ </DropdownMenu.Trigger>
103
+ </Tooltip.Trigger>
104
+ <DropdownMenu.Portal>
105
+ <DropdownMenu.Content classNames='z-[31]'>
106
+ <DropdownMenu.Viewport>
107
+ {actionGroups?.map((actions, index) => {
108
+ const separator = index > 0 ? <DropdownMenu.Separator /> : null;
109
+ return (
110
+ <Fragment key={index}>
111
+ {separator}
112
+ {actions.map((action) => {
113
+ const shortcut =
114
+ typeof action.properties.keyBinding === 'string'
115
+ ? action.properties.keyBinding
116
+ : action.properties.keyBinding?.[getHostPlatform()];
117
+
118
+ const menuItemType = action.properties.menuItemType;
119
+ const Root = menuItemType === 'toggle' ? DropdownMenu.CheckboxItem : DropdownMenu.Item;
120
+
121
+ return (
122
+ <Root
123
+ key={action.id}
124
+ onClick={(event) => {
125
+ if (action.properties.disabled) {
126
+ return;
127
+ }
128
+ event.stopPropagation();
129
+ // TODO(thure): Why does Dialog’s modal-ness cause issues if we don’t explicitly close the menu here?
130
+ suppressNextTooltip.current = true;
131
+ setOptionsMenuOpen(false);
132
+ onAction?.(action);
133
+ }}
134
+ classNames='gap-2'
135
+ disabled={action.properties.disabled}
136
+ checked={menuItemType === 'toggle' ? action.properties.isChecked : undefined}
137
+ {...(action.properties?.testId && { 'data-testid': action.properties.testId })}
138
+ >
139
+ <Icon icon={action.properties.icon ?? 'ph--placeholder--regular'} size={4} />
140
+ <span className='grow truncate'>{toLocalizedString(action.properties.label ?? '', t)}</span>
141
+ {menuItemType === 'toggle' && (
142
+ <DropdownMenu.ItemIndicator asChild>
143
+ <Icon icon='ph--check--regular' size={4} />
144
+ </DropdownMenu.ItemIndicator>
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>
155
168
  );
156
169
  },
157
170
  );