@brightlocal/ui-components 2.5.0 → 2.6.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.
@@ -1,21 +1,7 @@
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";
7
-
8
- /**
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
18
- */
4
+ import { Header } from "./header";
19
5
 
20
6
  interface GlobalLayoutProps extends React.ComponentProps<"div"> {
21
7
  /**
@@ -31,7 +17,8 @@ interface GlobalLayoutProps extends React.ComponentProps<"div"> {
31
17
  */
32
18
  trackingLabel?: string;
33
19
  /**
34
- * Maximum width for the global container (default: 1280px)
20
+ * Maximum width of the global container. Use `breakpoint` tokens from `@brightlocal/tokens/breakpoints`.
21
+ * @default breakpoint.xl
35
22
  */
36
23
  maxWidth?: string | number;
37
24
  }
@@ -40,7 +27,7 @@ const GlobalLayout = React.forwardRef<HTMLDivElement, GlobalLayoutProps>(
40
27
  (
41
28
  {
42
29
  className,
43
- maxWidth = MAX_WIDTH,
30
+ maxWidth = "var(--ds-breakpoint-xl)",
44
31
  dataHook,
45
32
  trackingEl,
46
33
  trackingLabel,
@@ -49,14 +36,14 @@ const GlobalLayout = React.forwardRef<HTMLDivElement, GlobalLayoutProps>(
49
36
  },
50
37
  ref
51
38
  ) => {
52
- const maxWidthStyle =
39
+ const resolvedMaxWidth =
53
40
  typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth;
54
41
 
55
42
  return (
56
43
  <div
57
44
  ref={ref}
58
45
  className={cn(
59
- "flex min-h-screen w-full flex-col px-4 md:px-6",
46
+ "py-section-sm pl-section-sm flex min-h-dvh w-full flex-col",
60
47
  className
61
48
  )}
62
49
  data-hook={dataHook}
@@ -66,9 +53,9 @@ const GlobalLayout = React.forwardRef<HTMLDivElement, GlobalLayoutProps>(
66
53
  {...props}
67
54
  >
68
55
  <div
69
- className="mx-auto flex w-full flex-1 gap-4 md:gap-6"
56
+ className="mx-auto flex w-full flex-1"
70
57
  data-slot="global-container"
71
- style={{ maxWidth: maxWidthStyle }}
58
+ style={{ maxWidth: resolvedMaxWidth }}
72
59
  >
73
60
  {children}
74
61
  </div>
@@ -102,10 +89,16 @@ const GlobalLayoutSidebar = React.forwardRef<
102
89
  return (
103
90
  <aside
104
91
  ref={ref}
105
- className={cn("hidden shrink-0 self-stretch lg:block", className)}
92
+ className={cn(
93
+ "sticky hidden shrink-0 self-start outline-none lg:block",
94
+ className
95
+ )}
106
96
  data-hook={dataHook}
107
97
  data-slot="sidebar-container"
108
- style={{ width: widthStyle }}
98
+ style={{
99
+ width: widthStyle,
100
+ top: "var(--ds-section-padding-y-sm)",
101
+ }}
109
102
  {...props}
110
103
  >
111
104
  {children}
@@ -115,26 +108,16 @@ const GlobalLayoutSidebar = React.forwardRef<
115
108
 
116
109
  GlobalLayoutSidebar.displayName = "GlobalLayoutSidebar";
117
110
 
118
- /**
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)
123
- */
124
- type ContentVariant = "full" | "md" | "sm";
125
-
126
111
  interface GlobalLayoutContentProps extends React.ComponentProps<"div"> {
127
112
  /**
128
113
  * Data hook for automated testing
129
114
  */
130
115
  dataHook?: string;
131
116
  /**
132
- * Content width variant:
133
- * - "full": Full width of available space
134
- * - "md": 768px max-width (medium)
135
- * - "sm": 374px max-width (small)
117
+ * Maximum width of the content area. Use `breakpoint` tokens from `@brightlocal/tokens/breakpoints`.
118
+ * @default breakpoint.lg
136
119
  */
137
- variant?: ContentVariant;
120
+ maxWidth?: string | number;
138
121
  /**
139
122
  * Custom padding for the content wrapper
140
123
  */
@@ -146,31 +129,32 @@ const GlobalLayoutContent = React.forwardRef<
146
129
  GlobalLayoutContentProps
147
130
  >(
148
131
  (
149
- { className, variant = "full", padding, dataHook, children, ...props },
132
+ {
133
+ className,
134
+ maxWidth = "var(--ds-breakpoint-lg)",
135
+ padding,
136
+ dataHook,
137
+ children,
138
+ ...props
139
+ },
150
140
  ref
151
141
  ) => {
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
- };
142
+ const resolvedMaxWidth =
143
+ typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth;
160
144
 
161
145
  return (
162
146
  <div
163
147
  ref={ref}
164
- className={cn("flex min-h-0 min-w-0 flex-1 self-stretch", className)}
148
+ className={cn("flex min-w-0 flex-1", className)}
165
149
  data-hook={dataHook}
166
150
  data-slot="content-wrapper"
167
151
  {...props}
168
152
  >
169
153
  <div
170
- className={cn("mx-auto w-full")}
154
+ className="pr-section-sm mx-auto w-full"
171
155
  data-slot="content-container"
172
156
  style={{
173
- maxWidth: contentMaxWidth[variant],
157
+ maxWidth: resolvedMaxWidth,
174
158
  padding,
175
159
  }}
176
160
  >
@@ -183,10 +167,143 @@ const GlobalLayoutContent = React.forwardRef<
183
167
 
184
168
  GlobalLayoutContent.displayName = "GlobalLayoutContent";
185
169
 
186
- export { GlobalLayout, GlobalLayoutSidebar, GlobalLayoutContent };
170
+ interface GlobalLayoutContentHeaderProps extends React.ComponentProps<"header"> {
171
+ /**
172
+ * Data hook for automated testing (required)
173
+ */
174
+ dataHook: string;
175
+ /**
176
+ * Tracking element identifier for analytics
177
+ */
178
+ trackingEl?: string;
179
+ /**
180
+ * Tracking label for analytics context
181
+ */
182
+ trackingLabel?: string;
183
+ }
184
+
185
+ const GlobalLayoutContentHeader = React.forwardRef<
186
+ HTMLElement,
187
+ GlobalLayoutContentHeaderProps
188
+ >(
189
+ (
190
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
191
+ ref
192
+ ) => {
193
+ return (
194
+ <Header
195
+ ref={ref}
196
+ className={cn("px-content justify-between gap-6 pb-9", className)}
197
+ data-slot="content-header"
198
+ dataHook={dataHook}
199
+ trackingEl={trackingEl}
200
+ trackingLabel={trackingLabel}
201
+ {...props}
202
+ >
203
+ {children}
204
+ </Header>
205
+ );
206
+ }
207
+ );
208
+
209
+ GlobalLayoutContentHeader.displayName = "GlobalLayoutContentHeader";
210
+
211
+ interface GlobalLayoutContentBodyProps extends React.ComponentProps<"div"> {
212
+ /**
213
+ * Data hook for automated testing
214
+ */
215
+ dataHook?: string;
216
+ /**
217
+ * Tracking element identifier for analytics
218
+ */
219
+ trackingEl?: string;
220
+ /**
221
+ * Tracking label for analytics context
222
+ */
223
+ trackingLabel?: string;
224
+ }
225
+
226
+ const GlobalLayoutContentBody = React.forwardRef<
227
+ HTMLDivElement,
228
+ GlobalLayoutContentBodyProps
229
+ >(
230
+ (
231
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
232
+ ref
233
+ ) => {
234
+ return (
235
+ <div
236
+ ref={ref}
237
+ className={cn("px-content flex flex-col gap-6", className)}
238
+ data-hook={dataHook}
239
+ data-slot="content-body"
240
+ data-tracking-el={trackingEl}
241
+ data-tracking-label={trackingLabel}
242
+ {...props}
243
+ >
244
+ {children}
245
+ </div>
246
+ );
247
+ }
248
+ );
249
+
250
+ GlobalLayoutContentBody.displayName = "GlobalLayoutContentBody";
251
+
252
+ interface GlobalLayoutMobileHeaderProps extends React.ComponentProps<"header"> {
253
+ /**
254
+ * Data hook for automated testing (required)
255
+ */
256
+ dataHook: string;
257
+ /**
258
+ * Tracking element identifier for analytics
259
+ */
260
+ trackingEl?: string;
261
+ /**
262
+ * Tracking label for analytics context
263
+ */
264
+ trackingLabel?: string;
265
+ }
266
+
267
+ const GlobalLayoutMobileHeader = React.forwardRef<
268
+ HTMLElement,
269
+ GlobalLayoutMobileHeaderProps
270
+ >(
271
+ (
272
+ { className, dataHook, trackingEl, trackingLabel, children, ...props },
273
+ ref
274
+ ) => {
275
+ return (
276
+ <Header
277
+ ref={ref}
278
+ className={cn("gap-2.5 px-2.5 py-2 lg:hidden", className)}
279
+ data-slot="mobile-header"
280
+ dataHook={dataHook}
281
+ trackingEl={trackingEl}
282
+ trackingLabel={trackingLabel}
283
+ {...props}
284
+ >
285
+ {children}
286
+ </Header>
287
+ );
288
+ }
289
+ );
290
+
291
+ GlobalLayoutMobileHeader.displayName = "GlobalLayoutMobileHeader";
292
+
293
+ export {
294
+ GlobalLayout,
295
+ GlobalLayoutSidebar,
296
+ GlobalLayoutContent,
297
+ GlobalLayoutContentHeader,
298
+ GlobalLayoutContentBody,
299
+ GlobalLayoutMobileHeader,
300
+ };
187
301
 
188
302
  export type {
189
303
  GlobalLayoutProps,
190
304
  GlobalLayoutSidebarProps,
191
305
  GlobalLayoutContentProps,
306
+ GlobalLayoutContentHeaderProps,
307
+ GlobalLayoutContentBodyProps,
308
+ GlobalLayoutMobileHeaderProps,
192
309
  };
@@ -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