@brightlocal/ui-components 2.11.0 → 2.13.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 (154) hide show
  1. package/component-meta.json +474 -27
  2. package/dist/blocks/data-table.cjs +1 -1
  3. package/dist/blocks/data-table.d.ts +16 -4
  4. package/dist/blocks/data-table.d.ts.map +1 -1
  5. package/dist/blocks/data-table.js +57 -53
  6. package/dist/blocks/input-list.cjs +2 -2
  7. package/dist/blocks/input-list.d.ts +7 -1
  8. package/dist/blocks/input-list.d.ts.map +1 -1
  9. package/dist/blocks/input-list.js +82 -81
  10. package/dist/blocks/sidebar.cjs +1 -1
  11. package/dist/blocks/sidebar.d.ts +221 -11
  12. package/dist/blocks/sidebar.d.ts.map +1 -1
  13. package/dist/blocks/sidebar.js +687 -406
  14. package/dist/breadcrumb.cjs +1 -1
  15. package/dist/breadcrumb.d.ts +14 -2
  16. package/dist/breadcrumb.d.ts.map +1 -1
  17. package/dist/breadcrumb.js +37 -37
  18. package/dist/callout.cjs +1 -1
  19. package/dist/callout.d.ts +3 -3
  20. package/dist/callout.d.ts.map +1 -1
  21. package/dist/callout.js +2 -1
  22. package/dist/carousel.cjs +1 -1
  23. package/dist/carousel.d.ts +24 -3
  24. package/dist/carousel.d.ts.map +1 -1
  25. package/dist/carousel.js +121 -117
  26. package/dist/chip.cjs +1 -1
  27. package/dist/chip.d.ts +11 -0
  28. package/dist/chip.d.ts.map +1 -1
  29. package/dist/chip.js +43 -38
  30. package/dist/combobox.cjs +3 -3
  31. package/dist/combobox.d.ts +20 -2
  32. package/dist/combobox.d.ts.map +1 -1
  33. package/dist/combobox.js +244 -238
  34. package/dist/command.cjs +1 -1
  35. package/dist/command.d.ts +5 -0
  36. package/dist/command.d.ts.map +1 -1
  37. package/dist/command.js +207 -206
  38. package/dist/date-picker.cjs +1 -1
  39. package/dist/date-picker.d.ts +10 -0
  40. package/dist/date-picker.d.ts.map +1 -1
  41. package/dist/date-picker.js +96 -96
  42. package/dist/dialog.cjs +1 -1
  43. package/dist/dialog.d.ts +7 -2
  44. package/dist/dialog.d.ts.map +1 -1
  45. package/dist/dialog.js +38 -30
  46. package/dist/drawer.d.ts +2 -2
  47. package/dist/dropdown-menu.cjs +1 -1
  48. package/dist/dropdown-menu.js +1 -1
  49. package/dist/global-layout.cjs +1 -1
  50. package/dist/global-layout.d.ts +5 -0
  51. package/dist/global-layout.d.ts.map +1 -1
  52. package/dist/global-layout.js +15 -7
  53. package/dist/index.cjs +1 -1
  54. package/dist/index.js +313 -305
  55. package/dist/input-chip.cjs +1 -1
  56. package/dist/input-chip.d.ts +7 -1
  57. package/dist/input-chip.d.ts.map +1 -1
  58. package/dist/input-chip.js +131 -130
  59. package/dist/input-group.d.ts +1 -1
  60. package/dist/input-password.cjs +1 -1
  61. package/dist/input-password.d.ts +10 -0
  62. package/dist/input-password.d.ts.map +1 -1
  63. package/dist/input-password.js +108 -106
  64. package/dist/link.cjs +1 -1
  65. package/dist/link.d.ts +1 -1
  66. package/dist/link.d.ts.map +1 -1
  67. package/dist/link.js +36 -37
  68. package/dist/list.cjs +1 -1
  69. package/dist/list.d.ts +25 -4
  70. package/dist/list.d.ts.map +1 -1
  71. package/dist/list.js +71 -53
  72. package/dist/logo.cjs +1 -1
  73. package/dist/logo.d.ts +6 -1
  74. package/dist/logo.d.ts.map +1 -1
  75. package/dist/logo.js +25 -22
  76. package/dist/map.cjs +1 -1
  77. package/dist/map.d.ts +17 -2
  78. package/dist/map.d.ts.map +1 -1
  79. package/dist/map.js +32 -26
  80. package/dist/pagination.cjs +1 -1
  81. package/dist/pagination.d.ts +29 -3
  82. package/dist/pagination.d.ts.map +1 -1
  83. package/dist/pagination.js +26 -25
  84. package/dist/popover.cjs +1 -1
  85. package/dist/popover.js +7 -7
  86. package/dist/rating.cjs +1 -1
  87. package/dist/rating.d.ts +6 -0
  88. package/dist/rating.d.ts.map +1 -1
  89. package/dist/rating.js +28 -20
  90. package/dist/resizable.d.ts +1 -1
  91. package/dist/select.cjs +2 -2
  92. package/dist/select.d.ts +17 -3
  93. package/dist/select.d.ts.map +1 -1
  94. package/dist/select.js +65 -58
  95. package/dist/separator.cjs +1 -1
  96. package/dist/separator.d.ts +16 -4
  97. package/dist/separator.d.ts.map +1 -1
  98. package/dist/separator.js +38 -35
  99. package/dist/sheet.cjs +1 -1
  100. package/dist/sheet.d.ts +6 -1
  101. package/dist/sheet.d.ts.map +1 -1
  102. package/dist/sheet.js +42 -41
  103. package/dist/skeleton.cjs +1 -1
  104. package/dist/skeleton.d.ts +5 -0
  105. package/dist/skeleton.d.ts.map +1 -1
  106. package/dist/skeleton.js +13 -11
  107. package/dist/table.cjs +1 -1
  108. package/dist/table.d.ts +14 -0
  109. package/dist/table.d.ts.map +1 -1
  110. package/dist/table.js +57 -39
  111. package/dist/tabs.cjs +1 -1
  112. package/dist/tabs.d.ts +25 -9
  113. package/dist/tabs.d.ts.map +1 -1
  114. package/dist/tabs.js +128 -113
  115. package/dist/text-reveal-motion.cjs +1 -1
  116. package/dist/text-reveal-motion.d.ts +5 -0
  117. package/dist/text-reveal-motion.d.ts.map +1 -1
  118. package/dist/text-reveal-motion.js +111 -110
  119. package/dist/typography.cjs +1 -1
  120. package/dist/typography.d.ts +1 -2
  121. package/dist/typography.d.ts.map +1 -1
  122. package/dist/typography.js +49 -50
  123. package/package.json +2 -3
  124. package/src/blocks/data-table.tsx +26 -9
  125. package/src/blocks/input-list.tsx +12 -1
  126. package/src/blocks/sidebar.tsx +638 -29
  127. package/src/components/breadcrumb.tsx +43 -26
  128. package/src/components/callout.tsx +5 -4
  129. package/src/components/carousel.tsx +33 -4
  130. package/src/components/chip.tsx +22 -2
  131. package/src/components/combobox.tsx +28 -3
  132. package/src/components/command.tsx +7 -1
  133. package/src/components/date-picker.tsx +17 -3
  134. package/src/components/dialog.tsx +17 -4
  135. package/src/components/drawer.tsx +2 -2
  136. package/src/components/dropdown-menu.tsx +1 -1
  137. package/src/components/global-layout.tsx +15 -2
  138. package/src/components/input-chip.tsx +12 -1
  139. package/src/components/input-password.tsx +73 -49
  140. package/src/components/link.tsx +29 -17
  141. package/src/components/list.tsx +45 -2
  142. package/src/components/logo.tsx +10 -2
  143. package/src/components/map.tsx +23 -0
  144. package/src/components/pagination.tsx +44 -11
  145. package/src/components/popover.tsx +1 -1
  146. package/src/components/rating.tsx +21 -3
  147. package/src/components/select.tsx +33 -3
  148. package/src/components/separator.tsx +40 -25
  149. package/src/components/sheet.tsx +28 -20
  150. package/src/components/skeleton.tsx +13 -2
  151. package/src/components/table.tsx +39 -2
  152. package/src/components/tabs.tsx +195 -146
  153. package/src/components/text-reveal-motion.tsx +7 -1
  154. package/src/components/typography.tsx +6 -7
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
 
3
3
  import * as React from "react";
4
- import * as SeparatorPrimitive from "@radix-ui/react-separator";
5
4
 
6
5
  import { cn } from "@brightlocal/ui-components/lib/utils";
7
6
 
@@ -13,9 +12,19 @@ export type SeparatorOrientation = "horizontal" | "vertical";
13
12
  /**
14
13
  * Props for the Separator component.
15
14
  */
16
- interface SeparatorProps extends React.ComponentProps<
17
- typeof SeparatorPrimitive.Root
18
- > {
15
+ interface SeparatorProps extends React.ComponentPropsWithoutRef<"div"> {
16
+ /**
17
+ * Visual orientation of the separator.
18
+ * Horizontal renders a native `<hr>`, vertical renders a `<div>`.
19
+ * @default "horizontal"
20
+ */
21
+ orientation?: SeparatorOrientation;
22
+ /**
23
+ * When true, the separator is purely decorative (role="none").
24
+ * When false, it carries separator semantics for assistive technology.
25
+ * @default true
26
+ */
27
+ decorative?: boolean;
19
28
  /**
20
29
  * Data hook for automated testing
21
30
  */
@@ -32,12 +41,10 @@ interface SeparatorProps extends React.ComponentProps<
32
41
 
33
42
  /**
34
43
  * Separator visually divides content using a horizontal or vertical line.
35
- * Built on Radix UI Separator primitive.
44
+ * Horizontal orientation renders a semantic `<hr>` element.
45
+ * Vertical orientation renders a `<div>` with appropriate ARIA attributes.
36
46
  */
37
- const Separator = React.forwardRef<
38
- React.ComponentRef<typeof SeparatorPrimitive.Root>,
39
- SeparatorProps
40
- >(
47
+ const Separator = React.forwardRef<HTMLElement, SeparatorProps>(
41
48
  (
42
49
  {
43
50
  className,
@@ -50,22 +57,30 @@ const Separator = React.forwardRef<
50
57
  },
51
58
  ref
52
59
  ) => {
53
- return (
54
- <SeparatorPrimitive.Root
55
- ref={ref}
56
- className={cn(
57
- "bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
58
- className
59
- )}
60
- data-hook={dataHook}
61
- data-slot="separator"
62
- data-tracking-el={trackingEl}
63
- data-tracking-label={trackingLabel}
64
- decorative={decorative}
65
- orientation={orientation}
66
- {...props}
67
- />
68
- );
60
+ const ariaProps = decorative
61
+ ? { role: "none" as const }
62
+ : orientation === "vertical"
63
+ ? {
64
+ "aria-orientation": "vertical" as const,
65
+ role: "separator" as const,
66
+ }
67
+ : {};
68
+
69
+ return React.createElement(orientation === "horizontal" ? "hr" : "div", {
70
+ ref,
71
+ className: cn(
72
+ "bg-border shrink-0",
73
+ orientation === "horizontal" ? "h-px w-full border-0" : "h-full w-px",
74
+ className
75
+ ),
76
+ "data-hook": dataHook,
77
+ "data-orientation": orientation,
78
+ "data-slot": "separator",
79
+ "data-tracking-el": trackingEl,
80
+ "data-tracking-label": trackingLabel,
81
+ ...ariaProps,
82
+ ...props,
83
+ });
69
84
  }
70
85
  );
71
86
 
@@ -185,6 +185,11 @@ interface SheetContentProps
185
185
  * Tracking label for analytics context
186
186
  */
187
187
  trackingLabel?: string;
188
+ /**
189
+ * Accessible label for the close button.
190
+ * @default "Close"
191
+ */
192
+ closeLabel?: string;
188
193
  }
189
194
 
190
195
  /**
@@ -203,29 +208,32 @@ const SheetContent = React.forwardRef<
203
208
  dataHook,
204
209
  trackingEl,
205
210
  trackingLabel,
211
+ closeLabel,
206
212
  ...props
207
213
  },
208
214
  ref
209
- ) => (
210
- <SheetPortal>
211
- <SheetOverlay />
212
- <SheetPrimitive.Content
213
- ref={ref}
214
- className={cn(sheetContentVariants({ side }), className)}
215
- data-hook={dataHook}
216
- data-slot="sheet-content"
217
- data-tracking-el={trackingEl}
218
- data-tracking-label={trackingLabel}
219
- {...props}
220
- >
221
- {children}
222
- <SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0">
223
- <X />
224
- <span className="sr-only">Close</span>
225
- </SheetPrimitive.Close>
226
- </SheetPrimitive.Content>
227
- </SheetPortal>
228
- )
215
+ ) => {
216
+ return (
217
+ <SheetPortal>
218
+ <SheetOverlay />
219
+ <SheetPrimitive.Content
220
+ ref={ref}
221
+ className={cn(sheetContentVariants({ side }), className)}
222
+ data-hook={dataHook}
223
+ data-slot="sheet-content"
224
+ data-tracking-el={trackingEl}
225
+ data-tracking-label={trackingLabel}
226
+ {...props}
227
+ >
228
+ {children}
229
+ <SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0">
230
+ <X />
231
+ <span className="sr-only">{closeLabel ?? "Close"}</span>
232
+ </SheetPrimitive.Close>
233
+ </SheetPrimitive.Content>
234
+ </SheetPortal>
235
+ );
236
+ }
229
237
  );
230
238
  SheetContent.displayName = "SheetContent";
231
239
 
@@ -18,6 +18,11 @@ interface SkeletonProps extends React.ComponentProps<"div"> {
18
18
  * Tracking label for analytics context
19
19
  */
20
20
  trackingLabel?: string;
21
+ /**
22
+ * Accessible label announced to screen readers during loading.
23
+ * @default "Loading"
24
+ */
25
+ loadingLabel?: string;
21
26
  }
22
27
 
23
28
  /**
@@ -26,17 +31,23 @@ interface SkeletonProps extends React.ComponentProps<"div"> {
26
31
  * Use to represent text, images, avatars, or any other content while data is being fetched.
27
32
  */
28
33
  const Skeleton = React.forwardRef<HTMLDivElement, SkeletonProps>(
29
- ({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => {
34
+ (
35
+ { className, dataHook, trackingEl, trackingLabel, loadingLabel, ...props },
36
+ ref
37
+ ) => {
30
38
  return (
31
39
  <div
32
40
  ref={ref}
41
+ aria-busy="true"
33
42
  className={cn("bg-accent animate-pulse rounded-md", className)}
34
43
  data-hook={dataHook}
35
44
  data-slot="skeleton"
36
45
  data-tracking-el={trackingEl}
37
46
  data-tracking-label={trackingLabel}
38
47
  {...props}
39
- />
48
+ >
49
+ <span className="sr-only">{loadingLabel ?? "Loading"}</span>
50
+ </div>
40
51
  );
41
52
  }
42
53
  );
@@ -64,14 +64,50 @@ interface TableProps extends React.ComponentProps<"table"> {
64
64
  * Tracking label for analytics context
65
65
  */
66
66
  trackingLabel?: string;
67
+ /**
68
+ * Minimum width for the table (e.g., "600px", "40rem").
69
+ * Prevents columns from compressing on narrow viewports and enables
70
+ * horizontal scroll via the built-in overflow container.
71
+ * When set, the scroll container becomes a focusable region for
72
+ * keyboard accessibility.
73
+ */
74
+ minWidth?: string;
75
+ /**
76
+ * Accessible label for the scroll container region.
77
+ * Used when `minWidth` is set to provide context for keyboard users.
78
+ * @default "Scrollable table"
79
+ */
80
+ scrollRegionLabel?: string;
67
81
  }
68
82
 
69
83
  const Table = React.forwardRef<HTMLTableElement, TableProps>(
70
- ({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => {
84
+ (
85
+ {
86
+ className,
87
+ dataHook,
88
+ trackingEl,
89
+ trackingLabel,
90
+ minWidth,
91
+ scrollRegionLabel,
92
+ style,
93
+ ...props
94
+ },
95
+ ref
96
+ ) => {
71
97
  return (
72
98
  <div
73
- className="relative w-full overflow-x-auto"
99
+ className={cn(
100
+ "relative w-full overflow-x-auto",
101
+ minWidth && "focus-visible:shadow-default rounded-md outline-none"
102
+ )}
74
103
  data-slot="table-container"
104
+ {...(minWidth
105
+ ? {
106
+ role: "region",
107
+ "aria-label": scrollRegionLabel ?? "Scrollable table",
108
+ tabIndex: 0,
109
+ }
110
+ : undefined)}
75
111
  >
76
112
  <table
77
113
  ref={ref}
@@ -80,6 +116,7 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
80
116
  data-slot="table"
81
117
  data-tracking-el={trackingEl}
82
118
  data-tracking-label={trackingLabel}
119
+ style={{ minWidth, ...style }}
83
120
  {...props}
84
121
  />
85
122
  </div>
@@ -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