@brightlocal/ui-components 2.22.0 → 2.24.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/AI_USAGE.md +1 -1
- package/README.md +4 -2
- package/component-meta.json +134 -25
- package/deprecations.json +22 -0
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +32 -35
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +151 -156
- package/dist/brand-illustration-motif.cjs +1 -0
- package/dist/brand-illustration-motif.d.ts +55 -0
- package/dist/brand-illustration-motif.d.ts.map +1 -0
- package/dist/brand-illustration-motif.js +67 -0
- package/dist/chart.cjs +7 -7
- package/dist/chart.d.ts +287 -2
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +408 -152
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +14 -1
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +387 -376
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +111 -109
- package/dist/data-table.cjs +1 -0
- package/dist/{blocks/data-table.d.ts → data-table.d.ts} +159 -4
- package/dist/data-table.d.ts.map +1 -0
- package/dist/data-table.js +721 -0
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/dropdown-menu.js +109 -121
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +16 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +23 -7
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +32 -2
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +179 -109
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +526 -509
- package/dist/label.cjs +1 -1
- package/dist/label.d.ts +9 -0
- package/dist/label.d.ts.map +1 -1
- package/dist/label.js +26 -22
- package/dist/lib/spring-settle.cjs +1 -0
- package/dist/lib/spring-settle.d.ts +20 -0
- package/dist/lib/spring-settle.d.ts.map +1 -0
- package/dist/lib/spring-settle.js +4 -0
- package/dist/link.cjs +1 -1
- package/dist/link.d.ts +3 -2
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +22 -11
- package/dist/loading.cjs +1 -0
- package/dist/loading.d.ts +47 -0
- package/dist/loading.d.ts.map +1 -0
- package/dist/loading.js +163 -0
- package/dist/map.cjs +1 -1
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +1 -1
- package/dist/menubar.cjs +1 -1
- package/dist/menubar.d.ts.map +1 -1
- package/dist/menubar.js +97 -99
- package/dist/popover.cjs +1 -1
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +27 -26
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +16 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +112 -85
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +29 -0
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +2 -2
- package/dist/text-reveal-motion.cjs +1 -1
- package/dist/text-reveal-motion.d.ts.map +1 -1
- package/dist/text-reveal-motion.js +236 -219
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts +21 -2
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +35 -32
- package/dist/typography.cjs +1 -1
- package/dist/typography.d.ts +20 -4
- package/dist/typography.d.ts.map +1 -1
- package/dist/typography.js +263 -228
- package/package.json +7 -7
- package/src/blocks/sidebar.tsx +11 -23
- package/src/components/alert.tsx +10 -17
- package/src/components/brand-illustration-motif.tsx +143 -0
- package/src/components/chart.tsx +632 -1
- package/src/components/combobox.tsx +47 -0
- package/src/components/context-menu.tsx +8 -3
- package/src/{blocks → components}/data-table.tsx +272 -18
- package/src/components/dropdown-menu.tsx +6 -15
- package/src/components/field.tsx +31 -0
- package/src/components/global-layout.tsx +144 -5
- package/src/components/label.tsx +13 -1
- package/src/components/link.tsx +13 -1
- package/src/components/loading.tsx +355 -0
- package/src/components/map.tsx +3 -1
- package/src/components/menubar.tsx +6 -5
- package/src/components/popover.tsx +6 -2
- package/src/components/select.tsx +87 -10
- package/src/components/table.tsx +31 -2
- package/src/components/text-reveal-motion.tsx +90 -64
- package/src/components/tooltip.tsx +28 -3
- package/src/components/typography.tsx +74 -18
- package/src/index.ts +3 -1
- package/src/lib/spring-settle.ts +19 -0
- package/dist/blocks/data-table.cjs +0 -1
- package/dist/blocks/data-table.d.ts.map +0 -1
- package/dist/blocks/data-table.js +0 -654
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
+
import { ArrowLeft } from "@brightlocal/icons";
|
|
3
4
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
4
5
|
import { Header } from "./header";
|
|
6
|
+
import { Link } from "./link";
|
|
5
7
|
import { ScrollArea } from "./scroll-area";
|
|
8
|
+
import { TypographyMuted } from "./typography";
|
|
6
9
|
|
|
7
10
|
interface GlobalLayoutProps extends React.ComponentProps<"div"> {
|
|
8
11
|
/**
|
|
@@ -167,6 +170,86 @@ const GlobalLayoutContent = React.forwardRef<
|
|
|
167
170
|
|
|
168
171
|
GlobalLayoutContent.displayName = "GlobalLayoutContent";
|
|
169
172
|
|
|
173
|
+
interface GlobalLayoutBackLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
174
|
+
/**
|
|
175
|
+
* Data hook for automated testing
|
|
176
|
+
* @default "content-header-back-link"
|
|
177
|
+
*/
|
|
178
|
+
dataHook?: string;
|
|
179
|
+
/**
|
|
180
|
+
* Accessible label for the icon-only back link.
|
|
181
|
+
* @default "Go back"
|
|
182
|
+
*/
|
|
183
|
+
ariaLabel?: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Icon-only back link for the page header. Place it as a direct child of
|
|
188
|
+
* `GlobalLayoutContentHeader` — the header positions it before the title.
|
|
189
|
+
* Pass `href` for URL navigation or `onClick` for SPA router navigation.
|
|
190
|
+
*/
|
|
191
|
+
const GlobalLayoutBackLink = React.forwardRef<
|
|
192
|
+
HTMLAnchorElement,
|
|
193
|
+
GlobalLayoutBackLinkProps
|
|
194
|
+
>(({ dataHook, ariaLabel, href, onClick, ...props }, ref) => {
|
|
195
|
+
// An anchor without href is not keyboard-focusable, so when only a click
|
|
196
|
+
// handler is given the link falls back to href="#" and cancels the hash
|
|
197
|
+
// navigation before delegating to the handler.
|
|
198
|
+
const handleClick: React.MouseEventHandler<HTMLAnchorElement> = (event) => {
|
|
199
|
+
if (href === undefined) {
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
}
|
|
202
|
+
onClick?.(event);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<Link
|
|
207
|
+
ref={ref}
|
|
208
|
+
// `||` rather than `??`: an icon-only link must never end up with an
|
|
209
|
+
// empty accessible name, so an empty string also falls back.
|
|
210
|
+
aria-label={ariaLabel || "Go back"}
|
|
211
|
+
data-slot="content-header-back-link"
|
|
212
|
+
dataHook={dataHook ?? "content-header-back-link"}
|
|
213
|
+
href={href ?? "#"}
|
|
214
|
+
variant="icon"
|
|
215
|
+
onClick={handleClick}
|
|
216
|
+
{...props}
|
|
217
|
+
>
|
|
218
|
+
<ArrowLeft aria-hidden="true" />
|
|
219
|
+
</Link>
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
GlobalLayoutBackLink.displayName = "GlobalLayoutBackLink";
|
|
224
|
+
|
|
225
|
+
interface GlobalLayoutSubtitleProps extends React.ComponentProps<"p"> {
|
|
226
|
+
/**
|
|
227
|
+
* Data hook for automated testing
|
|
228
|
+
* @default "content-header-subtitle"
|
|
229
|
+
*/
|
|
230
|
+
dataHook?: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Muted description text for the page header. Place it as a direct child of
|
|
235
|
+
* `GlobalLayoutContentHeader` — the header positions it below the title row.
|
|
236
|
+
*/
|
|
237
|
+
const GlobalLayoutSubtitle = React.forwardRef<
|
|
238
|
+
HTMLParagraphElement,
|
|
239
|
+
GlobalLayoutSubtitleProps
|
|
240
|
+
>(({ dataHook, ...props }, ref) => {
|
|
241
|
+
return (
|
|
242
|
+
<TypographyMuted
|
|
243
|
+
ref={ref}
|
|
244
|
+
data-slot="content-header-subtitle"
|
|
245
|
+
dataHook={dataHook ?? "content-header-subtitle"}
|
|
246
|
+
{...props}
|
|
247
|
+
/>
|
|
248
|
+
);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
GlobalLayoutSubtitle.displayName = "GlobalLayoutSubtitle";
|
|
252
|
+
|
|
170
253
|
interface GlobalLayoutContentHeaderProps extends React.ComponentProps<"header"> {
|
|
171
254
|
/**
|
|
172
255
|
* Data hook for automated testing (required)
|
|
@@ -190,13 +273,53 @@ const GlobalLayoutContentHeader = React.forwardRef<
|
|
|
190
273
|
{ className, dataHook, trackingEl, trackingLabel, children, ...props },
|
|
191
274
|
ref
|
|
192
275
|
) => {
|
|
276
|
+
// Slot the back link and subtitle out of the flat children so the
|
|
277
|
+
// header can lay them out per the design: back link before a column of
|
|
278
|
+
// title row + subtitle. Both must be direct children (not wrapped in
|
|
279
|
+
// fragments or other elements).
|
|
280
|
+
const backLinks: React.ReactNode[] = [];
|
|
281
|
+
const subtitles: React.ReactNode[] = [];
|
|
282
|
+
const titleChildren: React.ReactNode[] = [];
|
|
283
|
+
|
|
284
|
+
React.Children.forEach(children, (child) => {
|
|
285
|
+
if (React.isValidElement(child) && child.type === GlobalLayoutBackLink) {
|
|
286
|
+
backLinks.push(child);
|
|
287
|
+
} else if (
|
|
288
|
+
React.isValidElement(child) &&
|
|
289
|
+
child.type === GlobalLayoutSubtitle
|
|
290
|
+
) {
|
|
291
|
+
subtitles.push(child);
|
|
292
|
+
} else {
|
|
293
|
+
titleChildren.push(child);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// Without a back link or subtitle the header keeps its original flat
|
|
298
|
+
// structure — children are laid out directly by the header row.
|
|
299
|
+
if (backLinks.length === 0 && subtitles.length === 0) {
|
|
300
|
+
return (
|
|
301
|
+
<Header
|
|
302
|
+
ref={ref}
|
|
303
|
+
className={cn(
|
|
304
|
+
"mx-auto w-full flex-wrap justify-between gap-4",
|
|
305
|
+
className
|
|
306
|
+
)}
|
|
307
|
+
data-slot="content-header"
|
|
308
|
+
dataHook={dataHook}
|
|
309
|
+
style={{ maxWidth: "var(--ds-breakpoint-lg)" }}
|
|
310
|
+
trackingEl={trackingEl}
|
|
311
|
+
trackingLabel={trackingLabel}
|
|
312
|
+
{...props}
|
|
313
|
+
>
|
|
314
|
+
{children}
|
|
315
|
+
</Header>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
193
319
|
return (
|
|
194
320
|
<Header
|
|
195
321
|
ref={ref}
|
|
196
|
-
className={cn(
|
|
197
|
-
"mx-auto w-full flex-wrap justify-between gap-4",
|
|
198
|
-
className
|
|
199
|
-
)}
|
|
322
|
+
className={cn("mx-auto w-full items-start", className)}
|
|
200
323
|
data-slot="content-header"
|
|
201
324
|
dataHook={dataHook}
|
|
202
325
|
style={{ maxWidth: "var(--ds-breakpoint-lg)" }}
|
|
@@ -204,7 +327,19 @@ const GlobalLayoutContentHeader = React.forwardRef<
|
|
|
204
327
|
trackingLabel={trackingLabel}
|
|
205
328
|
{...props}
|
|
206
329
|
>
|
|
207
|
-
{
|
|
330
|
+
{backLinks}
|
|
331
|
+
<div
|
|
332
|
+
className="flex min-w-0 flex-1 flex-col gap-2"
|
|
333
|
+
data-slot="content-header-body"
|
|
334
|
+
>
|
|
335
|
+
<div
|
|
336
|
+
className="flex w-full flex-wrap items-center justify-between gap-4"
|
|
337
|
+
data-slot="content-header-title"
|
|
338
|
+
>
|
|
339
|
+
{titleChildren}
|
|
340
|
+
</div>
|
|
341
|
+
{subtitles}
|
|
342
|
+
</div>
|
|
208
343
|
</Header>
|
|
209
344
|
);
|
|
210
345
|
}
|
|
@@ -364,6 +499,8 @@ export {
|
|
|
364
499
|
GlobalLayoutContent,
|
|
365
500
|
GlobalLayoutContentActions,
|
|
366
501
|
GlobalLayoutContentHeader,
|
|
502
|
+
GlobalLayoutBackLink,
|
|
503
|
+
GlobalLayoutSubtitle,
|
|
367
504
|
GlobalLayoutContentBody,
|
|
368
505
|
GlobalLayoutMobileHeader,
|
|
369
506
|
};
|
|
@@ -374,6 +511,8 @@ export type {
|
|
|
374
511
|
GlobalLayoutContentProps,
|
|
375
512
|
GlobalLayoutContentActionsProps,
|
|
376
513
|
GlobalLayoutContentHeaderProps,
|
|
514
|
+
GlobalLayoutBackLinkProps,
|
|
515
|
+
GlobalLayoutSubtitleProps,
|
|
377
516
|
GlobalLayoutContentBodyProps,
|
|
378
517
|
GlobalLayoutMobileHeaderProps,
|
|
379
518
|
};
|
package/src/components/label.tsx
CHANGED
|
@@ -12,6 +12,9 @@ const labelVariants = cva(
|
|
|
12
12
|
optional: {
|
|
13
13
|
true: "after:ml-1 after:content-['(optional)']",
|
|
14
14
|
},
|
|
15
|
+
srOnly: {
|
|
16
|
+
true: "sr-only",
|
|
17
|
+
},
|
|
15
18
|
},
|
|
16
19
|
defaultVariants: {},
|
|
17
20
|
}
|
|
@@ -38,6 +41,14 @@ interface LabelProps extends React.ComponentPropsWithoutRef<"label"> {
|
|
|
38
41
|
* @default false
|
|
39
42
|
*/
|
|
40
43
|
optional?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Visually hides the label while keeping it in the accessibility tree,
|
|
46
|
+
* preserving the label/input association via `htmlFor`.
|
|
47
|
+
* The parent element must establish a positioning context (`relative`) —
|
|
48
|
+
* Field handles this automatically for FieldLabel.
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
srOnly?: boolean;
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
const Label = React.forwardRef<HTMLLabelElement, LabelProps>(
|
|
@@ -45,6 +56,7 @@ const Label = React.forwardRef<HTMLLabelElement, LabelProps>(
|
|
|
45
56
|
{
|
|
46
57
|
className,
|
|
47
58
|
optional,
|
|
59
|
+
srOnly,
|
|
48
60
|
dataHook,
|
|
49
61
|
trackingEl,
|
|
50
62
|
trackingLabel,
|
|
@@ -58,7 +70,7 @@ const Label = React.forwardRef<HTMLLabelElement, LabelProps>(
|
|
|
58
70
|
ref={ref}
|
|
59
71
|
className={cn(
|
|
60
72
|
"flex items-center select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
|
61
|
-
labelVariants({ optional }),
|
|
73
|
+
labelVariants({ optional, srOnly }),
|
|
62
74
|
className
|
|
63
75
|
)}
|
|
64
76
|
data-hook={dataHook}
|
package/src/components/link.tsx
CHANGED
|
@@ -82,6 +82,17 @@ const linkVariants = cva(
|
|
|
82
82
|
"text-foreground",
|
|
83
83
|
"hover:bg-accent",
|
|
84
84
|
],
|
|
85
|
+
// Icon-only, circular. Mirrors `ghost` in a fixed 36px square
|
|
86
|
+
// footprint for icon-only links (e.g. back navigation).
|
|
87
|
+
// Requires an `aria-label` since there is no text content.
|
|
88
|
+
icon: [
|
|
89
|
+
...buttonStyledBase,
|
|
90
|
+
"w-9",
|
|
91
|
+
"px-0",
|
|
92
|
+
"bg-transparent",
|
|
93
|
+
"text-foreground",
|
|
94
|
+
"hover:bg-accent",
|
|
95
|
+
],
|
|
85
96
|
},
|
|
86
97
|
},
|
|
87
98
|
defaultVariants: {
|
|
@@ -103,7 +114,8 @@ export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
|
103
114
|
/**
|
|
104
115
|
* Visual style variant. `inline` renders a standard text link; `filled`,
|
|
105
116
|
* `outline` and `ghost` render button-styled treatments for inline actions
|
|
106
|
-
* and high-priority navigation
|
|
117
|
+
* and high-priority navigation; `icon` renders a circular icon-only link
|
|
118
|
+
* (provide an `aria-label` since there is no text content).
|
|
107
119
|
* @default "inline"
|
|
108
120
|
*/
|
|
109
121
|
variant?: LinkVariant;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useEffect, useId, useMemo, useRef } from "react";
|
|
5
|
+
import { animate } from "framer-motion";
|
|
6
|
+
|
|
7
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
|
+
import { usePrefersReducedMotion } from "../hooks/use-prefers-reduced-motion";
|
|
9
|
+
import { SETTLE_REST_DELTA } from "../lib/spring-settle";
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Shape paths (500×500 viewBox)
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
const CIRCLE_PATH =
|
|
16
|
+
"M250 500C388.071 500 500 388.071 500 250C500 111.929 388.071 0 250 0C111.929 0 0 111.929 0 250C0 388.071 111.929 500 250 500Z";
|
|
17
|
+
|
|
18
|
+
const STAR_PATH =
|
|
19
|
+
"M492.425 259.355C332.265 293.145 293.145 332.265 259.355 492.425C257.225 502.525 242.775 502.525 240.645 492.425C206.855 332.265 167.735 293.145 7.575 259.355C-2.525 257.225 -2.525 242.775 7.575 240.645C167.735 206.855 206.855 167.735 240.645 7.575C242.775 -2.525 257.225 -2.525 259.355 7.575C293.145 167.735 332.265 206.855 492.425 240.645C502.525 242.775 502.525 257.225 492.425 259.355Z";
|
|
20
|
+
|
|
21
|
+
const STAR_BURST =
|
|
22
|
+
"M258.366 5.58795L296.379 97.3854C298.509 102.526 304.729 104.546 309.47 101.636L394.177 49.7215C401.057 45.5112 409.598 51.7117 407.708 59.5523L384.506 156.16C383.206 161.571 387.046 166.861 392.596 167.301L491.645 175.092C499.685 175.722 502.945 185.763 496.815 191.003L421.259 255.528C417.029 259.138 417.029 265.679 421.259 269.299L496.815 333.824C502.945 339.065 499.685 349.106 491.645 349.736L392.596 357.526C387.046 357.966 383.206 363.257 384.506 368.667L407.708 465.275C409.588 473.116 401.047 479.326 394.177 475.106L309.47 423.192C304.729 420.282 298.509 422.302 296.379 427.442L258.366 519.24C255.275 526.69 244.725 526.69 241.634 519.24L203.621 427.442C201.491 422.302 195.271 420.282 190.53 423.192L105.823 475.106C98.9428 479.316 90.4021 473.116 92.2922 465.275L115.494 368.667C116.794 363.257 112.954 357.966 107.403 357.526L8.35543 349.736C0.314784 349.106 -2.94548 339.065 3.18502 333.824L78.7411 269.299C82.9715 265.689 82.9715 259.148 78.7411 255.528L3.18502 191.003C-2.94548 185.763 0.314784 175.722 8.35543 175.092L107.403 167.301C112.954 166.861 116.794 161.571 115.494 156.16L92.2922 59.5523C90.4121 51.7117 98.9528 45.5012 105.823 49.7215L190.53 101.636C195.271 104.546 201.491 102.526 203.621 97.3854L241.634 5.58795C244.725 -1.86265 255.275 -1.86265 258.366 5.58795Z";
|
|
23
|
+
|
|
24
|
+
/** Clamp value to [0, 1] — avoids repeated Math.min/max in hot loops */
|
|
25
|
+
const clamp01 = (v: number) => (v < 0 ? 0 : v > 1 ? 1 : v);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Default 6-shape morph sequence: circle → star → burst → circle → burst → star.
|
|
29
|
+
* The repeated circle acts as a natural "blink" beat between orderings.
|
|
30
|
+
*/
|
|
31
|
+
const LOADING_SHAPES: string[] = [
|
|
32
|
+
CIRCLE_PATH,
|
|
33
|
+
STAR_PATH,
|
|
34
|
+
STAR_BURST,
|
|
35
|
+
CIRCLE_PATH,
|
|
36
|
+
STAR_BURST,
|
|
37
|
+
STAR_PATH,
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Baked-in animation tuning
|
|
42
|
+
//
|
|
43
|
+
// These values are fixed, not consumer-configurable — the balance was tuned in
|
|
44
|
+
// the Lab playground (DS-770). Consumers get a single, opinionated loader.
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
/** Pause (ms) each shape holds before morphing to the next */
|
|
48
|
+
const HOLD_MS = 150;
|
|
49
|
+
/** Spring stiffness for the morph + rotation */
|
|
50
|
+
const STIFFNESS = 30;
|
|
51
|
+
/**
|
|
52
|
+
* Spring damping — higher = less oscillation.
|
|
53
|
+
* Must stay ≥ 2×√(STIFFNESS×MASS) (≈7.75) so the spring never overshoots —
|
|
54
|
+
* the settle trick below depends on it (see SETTLE_REST_DELTA).
|
|
55
|
+
*/
|
|
56
|
+
const DAMPING = 9;
|
|
57
|
+
/** Spring mass — higher = more inertia */
|
|
58
|
+
const MASS = 0.5;
|
|
59
|
+
/** Degrees of rotation per morph cycle (clockwise) */
|
|
60
|
+
const ROTATION_DEG = 360;
|
|
61
|
+
/** Rendered size of the loader in pixels (width and height) */
|
|
62
|
+
const SIZE = 56;
|
|
63
|
+
/** Speed of the gradient angle drift */
|
|
64
|
+
const GRADIENT_WANDER_SPEED = 0.15;
|
|
65
|
+
/** How far the gradient endpoints swing from centre */
|
|
66
|
+
const GRADIENT_WANDER_RADIUS = 45;
|
|
67
|
+
/** Base gradient direction — `from` colour glowing from the top-right
|
|
68
|
+
* corner into the `to` colour toward bottom-left, matching the brand
|
|
69
|
+
* Gradient Green swatch. */
|
|
70
|
+
const GRADIENT_BASE_ANGLE = -Math.PI / 4;
|
|
71
|
+
/** How far the gradient angle may drift from the base direction (radians) */
|
|
72
|
+
const GRADIENT_WANDER_SWING = 0.5;
|
|
73
|
+
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Props
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Props for the Loading component.
|
|
80
|
+
* Extends native `svg` props for full attribute + layout-className support.
|
|
81
|
+
*/
|
|
82
|
+
export interface LoadingProps extends Omit<
|
|
83
|
+
React.ComponentPropsWithoutRef<"svg">,
|
|
84
|
+
"children"
|
|
85
|
+
> {
|
|
86
|
+
/**
|
|
87
|
+
* Required data-hook attribute for automated testing.
|
|
88
|
+
* @example "page-loading"
|
|
89
|
+
*/
|
|
90
|
+
dataHook: string;
|
|
91
|
+
/**
|
|
92
|
+
* Accessible label for the loading animation, announced by screen readers.
|
|
93
|
+
* @default "Loading"
|
|
94
|
+
*/
|
|
95
|
+
loadingLabel?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Tracking element identifier for analytics.
|
|
98
|
+
*/
|
|
99
|
+
trackingEl?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Tracking label for analytics context.
|
|
102
|
+
*/
|
|
103
|
+
trackingLabel?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Component
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Brand loading animation — a gradient shape that morphs between a circle, a
|
|
112
|
+
* star, and a starburst while gently rotating, with a slowly wandering gradient.
|
|
113
|
+
*
|
|
114
|
+
* The animation is fully self-contained and opinionated: size, timing, spring
|
|
115
|
+
* physics and colours are all baked in. The only accessibility hook is an
|
|
116
|
+
* optional `loadingLabel`. Colours come from the `--loading-gradient-from` /
|
|
117
|
+
* `--loading-gradient-to` design tokens — the brand "Gradient Green"
|
|
118
|
+
* (#FFF085 → #2AE855) in light mode, chart-token variants in dark mode.
|
|
119
|
+
*
|
|
120
|
+
* Respects `prefers-reduced-motion`: renders a static shape when reduced motion
|
|
121
|
+
* is requested.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* <Loading dataHook="page-loading" />
|
|
126
|
+
* <Loading dataHook="page-loading" loadingLabel={t("common.loading")} />
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
const Loading = React.forwardRef<SVGSVGElement, LoadingProps>(
|
|
130
|
+
(
|
|
131
|
+
{ className, dataHook, loadingLabel, trackingEl, trackingLabel, ...props },
|
|
132
|
+
ref
|
|
133
|
+
) => {
|
|
134
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
135
|
+
const rawId = useId();
|
|
136
|
+
const gradientId = useMemo(
|
|
137
|
+
() => `loading-gradient-${rawId.replace(/:/g, "")}`,
|
|
138
|
+
[rawId]
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const pathRef = useRef<SVGPathElement>(null);
|
|
142
|
+
const groupRef = useRef<SVGGElement>(null);
|
|
143
|
+
const gradientElRef = useRef<SVGLinearGradientElement>(null);
|
|
144
|
+
|
|
145
|
+
// -----------------------------------------------------------------------
|
|
146
|
+
// Slow wandering gradient direction
|
|
147
|
+
// -----------------------------------------------------------------------
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (reducedMotion) return;
|
|
150
|
+
const grad = gradientElRef.current;
|
|
151
|
+
if (!grad) return;
|
|
152
|
+
const gradEl: SVGLinearGradientElement = grad;
|
|
153
|
+
let raf: number;
|
|
154
|
+
let start: number | null = null;
|
|
155
|
+
const sA =
|
|
156
|
+
GRADIENT_WANDER_SPEED * 0.8 +
|
|
157
|
+
Math.random() * GRADIENT_WANDER_SPEED * 0.4;
|
|
158
|
+
const sB =
|
|
159
|
+
GRADIENT_WANDER_SPEED * 0.53 +
|
|
160
|
+
Math.random() * GRADIENT_WANDER_SPEED * 0.27;
|
|
161
|
+
const oA = Math.random() * Math.PI * 2;
|
|
162
|
+
const oB = Math.random() * Math.PI * 2;
|
|
163
|
+
let prevAngle = -Infinity;
|
|
164
|
+
function tick(now: number) {
|
|
165
|
+
if (start === null) start = now;
|
|
166
|
+
const t = (now - start) / 1000;
|
|
167
|
+
const angle =
|
|
168
|
+
GRADIENT_BASE_ANGLE +
|
|
169
|
+
Math.sin(t * sA + oA) * GRADIENT_WANDER_SWING +
|
|
170
|
+
Math.sin(t * sB + oB) * 0.25;
|
|
171
|
+
if (Math.abs(angle - prevAngle) > 0.01) {
|
|
172
|
+
prevAngle = angle;
|
|
173
|
+
const cos = Math.cos(angle);
|
|
174
|
+
const sin = Math.sin(angle);
|
|
175
|
+
gradEl.setAttribute("x1", `${50 + GRADIENT_WANDER_RADIUS * cos}%`);
|
|
176
|
+
gradEl.setAttribute("y1", `${50 + GRADIENT_WANDER_RADIUS * sin}%`);
|
|
177
|
+
gradEl.setAttribute("x2", `${50 - GRADIENT_WANDER_RADIUS * cos}%`);
|
|
178
|
+
gradEl.setAttribute("y2", `${50 - GRADIENT_WANDER_RADIUS * sin}%`);
|
|
179
|
+
}
|
|
180
|
+
raf = requestAnimationFrame(tick);
|
|
181
|
+
}
|
|
182
|
+
raf = requestAnimationFrame(tick);
|
|
183
|
+
return () => cancelAnimationFrame(raf);
|
|
184
|
+
}, [reducedMotion]);
|
|
185
|
+
|
|
186
|
+
// -----------------------------------------------------------------------
|
|
187
|
+
// Morph + rotation loop with holds between shapes
|
|
188
|
+
// -----------------------------------------------------------------------
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
const path = pathRef.current;
|
|
191
|
+
const group = groupRef.current;
|
|
192
|
+
if (!path || !group) return;
|
|
193
|
+
|
|
194
|
+
// The gradient counter-rotates against the shape so its orientation
|
|
195
|
+
// stays fixed on screen (yellow anchored top-right) while the shape
|
|
196
|
+
// spins beneath it.
|
|
197
|
+
const setRotation = (deg: number) => {
|
|
198
|
+
group.style.transform = `rotate(${deg}deg)`;
|
|
199
|
+
gradientElRef.current?.setAttribute(
|
|
200
|
+
"gradientTransform",
|
|
201
|
+
`rotate(${-deg} 0.5 0.5)`
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (reducedMotion) {
|
|
206
|
+
path.setAttribute("d", LOADING_SHAPES[0]!);
|
|
207
|
+
group.style.opacity = "1";
|
|
208
|
+
setRotation(0);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const signal = { cancelled: false };
|
|
213
|
+
|
|
214
|
+
async function loop() {
|
|
215
|
+
// Lazy-load flubber so it doesn't block first paint
|
|
216
|
+
const { interpolate } = await import("flubber");
|
|
217
|
+
if (signal.cancelled) return;
|
|
218
|
+
|
|
219
|
+
// Build one interpolator per transition up-front — constructing them is
|
|
220
|
+
// the expensive part (point matching), calling one per frame is cheap
|
|
221
|
+
// (tens of µs). Do NOT pre-sample into a frame table: the spring's slow
|
|
222
|
+
// settle tail makes discrete frames visible as a pop into the final
|
|
223
|
+
// shape at ~99%.
|
|
224
|
+
const morphs: Array<(t: number) => string> = [];
|
|
225
|
+
for (let i = 0; i < LOADING_SHAPES.length; i++) {
|
|
226
|
+
morphs.push(
|
|
227
|
+
interpolate(
|
|
228
|
+
LOADING_SHAPES[i]!,
|
|
229
|
+
LOADING_SHAPES[(i + 1) % LOADING_SHAPES.length]!
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
group!.style.opacity = "1";
|
|
235
|
+
let step = 0;
|
|
236
|
+
let rotation = 0;
|
|
237
|
+
|
|
238
|
+
while (!signal.cancelled) {
|
|
239
|
+
const morph = morphs[step]!;
|
|
240
|
+
|
|
241
|
+
// Hold on the current shape
|
|
242
|
+
await new Promise<void>((r) => setTimeout(r, HOLD_MS));
|
|
243
|
+
if (signal.cancelled) break;
|
|
244
|
+
|
|
245
|
+
const startRotation = rotation;
|
|
246
|
+
const targetRotation = rotation + ROTATION_DEG;
|
|
247
|
+
|
|
248
|
+
// Wrap animate so an in-flight spring is stopped on cleanup — without
|
|
249
|
+
// this, onUpdate keeps writing to detached DOM nodes if the component
|
|
250
|
+
// unmounts mid-morph (mirrors text-reveal-motion.tsx).
|
|
251
|
+
await new Promise<void>((resolve) => {
|
|
252
|
+
if (signal.cancelled) {
|
|
253
|
+
resolve();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const controls = animate(0, 1 + SETTLE_REST_DELTA, {
|
|
257
|
+
type: "spring",
|
|
258
|
+
stiffness: STIFFNESS,
|
|
259
|
+
damping: DAMPING,
|
|
260
|
+
mass: MASS,
|
|
261
|
+
restDelta: SETTLE_REST_DELTA,
|
|
262
|
+
onUpdate: (v: number) => {
|
|
263
|
+
if (signal.cancelled) {
|
|
264
|
+
controls.stop();
|
|
265
|
+
resolve();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const t = clamp01(v);
|
|
269
|
+
path!.setAttribute("d", morph(t));
|
|
270
|
+
setRotation(
|
|
271
|
+
startRotation + t * (targetRotation - startRotation)
|
|
272
|
+
);
|
|
273
|
+
},
|
|
274
|
+
onComplete: () => {
|
|
275
|
+
// Pin the exact end state — don't rely on motion-dom's
|
|
276
|
+
// internal guarantee that the final onUpdate fires with the
|
|
277
|
+
// snapped target value.
|
|
278
|
+
if (!signal.cancelled) {
|
|
279
|
+
path!.setAttribute("d", morph(1));
|
|
280
|
+
setRotation(targetRotation);
|
|
281
|
+
}
|
|
282
|
+
resolve();
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
rotation = targetRotation;
|
|
288
|
+
step = (step + 1) % LOADING_SHAPES.length;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
loop();
|
|
293
|
+
return () => {
|
|
294
|
+
signal.cancelled = true;
|
|
295
|
+
};
|
|
296
|
+
}, [reducedMotion]);
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<svg
|
|
300
|
+
ref={ref}
|
|
301
|
+
aria-label={loadingLabel ?? "Loading"}
|
|
302
|
+
className={cn("shrink-0", className)}
|
|
303
|
+
data-hook={dataHook}
|
|
304
|
+
data-slot="loading"
|
|
305
|
+
data-tracking-el={trackingEl}
|
|
306
|
+
data-tracking-label={trackingLabel}
|
|
307
|
+
fill="none"
|
|
308
|
+
height={SIZE}
|
|
309
|
+
role="img"
|
|
310
|
+
style={{ overflow: "visible" }}
|
|
311
|
+
viewBox="-30 -30 560 560"
|
|
312
|
+
width={SIZE}
|
|
313
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
314
|
+
{...props}
|
|
315
|
+
>
|
|
316
|
+
<defs>
|
|
317
|
+
{/* Static direction matches GRADIENT_BASE_ANGLE for the first
|
|
318
|
+
frame and the reduced-motion render. */}
|
|
319
|
+
<linearGradient
|
|
320
|
+
ref={gradientElRef}
|
|
321
|
+
id={gradientId}
|
|
322
|
+
x1="81.8%"
|
|
323
|
+
x2="18.2%"
|
|
324
|
+
y1="18.2%"
|
|
325
|
+
y2="81.8%"
|
|
326
|
+
>
|
|
327
|
+
{/* The from-stop sits far outside the shape so the brightest
|
|
328
|
+
visible point is already blended toward the to-colour —
|
|
329
|
+
pure yellow never shows. */}
|
|
330
|
+
<stop offset="-60%" stopColor="var(--loading-gradient-from)" />
|
|
331
|
+
<stop offset="120%" stopColor="var(--loading-gradient-to)" />
|
|
332
|
+
</linearGradient>
|
|
333
|
+
</defs>
|
|
334
|
+
<g
|
|
335
|
+
ref={groupRef}
|
|
336
|
+
style={{
|
|
337
|
+
opacity: 0,
|
|
338
|
+
transformOrigin: "250px 250px",
|
|
339
|
+
willChange: "transform",
|
|
340
|
+
}}
|
|
341
|
+
>
|
|
342
|
+
<path
|
|
343
|
+
ref={pathRef}
|
|
344
|
+
d={LOADING_SHAPES[0]}
|
|
345
|
+
fill={`url(#${gradientId})`}
|
|
346
|
+
/>
|
|
347
|
+
</g>
|
|
348
|
+
</svg>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
Loading.displayName = "Loading";
|
|
354
|
+
|
|
355
|
+
export { Loading };
|
package/src/components/map.tsx
CHANGED
|
@@ -141,7 +141,9 @@ const MAP_STYLES: Record<
|
|
|
141
141
|
// Shared dark mode store — one MutationObserver for all consumers
|
|
142
142
|
const _darkModeListeners = new Set<() => void>();
|
|
143
143
|
let _isDark =
|
|
144
|
-
typeof document !== "undefined" &&
|
|
144
|
+
typeof document !== "undefined" &&
|
|
145
|
+
!!document.body &&
|
|
146
|
+
document.body.classList.contains("dark");
|
|
145
147
|
let _darkModeObserverStarted = false;
|
|
146
148
|
|
|
147
149
|
function _initDarkModeObserver() {
|
|
@@ -3,7 +3,10 @@ import * as React from "react";
|
|
|
3
3
|
import * as MenubarPrimitive from "@radix-ui/react-menubar";
|
|
4
4
|
import { Check, ChevronRight, Circle } from "@brightlocal/icons";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
cn,
|
|
8
|
+
FLOATING_CONTENT_ANIMATION,
|
|
9
|
+
} from "@brightlocal/ui-components/lib/utils";
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Menubar component - A horizontal menu bar with multiple dropdown menus
|
|
@@ -112,8 +115,7 @@ function MenubarContent({
|
|
|
112
115
|
alignOffset={alignOffset}
|
|
113
116
|
className={cn(
|
|
114
117
|
"border-border bg-popover text-popover-foreground z-50 min-w-[12rem] origin-(--radix-menubar-content-transform-origin) rounded-md border p-1 shadow-md",
|
|
115
|
-
|
|
116
|
-
"data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
118
|
+
FLOATING_CONTENT_ANIMATION,
|
|
117
119
|
className
|
|
118
120
|
)}
|
|
119
121
|
data-slot="menubar-content"
|
|
@@ -407,8 +409,7 @@ function MenubarSubContent({
|
|
|
407
409
|
<MenubarPrimitive.SubContent
|
|
408
410
|
className={cn(
|
|
409
411
|
"border-border bg-popover text-popover-foreground z-50 min-w-[8rem] origin-(--radix-menubar-content-transform-origin) rounded-md border p-1 shadow-lg",
|
|
410
|
-
|
|
411
|
-
"data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
412
|
+
FLOATING_CONTENT_ANIMATION,
|
|
412
413
|
className
|
|
413
414
|
)}
|
|
414
415
|
data-slot="menubar-sub-content"
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
cn,
|
|
8
|
+
FLOATING_CONTENT_ANIMATION,
|
|
9
|
+
} from "@brightlocal/ui-components/lib/utils";
|
|
7
10
|
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
8
11
|
|
|
9
12
|
export interface PopoverProps extends React.ComponentProps<
|
|
@@ -93,7 +96,8 @@ const PopoverContent = React.forwardRef<
|
|
|
93
96
|
ref={ref}
|
|
94
97
|
align={align}
|
|
95
98
|
className={cn(
|
|
96
|
-
"bg-popover text-popover-foreground
|
|
99
|
+
"bg-popover text-popover-foreground z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
|
100
|
+
FLOATING_CONTENT_ANIMATION,
|
|
97
101
|
className
|
|
98
102
|
)}
|
|
99
103
|
data-hook={dataHook}
|