@brightlocal/ui-components 2.10.0 → 2.12.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 (163) hide show
  1. package/README.md +3 -1
  2. package/component-meta.json +200 -17
  3. package/dist/badge.cjs +1 -1
  4. package/dist/badge.d.ts.map +1 -1
  5. package/dist/badge.js +42 -25
  6. package/dist/blocks/data-table.cjs +1 -1
  7. package/dist/blocks/data-table.d.ts +16 -4
  8. package/dist/blocks/data-table.d.ts.map +1 -1
  9. package/dist/blocks/data-table.js +57 -53
  10. package/dist/blocks/input-list.cjs +2 -2
  11. package/dist/blocks/input-list.d.ts +7 -1
  12. package/dist/blocks/input-list.d.ts.map +1 -1
  13. package/dist/blocks/input-list.js +82 -81
  14. package/dist/blocks/sidebar.cjs +1 -1
  15. package/dist/blocks/sidebar.d.ts +19 -10
  16. package/dist/blocks/sidebar.d.ts.map +1 -1
  17. package/dist/blocks/sidebar.js +173 -169
  18. package/dist/breadcrumb.cjs +1 -1
  19. package/dist/breadcrumb.d.ts +14 -2
  20. package/dist/breadcrumb.d.ts.map +1 -1
  21. package/dist/breadcrumb.js +37 -37
  22. package/dist/button.cjs +1 -1
  23. package/dist/button.js +25 -25
  24. package/dist/callout.cjs +1 -1
  25. package/dist/callout.d.ts +3 -3
  26. package/dist/callout.d.ts.map +1 -1
  27. package/dist/callout.js +2 -1
  28. package/dist/card.cjs +1 -1
  29. package/dist/card.d.ts +10 -1
  30. package/dist/card.d.ts.map +1 -1
  31. package/dist/card.js +85 -82
  32. package/dist/carousel.cjs +1 -1
  33. package/dist/carousel.d.ts +37 -4
  34. package/dist/carousel.d.ts.map +1 -1
  35. package/dist/carousel.js +213 -163
  36. package/dist/chip.cjs +1 -1
  37. package/dist/chip.d.ts +11 -0
  38. package/dist/chip.d.ts.map +1 -1
  39. package/dist/chip.js +43 -38
  40. package/dist/combobox.cjs +3 -3
  41. package/dist/combobox.d.ts +12 -2
  42. package/dist/combobox.d.ts.map +1 -1
  43. package/dist/combobox.js +235 -230
  44. package/dist/command.cjs +1 -1
  45. package/dist/command.d.ts +106 -1
  46. package/dist/command.d.ts.map +1 -1
  47. package/dist/command.js +385 -120
  48. package/dist/date-picker.cjs +1 -1
  49. package/dist/date-picker.d.ts +10 -0
  50. package/dist/date-picker.d.ts.map +1 -1
  51. package/dist/date-picker.js +96 -96
  52. package/dist/dialog.cjs +1 -1
  53. package/dist/dialog.d.ts +7 -2
  54. package/dist/dialog.d.ts.map +1 -1
  55. package/dist/dialog.js +38 -30
  56. package/dist/drawer.d.ts +2 -2
  57. package/dist/global-layout.cjs +1 -1
  58. package/dist/global-layout.d.ts +5 -0
  59. package/dist/global-layout.d.ts.map +1 -1
  60. package/dist/global-layout.js +15 -7
  61. package/dist/hooks/use-breakpoint.cjs +1 -1
  62. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  63. package/dist/hooks/use-breakpoint.js +10 -10
  64. package/dist/index.cjs +1 -1
  65. package/dist/index.d.ts +1 -0
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +406 -395
  68. package/dist/input-chip.cjs +1 -1
  69. package/dist/input-chip.d.ts +8 -5
  70. package/dist/input-chip.d.ts.map +1 -1
  71. package/dist/input-chip.js +164 -170
  72. package/dist/input-group.d.ts +1 -1
  73. package/dist/input-password.cjs +1 -1
  74. package/dist/input-password.d.ts +10 -0
  75. package/dist/input-password.d.ts.map +1 -1
  76. package/dist/input-password.js +108 -106
  77. package/dist/link.cjs +1 -1
  78. package/dist/link.d.ts +1 -1
  79. package/dist/link.d.ts.map +1 -1
  80. package/dist/link.js +36 -37
  81. package/dist/list.d.ts +1 -1
  82. package/dist/logo.cjs +1 -1
  83. package/dist/logo.d.ts +6 -1
  84. package/dist/logo.d.ts.map +1 -1
  85. package/dist/logo.js +25 -22
  86. package/dist/map.cjs +1 -0
  87. package/dist/map.d.ts +207 -0
  88. package/dist/map.d.ts.map +1 -0
  89. package/dist/map.js +256 -0
  90. package/dist/pagination.cjs +1 -1
  91. package/dist/pagination.d.ts +29 -3
  92. package/dist/pagination.d.ts.map +1 -1
  93. package/dist/pagination.js +26 -25
  94. package/dist/rating.cjs +1 -1
  95. package/dist/rating.d.ts +6 -0
  96. package/dist/rating.d.ts.map +1 -1
  97. package/dist/rating.js +27 -19
  98. package/dist/resizable.d.ts +1 -1
  99. package/dist/select.cjs +2 -2
  100. package/dist/select.d.ts +7 -1
  101. package/dist/select.d.ts.map +1 -1
  102. package/dist/select.js +52 -51
  103. package/dist/separator.cjs +1 -1
  104. package/dist/separator.d.ts +16 -4
  105. package/dist/separator.d.ts.map +1 -1
  106. package/dist/separator.js +38 -35
  107. package/dist/sheet.cjs +1 -1
  108. package/dist/sheet.d.ts +6 -1
  109. package/dist/sheet.d.ts.map +1 -1
  110. package/dist/sheet.js +42 -41
  111. package/dist/skeleton.cjs +1 -1
  112. package/dist/skeleton.d.ts +5 -0
  113. package/dist/skeleton.d.ts.map +1 -1
  114. package/dist/skeleton.js +13 -11
  115. package/dist/sonner.cjs +1 -1
  116. package/dist/sonner.d.ts.map +1 -1
  117. package/dist/sonner.js +32 -30
  118. package/dist/tabs.cjs +1 -1
  119. package/dist/tabs.d.ts +4 -0
  120. package/dist/tabs.d.ts.map +1 -1
  121. package/dist/tabs.js +101 -52
  122. package/dist/text-reveal-motion.cjs +1 -1
  123. package/dist/text-reveal-motion.d.ts +5 -0
  124. package/dist/text-reveal-motion.d.ts.map +1 -1
  125. package/dist/text-reveal-motion.js +111 -110
  126. package/dist/typography.cjs +1 -1
  127. package/dist/typography.d.ts +1 -2
  128. package/dist/typography.d.ts.map +1 -1
  129. package/dist/typography.js +49 -50
  130. package/package.json +4 -5
  131. package/src/blocks/data-table.tsx +26 -9
  132. package/src/blocks/input-list.tsx +12 -1
  133. package/src/blocks/sidebar.tsx +61 -44
  134. package/src/components/badge.tsx +22 -5
  135. package/src/components/breadcrumb.tsx +43 -26
  136. package/src/components/button.tsx +13 -13
  137. package/src/components/callout.tsx +5 -4
  138. package/src/components/card.tsx +35 -19
  139. package/src/components/carousel.tsx +134 -13
  140. package/src/components/chip.tsx +22 -2
  141. package/src/components/combobox.tsx +18 -3
  142. package/src/components/command.tsx +644 -17
  143. package/src/components/date-picker.tsx +17 -3
  144. package/src/components/dialog.tsx +17 -4
  145. package/src/components/drawer.tsx +2 -2
  146. package/src/components/global-layout.tsx +15 -2
  147. package/src/components/input-chip.tsx +114 -66
  148. package/src/components/input-password.tsx +73 -49
  149. package/src/components/link.tsx +29 -17
  150. package/src/components/logo.tsx +10 -2
  151. package/src/components/map.tsx +597 -0
  152. package/src/components/pagination.tsx +44 -11
  153. package/src/components/rating.tsx +20 -2
  154. package/src/components/select.tsx +9 -1
  155. package/src/components/separator.tsx +40 -25
  156. package/src/components/sheet.tsx +28 -20
  157. package/src/components/skeleton.tsx +13 -2
  158. package/src/components/sonner.tsx +9 -3
  159. package/src/components/tabs.tsx +118 -22
  160. package/src/components/text-reveal-motion.tsx +7 -1
  161. package/src/components/typography.tsx +6 -7
  162. package/src/hooks/use-breakpoint.ts +2 -3
  163. package/src/index.ts +1 -0
@@ -28,6 +28,11 @@ interface LogoProps
28
28
  * Required data-hook attribute for testing and component identification
29
29
  */
30
30
  dataHook: string;
31
+ /**
32
+ * Accessible label for the logo image.
33
+ * @default "BrightLocal Logo"
34
+ */
35
+ ariaLabel?: string;
31
36
  /**
32
37
  * Optional tracking element identifier for analytics
33
38
  */
@@ -42,26 +47,27 @@ function Logo({
42
47
  className,
43
48
  variant = "logotype",
44
49
  dataHook,
50
+ ariaLabel,
45
51
  trackingEl,
46
52
  trackingLabel,
47
53
  ...props
48
54
  }: LogoProps) {
49
55
  return (
50
56
  <div
51
- aria-label="BrightLocal Logo"
52
57
  className={cn(logoVariants({ variant }), className)}
53
58
  data-hook={dataHook}
54
59
  data-slot="logo"
55
60
  data-tracking-el={trackingEl}
56
61
  data-tracking-label={trackingLabel}
57
62
  data-variant={variant}
58
- role="img"
59
63
  {...props}
60
64
  >
61
65
  {variant === "logotype" && (
62
66
  <svg
67
+ aria-label={ariaLabel ?? "BrightLocal Logo"}
63
68
  fill="none"
64
69
  height="24"
70
+ role="img"
65
71
  viewBox="0 0 128 24.1509"
66
72
  width="128"
67
73
  xmlns="http://www.w3.org/2000/svg"
@@ -81,8 +87,10 @@ function Logo({
81
87
  )}
82
88
  {variant === "mark" && (
83
89
  <svg
90
+ aria-label={ariaLabel ?? "BrightLocal Logo"}
84
91
  fill="none"
85
92
  height="21"
93
+ role="img"
86
94
  viewBox="0 0 23 21"
87
95
  width="23"
88
96
  xmlns="http://www.w3.org/2000/svg"
@@ -0,0 +1,597 @@
1
+ import * as React from "react";
2
+ import { AlertCircle } from "@brightlocal/icons";
3
+ import { Button } from "@brightlocal/ui-components/button";
4
+ import { Card, CardContent } from "@brightlocal/ui-components/card";
5
+ import { cn } from "@brightlocal/ui-components/lib/utils";
6
+ import {
7
+ Popover,
8
+ PopoverAnchor,
9
+ PopoverContent,
10
+ type PopoverProps,
11
+ type PopoverAnchorProps,
12
+ type PopoverContentProps,
13
+ } from "@brightlocal/ui-components/popover";
14
+
15
+ // ──────────────────────────────────────
16
+ // MapTypeId
17
+ // ──────────────────────────────────────
18
+
19
+ /**
20
+ * Vendor-agnostic map type identifiers.
21
+ * Values match `google.maps.MapTypeId` so they can be passed directly
22
+ * to Google Maps or any provider that accepts the same string literals.
23
+ */
24
+ const MapTypeId = {
25
+ /** Default road map view */
26
+ ROADMAP: "roadmap",
27
+ /** Satellite imagery */
28
+ SATELLITE: "satellite",
29
+ } as const;
30
+
31
+ /**
32
+ * Union of all map type identifier values.
33
+ */
34
+ type MapTypeIdValue = (typeof MapTypeId)[keyof typeof MapTypeId];
35
+
36
+ // ──────────────────────────────────────
37
+ // MapGridPin
38
+ // ──────────────────────────────────────
39
+
40
+ type MapGridPinVariant =
41
+ | "primary"
42
+ | "secondary"
43
+ | "destructive"
44
+ | "outline"
45
+ | "warning";
46
+
47
+ const gridPinPulseVar: Record<MapGridPinVariant, string> = {
48
+ primary: "var(--primary)",
49
+ secondary: "var(--secondary)",
50
+ destructive: "var(--destructive)",
51
+ outline: "var(--muted)",
52
+ warning: "var(--warning-background)",
53
+ };
54
+
55
+ /**
56
+ * Props for the MapGridPin component.
57
+ */
58
+ interface MapGridPinProps extends Omit<
59
+ React.ComponentProps<"button">,
60
+ "children" | "type"
61
+ > {
62
+ /** Value displayed inside the pin (number or short label) */
63
+ value: number | string;
64
+ /** Button variant — consumer controls this based on value thresholds */
65
+ variant?: MapGridPinVariant;
66
+ /** Enable infinite pulse animation radiating from the pin */
67
+ pulse?: boolean;
68
+ /** Required test hook identifier */
69
+ dataHook: string;
70
+ /** Analytics element identifier */
71
+ trackingEl?: string;
72
+ /** Analytics label */
73
+ trackingLabel?: string;
74
+ }
75
+
76
+ /**
77
+ * A circular map pin button that displays a numeric value with a colored background.
78
+ * Uses the Button component internally. Color is determined by the `variant` prop —
79
+ * the consumer controls which variant to apply based on the value.
80
+ * Supports an optional `pulse` animation for emphasis.
81
+ */
82
+ const MapGridPin = React.forwardRef<HTMLButtonElement, MapGridPinProps>(
83
+ (
84
+ {
85
+ value,
86
+ variant = "primary",
87
+ pulse = false,
88
+ dataHook,
89
+ className,
90
+ trackingEl,
91
+ trackingLabel,
92
+ ...props
93
+ },
94
+ ref
95
+ ) => {
96
+ return (
97
+ <Button
98
+ ref={ref}
99
+ className={cn(
100
+ "size-8 p-0",
101
+ pulse &&
102
+ "animate-grid-pin-pulse transition-none motion-reduce:animate-none",
103
+ className
104
+ )}
105
+ dataHook={dataHook}
106
+ size="sm"
107
+ style={
108
+ pulse
109
+ ? ({
110
+ "--grid-pin-pulse-color": gridPinPulseVar[variant],
111
+ } as React.CSSProperties)
112
+ : undefined
113
+ }
114
+ trackingEl={trackingEl || "map-grid-pin"}
115
+ trackingLabel={trackingLabel}
116
+ variant={variant}
117
+ {...props}
118
+ >
119
+ {String(value)}
120
+ </Button>
121
+ );
122
+ }
123
+ );
124
+
125
+ MapGridPin.displayName = "MapGridPin";
126
+
127
+ // ──────────────────────────────────────
128
+ // MapLocationPin
129
+ // ──────────────────────────────────────
130
+
131
+ /**
132
+ * Props for the MapLocationPin component.
133
+ */
134
+ interface MapLocationPinProps extends Omit<MapGridPinProps, "value"> {
135
+ /** Numeric value displayed inside the pin */
136
+ value?: number;
137
+ }
138
+
139
+ /**
140
+ * A map location pin marker.
141
+ * Thin wrapper around MapGridPin with a default value of 1.
142
+ * Designed to be placed inside any map marker component (e.g. AdvancedMarker).
143
+ */
144
+ const MapLocationPin = React.forwardRef<HTMLButtonElement, MapLocationPinProps>(
145
+ ({ value = 1, dataHook, ...props }, ref) => {
146
+ return (
147
+ <MapGridPin ref={ref} dataHook={dataHook} value={value} {...props} />
148
+ );
149
+ }
150
+ );
151
+
152
+ MapLocationPin.displayName = "MapLocationPin";
153
+
154
+ // ──────────────────────────────────────
155
+ // MapControlButton
156
+ // ──────────────────────────────────────
157
+
158
+ /**
159
+ * Props for the MapControlButton component.
160
+ */
161
+ interface MapControlButtonProps extends Omit<
162
+ React.ComponentProps<"button">,
163
+ "type"
164
+ > {
165
+ /** Required test hook identifier */
166
+ dataHook: string;
167
+ /** Analytics element identifier */
168
+ trackingEl?: string;
169
+ /** Analytics label */
170
+ trackingLabel?: string;
171
+ /** Button type attribute */
172
+ type?: "button" | "submit";
173
+ }
174
+
175
+ /**
176
+ * A floating control button for map UIs.
177
+ * Renders a square, shadowed button designed to overlay a map surface.
178
+ * Use for zoom, locate, layer toggles, and other map controls.
179
+ */
180
+ const MapControlButton = React.forwardRef<
181
+ HTMLButtonElement,
182
+ MapControlButtonProps
183
+ >(
184
+ (
185
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
186
+ ref
187
+ ) => {
188
+ return (
189
+ <Button
190
+ ref={ref}
191
+ className={cn("rounded-lg shadow-sm", className)}
192
+ data-slot="map-control-button"
193
+ dataHook={dataHook}
194
+ trackingEl={trackingEl || "map-control-button"}
195
+ trackingLabel={trackingLabel}
196
+ variant="outline"
197
+ {...props}
198
+ >
199
+ {children}
200
+ </Button>
201
+ );
202
+ }
203
+ );
204
+
205
+ MapControlButton.displayName = "MapControlButton";
206
+
207
+ // ──────────────────────────────────────
208
+ // MapLoadingState
209
+ // ──────────────────────────────────────
210
+
211
+ /**
212
+ * Props for the MapLoadingState component.
213
+ */
214
+ interface MapLoadingStateProps extends React.ComponentProps<"div"> {
215
+ /** Optional loading message */
216
+ message?: string;
217
+ /** Required test hook identifier */
218
+ dataHook: string;
219
+ /** Analytics element identifier */
220
+ trackingEl?: string;
221
+ /** Analytics label */
222
+ trackingLabel?: string;
223
+ }
224
+
225
+ /**
226
+ * A loading placeholder for map containers.
227
+ * Uses the same spinner pattern as ComboboxLoading.
228
+ * Use as a fallback while the map provider is loading.
229
+ */
230
+ const MapLoadingState = React.forwardRef<HTMLDivElement, MapLoadingStateProps>(
231
+ (
232
+ {
233
+ className,
234
+ message = "Loading map…",
235
+ dataHook,
236
+ trackingEl,
237
+ trackingLabel,
238
+ ...props
239
+ },
240
+ ref
241
+ ) => {
242
+ return (
243
+ <div
244
+ ref={ref}
245
+ aria-live="polite"
246
+ className={cn(
247
+ "text-muted-foreground flex items-center justify-center gap-2 py-6 text-sm",
248
+ className
249
+ )}
250
+ data-hook={dataHook}
251
+ data-slot="map-loading-state"
252
+ data-tracking-el={trackingEl || "map-loading-state"}
253
+ data-tracking-label={trackingLabel}
254
+ role="status"
255
+ {...props}
256
+ >
257
+ <div
258
+ aria-hidden="true"
259
+ className="size-4 animate-spin rounded-full border-2 border-current border-t-transparent"
260
+ />
261
+ {message}
262
+ </div>
263
+ );
264
+ }
265
+ );
266
+
267
+ MapLoadingState.displayName = "MapLoadingState";
268
+
269
+ // ──────────────────────────────────────
270
+ // MapErrorState
271
+ // ──────────────────────────────────────
272
+
273
+ /**
274
+ * Props for the MapErrorState component.
275
+ */
276
+ interface MapErrorStateProps extends React.ComponentProps<"div"> {
277
+ /** Error title */
278
+ title?: string;
279
+ /** Error description */
280
+ message?: string;
281
+ /** Retry callback — renders a "Try again" button when provided */
282
+ onRetry?: () => void;
283
+ /** Required test hook identifier */
284
+ dataHook: string;
285
+ /** Analytics element identifier */
286
+ trackingEl?: string;
287
+ /** Analytics label */
288
+ trackingLabel?: string;
289
+ }
290
+
291
+ /**
292
+ * An error state for map containers.
293
+ * Displays an alert icon, title, message, and an optional retry button.
294
+ * Use when the map provider fails to initialise or a network error occurs.
295
+ */
296
+ const MapErrorState = React.forwardRef<HTMLDivElement, MapErrorStateProps>(
297
+ (
298
+ {
299
+ className,
300
+ title = "Unable to load map",
301
+ message = "Something went wrong while loading the map. Please try again.",
302
+ onRetry,
303
+ dataHook,
304
+ trackingEl,
305
+ trackingLabel,
306
+ ...props
307
+ },
308
+ ref
309
+ ) => {
310
+ return (
311
+ <div
312
+ ref={ref}
313
+ className={cn(
314
+ "bg-muted/50 flex flex-col items-center justify-center gap-3 rounded-xl p-8 text-center",
315
+ className
316
+ )}
317
+ data-hook={dataHook}
318
+ data-slot="map-error-state"
319
+ data-tracking-el={trackingEl || "map-error-state"}
320
+ data-tracking-label={trackingLabel}
321
+ role="alert"
322
+ {...props}
323
+ >
324
+ <AlertCircle
325
+ aria-hidden="true"
326
+ className="text-muted-foreground/60"
327
+ size={40}
328
+ strokeWidth={1.5}
329
+ />
330
+ <div className="flex flex-col gap-1">
331
+ <h3
332
+ className="text-foreground text-sm font-semibold"
333
+ data-slot="map-error-title"
334
+ >
335
+ {title}
336
+ </h3>
337
+ {message && (
338
+ <p
339
+ className="text-muted-foreground max-w-xs text-xs"
340
+ data-slot="map-error-message"
341
+ >
342
+ {message}
343
+ </p>
344
+ )}
345
+ </div>
346
+ {onRetry && (
347
+ <Button
348
+ className="mt-1"
349
+ dataHook={`${dataHook}-retry`}
350
+ size="sm"
351
+ variant="primary"
352
+ onClick={onRetry}
353
+ >
354
+ Try again
355
+ </Button>
356
+ )}
357
+ </div>
358
+ );
359
+ }
360
+ );
361
+
362
+ MapErrorState.displayName = "MapErrorState";
363
+
364
+ // ──────────────────────────────────────
365
+ // MapLegend
366
+ // ──────────────────────────────────────
367
+
368
+ /**
369
+ * Props for the MapLegend component.
370
+ */
371
+ interface MapLegendProps extends React.ComponentProps<"div"> {
372
+ /** Required test hook identifier */
373
+ dataHook: string;
374
+ /** Analytics element identifier */
375
+ trackingEl?: string;
376
+ /** Analytics label */
377
+ trackingLabel?: string;
378
+ }
379
+
380
+ /**
381
+ * A flexible legend container for map UIs.
382
+ * Renders a horizontal pill-shaped bar — consumers define items via children.
383
+ */
384
+ const MapLegend = React.forwardRef<HTMLDivElement, MapLegendProps>(
385
+ (
386
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
387
+ ref
388
+ ) => {
389
+ return (
390
+ <Card
391
+ ref={ref}
392
+ className={cn("inline-flex w-auto flex-row items-center", className)}
393
+ data-slot="map-legend"
394
+ dataHook={dataHook}
395
+ density="condensed"
396
+ maxWidth="none"
397
+ trackingEl={trackingEl || "map-legend"}
398
+ trackingLabel={trackingLabel}
399
+ variant="filled"
400
+ {...props}
401
+ >
402
+ <CardContent className="flex items-center gap-3">
403
+ {children}
404
+ </CardContent>
405
+ </Card>
406
+ );
407
+ }
408
+ );
409
+
410
+ MapLegend.displayName = "MapLegend";
411
+
412
+ // ──────────────────────────────────────
413
+ // useMapPopoverHover
414
+ // ──────────────────────────────────────
415
+
416
+ /**
417
+ * Return type of {@link useMapPopoverHover}.
418
+ */
419
+ interface UseMapPopoverHoverReturn<T> {
420
+ /** The item currently being hovered, or `null` when idle. Use for `open` prop. */
421
+ activeItem: T | null;
422
+ /** Last non-null item — holds position stable during the close animation. Use for anchor positioning. */
423
+ anchorItem: T | null;
424
+ /** Set a new active item and cancel any pending close timer. */
425
+ showItem: (item: T) => void;
426
+ /** Start a delayed close (default 150 ms). Moving to another pin or the popover content cancels it. */
427
+ scheduleClose: () => void;
428
+ /** Cancel a pending close — call from `MapPopoverContent.onMouseEnter`. */
429
+ cancelClose: () => void;
430
+ }
431
+
432
+ /**
433
+ * Manages hover state for a single repositioning Popover on dense map grids.
434
+ *
435
+ * Wire the returned callbacks to `MapGridPin` mouse events and
436
+ * `MapPopoverContent` mouse events. The 150 ms grace period prevents
437
+ * flicker when the pointer travels between a pin and the popover content.
438
+ *
439
+ * @param delay - Close timer in ms.
440
+ * @default 150
441
+ */
442
+ function useMapPopoverHover<T>(delay = 150): UseMapPopoverHoverReturn<T> {
443
+ const [activeItem, setActiveItem] = React.useState<T | null>(null);
444
+ const [anchorItem, setAnchorItem] = React.useState<T | null>(null);
445
+ const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>(null);
446
+
447
+ const showItem = React.useCallback((item: T) => {
448
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
449
+ setAnchorItem(item);
450
+ setActiveItem(item);
451
+ }, []);
452
+
453
+ const scheduleClose = React.useCallback(() => {
454
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
455
+ timeoutRef.current = setTimeout(() => setActiveItem(null), delay);
456
+ }, [delay]);
457
+
458
+ const cancelClose = React.useCallback(() => {
459
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
460
+ }, []);
461
+
462
+ return {
463
+ activeItem,
464
+ anchorItem,
465
+ showItem,
466
+ scheduleClose,
467
+ cancelClose,
468
+ };
469
+ }
470
+
471
+ // ──────────────────────────────────────
472
+ // MapPopover & MapPopoverAnchor (re-exports)
473
+ // ──────────────────────────────────────
474
+
475
+ /**
476
+ * Controlled popover root for map UIs.
477
+ * Re-exports `Popover` so consumers import everything from the map module.
478
+ *
479
+ * @example
480
+ * ```tsx
481
+ * <MapPopover open={!!activeItem}>
482
+ * <MapPopoverAnchor />
483
+ * <MapPopoverContent dataHook="popover">…</MapPopoverContent>
484
+ * </MapPopover>
485
+ * ```
486
+ */
487
+ const MapPopover = Popover;
488
+
489
+ /**
490
+ * Props for the MapPopover component.
491
+ */
492
+ type MapPopoverProps = PopoverProps;
493
+
494
+ /**
495
+ * Virtual anchor that positions the popover without rendering a trigger.
496
+ * Re-exports `PopoverAnchor` so consumers import everything from the map module.
497
+ */
498
+ const MapPopoverAnchor = PopoverAnchor;
499
+ MapPopoverAnchor.displayName = "MapPopoverAnchor";
500
+
501
+ /**
502
+ * Props for the MapPopoverAnchor component.
503
+ */
504
+ type MapPopoverAnchorProps = PopoverAnchorProps;
505
+
506
+ // ──────────────────────────────────────
507
+ // MapPopoverContent
508
+ // ──────────────────────────────────────
509
+
510
+ /**
511
+ * Props for the MapPopoverContent component.
512
+ */
513
+ interface MapPopoverContentProps extends PopoverContentProps {
514
+ /** Test hook identifier */
515
+ dataHook: string;
516
+ /** Analytics element identifier */
517
+ trackingEl?: string;
518
+ /** Analytics label */
519
+ trackingLabel?: string;
520
+ }
521
+
522
+ /**
523
+ * Popover content panel with map-specific defaults.
524
+ * Compact sizing (`w-auto p-3`), top placement, and focus-prevention
525
+ * for hover-activated popovers.
526
+ *
527
+ * Use inside a controlled `<MapPopover open={!!activeItem}>` together
528
+ * with `MapPopoverAnchor` and {@link useMapPopoverHover}.
529
+ */
530
+ const MapPopoverContent = React.forwardRef<
531
+ React.ComponentRef<typeof PopoverContent>,
532
+ MapPopoverContentProps
533
+ >(
534
+ (
535
+ {
536
+ className,
537
+ side = "top",
538
+ sideOffset = 4,
539
+ dataHook,
540
+ trackingEl,
541
+ trackingLabel,
542
+ ...props
543
+ },
544
+ ref
545
+ ) => (
546
+ <PopoverContent
547
+ ref={ref}
548
+ className={cn(
549
+ "w-auto p-3 data-[state=closed]:animate-none data-[state=closed]:opacity-0",
550
+ className
551
+ )}
552
+ data-slot="map-popover-content"
553
+ data-tracking-el={trackingEl || "map-popover"}
554
+ data-tracking-label={trackingLabel}
555
+ dataHook={dataHook}
556
+ side={side}
557
+ sideOffset={sideOffset}
558
+ onOpenAutoFocus={(e) => e.preventDefault()}
559
+ {...props}
560
+ />
561
+ )
562
+ );
563
+
564
+ MapPopoverContent.displayName = "MapPopoverContent";
565
+
566
+ // ──────────────────────────────────────
567
+ // Exports
568
+ // ──────────────────────────────────────
569
+
570
+ export {
571
+ MapTypeId,
572
+ MapLocationPin,
573
+ MapGridPin,
574
+ MapControlButton,
575
+ MapLoadingState,
576
+ MapErrorState,
577
+ MapLegend,
578
+ MapPopover,
579
+ MapPopoverAnchor,
580
+ MapPopoverContent,
581
+ useMapPopoverHover,
582
+ };
583
+
584
+ export type {
585
+ MapTypeIdValue,
586
+ MapLocationPinProps,
587
+ MapGridPinProps,
588
+ MapGridPinVariant,
589
+ MapControlButtonProps,
590
+ MapLoadingStateProps,
591
+ MapErrorStateProps,
592
+ MapLegendProps,
593
+ MapPopoverProps,
594
+ MapPopoverAnchorProps,
595
+ MapPopoverContentProps,
596
+ UseMapPopoverHoverReturn,
597
+ };