@oxy.so/bloom 2.4.0 → 2.6.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.
Files changed (158) hide show
  1. package/README.md +3 -3
  2. package/docs/app-shell.mdx +10 -0
  3. package/docs/avatar-group.mdx +10 -17
  4. package/docs/hover-card.mdx +125 -0
  5. package/docs/user-hover-card.mdx +29 -9
  6. package/lib/commonjs/app-shell/AppShell.js +85 -18
  7. package/lib/commonjs/app-shell/AppShell.js.map +1 -1
  8. package/lib/commonjs/avatar-group/AvatarGroup.web.js +55 -85
  9. package/lib/commonjs/avatar-group/AvatarGroup.web.js.map +1 -1
  10. package/lib/commonjs/floating/use-anchor-rect.js +1 -0
  11. package/lib/commonjs/floating/use-anchor-rect.js.map +1 -1
  12. package/lib/commonjs/hover-card/HoverCard.js +104 -0
  13. package/lib/commonjs/hover-card/HoverCard.js.map +1 -0
  14. package/lib/commonjs/hover-card/HoverCard.web.js +155 -0
  15. package/lib/commonjs/hover-card/HoverCard.web.js.map +1 -0
  16. package/lib/commonjs/hover-card/HoverCardPanel.js +101 -0
  17. package/lib/commonjs/hover-card/HoverCardPanel.js.map +1 -0
  18. package/lib/commonjs/hover-card/constants.js +25 -0
  19. package/lib/commonjs/hover-card/constants.js.map +1 -0
  20. package/lib/commonjs/hover-card/context.js +37 -0
  21. package/lib/commonjs/hover-card/context.js.map +1 -0
  22. package/lib/commonjs/hover-card/index.js +44 -0
  23. package/lib/commonjs/hover-card/index.js.map +1 -0
  24. package/lib/commonjs/hover-card/index.web.js +44 -0
  25. package/lib/commonjs/hover-card/index.web.js.map +1 -0
  26. package/lib/commonjs/hover-card/types.js +6 -0
  27. package/lib/commonjs/hover-card/types.js.map +1 -0
  28. package/lib/commonjs/hover-card/use-hover-intent.js +49 -0
  29. package/lib/commonjs/hover-card/use-hover-intent.js.map +1 -0
  30. package/lib/commonjs/index.js +12 -0
  31. package/lib/commonjs/index.js.map +1 -1
  32. package/lib/commonjs/index.web.js +16 -4
  33. package/lib/commonjs/index.web.js.map +1 -1
  34. package/lib/commonjs/styles/web-view-style.js +25 -1
  35. package/lib/commonjs/styles/web-view-style.js.map +1 -1
  36. package/lib/commonjs/user-hover-card/UserHoverCard.js +16 -6
  37. package/lib/commonjs/user-hover-card/UserHoverCard.js.map +1 -1
  38. package/lib/commonjs/user-hover-card/constants.js +8 -2
  39. package/lib/commonjs/user-hover-card/constants.js.map +1 -1
  40. package/lib/module/app-shell/AppShell.js +86 -19
  41. package/lib/module/app-shell/AppShell.js.map +1 -1
  42. package/lib/module/avatar-group/AvatarGroup.web.js +55 -84
  43. package/lib/module/avatar-group/AvatarGroup.web.js.map +1 -1
  44. package/lib/module/floating/use-anchor-rect.js +1 -1
  45. package/lib/module/floating/use-anchor-rect.js.map +1 -1
  46. package/lib/module/hover-card/HoverCard.js +96 -0
  47. package/lib/module/hover-card/HoverCard.js.map +1 -0
  48. package/lib/module/hover-card/HoverCard.web.js +147 -0
  49. package/lib/module/hover-card/HoverCard.web.js.map +1 -0
  50. package/lib/module/hover-card/HoverCardPanel.js +95 -0
  51. package/lib/module/hover-card/HoverCardPanel.js.map +1 -0
  52. package/lib/module/hover-card/constants.js +21 -0
  53. package/lib/module/hover-card/constants.js.map +1 -0
  54. package/lib/module/hover-card/context.js +30 -0
  55. package/lib/module/hover-card/context.js.map +1 -0
  56. package/lib/module/hover-card/index.js +5 -0
  57. package/lib/module/hover-card/index.js.map +1 -0
  58. package/lib/module/hover-card/index.web.js +5 -0
  59. package/lib/module/hover-card/index.web.js.map +1 -0
  60. package/lib/module/hover-card/types.js +4 -0
  61. package/lib/module/hover-card/types.js.map +1 -0
  62. package/lib/module/hover-card/use-hover-intent.js +46 -0
  63. package/lib/module/hover-card/use-hover-intent.js.map +1 -0
  64. package/lib/module/index.js +1 -0
  65. package/lib/module/index.js.map +1 -1
  66. package/lib/module/index.web.js +1 -0
  67. package/lib/module/index.web.js.map +1 -1
  68. package/lib/module/styles/web-view-style.js +23 -0
  69. package/lib/module/styles/web-view-style.js.map +1 -1
  70. package/lib/module/user-hover-card/UserHoverCard.js +15 -5
  71. package/lib/module/user-hover-card/UserHoverCard.js.map +1 -1
  72. package/lib/module/user-hover-card/constants.js +9 -2
  73. package/lib/module/user-hover-card/constants.js.map +1 -1
  74. package/lib/typescript/commonjs/app-shell/AppShell.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/app-shell/types.d.ts +14 -0
  76. package/lib/typescript/commonjs/app-shell/types.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/avatar-group/AvatarGroup.web.d.ts.map +1 -1
  78. package/lib/typescript/commonjs/floating/use-anchor-rect.d.ts +7 -0
  79. package/lib/typescript/commonjs/floating/use-anchor-rect.d.ts.map +1 -1
  80. package/lib/typescript/commonjs/hover-card/HoverCard.d.ts +5 -0
  81. package/lib/typescript/commonjs/hover-card/HoverCard.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/hover-card/HoverCard.web.d.ts +5 -0
  83. package/lib/typescript/commonjs/hover-card/HoverCard.web.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/hover-card/HoverCardPanel.d.ts +45 -0
  85. package/lib/typescript/commonjs/hover-card/HoverCardPanel.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/hover-card/constants.d.ts +16 -0
  87. package/lib/typescript/commonjs/hover-card/constants.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/hover-card/context.d.ts +21 -0
  89. package/lib/typescript/commonjs/hover-card/context.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/hover-card/index.d.ts +4 -0
  91. package/lib/typescript/commonjs/hover-card/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/hover-card/index.web.d.ts +4 -0
  93. package/lib/typescript/commonjs/hover-card/index.web.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/hover-card/types.d.ts +50 -0
  95. package/lib/typescript/commonjs/hover-card/types.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/hover-card/use-hover-intent.d.ts +14 -0
  97. package/lib/typescript/commonjs/hover-card/use-hover-intent.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/index.d.ts +1 -0
  99. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  100. package/lib/typescript/commonjs/index.web.d.ts +1 -0
  101. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  102. package/lib/typescript/commonjs/styles/web-view-style.d.ts +19 -0
  103. package/lib/typescript/commonjs/styles/web-view-style.d.ts.map +1 -1
  104. package/lib/typescript/commonjs/user-hover-card/UserHoverCard.d.ts.map +1 -1
  105. package/lib/typescript/commonjs/user-hover-card/constants.d.ts +6 -1
  106. package/lib/typescript/commonjs/user-hover-card/constants.d.ts.map +1 -1
  107. package/lib/typescript/module/app-shell/AppShell.d.ts.map +1 -1
  108. package/lib/typescript/module/app-shell/types.d.ts +14 -0
  109. package/lib/typescript/module/app-shell/types.d.ts.map +1 -1
  110. package/lib/typescript/module/avatar-group/AvatarGroup.web.d.ts.map +1 -1
  111. package/lib/typescript/module/floating/use-anchor-rect.d.ts +7 -0
  112. package/lib/typescript/module/floating/use-anchor-rect.d.ts.map +1 -1
  113. package/lib/typescript/module/hover-card/HoverCard.d.ts +5 -0
  114. package/lib/typescript/module/hover-card/HoverCard.d.ts.map +1 -0
  115. package/lib/typescript/module/hover-card/HoverCard.web.d.ts +5 -0
  116. package/lib/typescript/module/hover-card/HoverCard.web.d.ts.map +1 -0
  117. package/lib/typescript/module/hover-card/HoverCardPanel.d.ts +45 -0
  118. package/lib/typescript/module/hover-card/HoverCardPanel.d.ts.map +1 -0
  119. package/lib/typescript/module/hover-card/constants.d.ts +16 -0
  120. package/lib/typescript/module/hover-card/constants.d.ts.map +1 -0
  121. package/lib/typescript/module/hover-card/context.d.ts +21 -0
  122. package/lib/typescript/module/hover-card/context.d.ts.map +1 -0
  123. package/lib/typescript/module/hover-card/index.d.ts +4 -0
  124. package/lib/typescript/module/hover-card/index.d.ts.map +1 -0
  125. package/lib/typescript/module/hover-card/index.web.d.ts +4 -0
  126. package/lib/typescript/module/hover-card/index.web.d.ts.map +1 -0
  127. package/lib/typescript/module/hover-card/types.d.ts +50 -0
  128. package/lib/typescript/module/hover-card/types.d.ts.map +1 -0
  129. package/lib/typescript/module/hover-card/use-hover-intent.d.ts +14 -0
  130. package/lib/typescript/module/hover-card/use-hover-intent.d.ts.map +1 -0
  131. package/lib/typescript/module/index.d.ts +1 -0
  132. package/lib/typescript/module/index.d.ts.map +1 -1
  133. package/lib/typescript/module/index.web.d.ts +1 -0
  134. package/lib/typescript/module/index.web.d.ts.map +1 -1
  135. package/lib/typescript/module/styles/web-view-style.d.ts +19 -0
  136. package/lib/typescript/module/styles/web-view-style.d.ts.map +1 -1
  137. package/lib/typescript/module/user-hover-card/UserHoverCard.d.ts.map +1 -1
  138. package/lib/typescript/module/user-hover-card/constants.d.ts +6 -1
  139. package/lib/typescript/module/user-hover-card/constants.d.ts.map +1 -1
  140. package/package.json +20 -1
  141. package/src/app-shell/AppShell.tsx +83 -16
  142. package/src/app-shell/types.ts +14 -0
  143. package/src/avatar-group/AvatarGroup.web.tsx +57 -126
  144. package/src/floating/use-anchor-rect.ts +1 -1
  145. package/src/hover-card/HoverCard.tsx +90 -0
  146. package/src/hover-card/HoverCard.web.tsx +160 -0
  147. package/src/hover-card/HoverCardPanel.tsx +112 -0
  148. package/src/hover-card/constants.ts +18 -0
  149. package/src/hover-card/context.ts +45 -0
  150. package/src/hover-card/index.ts +7 -0
  151. package/src/hover-card/index.web.ts +7 -0
  152. package/src/hover-card/types.ts +53 -0
  153. package/src/hover-card/use-hover-intent.ts +47 -0
  154. package/src/index.ts +1 -0
  155. package/src/index.web.ts +1 -0
  156. package/src/styles/web-view-style.ts +23 -0
  157. package/src/user-hover-card/UserHoverCard.tsx +30 -18
  158. package/src/user-hover-card/constants.ts +9 -2
@@ -1,5 +1,5 @@
1
1
  import React, { memo, useEffect } from 'react';
2
- import { Pressable, ScrollView, View, useWindowDimensions } from 'react-native';
2
+ import { Platform, Pressable, ScrollView, View, useWindowDimensions } from 'react-native';
3
3
  import Animated, {
4
4
  Easing,
5
5
  useAnimatedStyle,
@@ -14,6 +14,14 @@ import { Backdrop, OverlayRoot } from '../overlay';
14
14
  import { Portal } from '../portal';
15
15
  import { Sidebar } from '../sidebar';
16
16
  import { BREAKPOINTS } from '../styles/breakpoints';
17
+ import {
18
+ WEB_OVERFLOW_CLIP,
19
+ WEB_POSITION_FIXED,
20
+ WEB_POSITION_STICKY,
21
+ WEB_VIEWPORT_HEIGHT,
22
+ webViewportHeightMinus,
23
+ type WebCssStyle,
24
+ } from '../styles/web-view-style';
17
25
  import { useTheme } from '../theme/use-theme';
18
26
  import { AppShellHeader } from './AppShellHeader';
19
27
  import type { AppShellProps } from './types';
@@ -26,7 +34,8 @@ import type { AppShellProps } from './types';
26
34
  * lg and up the sidebar in flow (from `sm` for `variant: 'rail'`, whose
27
35
  * drawer below `sm` opens the panel); `overlay` pads the whole frame 12 with a
28
36
  * 16 gap, `reveal` sits the rail 12 from the top-left
29
- * main scrolls; the content column is centred, max 1300, gap 10:
37
+ * main scrolls — on web the DOCUMENT (see `scroll`), elsewhere its own
38
+ * ScrollView; the content column is centred, max 1300, gap 10:
30
39
  * header (breadcrumb + title row), then the content (gap 16,
31
40
  * 16 below). `overlay` insets the column 12 from the top at `sm`,
32
41
  * `reveal` pads the page 12 (24 on top at `sm`)
@@ -42,6 +51,29 @@ const REVEAL_EASE = Easing.bezier(0.42, 0, 0.58, 1);
42
51
  const REVEAL_MS = 325;
43
52
  const REVEAL_OFFSET = 272;
44
53
 
54
+ /**
55
+ * The page's scroller. In `document` mode it is a plain box and the page grows
56
+ * the document; otherwise a `ScrollView` filling the frame.
57
+ */
58
+ function Scroller({
59
+ document: inDocument,
60
+ style,
61
+ contentStyle,
62
+ children,
63
+ }: {
64
+ document: boolean;
65
+ style: WebCssStyle;
66
+ contentStyle: WebCssStyle;
67
+ children: React.ReactNode;
68
+ }) {
69
+ if (inDocument) return <View style={[style, contentStyle]}>{children}</View>;
70
+ return (
71
+ <ScrollView style={[{ flex: 1 }, style]} contentContainerStyle={contentStyle}>
72
+ {children}
73
+ </ScrollView>
74
+ );
75
+ }
76
+
45
77
  const AppShellComponent: React.FC<AppShellProps> = ({
46
78
  sidebar,
47
79
  drawer = 'overlay',
@@ -54,11 +86,14 @@ const AppShellComponent: React.FC<AppShellProps> = ({
54
86
  overlay,
55
87
  drawerOpen,
56
88
  onDrawerOpenChange,
89
+ scroll = 'document',
57
90
  style,
58
91
  testID,
59
92
  }) => {
60
93
  const theme = useTheme();
61
94
  const { width } = useWindowDimensions();
95
+ // Native has no document; `scroll` only chooses on web.
96
+ const doc = Platform.OS === 'web' && scroll === 'document';
62
97
  const small = width >= BREAKPOINTS.sm;
63
98
  // The rail is narrow enough to stay in flow from `sm`; the panel needs `lg`.
64
99
  const rail = sidebar?.variant === 'rail';
@@ -115,10 +150,10 @@ const AppShellComponent: React.FC<AppShellProps> = ({
115
150
  return (
116
151
  <View
117
152
  testID={testID}
118
- style={[{ flex: 1, height: '100%', flexDirection: 'row', overflow: 'hidden', backgroundColor: background }, style]}
153
+ style={[doc ? revealDocumentRoot : { flex: 1, height: '100%', overflow: 'hidden' }, { flexDirection: 'row', backgroundColor: background }, style]}
119
154
  >
120
155
  {sidebar && wide ? (
121
- <View style={{ paddingTop: 12, paddingBottom: 12, paddingLeft: 12, flexShrink: 0 }}>
156
+ <View style={[{ paddingTop: 12, paddingBottom: 12, paddingLeft: 12, flexShrink: 0 }, doc ? stickyRail(0) : null]}>
122
157
  <Sidebar {...sidebar} />
123
158
  </View>
124
159
  ) : null}
@@ -126,7 +161,9 @@ const AppShellComponent: React.FC<AppShellProps> = ({
126
161
  <View
127
162
  aria-hidden={!isOpen}
128
163
  pointerEvents={isOpen ? 'auto' : 'none'}
129
- style={{ position: 'absolute', top: 0, bottom: 0, left: 0, width: 272, paddingTop: 12, paddingBottom: 12, paddingLeft: 6 }}
164
+ // Fixed on web in document mode: the rail waits beneath the VIEWPORT,
165
+ // wherever the page is scrolled to.
166
+ style={{ position: doc ? WEB_POSITION_FIXED : 'absolute', top: 0, bottom: 0, left: 0, width: 272, paddingTop: 12, paddingBottom: 12, paddingLeft: 6 }}
130
167
  >
131
168
  <Animated.View style={[{ height: '100%', width: 260, transformOrigin: 'left center' }, railStyle]}>
132
169
  <Sidebar {...drawerSidebar} mobile flat onClose={() => setOpen(false)} />
@@ -134,14 +171,11 @@ const AppShellComponent: React.FC<AppShellProps> = ({
134
171
  </View>
135
172
  ) : null}
136
173
  <Animated.View
137
- style={[{ flex: 1, minWidth: 0, overflow: 'hidden', backgroundColor: background }, wide ? null : pageStyle]}
174
+ style={[{ flex: 1, minWidth: 0, overflow: doc ? WEB_OVERFLOW_CLIP : 'hidden', backgroundColor: background }, wide ? null : pageStyle]}
138
175
  >
139
- <ScrollView
140
- style={{ flex: 1 }}
141
- contentContainerStyle={{ padding: 12, paddingTop: small ? 24 : 12 }}
142
- >
176
+ <Scroller document={doc} style={{}} contentStyle={{ padding: 12, paddingTop: small ? 24 : 12 }}>
143
177
  {column}
144
- </ScrollView>
178
+ </Scroller>
145
179
  {!wide ? (
146
180
  <Animated.View
147
181
  pointerEvents={isOpen ? 'auto' : 'none'}
@@ -170,11 +204,20 @@ const AppShellComponent: React.FC<AppShellProps> = ({
170
204
  <View
171
205
  testID={testID}
172
206
  style={[
173
- { flex: 1, height: '100%', flexDirection: 'row', gap: 16, overflow: 'hidden', padding: 12, backgroundColor: background },
207
+ doc ? documentRoot : { flex: 1, height: '100%', overflow: 'hidden' },
208
+ { flexDirection: 'row', gap: 16, padding: 12, backgroundColor: background },
174
209
  style,
175
210
  ]}
176
211
  >
177
- {sidebar && wide ? <Sidebar {...sidebar} /> : null}
212
+ {sidebar && wide ? (
213
+ doc ? (
214
+ <View style={stickyRail(12)}>
215
+ <Sidebar {...sidebar} />
216
+ </View>
217
+ ) : (
218
+ <Sidebar {...sidebar} />
219
+ )
220
+ ) : null}
178
221
  {sidebar && isOpen ? (
179
222
  <Portal>
180
223
  <OverlayRoot>
@@ -195,16 +238,40 @@ const AppShellComponent: React.FC<AppShellProps> = ({
195
238
  </OverlayRoot>
196
239
  </Portal>
197
240
  ) : null}
198
- <ScrollView
241
+ <Scroller
242
+ document={doc}
199
243
  style={{ flex: 1, minWidth: 0, backgroundColor: background }}
200
- contentContainerStyle={{ paddingTop: small ? 12 : 0 }}
244
+ contentStyle={{ paddingTop: small ? 12 : 0 }}
201
245
  >
202
246
  {column}
203
- </ScrollView>
247
+ </Scroller>
204
248
  {overlay}
205
249
  </View>
206
250
  );
207
251
  };
208
252
 
253
+ /**
254
+ * Document mode: the frame is at least one viewport tall and grows with the
255
+ * page, so the browser scrolls the document (scroll restoration, the address
256
+ * bar collapsing, anchor links, `window.scrollTo`) exactly as it does for a
257
+ * `ContentPanel` page. Nothing here may be a scroll container — no `hidden`
258
+ * overflow — or the sticky rail would stick to a box that never scrolls.
259
+ */
260
+ const documentRoot: WebCssStyle = { flexGrow: 1, minHeight: WEB_VIEWPORT_HEIGHT };
261
+ // The page slides 272 right under `reveal`; `clip` keeps that from widening the
262
+ // document with a horizontal scrollbar, without becoming a scroll container.
263
+ const revealDocumentRoot: WebCssStyle = { ...documentRoot, overflow: WEB_OVERFLOW_CLIP };
264
+
265
+ /** The in-flow rail, pinned to the viewport while the document scrolls under it. */
266
+ function stickyRail(inset: number): WebCssStyle {
267
+ return {
268
+ position: WEB_POSITION_STICKY,
269
+ top: inset,
270
+ height: webViewportHeightMinus(inset * 2),
271
+ alignSelf: 'flex-start',
272
+ flexShrink: 0,
273
+ };
274
+ }
275
+
209
276
  export const AppShell = memo(AppShellComponent);
210
277
  AppShell.displayName = 'AppShell';
@@ -37,6 +37,20 @@ export interface AppShellProps {
37
37
  /** Controlled drawer state (below `lg`). */
38
38
  drawerOpen?: boolean;
39
39
  onDrawerOpenChange?: (open: boolean) => void;
40
+ /**
41
+ * What scrolls the page on WEB.
42
+ *
43
+ * - `document` (default) — the page grows the document and the browser
44
+ * scrolls it, like a `ContentPanel` page: scroll restoration, the mobile
45
+ * address bar collapsing, anchor links and `window.scrollTo` all work, and
46
+ * the in-flow sidebar stays pinned (`position: sticky`).
47
+ * - `container` — the shell fills its parent and the page scrolls inside its
48
+ * own `ScrollView`. For a shell embedded in a bounded box rather than
49
+ * owning the page.
50
+ *
51
+ * Native has no document and always scrolls its own `ScrollView`.
52
+ */
53
+ scroll?: 'document' | 'container';
40
54
  style?: StyleProp<ViewStyle>;
41
55
  testID?: string;
42
56
  }
@@ -1,16 +1,12 @@
1
1
  import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
2
- import { StyleSheet, View } from 'react-native';
2
+ import type { View } from 'react-native';
3
3
 
4
- import { OverlayRoot } from '../overlay';
5
- // `../portal/index.web`, not `../portal`: export conditions do not apply to
6
- // relative specifiers, so the bare name resolves to the NATIVE barrel in any
7
- // bundler that does not add web extensions to its resolution order. The native
8
- // Portal renders into a `PortalOutlet`, which a web app never mounts — both are
9
- // no-ops in the web fork — so the hover card would render nothing at all.
10
- // `Dialog.web.tsx` and `BottomSheet.web.tsx` already name it this way.
11
- import { Portal } from '../portal/index.web';
12
- import { WEB_POSITION_FIXED } from '../styles/web-view-style';
13
- import { USER_HOVER_CARD_WIDTH, UserHoverCard } from '../user-hover-card';
4
+ import type { FloatingAnchor } from '../floating/types';
5
+ import { rectOf } from '../floating/use-anchor-rect';
6
+ import { HOVER_CARD_CLOSE_DELAY } from '../hover-card/constants';
7
+ import { HoverCardPanel } from '../hover-card/HoverCardPanel';
8
+ import { useHoverIntent } from '../hover-card/use-hover-intent';
9
+ import { UserHoverCard } from '../user-hover-card';
14
10
  import {
15
11
  AvatarGroupBase,
16
12
  getItemName,
@@ -18,46 +14,33 @@ import {
18
14
  } from './AvatarGroupBase';
19
15
  import type { AvatarGroupItem, AvatarGroupProps } from './types';
20
16
 
21
- /** Delay before dismissing the card so the cursor can travel into it. */
22
- const CLOSE_DELAY_MS = 120;
23
- /** Gap between the anchored avatar and the floating card. */
24
- const CARD_GAP = 8;
25
- // The card's own width, never a second copy of it: this file CENTRES the card
26
- // on its anchor, so a private constant would mis-place it the first time
27
- // either number moved, and nothing would error.
28
- const CARD_WIDTH = USER_HOVER_CARD_WIDTH;
29
-
30
- interface HoverState {
17
+ interface HoverTarget {
31
18
  item: AvatarGroupItem;
32
19
  index: number;
33
- top: number;
34
- left: number;
20
+ anchor: FloatingAnchor;
35
21
  }
36
22
 
37
23
  /**
38
24
  * Web `AvatarGroup`. Identical layout rendering to native (stack / row /
39
25
  * cluster) via {@link AvatarGroupBase}, plus an optional hover card: when
40
26
  * `hoverCard` is enabled, hovering an avatar reveals a {@link UserHoverCard}
41
- * positioned beneath it. The card receives the per-item `renderItemAction` slot
42
- * so the app can drop its SDK FollowButton inside.
27
+ * beneath it. The card receives the per-item `renderItemAction` slot so the app
28
+ * can drop its SDK FollowButton inside.
29
+ *
30
+ * The card floats in `HoverCardPanel`, the same surface `HoverCardContent`
31
+ * renders — placement (flip and clamp), motion, Escape and outside-press
32
+ * dismissal, and the pointer bridge all come from there. What stays here is the
33
+ * one thing a single `HoverCard` cannot do: ONE card serving every face, which
34
+ * re-anchors as the cursor moves along the pile instead of closing and
35
+ * reopening per avatar. It opens with no delay for the same reason — the
36
+ * pointer is already on a row of people, and the card is what it came for.
43
37
  */
44
38
  const AvatarGroupWebComponent: React.FC<AvatarGroupProps> = (props) => {
45
39
  const { hoverCard, renderItemAction, onPressItem } = props;
46
- const [hover, setHover] = useState<HoverState | null>(null);
40
+ const [target, setTarget] = useState<HoverTarget | null>(null);
41
+ const [open, setOpen] = useState(false);
47
42
  const cellRefs = useRef<Map<number, View>>(new Map());
48
- const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
49
-
50
- const cancelClose = useCallback(() => {
51
- if (closeTimer.current) {
52
- clearTimeout(closeTimer.current);
53
- closeTimer.current = null;
54
- }
55
- }, []);
56
-
57
- const scheduleClose = useCallback(() => {
58
- cancelClose();
59
- closeTimer.current = setTimeout(() => setHover(null), CLOSE_DELAY_MS);
60
- }, [cancelClose]);
43
+ const { show, hide, hold } = useHoverIntent(open, setOpen, 0, HOVER_CARD_CLOSE_DELAY);
61
44
 
62
45
  const registerCellRef = useCallback((index: number, node: View | null) => {
63
46
  if (node) cellRefs.current.set(index, node);
@@ -66,109 +49,57 @@ const AvatarGroupWebComponent: React.FC<AvatarGroupProps> = (props) => {
66
49
 
67
50
  const handleHoverIn = useCallback(
68
51
  (item: AvatarGroupItem, index: number) => {
69
- cancelClose();
70
- const node = cellRefs.current.get(index);
71
- if (!node) return;
72
- node.measureInWindow((x, y, width, height) => {
73
- // Center the card under the avatar, clamped to the viewport.
74
- const viewportWidth =
75
- typeof window !== 'undefined' ? window.innerWidth : CARD_WIDTH;
76
- let left = x + width / 2 - CARD_WIDTH / 2;
77
- left = Math.max(
78
- CARD_GAP,
79
- Math.min(left, viewportWidth - CARD_WIDTH - CARD_GAP),
80
- );
81
- setHover({
82
- item,
83
- index,
84
- top: y + height + CARD_GAP,
85
- left,
86
- });
87
- });
52
+ const anchor = rectOf(cellRefs.current.get(index) ?? null);
53
+ if (!anchor) return;
54
+ setTarget({ item, index, anchor });
55
+ show();
88
56
  },
89
- [cancelClose],
57
+ [show],
90
58
  );
91
59
 
60
+ const dismiss = useCallback(() => {
61
+ hold();
62
+ setOpen(false);
63
+ }, [hold]);
64
+
92
65
  const hoverHandlers = useMemo<AvatarGroupCellHoverHandlers | undefined>(() => {
93
66
  if (!hoverCard) return undefined;
94
67
  return {
95
68
  onHoverIn: handleHoverIn,
96
- onHoverOut: scheduleClose,
69
+ onHoverOut: hide,
97
70
  registerCellRef,
98
71
  };
99
- }, [hoverCard, handleHoverIn, scheduleClose, registerCellRef]);
72
+ }, [hoverCard, handleHoverIn, hide, registerCellRef]);
100
73
 
101
74
  return (
102
75
  <>
103
76
  <AvatarGroupBase {...props} hoverHandlers={hoverHandlers} />
104
- {hoverCard && hover && (
105
- <Portal>
106
- {/* The hover card stacks by when it opened, like every other Bloom
107
- overlay (`src/overlay/stack.ts`). `box-none` keeps the area
108
- around it click-through. */}
109
- <OverlayRoot>
110
- {/*
111
- The hover-bridge keeps the card open while the cursor is over it.
112
- It is a `View` with the W3C pointer events (in React Native's own
113
- `ViewProps`, forwarded to the DOM by react-native-web — so no
114
- web-only type suppression) and NOT a `Pressable`, which is what it
115
- used to be.
116
-
117
- A `Pressable` bridge closes the card the moment the cursor reaches
118
- anything pressable INSIDE it — the identity area, or a FollowButton
119
- in the `action` slot. react-native-web's `Pressable` calls
120
- `useHover` with `contain: true`, which dispatches a BUBBLING
121
- `react-gui:hover:lock` event on itself; an ancestor `Pressable`
122
- that is currently hovered ends its own hover for any lock whose
123
- target is not itself. So a descendant `Pressable` fired this
124
- bridge's `onHoverOut` and the card dismissed ~120ms later, with
125
- nothing in the console. Measured in Chrome; jest cannot see it.
126
-
127
- `pointerenter`/`pointerleave` do not bubble and do not fire when
128
- the cursor moves between descendants, which is exactly the
129
- containment the bridge needs.
130
- */}
131
- <View
132
- onPointerEnter={cancelClose}
133
- onPointerLeave={scheduleClose}
134
- pointerEvents="auto"
135
- style={[
136
- webStyles.floating,
137
- { top: hover.top, left: hover.left, width: CARD_WIDTH },
138
- ]}
139
- >
140
- <UserHoverCard
141
- avatar={hover.item.uri ?? undefined}
142
- // `UserHoverCardProps.displayName` is contractually an
143
- // already-resolved string, and resolving it is precisely this
144
- // component's job. `''` is the honest terminal case: no field on
145
- // the item named the person at all, so there is nothing to show.
146
- displayName={getItemName(hover.item) ?? ''}
147
- username={hover.item.username}
148
- onPressProfile={
149
- onPressItem
150
- ? () => onPressItem(hover.item, hover.index)
151
- : undefined
152
- }
153
- action={renderItemAction?.(hover.item, hover.index)}
154
- style={webStyles.card}
155
- />
156
- </View>
157
- </OverlayRoot>
158
- </Portal>
159
- )}
77
+ {hoverCard && target ? (
78
+ <HoverCardPanel
79
+ open={open}
80
+ anchor={open ? target.anchor : null}
81
+ onDismiss={dismiss}
82
+ onPointerEnter={hold}
83
+ onPointerLeave={hide}
84
+ label={getItemName(target.item) ?? 'Profile'}>
85
+ <UserHoverCard
86
+ avatar={target.item.uri ?? undefined}
87
+ // `UserHoverCardProps.displayName` is contractually an
88
+ // already-resolved string, and resolving it is precisely this
89
+ // component's job. `''` is the honest terminal case: no field on the
90
+ // item named the person at all, so there is nothing to show.
91
+ displayName={getItemName(target.item) ?? ''}
92
+ username={target.item.username}
93
+ onPressProfile={
94
+ onPressItem ? () => onPressItem(target.item, target.index) : undefined
95
+ }
96
+ action={renderItemAction?.(target.item, target.index)}
97
+ />
98
+ </HoverCardPanel>
99
+ ) : null}
160
100
  </>
161
101
  );
162
102
  };
163
103
 
164
- const webStyles = StyleSheet.create({
165
- floating: {
166
- position: WEB_POSITION_FIXED,
167
- },
168
- card: {
169
- width: CARD_WIDTH,
170
- },
171
- });
172
-
173
104
  export const AvatarGroup = memo(AvatarGroupWebComponent);
174
105
  AvatarGroup.displayName = 'AvatarGroup';
@@ -19,7 +19,7 @@ import type { FloatingAnchor } from './types';
19
19
  * interface, so a ref that is NOT a DOM node (a jsdom stub, a native build that
20
20
  * reached this file by accident) answers `null` instead of throwing.
21
21
  */
22
- function rectOf(node: View | null): FloatingAnchor | null {
22
+ export function rectOf(node: View | null): FloatingAnchor | null {
23
23
  const element = node as unknown as { getBoundingClientRect?: () => DOMRect } | null;
24
24
  if (typeof element?.getBoundingClientRect !== 'function') return null;
25
25
  const box = element.getBoundingClientRect();
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `HoverCard` — NATIVE. There is no hover on a touch screen, so the card opens
3
+ * on a LONG PRESS of the trigger and presents as a bottom sheet — the shell
4
+ * `Popover`, `DropdownMenu` and `Select` use. A plain press stays with the
5
+ * element under the finger, which is what makes a hover card safe to put on a
6
+ * link or an avatar that already navigates.
7
+ *
8
+ * `openDelay` / `closeDelay` do nothing here: a long press is its own intent.
9
+ */
10
+ import React, { useCallback, useMemo, useRef } from 'react';
11
+ import type { View } from 'react-native';
12
+
13
+ import { SheetShell } from '../dialog/SheetShell';
14
+ import { TriggerSlot } from '../floating/TriggerSlot';
15
+ import { useSheetOpenBridge } from '../floating/use-sheet-open-bridge';
16
+ import { useControllableState } from '../hooks/use-controllable-state';
17
+ import { HOVER_CARD_TRIGGER_POPUP } from './constants';
18
+ import { HoverCardProvider, useHoverCard } from './context';
19
+ import type { HoverCardContentProps, HoverCardProps, HoverCardTriggerProps } from './types';
20
+
21
+ const noop = () => {};
22
+
23
+ export function HoverCard({ children, open, defaultOpen = false, onOpenChange }: HoverCardProps) {
24
+ const [isOpen, setOpen] = useControllableState<boolean>({
25
+ value: open,
26
+ defaultValue: defaultOpen,
27
+ onChange: onOpenChange,
28
+ });
29
+ const anchorRef = useRef<View | null>(null);
30
+ const value = useMemo(
31
+ () => ({
32
+ open: isOpen,
33
+ setOpen,
34
+ anchorRef,
35
+ show: () => setOpen(true),
36
+ hide: () => setOpen(false),
37
+ hold: noop,
38
+ }),
39
+ [isOpen, setOpen],
40
+ );
41
+
42
+ return <HoverCardProvider value={value}>{children}</HoverCardProvider>;
43
+ }
44
+
45
+ export function HoverCardTrigger({
46
+ children,
47
+ asChild,
48
+ disabled,
49
+ className,
50
+ style,
51
+ testID,
52
+ }: HoverCardTriggerProps) {
53
+ const card = useHoverCard();
54
+ const { setOpen } = card;
55
+ const openCard = useCallback(() => setOpen(true), [setOpen]);
56
+
57
+ return (
58
+ <TriggerSlot
59
+ asChild={asChild}
60
+ anchorRef={card.anchorRef}
61
+ className={className}
62
+ style={style}
63
+ testID={testID}
64
+ handle={{
65
+ // The press belongs to the child; composing a no-op keeps its own.
66
+ onPress: noop,
67
+ onLongPress: openCard,
68
+ disabled,
69
+ 'aria-haspopup': HOVER_CARD_TRIGGER_POPUP,
70
+ 'aria-expanded': card.open,
71
+ }}>
72
+ {children}
73
+ </TriggerSlot>
74
+ );
75
+ }
76
+
77
+ export function HoverCardContent({ children, label = 'Hover card', style }: HoverCardContentProps) {
78
+ const card = useHoverCard();
79
+ const { control, onSheetClose } = useSheetOpenBridge(card.open, card.setOpen);
80
+
81
+ return (
82
+ <SheetShell
83
+ control={control}
84
+ label={label}
85
+ onClose={onSheetClose}
86
+ contentStyle={[{ alignItems: 'center' }, style]}>
87
+ {children}
88
+ </SheetShell>
89
+ );
90
+ }