@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.
- package/component-meta.json +474 -27
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.d.ts +16 -4
- package/dist/blocks/data-table.d.ts.map +1 -1
- package/dist/blocks/data-table.js +57 -53
- package/dist/blocks/input-list.cjs +2 -2
- package/dist/blocks/input-list.d.ts +7 -1
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/input-list.js +82 -81
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +221 -11
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +687 -406
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts +14 -2
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +37 -37
- package/dist/callout.cjs +1 -1
- package/dist/callout.d.ts +3 -3
- package/dist/callout.d.ts.map +1 -1
- package/dist/callout.js +2 -1
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +24 -3
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +121 -117
- package/dist/chip.cjs +1 -1
- package/dist/chip.d.ts +11 -0
- package/dist/chip.d.ts.map +1 -1
- package/dist/chip.js +43 -38
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +20 -2
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +244 -238
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +5 -0
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +207 -206
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +10 -0
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +96 -96
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +7 -2
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +38 -30
- package/dist/drawer.d.ts +2 -2
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.js +1 -1
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +5 -0
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +15 -7
- package/dist/index.cjs +1 -1
- package/dist/index.js +313 -305
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +7 -1
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +131 -130
- package/dist/input-group.d.ts +1 -1
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +10 -0
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +108 -106
- package/dist/link.cjs +1 -1
- package/dist/link.d.ts +1 -1
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +36 -37
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts +25 -4
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +71 -53
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +6 -1
- package/dist/logo.d.ts.map +1 -1
- package/dist/logo.js +25 -22
- package/dist/map.cjs +1 -1
- package/dist/map.d.ts +17 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +32 -26
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +29 -3
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +26 -25
- package/dist/popover.cjs +1 -1
- package/dist/popover.js +7 -7
- package/dist/rating.cjs +1 -1
- package/dist/rating.d.ts +6 -0
- package/dist/rating.d.ts.map +1 -1
- package/dist/rating.js +28 -20
- package/dist/resizable.d.ts +1 -1
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +17 -3
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +65 -58
- package/dist/separator.cjs +1 -1
- package/dist/separator.d.ts +16 -4
- package/dist/separator.d.ts.map +1 -1
- package/dist/separator.js +38 -35
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +6 -1
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +42 -41
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.d.ts +5 -0
- package/dist/skeleton.d.ts.map +1 -1
- package/dist/skeleton.js +13 -11
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +14 -0
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +57 -39
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +25 -9
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +128 -113
- package/dist/text-reveal-motion.cjs +1 -1
- package/dist/text-reveal-motion.d.ts +5 -0
- package/dist/text-reveal-motion.d.ts.map +1 -1
- package/dist/text-reveal-motion.js +111 -110
- package/dist/typography.cjs +1 -1
- package/dist/typography.d.ts +1 -2
- package/dist/typography.d.ts.map +1 -1
- package/dist/typography.js +49 -50
- package/package.json +2 -3
- package/src/blocks/data-table.tsx +26 -9
- package/src/blocks/input-list.tsx +12 -1
- package/src/blocks/sidebar.tsx +638 -29
- package/src/components/breadcrumb.tsx +43 -26
- package/src/components/callout.tsx +5 -4
- package/src/components/carousel.tsx +33 -4
- package/src/components/chip.tsx +22 -2
- package/src/components/combobox.tsx +28 -3
- package/src/components/command.tsx +7 -1
- package/src/components/date-picker.tsx +17 -3
- package/src/components/dialog.tsx +17 -4
- package/src/components/drawer.tsx +2 -2
- package/src/components/dropdown-menu.tsx +1 -1
- package/src/components/global-layout.tsx +15 -2
- package/src/components/input-chip.tsx +12 -1
- package/src/components/input-password.tsx +73 -49
- package/src/components/link.tsx +29 -17
- package/src/components/list.tsx +45 -2
- package/src/components/logo.tsx +10 -2
- package/src/components/map.tsx +23 -0
- package/src/components/pagination.tsx +44 -11
- package/src/components/popover.tsx +1 -1
- package/src/components/rating.tsx +21 -3
- package/src/components/select.tsx +33 -3
- package/src/components/separator.tsx +40 -25
- package/src/components/sheet.tsx +28 -20
- package/src/components/skeleton.tsx +13 -2
- package/src/components/table.tsx +39 -2
- package/src/components/tabs.tsx +195 -146
- package/src/components/text-reveal-motion.tsx +7 -1
- 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.
|
|
17
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
package/src/components/sheet.tsx
CHANGED
|
@@ -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
|
-
|
|
211
|
-
<
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
<
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
(
|
|
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
|
);
|
package/src/components/table.tsx
CHANGED
|
@@ -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
|
-
(
|
|
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=
|
|
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>
|
package/src/components/tabs.tsx
CHANGED
|
@@ -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
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
274
|
+
const isActive = value === activeValue;
|
|
232
275
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (unmountOnExit && !isActive) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
276
|
+
if (lazyMount && !visitedTabs.has(value)) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
240
279
|
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
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
|
|