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