@brightlocal/ui-components 2.10.0 → 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 (58) 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/button.cjs +1 -1
  11. package/dist/button.js +25 -25
  12. package/dist/card.cjs +1 -1
  13. package/dist/card.d.ts +10 -1
  14. package/dist/card.d.ts.map +1 -1
  15. package/dist/card.js +85 -82
  16. package/dist/carousel.cjs +1 -1
  17. package/dist/carousel.d.ts +13 -1
  18. package/dist/carousel.d.ts.map +1 -1
  19. package/dist/carousel.js +196 -150
  20. package/dist/command.cjs +1 -1
  21. package/dist/command.d.ts +101 -1
  22. package/dist/command.d.ts.map +1 -1
  23. package/dist/command.js +383 -119
  24. package/dist/hooks/use-breakpoint.cjs +1 -1
  25. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  26. package/dist/hooks/use-breakpoint.js +10 -10
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +402 -391
  31. package/dist/input-chip.cjs +1 -1
  32. package/dist/input-chip.d.ts +1 -4
  33. package/dist/input-chip.d.ts.map +1 -1
  34. package/dist/input-chip.js +163 -170
  35. package/dist/map.cjs +1 -0
  36. package/dist/map.d.ts +192 -0
  37. package/dist/map.d.ts.map +1 -0
  38. package/dist/map.js +250 -0
  39. package/dist/sonner.cjs +1 -1
  40. package/dist/sonner.d.ts.map +1 -1
  41. package/dist/sonner.js +32 -30
  42. package/dist/tabs.cjs +1 -1
  43. package/dist/tabs.d.ts +4 -0
  44. package/dist/tabs.d.ts.map +1 -1
  45. package/dist/tabs.js +101 -52
  46. package/package.json +3 -3
  47. package/src/blocks/sidebar.tsx +21 -26
  48. package/src/components/badge.tsx +22 -5
  49. package/src/components/button.tsx +13 -13
  50. package/src/components/card.tsx +35 -19
  51. package/src/components/carousel.tsx +101 -9
  52. package/src/components/command.tsx +637 -16
  53. package/src/components/input-chip.tsx +102 -65
  54. package/src/components/map.tsx +574 -0
  55. package/src/components/sonner.tsx +9 -3
  56. package/src/components/tabs.tsx +118 -22
  57. package/src/hooks/use-breakpoint.ts +2 -3
  58. package/src/index.ts +1 -0
@@ -5,6 +5,20 @@ import * as TabsPrimitive from "@radix-ui/react-tabs";
5
5
 
6
6
  import { cn } from "@brightlocal/ui-components/lib/utils";
7
7
 
8
+ interface TabsContextValue {
9
+ lazyMount: boolean;
10
+ unmountOnExit: boolean;
11
+ activeValue: string | undefined;
12
+ visitedTabs: Set<string>;
13
+ }
14
+
15
+ const TabsContext = React.createContext<TabsContextValue>({
16
+ lazyMount: false,
17
+ unmountOnExit: false,
18
+ activeValue: undefined,
19
+ visitedTabs: new Set(),
20
+ });
21
+
8
22
  /**
9
23
  * Props for the Tabs component
10
24
  */
@@ -15,22 +29,83 @@ interface TabsProps extends React.ComponentProps<typeof TabsPrimitive.Root> {
15
29
  trackingEl?: string;
16
30
  /** Tracking label for analytics context */
17
31
  trackingLabel?: string;
32
+ /** Only mount tab panel content when the tab is first activated (opt-in) */
33
+ lazyMount?: boolean;
34
+ /** Unmount tab panel content when the tab becomes inactive */
35
+ unmountOnExit?: boolean;
18
36
  }
19
37
 
20
38
  const Tabs = React.forwardRef<
21
39
  React.ComponentRef<typeof TabsPrimitive.Root>,
22
40
  TabsProps
23
- >(({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => (
24
- <TabsPrimitive.Root
25
- ref={ref}
26
- className={cn("flex flex-col gap-2", className)}
27
- data-hook={dataHook}
28
- data-slot="tabs"
29
- data-tracking-el={trackingEl}
30
- data-tracking-label={trackingLabel}
31
- {...props}
32
- />
33
- ));
41
+ >(
42
+ (
43
+ {
44
+ className,
45
+ dataHook,
46
+ trackingEl,
47
+ trackingLabel,
48
+ lazyMount = false,
49
+ unmountOnExit = false,
50
+ value: controlledValue,
51
+ defaultValue,
52
+ onValueChange,
53
+ ...props
54
+ },
55
+ ref
56
+ ) => {
57
+ const needsTracking = lazyMount || unmountOnExit;
58
+ const [internalValue, setInternalValue] = React.useState(defaultValue);
59
+ const activeValue = controlledValue ?? internalValue;
60
+
61
+ const [visitedTabs, setVisitedTabs] = React.useState<Set<string>>(
62
+ () => new Set(activeValue != null ? [activeValue] : [])
63
+ );
64
+
65
+ const handleValueChange = React.useCallback(
66
+ (newValue: string) => {
67
+ setInternalValue(newValue);
68
+ if (lazyMount) {
69
+ setVisitedTabs((prev) => {
70
+ if (prev.has(newValue)) return prev;
71
+ const next = new Set(prev);
72
+ next.add(newValue);
73
+ return next;
74
+ });
75
+ }
76
+ onValueChange?.(newValue);
77
+ },
78
+ [lazyMount, onValueChange]
79
+ );
80
+
81
+ const contextValue = React.useMemo(
82
+ () => ({
83
+ lazyMount,
84
+ unmountOnExit,
85
+ activeValue,
86
+ visitedTabs,
87
+ }),
88
+ [lazyMount, unmountOnExit, activeValue, visitedTabs]
89
+ );
90
+
91
+ return (
92
+ <TabsContext.Provider value={contextValue}>
93
+ <TabsPrimitive.Root
94
+ ref={ref}
95
+ className={cn("flex flex-col gap-2", className)}
96
+ data-hook={dataHook}
97
+ data-slot="tabs"
98
+ data-tracking-el={trackingEl}
99
+ data-tracking-label={trackingLabel}
100
+ defaultValue={needsTracking ? undefined : defaultValue}
101
+ value={needsTracking ? activeValue : controlledValue}
102
+ onValueChange={needsTracking ? handleValueChange : onValueChange}
103
+ {...props}
104
+ />
105
+ </TabsContext.Provider>
106
+ );
107
+ }
108
+ );
34
109
 
35
110
  Tabs.displayName = "Tabs";
36
111
 
@@ -145,17 +220,38 @@ interface TabsContentProps extends React.ComponentProps<
145
220
  const TabsContent = React.forwardRef<
146
221
  React.ComponentRef<typeof TabsPrimitive.Content>,
147
222
  TabsContentProps
148
- >(({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => (
149
- <TabsPrimitive.Content
150
- ref={ref}
151
- className={cn("flex-1 outline-none", className)}
152
- data-hook={dataHook}
153
- data-slot="tabs-content"
154
- data-tracking-el={trackingEl}
155
- data-tracking-label={trackingLabel}
156
- {...props}
157
- />
158
- ));
223
+ >(
224
+ (
225
+ { className, dataHook, trackingEl, trackingLabel, value, ...props },
226
+ ref
227
+ ) => {
228
+ const { lazyMount, unmountOnExit, activeValue, visitedTabs } =
229
+ React.useContext(TabsContext);
230
+
231
+ const isActive = value === activeValue;
232
+
233
+ if (lazyMount && !visitedTabs.has(value!)) {
234
+ return null;
235
+ }
236
+
237
+ if (unmountOnExit && !isActive) {
238
+ return null;
239
+ }
240
+
241
+ return (
242
+ <TabsPrimitive.Content
243
+ ref={ref}
244
+ className={cn("flex-1 outline-none", className)}
245
+ data-hook={dataHook}
246
+ data-slot="tabs-content"
247
+ data-tracking-el={trackingEl}
248
+ data-tracking-label={trackingLabel}
249
+ value={value}
250
+ {...props}
251
+ />
252
+ );
253
+ }
254
+ );
159
255
 
160
256
  TabsContent.displayName = "TabsContent";
161
257
 
@@ -39,7 +39,7 @@ export function isBelowBreakpoint(size: Breakpoint = "sm"): boolean {
39
39
  * @default "sm"
40
40
  */
41
41
  export function useIsBelowBreakpoint(size: Breakpoint = "sm") {
42
- const [isBelow, setIsBelow] = React.useState<boolean | undefined>(undefined);
42
+ const [isBelow, setIsBelow] = React.useState(() => isBelowBreakpoint(size));
43
43
 
44
44
  React.useEffect(() => {
45
45
  const bp = getBreakpointValue(size);
@@ -48,11 +48,10 @@ export function useIsBelowBreakpoint(size: Breakpoint = "sm") {
48
48
  setIsBelow(window.innerWidth < bp);
49
49
  };
50
50
  mql.addEventListener("change", onChange);
51
- setIsBelow(window.innerWidth < bp);
52
51
  return () => mql.removeEventListener("change", onChange);
53
52
  }, [size]);
54
53
 
55
- return !!isBelow;
54
+ return isBelow;
56
55
  }
57
56
 
58
57
  export type { Breakpoint };
package/src/index.ts CHANGED
@@ -36,6 +36,7 @@ export * from "./components/label";
36
36
  export * from "./components/link";
37
37
  export * from "./components/list";
38
38
  export * from "./components/logo";
39
+ export * from "./components/map";
39
40
  export * from "./components/menubar";
40
41
  export * from "./components/navigation-menu";
41
42
  export * from "./components/pagination";