@brightlocal/ui-components 2.8.0 → 2.9.1

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 (46) hide show
  1. package/component-meta.json +1 -1
  2. package/dist/alert.cjs +1 -1
  3. package/dist/alert.js +1 -1
  4. package/dist/blocks/sidebar.cjs +1 -1
  5. package/dist/blocks/sidebar.d.ts +39 -21
  6. package/dist/blocks/sidebar.d.ts.map +1 -1
  7. package/dist/blocks/sidebar.js +379 -425
  8. package/dist/callout.cjs +1 -1
  9. package/dist/callout.js +1 -1
  10. package/dist/card.cjs +1 -1
  11. package/dist/card.js +11 -11
  12. package/dist/combobox.cjs +3 -3
  13. package/dist/combobox.d.ts +24 -3
  14. package/dist/combobox.d.ts.map +1 -1
  15. package/dist/combobox.js +327 -302
  16. package/dist/global-layout.cjs +1 -1
  17. package/dist/global-layout.d.ts +3 -7
  18. package/dist/global-layout.d.ts.map +1 -1
  19. package/dist/global-layout.js +85 -81
  20. package/dist/hooks/use-breakpoint.cjs +1 -0
  21. package/dist/hooks/use-breakpoint.d.ts +15 -0
  22. package/dist/hooks/use-breakpoint.d.ts.map +1 -0
  23. package/dist/hooks/use-breakpoint.js +30 -0
  24. package/dist/hooks/use-mobile.d.ts +13 -3
  25. package/dist/hooks/use-mobile.d.ts.map +1 -1
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +124 -121
  30. package/dist/scroll-area.cjs +1 -1
  31. package/dist/scroll-area.d.ts +5 -0
  32. package/dist/scroll-area.d.ts.map +1 -1
  33. package/dist/scroll-area.js +34 -25
  34. package/package.json +1 -1
  35. package/src/blocks/sidebar.tsx +134 -148
  36. package/src/components/alert.tsx +1 -1
  37. package/src/components/callout.tsx +1 -1
  38. package/src/components/card.tsx +1 -1
  39. package/src/components/combobox.tsx +72 -11
  40. package/src/components/global-layout.tsx +46 -45
  41. package/src/components/scroll-area.tsx +15 -1
  42. package/src/hooks/use-breakpoint.ts +58 -0
  43. package/src/hooks/use-mobile.ts +20 -40
  44. package/src/index.ts +1 -0
  45. package/dist/hooks/use-mobile.cjs +0 -1
  46. package/dist/hooks/use-mobile.js +0 -26
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
 
3
3
  import { cn } from "@brightlocal/ui-components/lib/utils";
4
4
  import { Header } from "./header";
5
+ import { ScrollArea } from "./scroll-area";
5
6
 
6
7
  interface GlobalLayoutProps extends React.ComponentProps<"div"> {
7
8
  /**
@@ -40,34 +41,36 @@ const GlobalLayout = React.forwardRef<HTMLDivElement, GlobalLayoutProps>(
40
41
  typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth;
41
42
 
42
43
  return (
43
- <div
44
- ref={ref}
45
- className={cn(
46
- "py-section-sm pl-section-sm flex min-h-dvh w-full flex-col",
47
- className
48
- )}
49
- data-hook={dataHook}
50
- data-slot="global-layout"
51
- data-tracking-el={trackingEl}
52
- data-tracking-label={trackingLabel}
53
- {...props}
44
+ <ScrollArea
45
+ className={cn("h-dvh w-full", className)}
46
+ dataHook={`${dataHook}-scroll`}
47
+ scrollOrientation="both"
54
48
  >
55
49
  <div
56
- className="mx-auto flex w-full flex-1"
57
- data-slot="global-container"
58
- style={{ maxWidth: resolvedMaxWidth }}
50
+ ref={ref}
51
+ className="p-section-sm flex min-h-dvh w-full flex-col"
52
+ data-hook={dataHook}
53
+ data-slot="global-layout"
54
+ data-tracking-el={trackingEl}
55
+ data-tracking-label={trackingLabel}
56
+ {...props}
59
57
  >
60
- {children}
58
+ <div
59
+ className="mx-auto flex w-full flex-1"
60
+ data-slot="global-container"
61
+ style={{ maxWidth: resolvedMaxWidth }}
62
+ >
63
+ {children}
64
+ </div>
61
65
  </div>
62
- </div>
66
+ </ScrollArea>
63
67
  );
64
68
  }
65
69
  );
66
70
 
67
71
  GlobalLayout.displayName = "GlobalLayout";
68
72
 
69
- // Matches 16rem (256px) and aligns with Figma design
70
- const SIDEBAR_WIDTH = "256px";
73
+ const SIDEBAR_WIDTH = "224px";
71
74
 
72
75
  interface GlobalLayoutSidebarProps extends React.ComponentProps<"aside"> {
73
76
  /**
@@ -75,7 +78,7 @@ interface GlobalLayoutSidebarProps extends React.ComponentProps<"aside"> {
75
78
  */
76
79
  dataHook?: string;
77
80
  /**
78
- * Width of the sidebar (default: 256px)
81
+ * Width of the sidebar (default: 224px)
79
82
  */
80
83
  width?: string | number;
81
84
  }
@@ -118,10 +121,6 @@ interface GlobalLayoutContentProps extends React.ComponentProps<"div"> {
118
121
  * @default breakpoint.lg
119
122
  */
120
123
  maxWidth?: string | number;
121
- /**
122
- * Custom padding for the content wrapper
123
- */
124
- padding?: string;
125
124
  }
126
125
 
127
126
  const GlobalLayoutContent = React.forwardRef<
@@ -132,7 +131,6 @@ const GlobalLayoutContent = React.forwardRef<
132
131
  {
133
132
  className,
134
133
  maxWidth = "var(--ds-breakpoint-lg)",
135
- padding,
136
134
  dataHook,
137
135
  children,
138
136
  ...props
@@ -145,21 +143,18 @@ const GlobalLayoutContent = React.forwardRef<
145
143
  return (
146
144
  <div
147
145
  ref={ref}
148
- className={cn("flex min-w-0 flex-1", className)}
146
+ className={cn(
147
+ "px-section-xs flex min-w-0 flex-1 flex-col gap-6",
148
+ className
149
+ )}
149
150
  data-hook={dataHook}
150
151
  data-slot="content-wrapper"
152
+ style={
153
+ { "--content-max-width": resolvedMaxWidth } as React.CSSProperties
154
+ }
151
155
  {...props}
152
156
  >
153
- <div
154
- className="pr-section-sm mx-auto w-full"
155
- data-slot="content-container"
156
- style={{
157
- maxWidth: resolvedMaxWidth,
158
- padding,
159
- }}
160
- >
161
- {children}
162
- </div>
157
+ {children}
163
158
  </div>
164
159
  );
165
160
  }
@@ -193,7 +188,7 @@ const GlobalLayoutContentHeader = React.forwardRef<
193
188
  return (
194
189
  <Header
195
190
  ref={ref}
196
- className={cn("px-content justify-between gap-6 pb-9", className)}
191
+ className={cn("w-full justify-between", className)}
197
192
  data-slot="content-header"
198
193
  dataHook={dataHook}
199
194
  trackingEl={trackingEl}
@@ -234,11 +229,12 @@ const GlobalLayoutContentBody = React.forwardRef<
234
229
  return (
235
230
  <div
236
231
  ref={ref}
237
- className={cn("px-content flex flex-col gap-6", className)}
232
+ className={cn("mx-auto flex w-full flex-1 flex-col gap-6", className)}
238
233
  data-hook={dataHook}
239
234
  data-slot="content-body"
240
235
  data-tracking-el={trackingEl}
241
236
  data-tracking-label={trackingLabel}
237
+ style={{ maxWidth: "var(--content-max-width)" }}
242
238
  {...props}
243
239
  >
244
240
  {children}
@@ -249,7 +245,7 @@ const GlobalLayoutContentBody = React.forwardRef<
249
245
 
250
246
  GlobalLayoutContentBody.displayName = "GlobalLayoutContentBody";
251
247
 
252
- interface GlobalLayoutMobileHeaderProps extends React.ComponentProps<"header"> {
248
+ interface GlobalLayoutMobileHeaderProps extends React.ComponentProps<"div"> {
253
249
  /**
254
250
  * Data hook for automated testing (required)
255
251
  */
@@ -265,7 +261,7 @@ interface GlobalLayoutMobileHeaderProps extends React.ComponentProps<"header"> {
265
261
  }
266
262
 
267
263
  const GlobalLayoutMobileHeader = React.forwardRef<
268
- HTMLElement,
264
+ HTMLDivElement,
269
265
  GlobalLayoutMobileHeaderProps
270
266
  >(
271
267
  (
@@ -273,17 +269,22 @@ const GlobalLayoutMobileHeader = React.forwardRef<
273
269
  ref
274
270
  ) => {
275
271
  return (
276
- <Header
272
+ <div
277
273
  ref={ref}
278
- className={cn("gap-2.5 px-2.5 py-2 lg:hidden", className)}
274
+ aria-label="Mobile navigation"
275
+ className={cn(
276
+ "flex w-full items-center justify-start gap-2.5 py-2 lg:hidden",
277
+ className
278
+ )}
279
+ data-hook={dataHook}
279
280
  data-slot="mobile-header"
280
- dataHook={dataHook}
281
- trackingEl={trackingEl}
282
- trackingLabel={trackingLabel}
281
+ data-tracking-el={trackingEl}
282
+ data-tracking-label={trackingLabel}
283
+ role="toolbar"
283
284
  {...props}
284
285
  >
285
286
  {children}
286
- </Header>
287
+ </div>
287
288
  );
288
289
  }
289
290
  );
@@ -22,6 +22,11 @@ interface ScrollAreaProps extends React.ComponentProps<
22
22
  * Tracking label for analytics context
23
23
  */
24
24
  trackingLabel?: string;
25
+ /**
26
+ * Scrollbar orientation. "vertical" shows only vertical, "both" adds horizontal.
27
+ * @default "vertical"
28
+ */
29
+ scrollOrientation?: "vertical" | "both";
25
30
  }
26
31
 
27
32
  /**
@@ -33,7 +38,15 @@ const ScrollArea = React.forwardRef<
33
38
  ScrollAreaProps
34
39
  >(
35
40
  (
36
- { className, children, dataHook, trackingEl, trackingLabel, ...props },
41
+ {
42
+ className,
43
+ children,
44
+ dataHook,
45
+ trackingEl,
46
+ trackingLabel,
47
+ scrollOrientation = "vertical",
48
+ ...props
49
+ },
37
50
  ref
38
51
  ) => {
39
52
  return (
@@ -54,6 +67,7 @@ const ScrollArea = React.forwardRef<
54
67
  {children}
55
68
  </ScrollAreaPrimitive.Viewport>
56
69
  <ScrollBar />
70
+ {scrollOrientation === "both" && <ScrollBar orientation="horizontal" />}
57
71
  <ScrollAreaPrimitive.Corner />
58
72
  </ScrollAreaPrimitive.Root>
59
73
  );
@@ -0,0 +1,58 @@
1
+ import * as React from "react";
2
+
3
+ /**
4
+ * Breakpoint name matching design token keys from `@brightlocal/tokens/breakpoints`.
5
+ */
6
+ type Breakpoint = "sm" | "md" | "lg" | "xl" | "2xl";
7
+
8
+ /** Fallback values when CSS variables are not available (e.g. SSR) */
9
+ const BREAKPOINT_FALLBACKS: Record<Breakpoint, number> = {
10
+ sm: 640,
11
+ md: 768,
12
+ lg: 1024,
13
+ xl: 1280,
14
+ "2xl": 1536,
15
+ };
16
+
17
+ export function getBreakpointValue(size: Breakpoint = "sm"): number {
18
+ if (typeof document === "undefined") return BREAKPOINT_FALLBACKS[size];
19
+
20
+ const raw = getComputedStyle(document.documentElement)
21
+ .getPropertyValue(`--ds-breakpoint-${size}`)
22
+ .trim();
23
+ const parsed = parseInt(raw, 10);
24
+
25
+ return Number.isNaN(parsed) ? BREAKPOINT_FALLBACKS[size] : parsed;
26
+ }
27
+
28
+ export function isBelowBreakpoint(size: Breakpoint = "sm"): boolean {
29
+ return (
30
+ typeof window !== "undefined" &&
31
+ window.innerWidth < getBreakpointValue(size)
32
+ );
33
+ }
34
+
35
+ /**
36
+ * Returns `true` when the viewport is below the given breakpoint.
37
+ *
38
+ * @param size - Design token breakpoint name from `@brightlocal/tokens/breakpoints`
39
+ * @default "sm"
40
+ */
41
+ export function useIsBelowBreakpoint(size: Breakpoint = "sm") {
42
+ const [isBelow, setIsBelow] = React.useState<boolean | undefined>(undefined);
43
+
44
+ React.useEffect(() => {
45
+ const bp = getBreakpointValue(size);
46
+ const mql = window.matchMedia(`(max-width: ${bp - 1}px)`);
47
+ const onChange = () => {
48
+ setIsBelow(window.innerWidth < bp);
49
+ };
50
+ mql.addEventListener("change", onChange);
51
+ setIsBelow(window.innerWidth < bp);
52
+ return () => mql.removeEventListener("change", onChange);
53
+ }, [size]);
54
+
55
+ return !!isBelow;
56
+ }
57
+
58
+ export type { Breakpoint };
@@ -1,40 +1,20 @@
1
- import * as React from "react";
2
-
3
- /** Fallback used when the CSS variable is not available (e.g. SSR) */
4
- const MOBILE_BREAKPOINT_FALLBACK = 640;
5
-
6
- export function getMobileBreakpoint(): number {
7
- if (typeof document === "undefined") return MOBILE_BREAKPOINT_FALLBACK;
8
-
9
- const raw = getComputedStyle(document.documentElement)
10
- .getPropertyValue("--ds-breakpoint-sm")
11
- .trim();
12
- const parsed = parseInt(raw, 10);
13
-
14
- return Number.isNaN(parsed) ? MOBILE_BREAKPOINT_FALLBACK : parsed;
15
- }
16
-
17
- export function isMobileViewport(): boolean {
18
- return (
19
- typeof window !== "undefined" && window.innerWidth < getMobileBreakpoint()
20
- );
21
- }
22
-
23
- export function useIsMobile() {
24
- const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
25
- undefined
26
- );
27
-
28
- React.useEffect(() => {
29
- const breakpoint = getMobileBreakpoint();
30
- const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
31
- const onChange = () => {
32
- setIsMobile(window.innerWidth < breakpoint);
33
- };
34
- mql.addEventListener("change", onChange);
35
- setIsMobile(window.innerWidth < breakpoint);
36
- return () => mql.removeEventListener("change", onChange);
37
- }, []);
38
-
39
- return !!isMobile;
40
- }
1
+ /**
2
+ * @deprecated Import from `@brightlocal/ui-components/hooks/use-breakpoint` instead.
3
+ * This module re-exports everything from `use-breakpoint` for backward compatibility.
4
+ */
5
+ export {
6
+ getBreakpointValue,
7
+ isBelowBreakpoint as isMobileViewport,
8
+ useIsBelowBreakpoint,
9
+ type Breakpoint,
10
+ } from "./use-breakpoint";
11
+
12
+ /**
13
+ * @deprecated Use `getBreakpointValue()` instead.
14
+ */
15
+ export { getBreakpointValue as getMobileBreakpoint } from "./use-breakpoint";
16
+
17
+ /**
18
+ * @deprecated Use `useIsBelowBreakpoint("sm")` instead.
19
+ */
20
+ export { useIsBelowBreakpoint as useIsMobile } from "./use-breakpoint";
package/src/index.ts CHANGED
@@ -70,6 +70,7 @@ export * from "./blocks/sidebar";
70
70
 
71
71
  // Hooks
72
72
  export * from "./hooks/use-debounce";
73
+ export * from "./hooks/use-breakpoint";
73
74
  export * from "./hooks/use-mobile";
74
75
  export * from "./hooks/use-prefers-reduced-motion";
75
76
 
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function a(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const c=a(u),s=640;function i(){if(typeof document>"u")return s;const e=getComputedStyle(document.documentElement).getPropertyValue("--ds-breakpoint-sm").trim(),t=parseInt(e,10);return Number.isNaN(t)?s:t}function d(){return typeof window<"u"&&window.innerWidth<i()}function l(){const[e,t]=c.useState(void 0);return c.useEffect(()=>{const n=i(),o=window.matchMedia(`(max-width: ${n-1}px)`),r=()=>{t(window.innerWidth<n)};return o.addEventListener("change",r),t(window.innerWidth<n),()=>o.removeEventListener("change",r)},[]),!!e}exports.getMobileBreakpoint=i;exports.isMobileViewport=d;exports.useIsMobile=l;
@@ -1,26 +0,0 @@
1
- import * as r from "react";
2
- const d = 640;
3
- function s() {
4
- if (typeof document > "u") return d;
5
- const n = getComputedStyle(document.documentElement).getPropertyValue("--ds-breakpoint-sm").trim(), e = parseInt(n, 10);
6
- return Number.isNaN(e) ? d : e;
7
- }
8
- function u() {
9
- return typeof window < "u" && window.innerWidth < s();
10
- }
11
- function a() {
12
- const [n, e] = r.useState(
13
- void 0
14
- );
15
- return r.useEffect(() => {
16
- const t = s(), o = window.matchMedia(`(max-width: ${t - 1}px)`), i = () => {
17
- e(window.innerWidth < t);
18
- };
19
- return o.addEventListener("change", i), e(window.innerWidth < t), () => o.removeEventListener("change", i);
20
- }, []), !!n;
21
- }
22
- export {
23
- s as getMobileBreakpoint,
24
- u as isMobileViewport,
25
- a as useIsMobile
26
- };