@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
@@ -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';
@@ -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