@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.
- package/component-meta.json +316 -19
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +203 -4
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +667 -393
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +5 -1
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +48 -31
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +8 -0
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +227 -226
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +450 -441
- 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/popover.cjs +1 -1
- package/dist/popover.js +7 -7
- package/dist/rating.cjs +1 -1
- package/dist/rating.js +13 -13
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +10 -2
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +36 -30
- 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/package.json +2 -2
- package/src/blocks/sidebar.tsx +596 -9
- package/src/components/card.tsx +23 -0
- package/src/components/combobox.tsx +10 -0
- package/src/components/dropdown-menu.tsx +1 -1
- package/src/components/list.tsx +45 -2
- package/src/components/popover.tsx +1 -1
- package/src/components/rating.tsx +1 -1
- package/src/components/select.tsx +24 -2
- package/src/components/table.tsx +39 -2
- package/src/components/tabs.tsx +195 -146
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
|
|