@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
@@ -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';
@@ -0,0 +1,53 @@
1
+ import type { StyleProp, ViewStyle } from 'react-native';
2
+
3
+ import type { FloatingPositionProps, OverlayOpenProps } from '../floating/types';
4
+
5
+ export interface HoverCardProps extends OverlayOpenProps {
6
+ children?: React.ReactNode;
7
+ /**
8
+ * Milliseconds the pointer (or keyboard focus) has to rest on the trigger
9
+ * before the card opens. Web only. Defaults to `400`.
10
+ */
11
+ openDelay?: number;
12
+ /**
13
+ * Milliseconds the card stays up after the pointer leaves the trigger or the
14
+ * card — long enough to cross the gap between them. Web only. Defaults to
15
+ * `150`.
16
+ */
17
+ closeDelay?: number;
18
+ }
19
+
20
+ export interface HoverCardTriggerProps {
21
+ children?: React.ReactNode;
22
+ /**
23
+ * NATIVE: merge the long-press into the single element child instead of
24
+ * wrapping it in Bloom's own `Pressable`. Use it whenever the child is itself
25
+ * pressable (a link, an avatar that opens a profile) — a wrapping `Pressable`
26
+ * never receives the long press, because the inner one wins the responder.
27
+ * WEB: ignored; the trigger listens for pointer and focus on a wrapper, so
28
+ * there is nothing to merge.
29
+ */
30
+ asChild?: boolean;
31
+ /** A disabled trigger never opens the card. */
32
+ disabled?: boolean;
33
+ className?: string;
34
+ style?: StyleProp<ViewStyle>;
35
+ testID?: string;
36
+ }
37
+
38
+ export interface HoverCardContentProps extends FloatingPositionProps {
39
+ children?: React.ReactNode;
40
+ /** Accessible name of the card. Defaults to `'Hover card'`. */
41
+ label?: string;
42
+ /**
43
+ * Draw Bloom's floating surface around the content (radius 16, 1px border,
44
+ * dropdown shadow, 15px inset). Defaults to `true`. A child that paints its
45
+ * own surface — `UserHoverCard` does, and detects this panel by itself — does
46
+ * not need `false`.
47
+ */
48
+ padded?: boolean;
49
+ /** Appended to the panel's own classes. */
50
+ className?: string;
51
+ style?: StyleProp<ViewStyle>;
52
+ testID?: string;
53
+ }
@@ -0,0 +1,47 @@
1
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
2
+
3
+ /**
4
+ * Delayed open/close for a hover surface. One timer, so a pending open and a
5
+ * pending close can never both fire: every call replaces what was scheduled.
6
+ *
7
+ * `setOpen` is only called when the value would CHANGE — a controlled
8
+ * `onOpenChange` is not told "false" every time the pointer brushes past a
9
+ * trigger whose card never opened.
10
+ */
11
+ export function useHoverIntent(
12
+ open: boolean,
13
+ setOpen: (open: boolean) => void,
14
+ openDelay: number,
15
+ closeDelay: number,
16
+ ) {
17
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
18
+ const latest = useRef({ open, setOpen });
19
+ latest.current = { open, setOpen };
20
+
21
+ const hold = useCallback(() => {
22
+ if (timer.current !== null) {
23
+ clearTimeout(timer.current);
24
+ timer.current = null;
25
+ }
26
+ }, []);
27
+
28
+ const schedule = useCallback(
29
+ (next: boolean, delay: number) => {
30
+ hold();
31
+ const apply = () => {
32
+ timer.current = null;
33
+ if (latest.current.open !== next) latest.current.setOpen(next);
34
+ };
35
+ if (delay <= 0) apply();
36
+ else timer.current = setTimeout(apply, delay);
37
+ },
38
+ [hold],
39
+ );
40
+
41
+ const show = useCallback(() => schedule(true, openDelay), [schedule, openDelay]);
42
+ const hide = useCallback(() => schedule(false, closeDelay), [schedule, closeDelay]);
43
+
44
+ useEffect(() => hold, [hold]);
45
+
46
+ return useMemo(() => ({ show, hide, hold }), [show, hide, hold]);
47
+ }
package/src/index.ts CHANGED
@@ -328,6 +328,7 @@ export * from './select';
328
328
  export * from './context-menu';
329
329
  export * from './menubar';
330
330
  export * from './popover';
331
+ export * from './hover-card';
331
332
  export { AlertDialog } from './alert-dialog';
332
333
  export type { AlertDialogProps, AlertDialogActionStyle } from './alert-dialog';
333
334
  export { Command } from './command';
package/src/index.web.ts CHANGED
@@ -333,6 +333,7 @@ export * from './select/index.web';
333
333
  export * from './context-menu/index.web';
334
334
  export * from './menubar/index.web';
335
335
  export * from './popover/index.web';
336
+ export * from './hover-card/index.web';
336
337
  export { AlertDialog } from './alert-dialog/index.web';
337
338
  export type { AlertDialogProps, AlertDialogActionStyle } from './alert-dialog/index.web';
338
339
  export { Command } from './command/index.web';
@@ -30,6 +30,29 @@ export const WEB_POSITION_FIXED = 'fixed' as ViewStyle['position'];
30
30
  */
31
31
  export const WEB_POSITION_STICKY = 'sticky' as ViewStyle['position'];
32
32
 
33
+ /**
34
+ * One viewport of height (`100dvh`), and one viewport minus a vertical inset,
35
+ * typed for React Native's `ViewStyle`. Same kind of gap as
36
+ * {@link WEB_POSITION_FIXED}: RN types lengths as a number or a percentage,
37
+ * while react-native-web passes any CSS length through. A percentage cannot say
38
+ * this in a page that scrolls the DOCUMENT — a percentage height needs a
39
+ * definite ancestor height, and an auto-height document-flow ancestor never has
40
+ * one. `dvh` rather than `vh` so a mobile browser's collapsing toolbar is not
41
+ * counted as viewport.
42
+ */
43
+ export const WEB_VIEWPORT_HEIGHT = '100dvh' as ViewStyle['height'];
44
+ export function webViewportHeightMinus(px: number): ViewStyle['height'] {
45
+ return `calc(100dvh - ${px}px)` as ViewStyle['height'];
46
+ }
47
+
48
+ /**
49
+ * `overflow: clip`, typed for React Native's `ViewStyle`. Clips like `hidden`
50
+ * without making the element a SCROLL CONTAINER — so a `position: sticky`
51
+ * descendant still sticks to the document instead of to a box that never
52
+ * scrolls.
53
+ */
54
+ export const WEB_OVERFLOW_CLIP = 'clip' as ViewStyle['overflow'];
55
+
33
56
  /**
34
57
  * A `ViewStyle` that may ALSO carry CSS react-native-web forwards straight to the
35
58
  * DOM node but React Native does not model at all.
@@ -20,6 +20,7 @@ import {
20
20
  MENU_MOTION_SCALE_FROM,
21
21
  } from '../floating/constants';
22
22
  import { resolveMenuPalette } from '../floating/menu-palette';
23
+ import { useInsideHoverCardSurface } from '../hover-card/context';
23
24
  import { RiVerifiedBadgeFill } from '../icons/remix/RiVerifiedBadgeFill';
24
25
  import { useImageResolver } from '../image-resolver/context';
25
26
  import { SUPPORTS_NATIVE_DRIVER } from '../styles/native-driver';
@@ -27,7 +28,11 @@ import type { WebCssStyle } from '../styles/web-view-style';
27
28
  import type { Theme } from '../theme/types';
28
29
  import { useTheme } from '../theme/use-theme';
29
30
  import { Text } from '../typography';
30
- import { USER_HOVER_CARD_INSET, USER_HOVER_CARD_WIDTH } from './constants';
31
+ import {
32
+ USER_HOVER_CARD_CONTENT_WIDTH,
33
+ USER_HOVER_CARD_INSET,
34
+ USER_HOVER_CARD_WIDTH,
35
+ } from './constants';
31
36
  import type { UserHoverCardProps } from './types';
32
37
 
33
38
  /**
@@ -188,29 +193,36 @@ const UserHoverCardComponent: React.FC<UserHoverCardProps> = ({
188
193
  const theme = useTheme();
189
194
  const palette = useMemo(() => resolveUserHoverCardPalette(theme), [theme]);
190
195
  const resolver = useImageResolver();
191
- const entrance = useEntrance(animateIn);
196
+ // Inside a `HoverCardContent` (or `AvatarGroup`'s hover card) the floating
197
+ // panel already IS the surface — border, background, shadow, inset — and runs
198
+ // the same entrance and an exit. Drawing them again would put a card inside a
199
+ // card and play the entrance twice.
200
+ const bare = useInsideHoverCardSurface();
201
+ const entrance = useEntrance(animateIn && !bare);
192
202
 
193
203
  const hasCover = typeof cover === 'string' && cover.length > 0;
194
204
  const coverUri = hasCover
195
205
  ? isUrl(cover) ? cover : resolver?.(cover, coverVariant)
196
206
  : undefined;
197
207
 
198
- const cardStyle: WebCssStyle = {
199
- width: WIDTH,
200
- paddingTop: PADDING,
201
- paddingBottom: PADDING,
202
- paddingLeft: PADDING,
203
- paddingRight: PADDING,
204
- borderRadius: RADIUS,
205
- borderWidth: 1,
206
- borderColor: palette.border,
207
- backgroundColor: palette.surface,
208
- boxShadow: palette.shadow,
209
- // The card clips nothing: the `footer` slot is documented as unclipped, and
210
- // the cover clips itself to the inner radius.
211
- overflow: 'visible',
212
- transformOrigin: 'top',
213
- };
208
+ const cardStyle: WebCssStyle = bare
209
+ ? { width: USER_HOVER_CARD_CONTENT_WIDTH, maxWidth: '100%', overflow: 'visible' }
210
+ : {
211
+ width: WIDTH,
212
+ paddingTop: PADDING,
213
+ paddingBottom: PADDING,
214
+ paddingLeft: PADDING,
215
+ paddingRight: PADDING,
216
+ borderRadius: RADIUS,
217
+ borderWidth: 1,
218
+ borderColor: palette.border,
219
+ backgroundColor: palette.surface,
220
+ boxShadow: palette.shadow,
221
+ // The card clips nothing: the `footer` slot is documented as unclipped,
222
+ // and the cover clips itself to the inner radius.
223
+ overflow: 'visible',
224
+ transformOrigin: 'top',
225
+ };
214
226
 
215
227
  // Where the avatar's visible band sits, so the action can centre on it.
216
228
  const avatarOuter = hasCover ? AVATAR_SIZE + AVATAR_RING * 2 : AVATAR_SIZE;
@@ -1,3 +1,5 @@
1
+ import { HOVER_CARD_INSET } from '../hover-card/constants';
2
+
1
3
  /**
2
4
  * The card's geometry, in one place, because two of these numbers are now a
3
5
  * CONTRACT rather than an implementation detail: the card has two consumer
@@ -24,8 +26,13 @@
24
26
  */
25
27
  export const USER_HOVER_CARD_CONTENT_WIDTH = 256;
26
28
 
27
- /** Padding on all four sides (15px — the card's own inset, not a spacing-scale rung). */
28
- export const USER_HOVER_CARD_INSET = 15;
29
+ /**
30
+ * Padding on all four sides (15px — the card's own inset, not a spacing-scale
31
+ * rung). The SAME number as the floating hover-card panel's inset, by reference:
32
+ * inside that panel the card draws no padding of its own and its full-bleed
33
+ * cover reaches the panel edge by pulling out exactly this far.
34
+ */
35
+ export const USER_HOVER_CARD_INSET = HOVER_CARD_INSET;
29
36
 
30
37
  /**
31
38
  * Total card width — derived, never the other way round. Anything positioning