@brightlocal/ui-components 2.9.2 → 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.
- package/README.md +3 -1
- package/component-meta.json +41 -9
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +42 -25
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +1 -3
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +46 -49
- package/dist/browser-entry.d.ts +17 -0
- package/dist/browser-entry.d.ts.map +1 -0
- package/dist/button.cjs +1 -1
- package/dist/button.js +25 -25
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +10 -1
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +85 -82
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +13 -1
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +196 -150
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +3 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +480 -440
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +101 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +383 -119
- package/dist/hooks/use-breakpoint.cjs +1 -1
- package/dist/hooks/use-breakpoint.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.js +10 -10
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +402 -391
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +1 -4
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +163 -170
- package/dist/map.cjs +1 -0
- package/dist/map.d.ts +192 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +250 -0
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +32 -30
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +4 -0
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +101 -52
- package/package.json +4 -1
- package/src/blocks/sidebar.tsx +21 -26
- package/src/browser-entry.ts +89 -0
- package/src/browser-tokens.css +1 -0
- package/src/components/badge.tsx +22 -5
- package/src/components/button.tsx +13 -13
- package/src/components/card.tsx +35 -19
- package/src/components/carousel.tsx +101 -9
- package/src/components/combobox.tsx +106 -28
- package/src/components/command.tsx +637 -16
- package/src/components/input-chip.tsx +102 -65
- package/src/components/map.tsx +574 -0
- package/src/components/sonner.tsx +9 -3
- package/src/components/tabs.tsx +118 -22
- package/src/hooks/use-breakpoint.ts +2 -3
- package/src/index.ts +1 -0
package/src/components/tabs.tsx
CHANGED
|
@@ -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
|
-
>(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
>(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
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
|
|
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";
|