@brightlocal/ui-components 2.25.0 → 2.27.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 +4 -2
- package/component-meta.json +3809 -182
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts +23 -9
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +95 -87
- package/dist/blocks/progress-screen.cjs +1 -0
- package/dist/blocks/progress-screen.d.ts +109 -0
- package/dist/blocks/progress-screen.d.ts.map +1 -0
- package/dist/blocks/progress-screen.js +339 -0
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +155 -153
- package/dist/brand-illustration-motif.d.ts +1 -1
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +44 -40
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +28 -28
- package/dist/chip.cjs +1 -1
- package/dist/chip.d.ts +1 -1
- package/dist/chip.d.ts.map +1 -1
- package/dist/chip.js +42 -41
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +4 -2
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +161 -161
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +155 -4
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +462 -309
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +31 -5
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +276 -194
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +462 -451
- package/dist/lib/motion.cjs +1 -1
- package/dist/lib/motion.js +10 -8
- package/dist/link.cjs +1 -1
- package/dist/link.d.ts +5 -2
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +97 -91
- package/dist/list.cjs +1 -1
- package/dist/list.js +65 -63
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +61 -3
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +142 -65
- package/dist/route-progress.cjs +1 -0
- package/dist/route-progress.d.ts +103 -0
- package/dist/route-progress.d.ts.map +1 -0
- package/dist/route-progress.js +106 -0
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +35 -2
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +102 -65
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +11 -15
- package/dist/spinner.cjs +1 -0
- package/dist/spinner.d.ts +57 -0
- package/dist/spinner.d.ts.map +1 -0
- package/dist/spinner.js +35 -0
- package/dist/stepper.cjs +1 -1
- package/dist/stepper.d.ts.map +1 -1
- package/dist/stepper.js +26 -25
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +6 -2
- package/package.json +15 -6
- package/src/blocks/progress-screen.tsx +481 -0
- package/src/blocks/sidebar.tsx +22 -15
- package/src/components/alert.tsx +68 -33
- package/src/components/breadcrumb.tsx +9 -4
- package/src/components/button.tsx +2 -5
- package/src/components/chip.tsx +4 -3
- package/src/components/combobox.tsx +15 -8
- package/src/components/data-table.tsx +358 -16
- package/src/components/global-layout.tsx +228 -62
- package/src/components/link.tsx +88 -63
- package/src/components/list.tsx +5 -5
- package/src/components/progress.tsx +217 -30
- package/src/components/route-progress.tsx +354 -0
- package/src/components/sheet.tsx +87 -5
- package/src/components/sonner.tsx +3 -12
- package/src/components/spinner.tsx +94 -0
- package/src/components/stepper.tsx +3 -4
- package/src/components/table.tsx +6 -2
- package/src/index.ts +3 -0
- package/dist/browser-entry.d.ts +0 -19
- package/dist/browser-entry.d.ts.map +0 -1
- package/src/browser-entry.ts +0 -99
- package/src/browser-tokens.css +0 -1
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { usePrefersReducedMotion } from "@brightlocal/ui-components/hooks/use-prefers-reduced-motion";
|
|
6
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
7
|
+
import {
|
|
8
|
+
MOTION_DURATION_BASE_MS,
|
|
9
|
+
MOTION_DURATION_FAST_MS,
|
|
10
|
+
} from "../lib/motion";
|
|
11
|
+
|
|
12
|
+
/* -------------------------------------------------------------------------------------------------
|
|
13
|
+
* Trickle constants
|
|
14
|
+
* -------------------------------------------------------------------------------------------------*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fill the bar starts at, as a percentage of the viewport width.
|
|
18
|
+
*
|
|
19
|
+
* Never zero: the bar's first job is to acknowledge the click, and a
|
|
20
|
+
* zero-width bar acknowledges nothing. This is the one place the Loading
|
|
21
|
+
* pattern's Restraint principle does not apply — there is no minimum wait
|
|
22
|
+
* before the bar appears, because it reports the input rather than the wait.
|
|
23
|
+
*/
|
|
24
|
+
const START_FILL = 12;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Ceiling the creep approaches while the navigation is still in flight.
|
|
28
|
+
*
|
|
29
|
+
* Below 100 by design: the bar must never claim to be finished while the
|
|
30
|
+
* destination is still resolving. The remaining 10% is spent by the
|
|
31
|
+
* completion sweep.
|
|
32
|
+
*/
|
|
33
|
+
const CREEP_TARGET = 90;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* How long the creep takes to travel from {@link START_FILL} to
|
|
37
|
+
* {@link CREEP_TARGET}.
|
|
38
|
+
*
|
|
39
|
+
* Deliberately off the motion duration scale: this is not a UI state change
|
|
40
|
+
* but a progress trickle, and the scale tops out at 300ms. Paired with
|
|
41
|
+
* {@link CREEP_EASE} it front-loads most of the travel into the first second
|
|
42
|
+
* — where the great majority of navigations finish — and then slows to a
|
|
43
|
+
* crawl, so a slow route still shows movement without ever arriving.
|
|
44
|
+
*/
|
|
45
|
+
const CREEP_MS = 12000;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Strongly decelerating curve for the creep, taken from the motion token
|
|
49
|
+
* scale (`ease-emphasized`). A single long CSS transition on this curve gives
|
|
50
|
+
* the asymptotic trickle without a timer: because transitions interpolate
|
|
51
|
+
* from the *current computed value*, the completion sweep can interrupt it at
|
|
52
|
+
* any point and pick up exactly where it is.
|
|
53
|
+
*/
|
|
54
|
+
const CREEP_EASE = "var(--ds-motion-ease-emphasized)";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Grace period on the *falling* edge only: `active` going false schedules the
|
|
58
|
+
* completion rather than firing it, and `active` returning true inside the
|
|
59
|
+
* window cancels it and keeps the creep running.
|
|
60
|
+
*
|
|
61
|
+
* This exists because a real "has it settled?" signal is usually two signals
|
|
62
|
+
* handed off in sequence — the router stops being pending, then the
|
|
63
|
+
* destination's route-critical queries start. Without the grace the bar would
|
|
64
|
+
* sweep to 100%, fade, and immediately restart from 12% in the gap between
|
|
65
|
+
* them. The rising edge is never debounced: the bar still starts on the click
|
|
66
|
+
* with no threshold.
|
|
67
|
+
*/
|
|
68
|
+
const SETTLE_GRACE_MS = MOTION_DURATION_FAST_MS;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Static fill used when `prefers-reduced-motion` is set — the bar is present
|
|
72
|
+
* for the whole navigation but never moves. Mid-track so it reads as
|
|
73
|
+
* in-progress rather than as almost-done.
|
|
74
|
+
*/
|
|
75
|
+
const STATIC_FILL = 50;
|
|
76
|
+
|
|
77
|
+
/* -------------------------------------------------------------------------------------------------
|
|
78
|
+
* RouteProgress
|
|
79
|
+
* -------------------------------------------------------------------------------------------------*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Lifecycle phase of the bar.
|
|
83
|
+
* - `idle` — no navigation in flight; the track is mounted but invisible.
|
|
84
|
+
* - `start` — navigation just began; the bar is painted at {@link START_FILL}.
|
|
85
|
+
* - `creep` — travelling toward {@link CREEP_TARGET} while the route resolves.
|
|
86
|
+
* - `complete` — sweeping to 100%, then fading out.
|
|
87
|
+
*/
|
|
88
|
+
type RouteProgressPhase = "idle" | "start" | "creep" | "complete";
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Props for the RouteProgress component.
|
|
92
|
+
*/
|
|
93
|
+
interface RouteProgressProps extends Omit<
|
|
94
|
+
React.ComponentPropsWithoutRef<"div">,
|
|
95
|
+
"children"
|
|
96
|
+
> {
|
|
97
|
+
/**
|
|
98
|
+
* Required data-hook attribute for testing and component identification
|
|
99
|
+
*/
|
|
100
|
+
dataHook: string;
|
|
101
|
+
/**
|
|
102
|
+
* Whether a full route navigation is in flight.
|
|
103
|
+
*
|
|
104
|
+
* Derive it from the router rather than from a click handler — that is what
|
|
105
|
+
* gives the remaining pattern guarantees for free: browser back and forward
|
|
106
|
+
* run the bar too, and in-page changes (tabs, filter changes, pagination
|
|
107
|
+
* refetches, modals) never touch it, because none of them are route
|
|
108
|
+
* navigations.
|
|
109
|
+
*
|
|
110
|
+
* ```tsx
|
|
111
|
+
* const navigating = useRouterState({
|
|
112
|
+
* select: (state) => state.status === "pending",
|
|
113
|
+
* });
|
|
114
|
+
* <RouteProgress active={navigating} dataHook="route-progress" />
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* Prefer `status === "pending"` over `isLoading`: `isLoading` clears as soon
|
|
118
|
+
* as the route's loaders resolve, whereas `status` returns to `"idle"` only
|
|
119
|
+
* once `isLoading`, `isTransitioning` and `hasPendingMatches` are all false
|
|
120
|
+
* — so it also covers the React transition that commits the new route. And
|
|
121
|
+
* always pass `select`; `useRouterState()` with no selector re-renders the
|
|
122
|
+
* whole subtree on any router state change.
|
|
123
|
+
*
|
|
124
|
+
* **Router pending alone only means "the page is here", not "the page is
|
|
125
|
+
* ready."** It is the whole answer when the route declares its
|
|
126
|
+
* route-critical data in a loader — with TanStack Router,
|
|
127
|
+
* `loader: () => queryClient.ensureQueryData(...)` keeps `status` pending
|
|
128
|
+
* until that data has landed, which is exactly the signal this bar wants.
|
|
129
|
+
*
|
|
130
|
+
* Where components instead fetch on mount, the router goes idle as soon as
|
|
131
|
+
* the route commits and the bar finishes while skeletons are still
|
|
132
|
+
* rendering. Add the destination's own queries — **scoped to the route**,
|
|
133
|
+
* never a global `useIsFetching()`, which a polling or failing section would
|
|
134
|
+
* hold open forever:
|
|
135
|
+
*
|
|
136
|
+
* ```tsx
|
|
137
|
+
* const navigating = useRouterState({ select: (s) => s.status === "pending" });
|
|
138
|
+
* const loadingPage = useIsFetching({ queryKey: ["location", locationId] }) > 0;
|
|
139
|
+
* <RouteProgress active={navigating || loadingPage} dataHook="route-progress" />
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* Handing off between two such signals is safe: the bar debounces the
|
|
143
|
+
* falling edge, so it stays continuous through the gap instead of sweeping
|
|
144
|
+
* and restarting. The rising edge is never debounced.
|
|
145
|
+
*
|
|
146
|
+
* Aim at *route-critical* content, not every query on the page. A
|
|
147
|
+
* below-the-fold widget that is slow, failing, or polling must keep its own
|
|
148
|
+
* skeleton and let the bar finish — a bar still running on a usable page
|
|
149
|
+
* reads as a hang.
|
|
150
|
+
*/
|
|
151
|
+
active: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Optional tracking element identifier for analytics
|
|
154
|
+
*/
|
|
155
|
+
trackingEl?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Optional tracking label for analytics
|
|
158
|
+
*/
|
|
159
|
+
trackingLabel?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Announced politely to screen readers while `active` is true. The bar
|
|
162
|
+
* itself is decorative — its fill is a trickle, not measured progress, so
|
|
163
|
+
* it exposes no `progressbar` role or `aria-valuenow`.
|
|
164
|
+
* @default "Loading page"
|
|
165
|
+
*/
|
|
166
|
+
navigatingLabel?: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* A slim bar pinned to the top edge of the viewport that reports a full route
|
|
171
|
+
* navigation: it starts the moment the navigation begins and completes when
|
|
172
|
+
* the destination's route-critical content has settled.
|
|
173
|
+
*
|
|
174
|
+
* Its appearance answers *did my click work?*; its completion answers *is the
|
|
175
|
+
* page here yet?* It runs alongside the destination's own skeletons rather
|
|
176
|
+
* than instead of them — the two work at different scopes, and
|
|
177
|
+
* `RouteProgress (the navigation) over destination skeletons (each section) →
|
|
178
|
+
* content` is the normal lifecycle.
|
|
179
|
+
*
|
|
180
|
+
* Position is `fixed` at the viewport's top edge, so the bar blocks nothing
|
|
181
|
+
* and shifts nothing. Per the className policy the outer box is the
|
|
182
|
+
* consumer's: pass `className` to re-anchor it (for example `absolute` inside
|
|
183
|
+
* a positioned container), and the bar's own identity stays ours.
|
|
184
|
+
*
|
|
185
|
+
* Keeping the current page mounted until the destination commits is the
|
|
186
|
+
* router's job, not the bar's — tearing down a working screen costs people
|
|
187
|
+
* their context.
|
|
188
|
+
*
|
|
189
|
+
* See `Patterns/Loading → Page loading → Route transitions` in Storybook for
|
|
190
|
+
* the full guidance and the end-to-end demo.
|
|
191
|
+
*/
|
|
192
|
+
const RouteProgress = React.forwardRef<HTMLDivElement, RouteProgressProps>(
|
|
193
|
+
(
|
|
194
|
+
{
|
|
195
|
+
className,
|
|
196
|
+
active,
|
|
197
|
+
dataHook,
|
|
198
|
+
trackingEl,
|
|
199
|
+
trackingLabel,
|
|
200
|
+
navigatingLabel = "Loading page",
|
|
201
|
+
style,
|
|
202
|
+
...props
|
|
203
|
+
},
|
|
204
|
+
ref
|
|
205
|
+
) => {
|
|
206
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
207
|
+
const [phase, setPhase] = React.useState<RouteProgressPhase>("idle");
|
|
208
|
+
|
|
209
|
+
// Navigation started: rise immediately, with no threshold. A navigation
|
|
210
|
+
// that begins while the previous one is still fading restarts the bar.
|
|
211
|
+
//
|
|
212
|
+
// Navigation ended: schedule the completion rather than firing it, so a
|
|
213
|
+
// hand-off between two signals (router pending → destination queries)
|
|
214
|
+
// keeps one continuous bar instead of a sweep-and-restart. Completing from
|
|
215
|
+
// `idle` would flash a bar for a navigation that was never announced, so
|
|
216
|
+
// idle stays idle.
|
|
217
|
+
React.useEffect(() => {
|
|
218
|
+
if (active) {
|
|
219
|
+
setPhase((current) =>
|
|
220
|
+
current === "start" || current === "creep" ? current : "start"
|
|
221
|
+
);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const timer = setTimeout(
|
|
225
|
+
() => setPhase((current) => (current === "idle" ? "idle" : "complete")),
|
|
226
|
+
SETTLE_GRACE_MS
|
|
227
|
+
);
|
|
228
|
+
return () => clearTimeout(timer);
|
|
229
|
+
}, [active]);
|
|
230
|
+
|
|
231
|
+
// Hand off from the start fill to the creep. Two frames: the first lets
|
|
232
|
+
// the browser paint the bar at START_FILL, the second changes the target
|
|
233
|
+
// so the transition actually runs instead of being collapsed into the
|
|
234
|
+
// same commit.
|
|
235
|
+
React.useEffect(() => {
|
|
236
|
+
if (phase !== "start" || prefersReducedMotion) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
let inner = 0;
|
|
240
|
+
const outer = requestAnimationFrame(() => {
|
|
241
|
+
inner = requestAnimationFrame(() =>
|
|
242
|
+
setPhase((current) => (current === "start" ? "creep" : current))
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
return () => {
|
|
246
|
+
cancelAnimationFrame(outer);
|
|
247
|
+
cancelAnimationFrame(inner);
|
|
248
|
+
};
|
|
249
|
+
}, [phase, prefersReducedMotion]);
|
|
250
|
+
|
|
251
|
+
// Reset once the sweep and the fade have played out, so the next
|
|
252
|
+
// navigation starts from a clean track.
|
|
253
|
+
React.useEffect(() => {
|
|
254
|
+
if (phase !== "complete") {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const timer = setTimeout(
|
|
258
|
+
() =>
|
|
259
|
+
setPhase((current) => (current === "complete" ? "idle" : current)),
|
|
260
|
+
prefersReducedMotion
|
|
261
|
+
? 0
|
|
262
|
+
: MOTION_DURATION_BASE_MS + MOTION_DURATION_FAST_MS
|
|
263
|
+
);
|
|
264
|
+
return () => clearTimeout(timer);
|
|
265
|
+
}, [phase, prefersReducedMotion]);
|
|
266
|
+
|
|
267
|
+
const navigating = phase === "start" || phase === "creep";
|
|
268
|
+
|
|
269
|
+
// Idle rests at START_FILL rather than 0 so the next navigation's first
|
|
270
|
+
// painted frame is already the start fill — nothing to animate in.
|
|
271
|
+
const fill =
|
|
272
|
+
phase === "complete"
|
|
273
|
+
? 100
|
|
274
|
+
: phase === "creep"
|
|
275
|
+
? CREEP_TARGET
|
|
276
|
+
: phase === "start" && prefersReducedMotion
|
|
277
|
+
? STATIC_FILL
|
|
278
|
+
: START_FILL;
|
|
279
|
+
|
|
280
|
+
let transition = "none";
|
|
281
|
+
if (!prefersReducedMotion) {
|
|
282
|
+
if (phase === "creep") {
|
|
283
|
+
transition = `clip-path ${CREEP_MS}ms ${CREEP_EASE}`;
|
|
284
|
+
} else if (phase === "complete") {
|
|
285
|
+
// The delayed opacity keeps the bar visible for the whole sweep, then
|
|
286
|
+
// fades it — completion has to be seen to mean anything. Durations
|
|
287
|
+
// come from the token scale; MOTION_DURATION_*_MS below is the JS
|
|
288
|
+
// mirror of the same values, used only to time the reset.
|
|
289
|
+
transition =
|
|
290
|
+
"clip-path var(--ds-motion-duration-base) ease-out, opacity var(--ds-motion-duration-fast) ease-out var(--ds-motion-duration-base)";
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return (
|
|
295
|
+
<>
|
|
296
|
+
<div
|
|
297
|
+
ref={ref}
|
|
298
|
+
aria-hidden="true"
|
|
299
|
+
className={cn(
|
|
300
|
+
// z-60, not z-50: every DS overlay (Dialog, Sheet, Drawer,
|
|
301
|
+
// AlertDialog) is `fixed inset-0 z-50` and portals to <body>, so at
|
|
302
|
+
// an equal z-index it would paint over the bar by DOM order. A
|
|
303
|
+
// navigation started from inside a modal must still be reported.
|
|
304
|
+
"pointer-events-none fixed inset-x-0 top-0 z-60 h-0.5 overflow-hidden",
|
|
305
|
+
className
|
|
306
|
+
)}
|
|
307
|
+
data-hook={dataHook}
|
|
308
|
+
data-slot="route-progress"
|
|
309
|
+
data-state={phase}
|
|
310
|
+
data-tracking-el={trackingEl}
|
|
311
|
+
data-tracking-label={trackingLabel}
|
|
312
|
+
style={style}
|
|
313
|
+
{...props}
|
|
314
|
+
>
|
|
315
|
+
<span
|
|
316
|
+
/* Solid brand green, the same colour as the primary button.
|
|
317
|
+
`--primary` flips to green-900 in dark because it is a button
|
|
318
|
+
*fill* sitting under light text, and as a 2px hairline that
|
|
319
|
+
reads at ~2.15:1 — so dark keeps the light-mode primary value
|
|
320
|
+
instead. Same override the Button itself uses for its label
|
|
321
|
+
(`dark:text-[var(--ds-colors-primary-foreground-light)]`), and
|
|
322
|
+
the same thing the Figma component does in its dark showcase. */
|
|
323
|
+
className="bg-primary absolute inset-0 dark:bg-[var(--ds-colors-primary-light)]"
|
|
324
|
+
data-slot="route-progress-bar"
|
|
325
|
+
style={{
|
|
326
|
+
/* Painted across the full track and revealed by clip-path, so
|
|
327
|
+
the fill's colour is identical at every width. */
|
|
328
|
+
clipPath: `inset(0 ${100 - fill}% 0 0)`,
|
|
329
|
+
opacity: navigating ? 1 : 0,
|
|
330
|
+
transition,
|
|
331
|
+
}}
|
|
332
|
+
/>
|
|
333
|
+
</div>
|
|
334
|
+
{/* `sr-only` is position:absolute, which resolves against whatever
|
|
335
|
+
positioned ancestor the consumer happens to have and can inflate a
|
|
336
|
+
scroll container's scrollHeight. `fixed` resolves against the
|
|
337
|
+
viewport instead, so this 1px node can never affect layout. */}
|
|
338
|
+
<span
|
|
339
|
+
aria-atomic="true"
|
|
340
|
+
aria-live="polite"
|
|
341
|
+
className="sr-only fixed"
|
|
342
|
+
data-slot="route-progress-status"
|
|
343
|
+
>
|
|
344
|
+
{navigating ? navigatingLabel : ""}
|
|
345
|
+
</span>
|
|
346
|
+
</>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
RouteProgress.displayName = "RouteProgress";
|
|
352
|
+
|
|
353
|
+
export { RouteProgress };
|
|
354
|
+
export type { RouteProgressProps };
|
package/src/components/sheet.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
6
6
|
import { X } from "@brightlocal/icons";
|
|
7
7
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
+
import { ScrollArea } from "@brightlocal/ui-components/scroll-area";
|
|
9
10
|
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -17,6 +18,14 @@ import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-over
|
|
|
17
18
|
*/
|
|
18
19
|
export type SheetSide = "top" | "right" | "bottom" | "left";
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Available sheet size variants (side panels only — ignored for top/bottom)
|
|
23
|
+
* - default: Panel fills 75% of the viewport up to 384px
|
|
24
|
+
* - sm: Panel hugs its content between 288 and 320px, keeping the page
|
|
25
|
+
* partly visible behind it on phones (used by the Sidebar mobile nav)
|
|
26
|
+
*/
|
|
27
|
+
export type SheetSize = "default" | "sm";
|
|
28
|
+
|
|
20
29
|
const sheetContentVariants = cva(
|
|
21
30
|
[
|
|
22
31
|
"bg-background",
|
|
@@ -55,9 +64,7 @@ const sheetContentVariants = cva(
|
|
|
55
64
|
"inset-y-0",
|
|
56
65
|
"right-0",
|
|
57
66
|
"h-full",
|
|
58
|
-
"w-3/4",
|
|
59
67
|
"border-l",
|
|
60
|
-
"sm:max-w-sm",
|
|
61
68
|
],
|
|
62
69
|
bottom: [
|
|
63
70
|
"data-[state=closed]:slide-out-to-bottom",
|
|
@@ -73,14 +80,38 @@ const sheetContentVariants = cva(
|
|
|
73
80
|
"inset-y-0",
|
|
74
81
|
"left-0",
|
|
75
82
|
"h-full",
|
|
76
|
-
"w-3/4",
|
|
77
83
|
"border-r",
|
|
78
|
-
"sm:max-w-sm",
|
|
79
84
|
],
|
|
80
85
|
},
|
|
86
|
+
size: {
|
|
87
|
+
default: [],
|
|
88
|
+
sm: [],
|
|
89
|
+
},
|
|
81
90
|
},
|
|
91
|
+
compoundVariants: [
|
|
92
|
+
// Width only applies to side panels — top/bottom sheets span the
|
|
93
|
+
// viewport and size their height from content on every size.
|
|
94
|
+
{
|
|
95
|
+
side: ["left", "right"],
|
|
96
|
+
size: "default",
|
|
97
|
+
className: ["w-3/4", "sm:max-w-sm"],
|
|
98
|
+
},
|
|
99
|
+
// sm side panels hug their content between 288 and 320px (DS-860) so
|
|
100
|
+
// the page stays partly visible behind them on phones — used by the
|
|
101
|
+
// Sidebar mobile navigation sheet.
|
|
102
|
+
{
|
|
103
|
+
side: ["left", "right"],
|
|
104
|
+
size: "sm",
|
|
105
|
+
className: [
|
|
106
|
+
"w-fit",
|
|
107
|
+
"min-w-(--ds-container-2xs)",
|
|
108
|
+
"max-w-(--ds-container-xs)",
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
82
112
|
defaultVariants: {
|
|
83
113
|
side: "right",
|
|
114
|
+
size: "default",
|
|
84
115
|
},
|
|
85
116
|
}
|
|
86
117
|
);
|
|
@@ -178,6 +209,13 @@ interface SheetContentProps
|
|
|
178
209
|
* @default "right"
|
|
179
210
|
*/
|
|
180
211
|
side?: SheetSide;
|
|
212
|
+
/**
|
|
213
|
+
* Width preset for side panels. `sm` hugs the content between 288 and
|
|
214
|
+
* 320px; `default` keeps the classic 75%-up-to-384px drawer width.
|
|
215
|
+
* Ignored for top/bottom sheets.
|
|
216
|
+
* @default "default"
|
|
217
|
+
*/
|
|
218
|
+
size?: SheetSize;
|
|
181
219
|
/**
|
|
182
220
|
* Data hook for automated testing
|
|
183
221
|
*/
|
|
@@ -210,6 +248,7 @@ const SheetContent = React.forwardRef<
|
|
|
210
248
|
className,
|
|
211
249
|
children,
|
|
212
250
|
side,
|
|
251
|
+
size,
|
|
213
252
|
dataHook,
|
|
214
253
|
trackingEl,
|
|
215
254
|
trackingLabel,
|
|
@@ -226,7 +265,7 @@ const SheetContent = React.forwardRef<
|
|
|
226
265
|
<SheetOverlay />
|
|
227
266
|
<SheetPrimitive.Content
|
|
228
267
|
ref={ref}
|
|
229
|
-
className={cn(sheetContentVariants({ side }), className)}
|
|
268
|
+
className={cn(sheetContentVariants({ side, size }), className)}
|
|
230
269
|
data-hook={dataHook}
|
|
231
270
|
data-slot="sheet-content"
|
|
232
271
|
data-tracking-el={trackingEl}
|
|
@@ -262,6 +301,47 @@ const SheetHeader = React.forwardRef<
|
|
|
262
301
|
));
|
|
263
302
|
SheetHeader.displayName = "SheetHeader";
|
|
264
303
|
|
|
304
|
+
/**
|
|
305
|
+
* Props for the SheetBody component
|
|
306
|
+
*/
|
|
307
|
+
interface SheetBodyProps extends Omit<
|
|
308
|
+
React.ComponentProps<typeof ScrollArea>,
|
|
309
|
+
"dataHook"
|
|
310
|
+
> {
|
|
311
|
+
/**
|
|
312
|
+
* Data hook for automated testing
|
|
313
|
+
* @default "sheet-body"
|
|
314
|
+
*/
|
|
315
|
+
dataHook?: string;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Sheet body — the scrollable region between a pinned SheetHeader and
|
|
320
|
+
* SheetFooter. Wraps ScrollArea so long content scrolls with DS-styled
|
|
321
|
+
* scrollbars inside a keyboard-focusable viewport, while the close button,
|
|
322
|
+
* header, and footer stay visible.
|
|
323
|
+
*/
|
|
324
|
+
const SheetBody = React.forwardRef<
|
|
325
|
+
React.ComponentRef<typeof ScrollArea>,
|
|
326
|
+
SheetBodyProps
|
|
327
|
+
>(({ className, children, dataHook, ...props }, ref) => (
|
|
328
|
+
<ScrollArea
|
|
329
|
+
ref={ref}
|
|
330
|
+
// -mx-6 escapes SheetContent's p-6 so the scrollbar sits at the panel
|
|
331
|
+
// edge; the inner px-5 plus the viewport's built-in p-1 restores the
|
|
332
|
+
// 24px content inset.
|
|
333
|
+
className={cn("-mx-6 min-h-0 flex-1", className)}
|
|
334
|
+
data-slot="sheet-body"
|
|
335
|
+
dataHook={dataHook ?? "sheet-body"}
|
|
336
|
+
{...props}
|
|
337
|
+
>
|
|
338
|
+
<div className="px-5" data-slot="sheet-body-content">
|
|
339
|
+
{children}
|
|
340
|
+
</div>
|
|
341
|
+
</ScrollArea>
|
|
342
|
+
));
|
|
343
|
+
SheetBody.displayName = "SheetBody";
|
|
344
|
+
|
|
265
345
|
/**
|
|
266
346
|
* Sheet footer section for actions and buttons.
|
|
267
347
|
* Stacks buttons on mobile, aligns to end on larger screens.
|
|
@@ -363,6 +443,7 @@ SheetDescription.displayName = "SheetDescription";
|
|
|
363
443
|
|
|
364
444
|
export {
|
|
365
445
|
Sheet,
|
|
446
|
+
SheetBody,
|
|
366
447
|
SheetClose,
|
|
367
448
|
SheetContent,
|
|
368
449
|
SheetDescription,
|
|
@@ -375,6 +456,7 @@ export {
|
|
|
375
456
|
};
|
|
376
457
|
|
|
377
458
|
export type {
|
|
459
|
+
SheetBodyProps,
|
|
378
460
|
SheetContentProps,
|
|
379
461
|
SheetDescriptionProps,
|
|
380
462
|
SheetTitleProps,
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
AlertTriangle,
|
|
5
|
-
CheckCircle2,
|
|
6
|
-
Info,
|
|
7
|
-
Loader2,
|
|
8
|
-
XCircle,
|
|
9
|
-
} from "@brightlocal/icons";
|
|
3
|
+
import { AlertTriangle, CheckCircle2, Info, XCircle } from "@brightlocal/icons";
|
|
10
4
|
import { cva } from "class-variance-authority";
|
|
11
5
|
import { toast as sonnerToast, Toaster as SonnerToaster } from "sonner";
|
|
12
6
|
|
|
13
7
|
import { Button, type ButtonVariant } from "@brightlocal/ui-components/button";
|
|
14
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
+
import { Spinner } from "@brightlocal/ui-components/spinner";
|
|
15
10
|
|
|
16
11
|
/**
|
|
17
12
|
* Supported button variant values for toast action buttons.
|
|
@@ -161,11 +156,7 @@ function renderToastIcon(type: ToastIconType, schema: "default" | "success") {
|
|
|
161
156
|
case "error":
|
|
162
157
|
return <XCircle className={cn(ICON_VARIANTS({ colorSchema: schema }))} />;
|
|
163
158
|
case "loading":
|
|
164
|
-
return (
|
|
165
|
-
<Loader2
|
|
166
|
-
className={cn(ICON_VARIANTS({ colorSchema: schema }), "animate-spin")}
|
|
167
|
-
/>
|
|
168
|
-
);
|
|
159
|
+
return <Spinner className={cn(ICON_VARIANTS({ colorSchema: schema }))} />;
|
|
169
160
|
default:
|
|
170
161
|
return null;
|
|
171
162
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { LoaderCircle } from "@brightlocal/icons";
|
|
4
|
+
|
|
5
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Spinner size scale — three sizes, one shared speed.
|
|
9
|
+
* sm 14 (chips, table cells, nav items) · md 16 (buttons, inputs — the
|
|
10
|
+
* default) · lg 20 (standing alone in a region).
|
|
11
|
+
*/
|
|
12
|
+
const SPINNER_SIZES = { sm: 14, md: 16, lg: 20 } as const;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Spinner size options
|
|
16
|
+
*/
|
|
17
|
+
type SpinnerSize = keyof typeof SPINNER_SIZES;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Props for the Spinner component
|
|
21
|
+
*/
|
|
22
|
+
interface SpinnerProps extends Omit<
|
|
23
|
+
React.ComponentPropsWithoutRef<typeof LoaderCircle>,
|
|
24
|
+
"size"
|
|
25
|
+
> {
|
|
26
|
+
/**
|
|
27
|
+
* Data hook for automated testing (optional for Spinner as it's purely presentational)
|
|
28
|
+
*/
|
|
29
|
+
dataHook?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Tracking element identifier for analytics
|
|
32
|
+
*/
|
|
33
|
+
trackingEl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Tracking label for analytics context
|
|
36
|
+
*/
|
|
37
|
+
trackingLabel?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Spinner size: sm 14 (chips, cells, nav items), md 16, lg 20 (standing alone).
|
|
40
|
+
* @default "md"
|
|
41
|
+
*/
|
|
42
|
+
size?: SpinnerSize;
|
|
43
|
+
/**
|
|
44
|
+
* Accessible label announced to screen readers (`role="status"`).
|
|
45
|
+
* When omitted the spinner is decorative (`aria-hidden`) — omit inside a
|
|
46
|
+
* control that already announces busy (e.g. a Button with `aria-busy`).
|
|
47
|
+
* @default undefined
|
|
48
|
+
* @example "Loading"
|
|
49
|
+
*/
|
|
50
|
+
loadingLabel?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Spinner — the one indeterminate loading indicator.
|
|
55
|
+
* Renders the LoaderCircle glyph rotating at the shared
|
|
56
|
+
* `--ds-motion-spinner-duration` speed, so every spinner in a view moves at
|
|
57
|
+
* the same rate. Size varies by context; speed never does.
|
|
58
|
+
* Color follows `currentColor` — set it from the surrounding text color.
|
|
59
|
+
*/
|
|
60
|
+
const Spinner = React.forwardRef<SVGSVGElement, SpinnerProps>(
|
|
61
|
+
(
|
|
62
|
+
{
|
|
63
|
+
className,
|
|
64
|
+
size = "md",
|
|
65
|
+
loadingLabel,
|
|
66
|
+
dataHook,
|
|
67
|
+
trackingEl,
|
|
68
|
+
trackingLabel,
|
|
69
|
+
...props
|
|
70
|
+
},
|
|
71
|
+
ref
|
|
72
|
+
) => {
|
|
73
|
+
return (
|
|
74
|
+
<LoaderCircle
|
|
75
|
+
ref={ref}
|
|
76
|
+
aria-hidden={loadingLabel ? undefined : true}
|
|
77
|
+
aria-label={loadingLabel}
|
|
78
|
+
className={cn("animate-spinner", className)}
|
|
79
|
+
data-hook={dataHook}
|
|
80
|
+
data-slot="spinner"
|
|
81
|
+
data-tracking-el={trackingEl}
|
|
82
|
+
data-tracking-label={trackingLabel}
|
|
83
|
+
role={loadingLabel ? "status" : undefined}
|
|
84
|
+
size={SPINNER_SIZES[size]}
|
|
85
|
+
{...props}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
Spinner.displayName = "Spinner";
|
|
91
|
+
|
|
92
|
+
export { Spinner, SPINNER_SIZES };
|
|
93
|
+
|
|
94
|
+
export type { SpinnerProps, SpinnerSize };
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Slot } from "@radix-ui/react-slot";
|
|
5
5
|
import { cva } from "class-variance-authority";
|
|
6
|
-
import { Check,
|
|
6
|
+
import { Check, X } from "@brightlocal/icons";
|
|
7
7
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
+
import { Spinner } from "@brightlocal/ui-components/spinner";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Orientation of the stepper layout.
|
|
@@ -565,9 +566,7 @@ const StepperIndicator = React.forwardRef<
|
|
|
565
566
|
{state === "error" && !isLoading && (
|
|
566
567
|
<X className="absolute" size={16} />
|
|
567
568
|
)}
|
|
568
|
-
{isLoading &&
|
|
569
|
-
<LoaderCircle className="absolute animate-spin" size={16} />
|
|
570
|
-
)}
|
|
569
|
+
{isLoading && <Spinner className="absolute" size="md" />}
|
|
571
570
|
{stateLabel}
|
|
572
571
|
</>
|
|
573
572
|
)}
|
package/src/components/table.tsx
CHANGED
|
@@ -32,7 +32,9 @@ const tableCellVariants = cva(
|
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
const tableHeadVariants = cva(
|
|
35
|
-
|
|
35
|
+
// bg-muted only for column headers inside <thead> — a <TableHead
|
|
36
|
+
// scope="row"> in the body must not paint over its row's state tint.
|
|
37
|
+
"[thead_&]:bg-muted h-12 p-2 align-middle text-muted-foreground text-sm font-medium leading-normal break-words outline-none focus-visible:shadow-default transition-[background-color,box-shadow] duration-fast ease-out",
|
|
36
38
|
{
|
|
37
39
|
variants: {
|
|
38
40
|
align: {
|
|
@@ -233,7 +235,9 @@ const TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(
|
|
|
233
235
|
<tr
|
|
234
236
|
ref={ref}
|
|
235
237
|
className={cn(
|
|
236
|
-
|
|
238
|
+
// Selected rows share the table head's surface (bg-muted).
|
|
239
|
+
"data-[state=selected]:bg-muted",
|
|
240
|
+
"duration-fast transition-colors ease-out",
|
|
237
241
|
className
|
|
238
242
|
)}
|
|
239
243
|
data-hook={dataHook}
|