@brightlocal/ui-components 2.5.0 → 2.6.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.
@@ -1,21 +1,21 @@
1
1
  import * as React from "react";
2
2
 
3
3
  import { cn } from "@brightlocal/ui-components/lib/utils";
4
-
5
- // Matches Tailwind's max-w-7xl (1280px) and aligns with Figma design
6
- const MAX_WIDTH = "1280px";
4
+ import { Header } from "./header";
7
5
 
8
6
  /**
9
- * GlobalLayout provides a responsive layout structure with optional sidebar
10
- * and content containers that adapt to different breakpoints.
11
- *
12
- * Breakpoints:
13
- * - Mobile (< 768px): Full width content, no sidebar
14
- * - Tablet (768px - 1023px): Full width content, no sidebar
15
- * - Desktop (≥ 1024px): Sidebar + content with max-width container
16
- *
17
- * @see https://ui.shadcn.com/docs/components/sidebar for sidebar patterns
7
+ * Container width variants for GlobalLayout, matching Figma GlobalContainer `width` property.
8
+ * - "xl": 1280px max-width
9
+ * - "lg": 1024px max-width
10
+ * - "sm": 640px max-width
18
11
  */
12
+ type ContainerVariant = "xl" | "lg" | "sm";
13
+
14
+ const containerMaxWidth: Record<ContainerVariant, string> = {
15
+ xl: "var(--ds-breakpoint-xl)",
16
+ lg: "var(--ds-breakpoint-lg)",
17
+ sm: "var(--ds-breakpoint-sm)",
18
+ };
19
19
 
20
20
  interface GlobalLayoutProps extends React.ComponentProps<"div"> {
21
21
  /**
@@ -31,7 +31,12 @@ interface GlobalLayoutProps extends React.ComponentProps<"div"> {
31
31
  */
32
32
  trackingLabel?: string;
33
33
  /**
34
- * Maximum width for the global container (default: 1280px)
34
+ * Container max-width variant, matching Figma GlobalContainer `width` property.
35
+ * @default "xl"
36
+ */
37
+ variant?: ContainerVariant;
38
+ /**
39
+ * Custom maximum width for the global container. Overrides `variant` when set.
35
40
  */
36
41
  maxWidth?: string | number;
37
42
  }
@@ -40,7 +45,8 @@ const GlobalLayout = React.forwardRef<HTMLDivElement, GlobalLayoutProps>(
40
45
  (
41
46
  {
42
47
  className,
43
- maxWidth = MAX_WIDTH,
48
+ variant = "xl",
49
+ maxWidth,
44
50
  dataHook,
45
51
  trackingEl,
46
52
  trackingLabel,
@@ -49,14 +55,18 @@ const GlobalLayout = React.forwardRef<HTMLDivElement, GlobalLayoutProps>(
49
55
  },
50
56
  ref
51
57
  ) => {
52
- const maxWidthStyle =
53
- typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth;
58
+ const resolvedMaxWidth =
59
+ maxWidth != null
60
+ ? typeof maxWidth === "number"
61
+ ? `${maxWidth}px`
62
+ : maxWidth
63
+ : containerMaxWidth[variant];
54
64
 
55
65
  return (
56
66
  <div
57
67
  ref={ref}
58
68
  className={cn(
59
- "flex min-h-screen w-full flex-col px-4 md:px-6",
69
+ "py-section-sm pl-section-sm flex h-dvh w-full flex-col overflow-hidden",
60
70
  className
61
71
  )}
62
72
  data-hook={dataHook}
@@ -66,9 +76,9 @@ const GlobalLayout = React.forwardRef<HTMLDivElement, GlobalLayoutProps>(
66
76
  {...props}
67
77
  >
68
78
  <div
69
- className="mx-auto flex w-full flex-1 gap-4 md:gap-6"
79
+ className="mx-auto flex h-full w-full"
70
80
  data-slot="global-container"
71
- style={{ maxWidth: maxWidthStyle }}
81
+ style={{ maxWidth: resolvedMaxWidth }}
72
82
  >
73
83
  {children}
74
84
  </div>
@@ -102,10 +112,14 @@ const GlobalLayoutSidebar = React.forwardRef<
102
112
  return (
103
113
  <aside
104
114
  ref={ref}
105
- className={cn("hidden shrink-0 self-stretch lg:block", className)}
115
+ className={cn(
116
+ "focus-visible:shadow-default hidden h-full shrink-0 overflow-y-auto outline-none lg:block",
117
+ className
118
+ )}
106
119
  data-hook={dataHook}
107
120
  data-slot="sidebar-container"
108
121
  style={{ width: widthStyle }}
122
+ tabIndex={0}
109
123
  {...props}
110
124
  >
111
125
  {children}
@@ -116,12 +130,18 @@ const GlobalLayoutSidebar = React.forwardRef<
116
130
  GlobalLayoutSidebar.displayName = "GlobalLayoutSidebar";
117
131
 
118
132
  /**
119
- * Content width variants for GlobalLayoutContent
120
- * - "full": Full width of available space
121
- * - "md": Medium width (768px max-width)
122
- * - "sm": Small width (374px max-width)
133
+ * Content width variants for GlobalLayoutContent, matching Figma Content `width` property.
134
+ * - "lg": 1024px max-width
135
+ * - "md": 768px max-width
136
+ * - "sm": 640px max-width
123
137
  */
124
- type ContentVariant = "full" | "md" | "sm";
138
+ type ContentVariant = "lg" | "md" | "sm";
139
+
140
+ const contentMaxWidth: Record<ContentVariant, string> = {
141
+ lg: "var(--ds-breakpoint-lg)",
142
+ md: "var(--ds-breakpoint-md)",
143
+ sm: "var(--ds-breakpoint-sm)",
144
+ };
125
145
 
126
146
  interface GlobalLayoutContentProps extends React.ComponentProps<"div"> {
127
147
  /**
@@ -129,10 +149,8 @@ interface GlobalLayoutContentProps extends React.ComponentProps<"div"> {
129
149
  */
130
150
  dataHook?: string;
131
151
  /**
132
- * Content width variant:
133
- * - "full": Full width of available space
134
- * - "md": 768px max-width (medium)
135
- * - "sm": 374px max-width (small)
152
+ * Content max-width variant, matching Figma Content `width` property.
153
+ * @default "lg"
136
154
  */
137
155
  variant?: ContentVariant;
138
156
  /**
@@ -146,28 +164,23 @@ const GlobalLayoutContent = React.forwardRef<
146
164
  GlobalLayoutContentProps
147
165
  >(
148
166
  (
149
- { className, variant = "full", padding, dataHook, children, ...props },
167
+ { className, variant = "lg", padding, dataHook, children, ...props },
150
168
  ref
151
169
  ) => {
152
- // Aligned with Figma design and Tailwind breakpoints
153
- // md: 768px - matches Tailwind's max-w-3xl
154
- // sm: 374px - optimized for mobile content
155
- const contentMaxWidth: Record<ContentVariant, string> = {
156
- full: "100%",
157
- md: "768px",
158
- sm: "374px",
159
- };
160
-
161
170
  return (
162
171
  <div
163
172
  ref={ref}
164
- className={cn("flex min-h-0 min-w-0 flex-1 self-stretch", className)}
173
+ className={cn(
174
+ "focus-visible:shadow-default flex h-full min-h-0 min-w-0 flex-1 overflow-y-auto outline-none",
175
+ className
176
+ )}
165
177
  data-hook={dataHook}
166
178
  data-slot="content-wrapper"
179
+ tabIndex={0}
167
180
  {...props}
168
181
  >
169
182
  <div
170
- className={cn("mx-auto w-full")}
183
+ className="pr-section-sm mx-auto w-full"
171
184
  data-slot="content-container"
172
185
  style={{
173
186
  maxWidth: contentMaxWidth[variant],
@@ -183,10 +196,145 @@ const GlobalLayoutContent = React.forwardRef<
183
196
 
184
197
  GlobalLayoutContent.displayName = "GlobalLayoutContent";
185
198
 
186
- export { GlobalLayout, GlobalLayoutSidebar, GlobalLayoutContent };
199
+ interface GlobalLayoutContentHeaderProps extends React.ComponentProps<"header"> {
200
+ /**
201
+ * Data hook for automated testing (required)
202
+ */
203
+ dataHook: string;
204
+ /**
205
+ * Tracking element identifier for analytics
206
+ */
207
+ trackingEl?: string;
208
+ /**
209
+ * Tracking label for analytics context
210
+ */
211
+ trackingLabel?: string;
212
+ }
213
+
214
+ const GlobalLayoutContentHeader = React.forwardRef<
215
+ HTMLElement,
216
+ GlobalLayoutContentHeaderProps
217
+ >(
218
+ (
219
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
220
+ ref
221
+ ) => {
222
+ return (
223
+ <Header
224
+ ref={ref}
225
+ className={cn("px-content justify-between gap-6 pb-9", className)}
226
+ data-slot="content-header"
227
+ dataHook={dataHook}
228
+ trackingEl={trackingEl}
229
+ trackingLabel={trackingLabel}
230
+ {...props}
231
+ >
232
+ {children}
233
+ </Header>
234
+ );
235
+ }
236
+ );
237
+
238
+ GlobalLayoutContentHeader.displayName = "GlobalLayoutContentHeader";
239
+
240
+ interface GlobalLayoutContentBodyProps extends React.ComponentProps<"div"> {
241
+ /**
242
+ * Data hook for automated testing
243
+ */
244
+ dataHook?: string;
245
+ /**
246
+ * Tracking element identifier for analytics
247
+ */
248
+ trackingEl?: string;
249
+ /**
250
+ * Tracking label for analytics context
251
+ */
252
+ trackingLabel?: string;
253
+ }
254
+
255
+ const GlobalLayoutContentBody = React.forwardRef<
256
+ HTMLDivElement,
257
+ GlobalLayoutContentBodyProps
258
+ >(
259
+ (
260
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
261
+ ref
262
+ ) => {
263
+ return (
264
+ <div
265
+ ref={ref}
266
+ className={cn("px-content flex flex-col gap-6", className)}
267
+ data-hook={dataHook}
268
+ data-slot="content-body"
269
+ data-tracking-el={trackingEl}
270
+ data-tracking-label={trackingLabel}
271
+ {...props}
272
+ >
273
+ {children}
274
+ </div>
275
+ );
276
+ }
277
+ );
278
+
279
+ GlobalLayoutContentBody.displayName = "GlobalLayoutContentBody";
280
+
281
+ interface GlobalLayoutMobileHeaderProps extends React.ComponentProps<"header"> {
282
+ /**
283
+ * Data hook for automated testing (required)
284
+ */
285
+ dataHook: string;
286
+ /**
287
+ * Tracking element identifier for analytics
288
+ */
289
+ trackingEl?: string;
290
+ /**
291
+ * Tracking label for analytics context
292
+ */
293
+ trackingLabel?: string;
294
+ }
295
+
296
+ const GlobalLayoutMobileHeader = React.forwardRef<
297
+ HTMLElement,
298
+ GlobalLayoutMobileHeaderProps
299
+ >(
300
+ (
301
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
302
+ ref
303
+ ) => {
304
+ return (
305
+ <Header
306
+ ref={ref}
307
+ className={cn("gap-2.5 px-2.5 py-2 lg:hidden", className)}
308
+ data-slot="mobile-header"
309
+ dataHook={dataHook}
310
+ trackingEl={trackingEl}
311
+ trackingLabel={trackingLabel}
312
+ {...props}
313
+ >
314
+ {children}
315
+ </Header>
316
+ );
317
+ }
318
+ );
319
+
320
+ GlobalLayoutMobileHeader.displayName = "GlobalLayoutMobileHeader";
321
+
322
+ export {
323
+ GlobalLayout,
324
+ GlobalLayoutSidebar,
325
+ GlobalLayoutContent,
326
+ GlobalLayoutContentHeader,
327
+ GlobalLayoutContentBody,
328
+ GlobalLayoutMobileHeader,
329
+ };
187
330
 
188
331
  export type {
332
+ ContainerVariant,
333
+ ContentVariant,
189
334
  GlobalLayoutProps,
190
335
  GlobalLayoutSidebarProps,
191
336
  GlobalLayoutContentProps,
337
+ GlobalLayoutContentHeaderProps,
338
+ GlobalLayoutContentBodyProps,
339
+ GlobalLayoutMobileHeaderProps,
192
340
  };
@@ -3,7 +3,7 @@ import * as React from "react";
3
3
  /** Fallback used when the CSS variable is not available (e.g. SSR) */
4
4
  const MOBILE_BREAKPOINT_FALLBACK = 640;
5
5
 
6
- function getMobileBreakpoint(): number {
6
+ export function getMobileBreakpoint(): number {
7
7
  if (typeof document === "undefined") return MOBILE_BREAKPOINT_FALLBACK;
8
8
 
9
9
  const raw = getComputedStyle(document.documentElement)
@@ -14,6 +14,12 @@ function getMobileBreakpoint(): number {
14
14
  return Number.isNaN(parsed) ? MOBILE_BREAKPOINT_FALLBACK : parsed;
15
15
  }
16
16
 
17
+ export function isMobileViewport(): boolean {
18
+ return (
19
+ typeof window !== "undefined" && window.innerWidth < getMobileBreakpoint()
20
+ );
21
+ }
22
+
17
23
  export function useIsMobile() {
18
24
  const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
19
25
  undefined