@oxy.so/bloom 2.4.0 → 2.5.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 (136) hide show
  1. package/README.md +3 -3
  2. package/docs/avatar-group.mdx +10 -17
  3. package/docs/hover-card.mdx +125 -0
  4. package/docs/user-hover-card.mdx +29 -9
  5. package/lib/commonjs/avatar-group/AvatarGroup.web.js +55 -85
  6. package/lib/commonjs/avatar-group/AvatarGroup.web.js.map +1 -1
  7. package/lib/commonjs/floating/use-anchor-rect.js +1 -0
  8. package/lib/commonjs/floating/use-anchor-rect.js.map +1 -1
  9. package/lib/commonjs/hover-card/HoverCard.js +104 -0
  10. package/lib/commonjs/hover-card/HoverCard.js.map +1 -0
  11. package/lib/commonjs/hover-card/HoverCard.web.js +155 -0
  12. package/lib/commonjs/hover-card/HoverCard.web.js.map +1 -0
  13. package/lib/commonjs/hover-card/HoverCardPanel.js +101 -0
  14. package/lib/commonjs/hover-card/HoverCardPanel.js.map +1 -0
  15. package/lib/commonjs/hover-card/constants.js +25 -0
  16. package/lib/commonjs/hover-card/constants.js.map +1 -0
  17. package/lib/commonjs/hover-card/context.js +37 -0
  18. package/lib/commonjs/hover-card/context.js.map +1 -0
  19. package/lib/commonjs/hover-card/index.js +44 -0
  20. package/lib/commonjs/hover-card/index.js.map +1 -0
  21. package/lib/commonjs/hover-card/index.web.js +44 -0
  22. package/lib/commonjs/hover-card/index.web.js.map +1 -0
  23. package/lib/commonjs/hover-card/types.js +6 -0
  24. package/lib/commonjs/hover-card/types.js.map +1 -0
  25. package/lib/commonjs/hover-card/use-hover-intent.js +49 -0
  26. package/lib/commonjs/hover-card/use-hover-intent.js.map +1 -0
  27. package/lib/commonjs/index.js +12 -0
  28. package/lib/commonjs/index.js.map +1 -1
  29. package/lib/commonjs/index.web.js +16 -4
  30. package/lib/commonjs/index.web.js.map +1 -1
  31. package/lib/commonjs/user-hover-card/UserHoverCard.js +16 -6
  32. package/lib/commonjs/user-hover-card/UserHoverCard.js.map +1 -1
  33. package/lib/commonjs/user-hover-card/constants.js +8 -2
  34. package/lib/commonjs/user-hover-card/constants.js.map +1 -1
  35. package/lib/module/avatar-group/AvatarGroup.web.js +55 -84
  36. package/lib/module/avatar-group/AvatarGroup.web.js.map +1 -1
  37. package/lib/module/floating/use-anchor-rect.js +1 -1
  38. package/lib/module/floating/use-anchor-rect.js.map +1 -1
  39. package/lib/module/hover-card/HoverCard.js +96 -0
  40. package/lib/module/hover-card/HoverCard.js.map +1 -0
  41. package/lib/module/hover-card/HoverCard.web.js +147 -0
  42. package/lib/module/hover-card/HoverCard.web.js.map +1 -0
  43. package/lib/module/hover-card/HoverCardPanel.js +95 -0
  44. package/lib/module/hover-card/HoverCardPanel.js.map +1 -0
  45. package/lib/module/hover-card/constants.js +21 -0
  46. package/lib/module/hover-card/constants.js.map +1 -0
  47. package/lib/module/hover-card/context.js +30 -0
  48. package/lib/module/hover-card/context.js.map +1 -0
  49. package/lib/module/hover-card/index.js +5 -0
  50. package/lib/module/hover-card/index.js.map +1 -0
  51. package/lib/module/hover-card/index.web.js +5 -0
  52. package/lib/module/hover-card/index.web.js.map +1 -0
  53. package/lib/module/hover-card/types.js +4 -0
  54. package/lib/module/hover-card/types.js.map +1 -0
  55. package/lib/module/hover-card/use-hover-intent.js +46 -0
  56. package/lib/module/hover-card/use-hover-intent.js.map +1 -0
  57. package/lib/module/index.js +1 -0
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/index.web.js +1 -0
  60. package/lib/module/index.web.js.map +1 -1
  61. package/lib/module/user-hover-card/UserHoverCard.js +15 -5
  62. package/lib/module/user-hover-card/UserHoverCard.js.map +1 -1
  63. package/lib/module/user-hover-card/constants.js +9 -2
  64. package/lib/module/user-hover-card/constants.js.map +1 -1
  65. package/lib/typescript/commonjs/avatar-group/AvatarGroup.web.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/floating/use-anchor-rect.d.ts +7 -0
  67. package/lib/typescript/commonjs/floating/use-anchor-rect.d.ts.map +1 -1
  68. package/lib/typescript/commonjs/hover-card/HoverCard.d.ts +5 -0
  69. package/lib/typescript/commonjs/hover-card/HoverCard.d.ts.map +1 -0
  70. package/lib/typescript/commonjs/hover-card/HoverCard.web.d.ts +5 -0
  71. package/lib/typescript/commonjs/hover-card/HoverCard.web.d.ts.map +1 -0
  72. package/lib/typescript/commonjs/hover-card/HoverCardPanel.d.ts +45 -0
  73. package/lib/typescript/commonjs/hover-card/HoverCardPanel.d.ts.map +1 -0
  74. package/lib/typescript/commonjs/hover-card/constants.d.ts +16 -0
  75. package/lib/typescript/commonjs/hover-card/constants.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/hover-card/context.d.ts +21 -0
  77. package/lib/typescript/commonjs/hover-card/context.d.ts.map +1 -0
  78. package/lib/typescript/commonjs/hover-card/index.d.ts +4 -0
  79. package/lib/typescript/commonjs/hover-card/index.d.ts.map +1 -0
  80. package/lib/typescript/commonjs/hover-card/index.web.d.ts +4 -0
  81. package/lib/typescript/commonjs/hover-card/index.web.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/hover-card/types.d.ts +50 -0
  83. package/lib/typescript/commonjs/hover-card/types.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/hover-card/use-hover-intent.d.ts +14 -0
  85. package/lib/typescript/commonjs/hover-card/use-hover-intent.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/index.d.ts +1 -0
  87. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  88. package/lib/typescript/commonjs/index.web.d.ts +1 -0
  89. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  90. package/lib/typescript/commonjs/user-hover-card/UserHoverCard.d.ts.map +1 -1
  91. package/lib/typescript/commonjs/user-hover-card/constants.d.ts +6 -1
  92. package/lib/typescript/commonjs/user-hover-card/constants.d.ts.map +1 -1
  93. package/lib/typescript/module/avatar-group/AvatarGroup.web.d.ts.map +1 -1
  94. package/lib/typescript/module/floating/use-anchor-rect.d.ts +7 -0
  95. package/lib/typescript/module/floating/use-anchor-rect.d.ts.map +1 -1
  96. package/lib/typescript/module/hover-card/HoverCard.d.ts +5 -0
  97. package/lib/typescript/module/hover-card/HoverCard.d.ts.map +1 -0
  98. package/lib/typescript/module/hover-card/HoverCard.web.d.ts +5 -0
  99. package/lib/typescript/module/hover-card/HoverCard.web.d.ts.map +1 -0
  100. package/lib/typescript/module/hover-card/HoverCardPanel.d.ts +45 -0
  101. package/lib/typescript/module/hover-card/HoverCardPanel.d.ts.map +1 -0
  102. package/lib/typescript/module/hover-card/constants.d.ts +16 -0
  103. package/lib/typescript/module/hover-card/constants.d.ts.map +1 -0
  104. package/lib/typescript/module/hover-card/context.d.ts +21 -0
  105. package/lib/typescript/module/hover-card/context.d.ts.map +1 -0
  106. package/lib/typescript/module/hover-card/index.d.ts +4 -0
  107. package/lib/typescript/module/hover-card/index.d.ts.map +1 -0
  108. package/lib/typescript/module/hover-card/index.web.d.ts +4 -0
  109. package/lib/typescript/module/hover-card/index.web.d.ts.map +1 -0
  110. package/lib/typescript/module/hover-card/types.d.ts +50 -0
  111. package/lib/typescript/module/hover-card/types.d.ts.map +1 -0
  112. package/lib/typescript/module/hover-card/use-hover-intent.d.ts +14 -0
  113. package/lib/typescript/module/hover-card/use-hover-intent.d.ts.map +1 -0
  114. package/lib/typescript/module/index.d.ts +1 -0
  115. package/lib/typescript/module/index.d.ts.map +1 -1
  116. package/lib/typescript/module/index.web.d.ts +1 -0
  117. package/lib/typescript/module/index.web.d.ts.map +1 -1
  118. package/lib/typescript/module/user-hover-card/UserHoverCard.d.ts.map +1 -1
  119. package/lib/typescript/module/user-hover-card/constants.d.ts +6 -1
  120. package/lib/typescript/module/user-hover-card/constants.d.ts.map +1 -1
  121. package/package.json +20 -1
  122. package/src/avatar-group/AvatarGroup.web.tsx +57 -126
  123. package/src/floating/use-anchor-rect.ts +1 -1
  124. package/src/hover-card/HoverCard.tsx +90 -0
  125. package/src/hover-card/HoverCard.web.tsx +160 -0
  126. package/src/hover-card/HoverCardPanel.tsx +112 -0
  127. package/src/hover-card/constants.ts +18 -0
  128. package/src/hover-card/context.ts +45 -0
  129. package/src/hover-card/index.ts +7 -0
  130. package/src/hover-card/index.web.ts +7 -0
  131. package/src/hover-card/types.ts +53 -0
  132. package/src/hover-card/use-hover-intent.ts +47 -0
  133. package/src/index.ts +1 -0
  134. package/src/index.web.ts +1 -0
  135. package/src/user-hover-card/UserHoverCard.tsx +30 -18
  136. package/src/user-hover-card/constants.ts +9 -2
@@ -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
+ }
@@ -0,0 +1,160 @@
1
+ /**
2
+ * `HoverCard` — WEB. A card that opens while the pointer rests on its trigger
3
+ * (or keyboard focus lands on it) and stays up while the pointer travels onto
4
+ * it. Positioned, portaled, ranked and dismissed by `floating/FloatingPanel`
5
+ * through `HoverCardPanel`.
6
+ *
7
+ * Touch pointers are ignored on purpose: a tap on a touch screen is a press, and
8
+ * the element under it (a link, an avatar) owns that. A touch device reaches the
9
+ * card the way native does — see `HoverCard.tsx`.
10
+ */
11
+ import React, { useCallback, useMemo, useRef } from 'react';
12
+ import type { NativeSyntheticEvent, View } from 'react-native';
13
+
14
+ import { useAnchorRect } from '../floating/use-anchor-rect';
15
+ import { useControllableState } from '../hooks/use-controllable-state';
16
+ import { StyledView } from '../styles/styled-primitives';
17
+ import {
18
+ HOVER_CARD_CLOSE_DELAY,
19
+ HOVER_CARD_OPEN_DELAY,
20
+ HOVER_CARD_TRIGGER_POPUP,
21
+ } from './constants';
22
+ import { HoverCardProvider, useHoverCard } from './context';
23
+ import { HoverCardPanel } from './HoverCardPanel';
24
+ import type { HoverCardContentProps, HoverCardProps, HoverCardTriggerProps } from './types';
25
+ import { useHoverIntent } from './use-hover-intent';
26
+
27
+ export function HoverCard({
28
+ children,
29
+ open,
30
+ defaultOpen = false,
31
+ onOpenChange,
32
+ openDelay = HOVER_CARD_OPEN_DELAY,
33
+ closeDelay = HOVER_CARD_CLOSE_DELAY,
34
+ }: HoverCardProps) {
35
+ const [isOpen, setOpen] = useControllableState<boolean>({
36
+ value: open,
37
+ defaultValue: defaultOpen,
38
+ onChange: onOpenChange,
39
+ });
40
+ const anchorRef = useRef<View | null>(null);
41
+ const intent = useHoverIntent(isOpen, setOpen, openDelay, closeDelay);
42
+ const value = useMemo(
43
+ () => ({ open: isOpen, setOpen, anchorRef, ...intent }),
44
+ [isOpen, setOpen, intent],
45
+ );
46
+
47
+ return <HoverCardProvider value={value}>{children}</HoverCardProvider>;
48
+ }
49
+
50
+ type PointerLike = NativeSyntheticEvent<{ pointerType?: string }>;
51
+ type FocusLike = { target?: unknown };
52
+
53
+ /** Mouse and pen hover; a touch "hover" is the first half of a tap. */
54
+ function isHoverPointer(event: PointerLike): boolean {
55
+ return event.nativeEvent?.pointerType !== 'touch';
56
+ }
57
+
58
+ /**
59
+ * Keyboard focus only. A mouse click focuses the element it lands on too, and
60
+ * opening on that would reopen a card the click just meant to get past.
61
+ */
62
+ function isFocusVisible(event: FocusLike): boolean {
63
+ const target = event.target as { matches?: (selector: string) => boolean } | null;
64
+ try {
65
+ return target?.matches?.(':focus-visible') ?? false;
66
+ } catch {
67
+ // An engine without `:focus-visible` throws on the selector.
68
+ return false;
69
+ }
70
+ }
71
+
72
+ export function HoverCardTrigger({
73
+ children,
74
+ disabled,
75
+ className,
76
+ style,
77
+ testID,
78
+ }: HoverCardTriggerProps) {
79
+ const card = useHoverCard();
80
+ const { show, hide } = card;
81
+
82
+ const onPointerEnter = useCallback(
83
+ (event: PointerLike) => {
84
+ if (!disabled && isHoverPointer(event)) show();
85
+ },
86
+ [disabled, show],
87
+ );
88
+ const onPointerLeave = useCallback(
89
+ (event: PointerLike) => {
90
+ if (isHoverPointer(event)) hide();
91
+ },
92
+ [hide],
93
+ );
94
+ const onFocus = useCallback(
95
+ (event: FocusLike) => {
96
+ if (!disabled && isFocusVisible(event)) show();
97
+ },
98
+ [disabled, show],
99
+ );
100
+
101
+
102
+ return (
103
+ <StyledView
104
+ ref={card.anchorRef}
105
+ className={className}
106
+ style={[{ alignSelf: 'flex-start' }, style]}
107
+ testID={testID}
108
+ onPointerEnter={onPointerEnter}
109
+ onPointerLeave={onPointerLeave}
110
+ aria-haspopup={HOVER_CARD_TRIGGER_POPUP}
111
+ aria-expanded={card.open}
112
+ // Focus and blur BUBBLE here from the focusable child (React's `onFocus`
113
+ // is `focusin`), so the wrapper needs no tab stop of its own.
114
+ onFocus={onFocus}
115
+ onBlur={hide}>
116
+ {children}
117
+ </StyledView>
118
+ );
119
+ }
120
+
121
+ export function HoverCardContent({
122
+ children,
123
+ label = 'Hover card',
124
+ padded,
125
+ side,
126
+ align,
127
+ sideOffset,
128
+ alignOffset,
129
+ className,
130
+ style,
131
+ testID,
132
+ }: HoverCardContentProps) {
133
+ const card = useHoverCard();
134
+ const anchor = useAnchorRect(card.anchorRef, card.open);
135
+ const { setOpen, hold, hide } = card;
136
+ const dismiss = useCallback(() => {
137
+ hold();
138
+ setOpen(false);
139
+ }, [hold, setOpen]);
140
+
141
+ return (
142
+ <HoverCardPanel
143
+ open={card.open}
144
+ anchor={anchor}
145
+ onDismiss={dismiss}
146
+ onPointerEnter={hold}
147
+ onPointerLeave={hide}
148
+ label={label}
149
+ padded={padded}
150
+ side={side}
151
+ align={align}
152
+ sideOffset={sideOffset}
153
+ alignOffset={alignOffset}
154
+ className={className}
155
+ style={style}
156
+ testID={testID}>
157
+ {children}
158
+ </HoverCardPanel>
159
+ );
160
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * The floating hover-card surface — WEB ONLY, imported by `.web.tsx` files and
3
+ * nothing else (it renders `floating/FloatingPanel`, which portals through
4
+ * `../portal/index.web`).
5
+ *
6
+ * Shared by `HoverCardContent` and `AvatarGroup`'s web hover card, so the two
7
+ * agree on placement, motion, dismissal and the pointer bridge by construction.
8
+ *
9
+ * What it adds to `FloatingPanel`:
10
+ *
11
+ * - The MENU surface (radius 16, 1px border, dropdown shadow, 150ms fade +
12
+ * `scale-95` + 2px blur), NON-modal: nothing is laid over the app, so the
13
+ * page under a hover card stays scrollable and clickable, and an outside
14
+ * press or Escape dismisses it.
15
+ * - `overflow: visible` and its own inset. The menu panel clips and pads for
16
+ * rows; a hover card's content is arbitrary, and `UserHoverCard`'s `footer`
17
+ * is documented as unclipped.
18
+ * - The pointer BRIDGE, on a `View` inside the panel that fills it. It listens
19
+ * to `pointerenter`/`pointerleave`, never to a `Pressable`'s hover: RNW's
20
+ * `Pressable` dispatches a bubbling `react-gui:hover:lock` on itself, and a
21
+ * hovered ancestor `Pressable` ends its own hover for any lock it did not
22
+ * send — so a `Pressable` bridge dismissed the card the moment the cursor
23
+ * reached a button inside it. Pointer enter/leave do not bubble and do not
24
+ * fire between descendants.
25
+ */
26
+ import React from 'react';
27
+ import { StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
28
+
29
+ import { FloatingPanel } from '../floating/FloatingPanel';
30
+ import type { FloatingAnchor, FloatingPositionProps } from '../floating/types';
31
+ import type { WebCssStyle } from '../styles/web-view-style';
32
+ import { HOVER_CARD_INSET, HOVER_CARD_SIDE_OFFSET } from './constants';
33
+ import { HoverCardSurfaceProvider } from './context';
34
+
35
+ export interface HoverCardPanelProps extends FloatingPositionProps {
36
+ open: boolean;
37
+ anchor: FloatingAnchor | null;
38
+ onDismiss: () => void;
39
+ /** The pointer reached the card. */
40
+ onPointerEnter: () => void;
41
+ /** The pointer left the card. */
42
+ onPointerLeave: () => void;
43
+ label: string;
44
+ padded?: boolean;
45
+ className?: string;
46
+ style?: StyleProp<ViewStyle>;
47
+ testID?: string;
48
+ children?: React.ReactNode;
49
+ }
50
+
51
+ export function HoverCardPanel({
52
+ open,
53
+ anchor,
54
+ onDismiss,
55
+ onPointerEnter,
56
+ onPointerLeave,
57
+ label,
58
+ padded = true,
59
+ side = 'bottom',
60
+ align = 'center',
61
+ sideOffset = HOVER_CARD_SIDE_OFFSET,
62
+ alignOffset,
63
+ className,
64
+ style,
65
+ testID,
66
+ children,
67
+ }: HoverCardPanelProps) {
68
+ return (
69
+ <FloatingPanel
70
+ open={open}
71
+ anchor={anchor}
72
+ surface="menu"
73
+ modal={false}
74
+ role="dialog"
75
+ label={label}
76
+ side={side}
77
+ align={align}
78
+ sideOffset={sideOffset}
79
+ alignOffset={alignOffset}
80
+ onDismiss={onDismiss}
81
+ className={className}
82
+ style={[styles.panel, style]}
83
+ testID={testID}>
84
+ <View
85
+ onPointerEnter={onPointerEnter}
86
+ onPointerLeave={onPointerLeave}
87
+ style={padded ? styles.padded : null}>
88
+ <HoverCardSurfaceProvider value>{children}</HoverCardSurfaceProvider>
89
+ </View>
90
+ </FloatingPanel>
91
+ );
92
+ }
93
+
94
+ const panel: WebCssStyle = {
95
+ // The menu class pads and clips for ROWS; the bridge has to cover the whole
96
+ // panel, so the inset moves onto it.
97
+ paddingTop: 0,
98
+ paddingBottom: 0,
99
+ paddingLeft: 0,
100
+ paddingRight: 0,
101
+ overflow: 'visible',
102
+ };
103
+
104
+ const styles = StyleSheet.create({
105
+ panel,
106
+ padded: {
107
+ paddingTop: HOVER_CARD_INSET,
108
+ paddingBottom: HOVER_CARD_INSET,
109
+ paddingLeft: HOVER_CARD_INSET,
110
+ paddingRight: HOVER_CARD_INSET,
111
+ },
112
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Hover intent timings. A card that opens the instant a cursor crosses a name
3
+ * flashes across every link the pointer travels over on its way somewhere else;
4
+ * one that closes the instant the cursor leaves the trigger can never be
5
+ * reached. The open delay filters the first, the close delay bridges the second
6
+ * — the cursor crosses the `HOVER_CARD_SIDE_OFFSET` gap well inside it.
7
+ */
8
+ export const HOVER_CARD_OPEN_DELAY = 400;
9
+ export const HOVER_CARD_CLOSE_DELAY = 150;
10
+
11
+ /** Gap between the trigger and the card. */
12
+ export const HOVER_CARD_SIDE_OFFSET = 8;
13
+
14
+ /** Panel inset, the same one `UserHoverCard` draws on its own. */
15
+ export const HOVER_CARD_INSET = 15;
16
+
17
+ /** What a trigger announces it opens. */
18
+ export const HOVER_CARD_TRIGGER_POPUP = 'dialog';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `HoverCard`'s own state, plus the one fact a child card needs to know.
3
+ */
4
+ import { createContext, useContext, type RefObject } from 'react';
5
+ import type { View } from 'react-native';
6
+
7
+ export interface HoverCardContextValue {
8
+ open: boolean;
9
+ setOpen: (open: boolean) => void;
10
+ anchorRef: RefObject<View | null>;
11
+ /** Open after the open delay (restarts nothing if already pending). */
12
+ show: () => void;
13
+ /** Close after the close delay. */
14
+ hide: () => void;
15
+ /** Cancel whatever is pending — the pointer arrived where it was headed. */
16
+ hold: () => void;
17
+ }
18
+
19
+ const HoverCardContext = createContext<HoverCardContextValue | null>(null);
20
+ HoverCardContext.displayName = 'BloomHoverCardContext';
21
+
22
+ export const HoverCardProvider = HoverCardContext.Provider;
23
+
24
+ export function useHoverCard(): HoverCardContextValue {
25
+ const value = useContext(HoverCardContext);
26
+ if (!value) {
27
+ throw new Error('HoverCard parts must be rendered inside a <HoverCard>.');
28
+ }
29
+ return value;
30
+ }
31
+
32
+ /**
33
+ * `true` inside a floating hover-card panel that ALREADY draws the surface
34
+ * (border, background, shadow, inset) and runs the entrance. `UserHoverCard`
35
+ * reads it to paint only its content, so the card never renders a surface
36
+ * inside a surface.
37
+ */
38
+ const HoverCardSurfaceContext = createContext(false);
39
+ HoverCardSurfaceContext.displayName = 'BloomHoverCardSurfaceContext';
40
+
41
+ export const HoverCardSurfaceProvider = HoverCardSurfaceContext.Provider;
42
+
43
+ export function useInsideHoverCardSurface(): boolean {
44
+ return useContext(HoverCardSurfaceContext);
45
+ }
@@ -0,0 +1,7 @@
1
+ export { HoverCard, HoverCardTrigger, HoverCardContent } from './HoverCard';
2
+ export {
3
+ HOVER_CARD_CLOSE_DELAY,
4
+ HOVER_CARD_OPEN_DELAY,
5
+ HOVER_CARD_SIDE_OFFSET,
6
+ } from './constants';
7
+ export type { HoverCardProps, HoverCardTriggerProps, HoverCardContentProps } from './types';
@@ -0,0 +1,7 @@
1
+ export { HoverCard, HoverCardTrigger, HoverCardContent } from './HoverCard.web';
2
+ export {
3
+ HOVER_CARD_CLOSE_DELAY,
4
+ HOVER_CARD_OPEN_DELAY,
5
+ HOVER_CARD_SIDE_OFFSET,
6
+ } from './constants';
7
+ export type { HoverCardProps, HoverCardTriggerProps, HoverCardContentProps } from './types';