@brightlocal/ui-components 2.12.0 → 2.14.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 (48) hide show
  1. package/component-meta.json +316 -19
  2. package/dist/blocks/sidebar.cjs +1 -1
  3. package/dist/blocks/sidebar.d.ts +203 -4
  4. package/dist/blocks/sidebar.d.ts.map +1 -1
  5. package/dist/blocks/sidebar.js +667 -393
  6. package/dist/card.cjs +1 -1
  7. package/dist/card.d.ts +5 -1
  8. package/dist/card.d.ts.map +1 -1
  9. package/dist/card.js +48 -31
  10. package/dist/combobox.cjs +3 -3
  11. package/dist/combobox.d.ts +8 -0
  12. package/dist/combobox.d.ts.map +1 -1
  13. package/dist/combobox.js +227 -226
  14. package/dist/dropdown-menu.cjs +1 -1
  15. package/dist/dropdown-menu.js +1 -1
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.js +450 -441
  18. package/dist/list.cjs +1 -1
  19. package/dist/list.d.ts +25 -4
  20. package/dist/list.d.ts.map +1 -1
  21. package/dist/list.js +71 -53
  22. package/dist/popover.cjs +1 -1
  23. package/dist/popover.js +7 -7
  24. package/dist/rating.cjs +1 -1
  25. package/dist/rating.js +13 -13
  26. package/dist/select.cjs +2 -2
  27. package/dist/select.d.ts +10 -2
  28. package/dist/select.d.ts.map +1 -1
  29. package/dist/select.js +36 -30
  30. package/dist/table.cjs +1 -1
  31. package/dist/table.d.ts +14 -0
  32. package/dist/table.d.ts.map +1 -1
  33. package/dist/table.js +57 -39
  34. package/dist/tabs.cjs +1 -1
  35. package/dist/tabs.d.ts +25 -9
  36. package/dist/tabs.d.ts.map +1 -1
  37. package/dist/tabs.js +128 -113
  38. package/package.json +2 -2
  39. package/src/blocks/sidebar.tsx +596 -9
  40. package/src/components/card.tsx +23 -0
  41. package/src/components/combobox.tsx +10 -0
  42. package/src/components/dropdown-menu.tsx +1 -1
  43. package/src/components/list.tsx +45 -2
  44. package/src/components/popover.tsx +1 -1
  45. package/src/components/rating.tsx +1 -1
  46. package/src/components/select.tsx +24 -2
  47. package/src/components/table.tsx +39 -2
  48. package/src/components/tabs.tsx +195 -146
@@ -20,9 +20,14 @@ const TabsContext = React.createContext<TabsContextValue>({
20
20
  });
21
21
 
22
22
  /**
23
- * Props for the Tabs component
23
+ * Props for the Tabs component.
24
+ * Generic over the tab value type for type-safe `value` and `onValueChange`.
25
+ * @typeParam T - The type of tab values, defaults to `string`
24
26
  */
25
- interface TabsProps extends React.ComponentProps<typeof TabsPrimitive.Root> {
27
+ interface TabsProps<T extends string = string> extends Omit<
28
+ React.ComponentProps<typeof TabsPrimitive.Root>,
29
+ "value" | "defaultValue" | "onValueChange"
30
+ > {
26
31
  /** Data hook for automated testing (required) */
27
32
  dataHook: string;
28
33
  /** Tracking element identifier for analytics */
@@ -33,81 +38,91 @@ interface TabsProps extends React.ComponentProps<typeof TabsPrimitive.Root> {
33
38
  lazyMount?: boolean;
34
39
  /** Unmount tab panel content when the tab becomes inactive */
35
40
  unmountOnExit?: boolean;
41
+ /** The controlled value of the active tab */
42
+ value?: T;
43
+ /** The default value of the active tab (uncontrolled) */
44
+ defaultValue?: T;
45
+ /** Callback when the active tab changes */
46
+ onValueChange?: (value: T) => void;
36
47
  }
37
48
 
38
- const Tabs = React.forwardRef<
39
- React.ComponentRef<typeof TabsPrimitive.Root>,
40
- TabsProps
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
49
+ function TabsInner<T extends string = string>(
50
+ {
51
+ className,
52
+ dataHook,
53
+ trackingEl,
54
+ trackingLabel,
55
+ lazyMount = false,
56
+ unmountOnExit = false,
57
+ value: controlledValue,
58
+ defaultValue,
59
+ onValueChange,
60
+ ...props
61
+ }: TabsProps<T>,
62
+ ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Root>>
63
+ ) {
64
+ const needsTracking = lazyMount || unmountOnExit;
65
+ const [internalValue, setInternalValue] = React.useState(defaultValue);
66
+ const activeValue = controlledValue ?? internalValue;
67
+
68
+ const [visitedTabs, setVisitedTabs] = React.useState<Set<string>>(
69
+ () => new Set(activeValue != null ? [activeValue] : [])
70
+ );
71
+
72
+ const handleValueChange = React.useCallback(
73
+ (newValue: string) => {
74
+ setInternalValue(newValue as T);
75
+ if (lazyMount) {
76
+ setVisitedTabs((prev) => {
77
+ if (prev.has(newValue)) return prev;
78
+ const next = new Set(prev);
79
+ next.add(newValue);
80
+ return next;
81
+ });
82
+ }
83
+ onValueChange?.(newValue as T);
54
84
  },
55
- ref
56
- ) => {
57
- const needsTracking = lazyMount || unmountOnExit;
58
- const [internalValue, setInternalValue] = React.useState(defaultValue);
59
- const activeValue = controlledValue ?? internalValue;
85
+ [lazyMount, onValueChange]
86
+ );
60
87
 
61
- const [visitedTabs, setVisitedTabs] = React.useState<Set<string>>(
62
- () => new Set(activeValue != null ? [activeValue] : [])
63
- );
88
+ const contextValue = React.useMemo(
89
+ () => ({
90
+ lazyMount,
91
+ unmountOnExit,
92
+ activeValue,
93
+ visitedTabs,
94
+ }),
95
+ [lazyMount, unmountOnExit, activeValue, visitedTabs]
96
+ );
64
97
 
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
- });
98
+ return (
99
+ <TabsContext.Provider value={contextValue}>
100
+ <TabsPrimitive.Root
101
+ ref={ref}
102
+ className={cn("flex flex-col gap-2", className)}
103
+ data-hook={dataHook}
104
+ data-slot="tabs"
105
+ data-tracking-el={trackingEl}
106
+ data-tracking-label={trackingLabel}
107
+ defaultValue={needsTracking ? undefined : defaultValue}
108
+ value={needsTracking ? activeValue : controlledValue}
109
+ onValueChange={
110
+ needsTracking
111
+ ? handleValueChange
112
+ : (onValueChange as ((value: string) => void) | undefined)
75
113
  }
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
- );
114
+ {...props}
115
+ />
116
+ </TabsContext.Provider>
117
+ );
118
+ }
90
119
 
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
- );
120
+ const Tabs = React.forwardRef(TabsInner) as <T extends string = string>(
121
+ props: TabsProps<T> &
122
+ React.RefAttributes<React.ComponentRef<typeof TabsPrimitive.Root>>
123
+ ) => React.ReactElement | null;
109
124
 
110
- Tabs.displayName = "Tabs";
125
+ (Tabs as React.FC).displayName = "Tabs";
111
126
 
112
127
  /**
113
128
  * Props for the TabsList component
@@ -149,10 +164,13 @@ const TabsList = React.forwardRef<
149
164
  TabsList.displayName = "TabsList";
150
165
 
151
166
  /**
152
- * Props for the TabsTrigger component
167
+ * Props for the TabsTrigger component.
168
+ * Generic over the tab value type for type-safe `value` prop.
169
+ * @typeParam T - The type of tab values, defaults to `string`
153
170
  */
154
- interface TabsTriggerProps extends React.ComponentProps<
155
- typeof TabsPrimitive.Trigger
171
+ interface TabsTriggerProps<T extends string = string> extends Omit<
172
+ React.ComponentProps<typeof TabsPrimitive.Trigger>,
173
+ "value"
156
174
  > {
157
175
  /** Data hook for automated testing */
158
176
  dataHook?: string;
@@ -160,54 +178,74 @@ interface TabsTriggerProps extends React.ComponentProps<
160
178
  trackingEl?: string;
161
179
  /** Tracking label for analytics context */
162
180
  trackingLabel?: string;
181
+ /** The value that identifies this tab */
182
+ value: T;
163
183
  }
164
184
 
165
- const TabsTrigger = React.forwardRef<
166
- React.ComponentRef<typeof TabsPrimitive.Trigger>,
167
- TabsTriggerProps
168
- >(({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => (
169
- <TabsPrimitive.Trigger
170
- ref={ref}
171
- className={cn(
172
- // Layout
173
- "inline-flex items-center justify-center gap-2 px-2 py-1",
174
- // Typography
175
- "text-sm font-medium whitespace-nowrap",
176
- // Border radius
177
- "rounded-md",
178
- // Border
179
- "border border-transparent",
180
- // Text color
181
- "text-foreground",
182
- // Transition with explicit duration and easing
183
- "transition-[color,box-shadow] duration-150 ease-in-out",
184
- // Active state
185
- "data-[state=active]:bg-background data-[state=active]:shadow-sm",
186
- // Focus state - use compound selector for active+focused to override shadow-sm with shadow-default
187
- "focus-visible:border-ring focus-visible:outline-none",
188
- "data-[state=inactive]:focus-visible:shadow-default",
189
- "data-[state=active]:focus-visible:shadow-default",
190
- // Dark mode active state
191
- "dark:data-[state=active]:border-white/15 dark:data-[state=active]:bg-white/5",
192
- // Disabled state
193
- "disabled:pointer-events-none disabled:opacity-50",
194
- className
195
- )}
196
- data-hook={dataHook}
197
- data-slot="tabs-trigger"
198
- data-tracking-el={trackingEl}
199
- data-tracking-label={trackingLabel}
200
- {...props}
201
- />
202
- ));
185
+ function TabsTriggerInner<T extends string = string>(
186
+ {
187
+ className,
188
+ dataHook,
189
+ trackingEl,
190
+ trackingLabel,
191
+ ...props
192
+ }: TabsTriggerProps<T>,
193
+ ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Trigger>>
194
+ ) {
195
+ return (
196
+ <TabsPrimitive.Trigger
197
+ ref={ref}
198
+ className={cn(
199
+ // Layout
200
+ "inline-flex items-center justify-center gap-2 px-2 py-1",
201
+ // Typography
202
+ "text-sm font-medium whitespace-nowrap",
203
+ // Border radius
204
+ "rounded-md",
205
+ // Border
206
+ "border border-transparent",
207
+ // Text color
208
+ "text-foreground",
209
+ // Transition with explicit duration and easing
210
+ "transition-[color,box-shadow] duration-150 ease-in-out",
211
+ // Active state
212
+ "data-[state=active]:bg-background data-[state=active]:shadow-sm",
213
+ // Focus state - use compound selector for active+focused to override shadow-sm with shadow-default
214
+ "focus-visible:border-ring focus-visible:outline-none",
215
+ "data-[state=inactive]:focus-visible:shadow-default",
216
+ "data-[state=active]:focus-visible:shadow-default",
217
+ // Dark mode active state
218
+ "dark:data-[state=active]:border-white/15 dark:data-[state=active]:bg-white/5",
219
+ // Disabled state
220
+ "disabled:pointer-events-none disabled:opacity-50",
221
+ className
222
+ )}
223
+ data-hook={dataHook}
224
+ data-slot="tabs-trigger"
225
+ data-tracking-el={trackingEl}
226
+ data-tracking-label={trackingLabel}
227
+ {...props}
228
+ />
229
+ );
230
+ }
203
231
 
204
- TabsTrigger.displayName = "TabsTrigger";
232
+ const TabsTrigger = React.forwardRef(TabsTriggerInner) as <
233
+ T extends string = string,
234
+ >(
235
+ props: TabsTriggerProps<T> &
236
+ React.RefAttributes<React.ComponentRef<typeof TabsPrimitive.Trigger>>
237
+ ) => React.ReactElement | null;
238
+
239
+ (TabsTrigger as React.FC).displayName = "TabsTrigger";
205
240
 
206
241
  /**
207
- * Props for the TabsContent component
242
+ * Props for the TabsContent component.
243
+ * Generic over the tab value type for type-safe `value` prop.
244
+ * @typeParam T - The type of tab values, defaults to `string`
208
245
  */
209
- interface TabsContentProps extends React.ComponentProps<
210
- typeof TabsPrimitive.Content
246
+ interface TabsContentProps<T extends string = string> extends Omit<
247
+ React.ComponentProps<typeof TabsPrimitive.Content>,
248
+ "value"
211
249
  > {
212
250
  /** Data hook for automated testing */
213
251
  dataHook?: string;
@@ -215,45 +253,56 @@ interface TabsContentProps extends React.ComponentProps<
215
253
  trackingEl?: string;
216
254
  /** Tracking label for analytics context */
217
255
  trackingLabel?: string;
256
+ /** The value that identifies which tab this content belongs to */
257
+ value: T;
218
258
  }
219
259
 
220
- const TabsContent = React.forwardRef<
221
- React.ComponentRef<typeof TabsPrimitive.Content>,
222
- TabsContentProps
223
- >(
224
- (
225
- { className, dataHook, trackingEl, trackingLabel, value, ...props },
226
- ref
227
- ) => {
228
- const { lazyMount, unmountOnExit, activeValue, visitedTabs } =
229
- React.useContext(TabsContext);
260
+ function TabsContentInner<T extends string = string>(
261
+ {
262
+ className,
263
+ dataHook,
264
+ trackingEl,
265
+ trackingLabel,
266
+ value,
267
+ ...props
268
+ }: TabsContentProps<T>,
269
+ ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Content>>
270
+ ) {
271
+ const { lazyMount, unmountOnExit, activeValue, visitedTabs } =
272
+ React.useContext(TabsContext);
230
273
 
231
- const isActive = value === activeValue;
274
+ const isActive = value === activeValue;
232
275
 
233
- if (lazyMount && !visitedTabs.has(value!)) {
234
- return null;
235
- }
236
-
237
- if (unmountOnExit && !isActive) {
238
- return null;
239
- }
276
+ if (lazyMount && !visitedTabs.has(value)) {
277
+ return null;
278
+ }
240
279
 
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
- );
280
+ if (unmountOnExit && !isActive) {
281
+ return null;
253
282
  }
254
- );
255
283
 
256
- TabsContent.displayName = "TabsContent";
284
+ return (
285
+ <TabsPrimitive.Content
286
+ ref={ref}
287
+ className={cn("flex-1 outline-none", className)}
288
+ data-hook={dataHook}
289
+ data-slot="tabs-content"
290
+ data-tracking-el={trackingEl}
291
+ data-tracking-label={trackingLabel}
292
+ value={value}
293
+ {...props}
294
+ />
295
+ );
296
+ }
297
+
298
+ const TabsContent = React.forwardRef(TabsContentInner) as <
299
+ T extends string = string,
300
+ >(
301
+ props: TabsContentProps<T> &
302
+ React.RefAttributes<React.ComponentRef<typeof TabsPrimitive.Content>>
303
+ ) => React.ReactElement | null;
304
+
305
+ (TabsContent as React.FC).displayName = "TabsContent";
257
306
 
258
307
  export { Tabs, TabsList, TabsTrigger, TabsContent };
259
308