@brightlocal/ui-components 3.0.0 → 3.1.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 +2 -1
- package/component-meta.json +90 -19
- package/deprecations.json +113 -3
- package/dist/accordion.cjs +1 -1
- package/dist/accordion.d.ts +36 -0
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +74 -61
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +41 -49
- package/dist/button-group.cjs +1 -0
- package/dist/button-group.d.ts +36 -0
- package/dist/button-group.d.ts.map +1 -0
- package/dist/button-group.js +47 -0
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +20 -2
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +83 -75
- package/dist/chart.cjs +2 -2
- package/dist/chart.d.ts +40 -12
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +86 -71
- package/dist/chip.cjs +1 -1
- package/dist/chip.d.ts +38 -4
- package/dist/chip.d.ts.map +1 -1
- package/dist/chip.js +95 -81
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +23 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +250 -224
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +32 -1
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +340 -330
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +13 -5
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +54 -53
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +8 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +79 -52
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +105 -13
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +146 -129
- package/dist/grid.d.ts +2 -2
- package/dist/hooks/use-mobile.cjs +1 -0
- package/dist/hooks/use-mobile.js +8 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +547 -538
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +17 -9
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +26 -25
- package/dist/lib/empty-chip.cjs +1 -0
- package/dist/lib/empty-chip.d.ts +4 -0
- package/dist/lib/empty-chip.d.ts.map +1 -0
- package/dist/lib/empty-chip.js +13 -0
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +3 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +57 -57
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +15 -6
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +38 -36
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +13 -2
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +87 -83
- package/dist/typography-heading.cjs +1 -1
- package/dist/typography-heading.d.ts +13 -0
- package/dist/typography-heading.d.ts.map +1 -1
- package/dist/typography-heading.js +32 -21
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +14 -0
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +35 -24
- package/package.json +1 -1
- package/src/blocks/empty-state.tsx +9 -21
- package/src/components/accordion.tsx +82 -27
- package/src/components/button-group.tsx +112 -0
- package/src/components/button.tsx +1 -1
- package/src/components/card.tsx +38 -3
- package/src/components/chart.tsx +63 -18
- package/src/components/chip.tsx +83 -10
- package/src/components/command.tsx +55 -3
- package/src/components/data-table.tsx +67 -7
- package/src/components/date-picker.tsx +18 -7
- package/src/components/field.tsx +81 -12
- package/src/components/global-layout.tsx +176 -38
- package/src/components/grid.tsx +2 -2
- package/src/components/input-password.tsx +23 -11
- package/src/components/pagination.tsx +10 -3
- package/src/components/scroll-area.tsx +23 -10
- package/src/components/select.tsx +30 -6
- package/src/components/typography-heading.tsx +24 -0
- package/src/components/typography-text.tsx +26 -1
- package/src/index.ts +1 -0
- package/src/lib/empty-chip.ts +24 -0
package/src/components/field.tsx
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
1
4
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
5
|
|
|
3
6
|
import { AlertCircle, type LucideProps } from "@brightlocal/icons";
|
|
@@ -82,6 +85,10 @@ const fieldVariants = cva(
|
|
|
82
85
|
"[[data-slot=radio-group]_&]:relative [[data-slot=radio-group]_&]:cursor-pointer [[data-slot=radio-group]_&]:gap-3 [[data-slot=radio-group]_&]:has-[[data-disabled]]:cursor-not-allowed",
|
|
83
86
|
// RadioGroup context: label overlay spans the full Field for clickable row
|
|
84
87
|
"[[data-slot=radio-group]_&_[data-slot=field-label]]:after:absolute [[data-slot=radio-group]_&_[data-slot=field-label]]:after:inset-0 [[data-slot=radio-group]_&_[data-slot=field-label]]:after:cursor-pointer [[data-slot=radio-group]_&:has([data-disabled])_[data-slot=field-label]]:after:cursor-not-allowed",
|
|
88
|
+
// DS-772: lift the control above the label overlay so a direct click on the
|
|
89
|
+
// control passes pointer hit-testing (Playwright check()/click() without
|
|
90
|
+
// force). Row/label clicks still delegate via the label's htmlFor.
|
|
91
|
+
"[[data-slot=radio-group]_&_[data-slot=radio-group-item]]:z-10",
|
|
85
92
|
// Checkbox context: match RadioGroup gap-3 spacing
|
|
86
93
|
"has-[>[role=checkbox]]:gap-3",
|
|
87
94
|
// Label leading overrides: use leading-normal for wrap-capable labels (checkbox)
|
|
@@ -124,6 +131,13 @@ const fieldVariants = cva(
|
|
|
124
131
|
"rounded-lg border border-border bg-background p-3",
|
|
125
132
|
"transition-colors duration-fast ease-out",
|
|
126
133
|
"[&_[data-slot=field-label]]:after:absolute [&_[data-slot=field-label]]:after:inset-0 [&_[data-slot=field-label]]:after:cursor-pointer",
|
|
134
|
+
// DS-772: lift controls above the label's full-card overlay so a
|
|
135
|
+
// direct click on the control passes pointer hit-testing (Playwright
|
|
136
|
+
// check()/click() without force). Card clicks still delegate via the
|
|
137
|
+
// label's htmlFor.
|
|
138
|
+
"[&_[data-slot=checkbox]]:relative [&_[data-slot=checkbox]]:z-10",
|
|
139
|
+
"[&_[data-slot=radio-group-item]]:z-10",
|
|
140
|
+
"[&_[data-slot=switch]]:relative [&_[data-slot=switch]]:z-10",
|
|
127
141
|
// Focus ring when a child control receives focus
|
|
128
142
|
"has-[:focus-visible]:shadow-default has-[:focus-visible]:border-ring",
|
|
129
143
|
// Checked-state for radio/checkbox (not switch)
|
|
@@ -310,6 +324,23 @@ interface FieldErrorProps extends Omit<
|
|
|
310
324
|
errors?: Array<FieldErrorItem | undefined>;
|
|
311
325
|
}
|
|
312
326
|
|
|
327
|
+
const emptySubscribe = () => () => {};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* True for renders driven by the client after hydration; false on the server
|
|
331
|
+
* and during hydration of server-rendered HTML (getServerSnapshot is used for
|
|
332
|
+
* both). Lets FieldError keep server-rendered messages in the initial HTML
|
|
333
|
+
* while deferring only client-side appearances for the live-region
|
|
334
|
+
* announcement — without hydration mismatches.
|
|
335
|
+
*/
|
|
336
|
+
function useIsClientRender() {
|
|
337
|
+
return React.useSyncExternalStore(
|
|
338
|
+
emptySubscribe,
|
|
339
|
+
() => true,
|
|
340
|
+
() => false
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
313
344
|
interface FieldErrorIconProps extends Omit<LucideProps, "ref"> {
|
|
314
345
|
/**
|
|
315
346
|
* Custom icon component to render instead of the default AlertCircle.
|
|
@@ -360,7 +391,13 @@ function FieldErrorIcon({
|
|
|
360
391
|
* FieldError displays validation error messages within a Field.
|
|
361
392
|
*
|
|
362
393
|
* Supports both direct children content and an errors array for form library integration.
|
|
363
|
-
*
|
|
394
|
+
* Renders a polite live region (role="status" / aria-live="polite") so screen readers
|
|
395
|
+
* announce the message when it appears and again whenever it changes (DS-964).
|
|
396
|
+
* A message that appears client-side is committed one tick after the region mounts —
|
|
397
|
+
* a live region is only announced reliably when it exists in the accessibility tree
|
|
398
|
+
* before its content does, and consumers mount FieldError conditionally, together with
|
|
399
|
+
* the message. Server-rendered messages stay in the initial HTML (no deferral): they
|
|
400
|
+
* are part of the page screen readers read on load, so they need no announcement.
|
|
364
401
|
* No icon is displayed by default - use FieldErrorIcon for composition.
|
|
365
402
|
*
|
|
366
403
|
* @example
|
|
@@ -397,8 +434,37 @@ function FieldError({
|
|
|
397
434
|
Boolean(e?.message)
|
|
398
435
|
);
|
|
399
436
|
|
|
437
|
+
const hasMessage = Boolean(children) || Boolean(errorMessages?.length);
|
|
438
|
+
|
|
439
|
+
// Screen readers only announce live-region content that arrives *after* the
|
|
440
|
+
// region is in the accessibility tree. Consumers typically mount FieldError
|
|
441
|
+
// together with the message, so when a message appears client-side the
|
|
442
|
+
// region renders empty for the first paint and the message is committed
|
|
443
|
+
// right after — the resulting content mutation is what gets announced
|
|
444
|
+
// (DS-964). A FieldError whose first render happens on the server or during
|
|
445
|
+
// hydration keeps its message synchronous instead: the message must be in
|
|
446
|
+
// the server-rendered HTML, and content present at page load is read with
|
|
447
|
+
// the page, so it needs no announcement. The distinction is captured as the
|
|
448
|
+
// initial state of `defer` (a post-hydration re-render must not blank a
|
|
449
|
+
// server-rendered message) and latches to "defer" once the message clears
|
|
450
|
+
// client-side, because any later message is a client-side appearance.
|
|
451
|
+
const isClientRender = useIsClientRender();
|
|
452
|
+
const [defer, setDefer] = React.useState(isClientRender);
|
|
453
|
+
const [announced, setAnnounced] = React.useState(false);
|
|
454
|
+
|
|
455
|
+
React.useEffect(() => {
|
|
456
|
+
if (!hasMessage) {
|
|
457
|
+
setDefer(true);
|
|
458
|
+
setAnnounced(false);
|
|
459
|
+
} else if (defer) {
|
|
460
|
+
setAnnounced(true);
|
|
461
|
+
}
|
|
462
|
+
}, [defer, hasMessage]);
|
|
463
|
+
|
|
464
|
+
const showMessage = hasMessage && (!defer || announced);
|
|
465
|
+
|
|
400
466
|
// If no children and no valid errors, don't render anything
|
|
401
|
-
if (!
|
|
467
|
+
if (!hasMessage) {
|
|
402
468
|
return null;
|
|
403
469
|
}
|
|
404
470
|
|
|
@@ -415,21 +481,24 @@ function FieldError({
|
|
|
415
481
|
|
|
416
482
|
return (
|
|
417
483
|
<div
|
|
484
|
+
aria-atomic="true"
|
|
485
|
+
aria-live="polite"
|
|
418
486
|
className={baseStyles}
|
|
419
487
|
data-hook={dataHook}
|
|
420
488
|
data-slot="field-error"
|
|
421
|
-
role="
|
|
489
|
+
role="status"
|
|
422
490
|
{...props}
|
|
423
491
|
>
|
|
424
|
-
{
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
492
|
+
{showMessage &&
|
|
493
|
+
(isMultiple ? (
|
|
494
|
+
<ul className="list-disc space-y-1 pl-4">
|
|
495
|
+
{errorMessages.map((error, index) => (
|
|
496
|
+
<li key={index}>{error.message}</li>
|
|
497
|
+
))}
|
|
498
|
+
</ul>
|
|
499
|
+
) : (
|
|
500
|
+
<p className="m-0">{children || errorMessages?.[0]?.message}</p>
|
|
501
|
+
))}
|
|
433
502
|
</div>
|
|
434
503
|
);
|
|
435
504
|
}
|
|
@@ -3,6 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import { ArrowLeft } from "@brightlocal/icons";
|
|
4
4
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
5
5
|
import { Breadcrumb } from "./breadcrumb";
|
|
6
|
+
import { Button } from "./button";
|
|
6
7
|
import { Header } from "./header";
|
|
7
8
|
import { Link } from "./link";
|
|
8
9
|
import { ScrollArea } from "./scroll-area";
|
|
@@ -193,50 +194,140 @@ GlobalLayoutContent.displayName = "GlobalLayoutContent";
|
|
|
193
194
|
// the full width.
|
|
194
195
|
const CONTENT_REGION_PX = "px-4 md:px-6 lg:px-section-xs";
|
|
195
196
|
|
|
196
|
-
interface
|
|
197
|
+
interface GlobalLayoutBackLinkCommonProps {
|
|
197
198
|
/**
|
|
198
199
|
* Data hook for automated testing
|
|
199
200
|
* @default "content-header-back-link"
|
|
200
201
|
*/
|
|
201
202
|
dataHook?: string;
|
|
202
203
|
/**
|
|
203
|
-
* Accessible label for the icon-only back
|
|
204
|
+
* Accessible label for the icon-only back control.
|
|
204
205
|
* @default "Go back"
|
|
205
206
|
*/
|
|
206
207
|
ariaLabel?: string;
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
// Attributes that exist on only one of the two rendered elements. Each mode
|
|
211
|
+
// explicitly rejects the other's (`?: never`, mirroring EmptyState's
|
|
212
|
+
// size-exclusive props) so a cross-mode attribute — `disabled` on the anchor,
|
|
213
|
+
// `target` on the button — fails to compile instead of silently landing on
|
|
214
|
+
// the wrong element.
|
|
215
|
+
type AnchorOnlyAttributes = Omit<
|
|
216
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
217
|
+
keyof React.ButtonHTMLAttributes<HTMLButtonElement>
|
|
218
|
+
>;
|
|
219
|
+
type ButtonOnlyAttributes = Omit<
|
|
220
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
221
|
+
keyof React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
222
|
+
>;
|
|
223
|
+
type ForbiddenAttributes<T> = { [K in keyof T]?: never };
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Anchor mode: a real destination, rendered as `Link variant="icon"`.
|
|
227
|
+
*/
|
|
228
|
+
interface GlobalLayoutBackLinkAnchorProps
|
|
229
|
+
extends
|
|
230
|
+
GlobalLayoutBackLinkCommonProps,
|
|
231
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
232
|
+
ForbiddenAttributes<ButtonOnlyAttributes> {
|
|
233
|
+
/** Destination URL — renders a real link (`<a>`). */
|
|
234
|
+
href: string;
|
|
235
|
+
}
|
|
236
|
+
|
|
209
237
|
/**
|
|
210
|
-
*
|
|
238
|
+
* Button mode: no destination, rendered as an icon `<button>` for SPA
|
|
239
|
+
* router navigation via `onClick`.
|
|
240
|
+
*/
|
|
241
|
+
interface GlobalLayoutBackLinkButtonProps
|
|
242
|
+
extends
|
|
243
|
+
GlobalLayoutBackLinkCommonProps,
|
|
244
|
+
Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type">,
|
|
245
|
+
ForbiddenAttributes<AnchorOnlyAttributes> {
|
|
246
|
+
/** Omit `href` to render a `<button>` for SPA router navigation. */
|
|
247
|
+
href?: undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Button type attribute (button mode only).
|
|
250
|
+
* @default "button"
|
|
251
|
+
*/
|
|
252
|
+
type?: "button" | "submit";
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Discriminated on `href` so the impossible combinations don't compile:
|
|
257
|
+
* anchor-only attributes (target, rel, download, …) require an `href`, and
|
|
258
|
+
* button-only attributes (disabled, form*, …) apply only without one. DS-847
|
|
259
|
+
* removed the old `href="#"` + preventDefault fallback — an action that
|
|
260
|
+
* doesn't navigate now has real button semantics.
|
|
261
|
+
*
|
|
262
|
+
* The leading inline block restates the shared props (plus `href`, the
|
|
263
|
+
* discriminant) so the registry's props extractor, which reads the first
|
|
264
|
+
* braced block after this declaration, documents them; the mode interfaces
|
|
265
|
+
* remain the source of the per-mode constraints.
|
|
266
|
+
*/
|
|
267
|
+
type GlobalLayoutBackLinkProps = {
|
|
268
|
+
/**
|
|
269
|
+
* Data hook for automated testing
|
|
270
|
+
* @default "content-header-back-link"
|
|
271
|
+
*/
|
|
272
|
+
dataHook?: string;
|
|
273
|
+
/**
|
|
274
|
+
* Accessible label for the icon-only back control.
|
|
275
|
+
* @default "Go back"
|
|
276
|
+
*/
|
|
277
|
+
ariaLabel?: string;
|
|
278
|
+
/**
|
|
279
|
+
* Destination URL. Set, the control renders a real link
|
|
280
|
+
* (`Link variant="icon"`); omitted, it renders an identically styled
|
|
281
|
+
* `<button>` for SPA router navigation via `onClick` — there is no
|
|
282
|
+
* `href="#"` fallback.
|
|
283
|
+
*/
|
|
284
|
+
href?: string;
|
|
285
|
+
} & (GlobalLayoutBackLinkAnchorProps | GlobalLayoutBackLinkButtonProps);
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Icon-only back control for the page header. Place it as a direct child of
|
|
211
289
|
* `GlobalLayoutContentHeader` — the header positions it before the title.
|
|
212
|
-
* Pass `href` for URL navigation
|
|
290
|
+
* Pass `href` for URL navigation (renders a `Link variant="icon"` anchor);
|
|
291
|
+
* omit it and pass `onClick` for SPA router navigation (renders an
|
|
292
|
+
* identically styled icon `<button>`). Both modes are keyboard-focusable and
|
|
293
|
+
* carry the "Go back" accessible name by default.
|
|
213
294
|
*/
|
|
214
295
|
const GlobalLayoutBackLink = React.forwardRef<
|
|
215
|
-
HTMLAnchorElement,
|
|
296
|
+
HTMLAnchorElement | HTMLButtonElement,
|
|
216
297
|
GlobalLayoutBackLinkProps
|
|
217
|
-
>((
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
298
|
+
>((props, ref) => {
|
|
299
|
+
if (props.href === undefined) {
|
|
300
|
+
// `buttonProps` still carries `href: undefined` — Button doesn't declare
|
|
301
|
+
// it, and React drops undefined-valued attributes, so nothing renders.
|
|
302
|
+
const { dataHook, ariaLabel, ...buttonProps } = props;
|
|
303
|
+
return (
|
|
304
|
+
<Button
|
|
305
|
+
ref={ref as React.Ref<HTMLButtonElement>}
|
|
306
|
+
// Button's ghost variant is the treatment Link variant="icon" derives
|
|
307
|
+
// from, and a single icon child triggers Button's icon-only footprint
|
|
308
|
+
// (size-9 p-0) — so both modes render identically. `||` rather than
|
|
309
|
+
// `??`: an icon-only control must never end up with an empty
|
|
310
|
+
// accessible name, so an empty string also falls back.
|
|
311
|
+
ariaLabel={ariaLabel || "Go back"}
|
|
312
|
+
data-slot="content-header-back-link"
|
|
313
|
+
dataHook={dataHook ?? "content-header-back-link"}
|
|
314
|
+
variant="ghost"
|
|
315
|
+
{...buttonProps}
|
|
316
|
+
>
|
|
317
|
+
<ArrowLeft aria-hidden="true" />
|
|
318
|
+
</Button>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
227
321
|
|
|
322
|
+
const { dataHook, ariaLabel, ...anchorProps } = props;
|
|
228
323
|
return (
|
|
229
324
|
<Link
|
|
230
|
-
ref={ref}
|
|
231
|
-
// `||` rather than `??`: an icon-only link must never end up with an
|
|
232
|
-
// empty accessible name, so an empty string also falls back.
|
|
325
|
+
ref={ref as React.Ref<HTMLAnchorElement>}
|
|
233
326
|
aria-label={ariaLabel || "Go back"}
|
|
234
327
|
data-slot="content-header-back-link"
|
|
235
328
|
dataHook={dataHook ?? "content-header-back-link"}
|
|
236
|
-
href={href ?? "#"}
|
|
237
329
|
variant="icon"
|
|
238
|
-
|
|
239
|
-
{...props}
|
|
330
|
+
{...anchorProps}
|
|
240
331
|
>
|
|
241
332
|
<ArrowLeft aria-hidden="true" />
|
|
242
333
|
</Link>
|
|
@@ -361,9 +452,9 @@ interface GlobalLayoutContentHeaderProps extends React.ComponentProps<"header">
|
|
|
361
452
|
* <TypographyHeading level={1} variant="page" dataHook="page-title">
|
|
362
453
|
* All Locations
|
|
363
454
|
* </TypographyHeading>
|
|
364
|
-
* <
|
|
455
|
+
* <GlobalLayoutActions dataHook="header-actions">
|
|
365
456
|
* <Button dataHook="add-location">Add Location</Button>
|
|
366
|
-
* </
|
|
457
|
+
* </GlobalLayoutActions>
|
|
367
458
|
* <GlobalLayoutSubtitle>Manage your business locations.</GlobalLayoutSubtitle>
|
|
368
459
|
* </GlobalLayoutContentHeader>
|
|
369
460
|
*/
|
|
@@ -403,7 +494,7 @@ const GlobalLayoutContentHeader = React.forwardRef<
|
|
|
403
494
|
subtitles.push(child);
|
|
404
495
|
} else if (
|
|
405
496
|
React.isValidElement(child) &&
|
|
406
|
-
child.type ===
|
|
497
|
+
child.type === GlobalLayoutActions
|
|
407
498
|
) {
|
|
408
499
|
actions.push(child);
|
|
409
500
|
} else {
|
|
@@ -470,7 +561,7 @@ const GlobalLayoutContentHeader = React.forwardRef<
|
|
|
470
561
|
>
|
|
471
562
|
{breadcrumbs}
|
|
472
563
|
{actions.length > 0 ? (
|
|
473
|
-
// With a slotted
|
|
564
|
+
// With a slotted GlobalLayoutActions the header follows
|
|
474
565
|
// the Figma Page Header structure: a text block (title +
|
|
475
566
|
// description) with the actions beside it — and below it on
|
|
476
567
|
// mobile, so the action lands under the description.
|
|
@@ -510,11 +601,11 @@ const GlobalLayoutContentHeader = React.forwardRef<
|
|
|
510
601
|
GlobalLayoutContentHeader.displayName = "GlobalLayoutContentHeader";
|
|
511
602
|
|
|
512
603
|
// True while rendering inside GlobalLayoutContentHeader's actions slot —
|
|
513
|
-
//
|
|
604
|
+
// GlobalLayoutActions switches from its standalone desktop-row
|
|
514
605
|
// styling to an inline title-row group.
|
|
515
606
|
const GlobalLayoutHeaderSlotContext = React.createContext(false);
|
|
516
607
|
|
|
517
|
-
interface
|
|
608
|
+
interface GlobalLayoutActionsProps extends React.ComponentProps<"div"> {
|
|
518
609
|
/**
|
|
519
610
|
* Data hook for automated testing (required)
|
|
520
611
|
*/
|
|
@@ -529,9 +620,15 @@ interface GlobalLayoutContentActionsProps extends React.ComponentProps<"div"> {
|
|
|
529
620
|
trackingLabel?: string;
|
|
530
621
|
}
|
|
531
622
|
|
|
532
|
-
|
|
623
|
+
/**
|
|
624
|
+
* Action row for the page header. Place it as a direct child of
|
|
625
|
+
* `GlobalLayoutContentHeader` — the header positions it beside the title row
|
|
626
|
+
* (below it on mobile). Standalone it keeps the legacy desktop-only
|
|
627
|
+
* full-width row.
|
|
628
|
+
*/
|
|
629
|
+
const GlobalLayoutActions = React.forwardRef<
|
|
533
630
|
HTMLDivElement,
|
|
534
|
-
|
|
631
|
+
GlobalLayoutActionsProps
|
|
535
632
|
>(
|
|
536
633
|
(
|
|
537
634
|
{ className, dataHook, trackingEl, trackingLabel, children, ...props },
|
|
@@ -575,9 +672,17 @@ const GlobalLayoutContentActions = React.forwardRef<
|
|
|
575
672
|
}
|
|
576
673
|
);
|
|
577
674
|
|
|
578
|
-
|
|
675
|
+
GlobalLayoutActions.displayName = "GlobalLayoutActions";
|
|
579
676
|
|
|
580
|
-
|
|
677
|
+
/**
|
|
678
|
+
* @deprecated Renamed `GlobalLayoutActions` (DS-855) — the `Content`
|
|
679
|
+
* discriminator was unearned: no sibling actions row exists to discriminate
|
|
680
|
+
* against (DS-809: discriminate siblings only). This alias will be removed in
|
|
681
|
+
* the next major.
|
|
682
|
+
*/
|
|
683
|
+
const GlobalLayoutContentActions = GlobalLayoutActions;
|
|
684
|
+
|
|
685
|
+
interface GlobalLayoutBodyProps extends React.ComponentProps<"div"> {
|
|
581
686
|
/**
|
|
582
687
|
* Data hook for automated testing
|
|
583
688
|
*/
|
|
@@ -592,9 +697,14 @@ interface GlobalLayoutContentBodyProps extends React.ComponentProps<"div"> {
|
|
|
592
697
|
trackingLabel?: string;
|
|
593
698
|
}
|
|
594
699
|
|
|
595
|
-
|
|
700
|
+
/**
|
|
701
|
+
* Main content region below the page header. Carries the content max-width
|
|
702
|
+
* set by `GlobalLayoutContent` and the shared region padding, so full-width
|
|
703
|
+
* treatments on sibling regions (header border, sticky header) stay possible.
|
|
704
|
+
*/
|
|
705
|
+
const GlobalLayoutBody = React.forwardRef<
|
|
596
706
|
HTMLDivElement,
|
|
597
|
-
|
|
707
|
+
GlobalLayoutBodyProps
|
|
598
708
|
>(
|
|
599
709
|
(
|
|
600
710
|
{ className, dataHook, trackingEl, trackingLabel, children, ...props },
|
|
@@ -622,7 +732,15 @@ const GlobalLayoutContentBody = React.forwardRef<
|
|
|
622
732
|
}
|
|
623
733
|
);
|
|
624
734
|
|
|
625
|
-
|
|
735
|
+
GlobalLayoutBody.displayName = "GlobalLayoutBody";
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* @deprecated Renamed `GlobalLayoutBody` (DS-855) — the `Content`
|
|
739
|
+
* discriminator was unearned: no sibling body region exists to discriminate
|
|
740
|
+
* against (DS-809: discriminate siblings only). This alias will be removed in
|
|
741
|
+
* the next major.
|
|
742
|
+
*/
|
|
743
|
+
const GlobalLayoutContentBody = GlobalLayoutBody;
|
|
626
744
|
|
|
627
745
|
interface GlobalLayoutMobileHeaderProps extends React.ComponentProps<"div"> {
|
|
628
746
|
/**
|
|
@@ -694,24 +812,44 @@ export {
|
|
|
694
812
|
GlobalLayout,
|
|
695
813
|
GlobalLayoutSidebar,
|
|
696
814
|
GlobalLayoutContent,
|
|
697
|
-
|
|
815
|
+
GlobalLayoutActions,
|
|
698
816
|
GlobalLayoutContentHeader,
|
|
699
817
|
GlobalLayoutBackLink,
|
|
700
818
|
GlobalLayoutSubtitle,
|
|
701
819
|
GlobalLayoutImage,
|
|
702
|
-
|
|
820
|
+
GlobalLayoutBody,
|
|
703
821
|
GlobalLayoutMobileHeader,
|
|
822
|
+
GlobalLayoutContentActions,
|
|
823
|
+
GlobalLayoutContentBody,
|
|
704
824
|
};
|
|
705
825
|
|
|
706
826
|
export type {
|
|
707
827
|
GlobalLayoutProps,
|
|
708
828
|
GlobalLayoutSidebarProps,
|
|
709
829
|
GlobalLayoutContentProps,
|
|
710
|
-
|
|
830
|
+
GlobalLayoutActionsProps,
|
|
711
831
|
GlobalLayoutContentHeaderProps,
|
|
712
832
|
GlobalLayoutBackLinkProps,
|
|
713
833
|
GlobalLayoutSubtitleProps,
|
|
714
834
|
GlobalLayoutImageProps,
|
|
715
|
-
|
|
835
|
+
GlobalLayoutBodyProps,
|
|
716
836
|
GlobalLayoutMobileHeaderProps,
|
|
837
|
+
GlobalLayoutContentActionsProps,
|
|
838
|
+
GlobalLayoutContentBodyProps,
|
|
717
839
|
};
|
|
840
|
+
|
|
841
|
+
// Deprecated prop-type aliases (DS-855), declared after the export blocks on
|
|
842
|
+
// purpose: the registry's props extractor scrapes the first braced block that
|
|
843
|
+
// follows a `type <Name>Props` declaration, so a bare alias sitting mid-file
|
|
844
|
+
// would document the *next* interface's props under the deprecated name.
|
|
845
|
+
// Down here nothing follows, and only the canonical names carry props.
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* @deprecated Renamed `GlobalLayoutActionsProps` (DS-855).
|
|
849
|
+
*/
|
|
850
|
+
type GlobalLayoutContentActionsProps = GlobalLayoutActionsProps;
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* @deprecated Renamed `GlobalLayoutBodyProps` (DS-855).
|
|
854
|
+
*/
|
|
855
|
+
type GlobalLayoutContentBodyProps = GlobalLayoutBodyProps;
|
package/src/components/grid.tsx
CHANGED
|
@@ -81,7 +81,7 @@ export type GridProps = GridCenteredProps;
|
|
|
81
81
|
*
|
|
82
82
|
* @example
|
|
83
83
|
* ```tsx
|
|
84
|
-
* <
|
|
84
|
+
* <GlobalLayoutBody dataHook="locations-body">
|
|
85
85
|
* <Grid dataHook="locations-empty-center" variant="centered">
|
|
86
86
|
* <EmptyState
|
|
87
87
|
* dataHook="locations-empty"
|
|
@@ -90,7 +90,7 @@ export type GridProps = GridCenteredProps;
|
|
|
90
90
|
* title={t("locations.empty.title")}
|
|
91
91
|
* />
|
|
92
92
|
* </Grid>
|
|
93
|
-
* </
|
|
93
|
+
* </GlobalLayoutBody>
|
|
94
94
|
* ```
|
|
95
95
|
*/
|
|
96
96
|
const Grid = React.forwardRef<HTMLDivElement, GridProps>(
|
|
@@ -114,17 +114,17 @@ function useInputPasswordContext() {
|
|
|
114
114
|
const context = React.useContext(InputPasswordContext);
|
|
115
115
|
if (!context) {
|
|
116
116
|
throw new Error(
|
|
117
|
-
"InputPassword compound components must be used within
|
|
117
|
+
"InputPassword compound components must be used within InputPassword"
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
return context;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// ============================================================================
|
|
124
|
-
//
|
|
124
|
+
// InputPassword (root)
|
|
125
125
|
// ============================================================================
|
|
126
126
|
|
|
127
|
-
export interface
|
|
127
|
+
export interface InputPasswordProps<
|
|
128
128
|
T extends string = DefaultPasswordStrength,
|
|
129
129
|
> {
|
|
130
130
|
/**
|
|
@@ -192,16 +192,16 @@ export interface InputPasswordRootProps<
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
|
-
*
|
|
195
|
+
* InputPassword - Root component that provides context for all InputPassword parts
|
|
196
196
|
*
|
|
197
197
|
* Generic type parameter T allows custom strength levels:
|
|
198
198
|
* @example
|
|
199
199
|
* // Using default levels
|
|
200
|
-
* <
|
|
200
|
+
* <InputPassword dataHook="password">...</InputPassword>
|
|
201
201
|
*
|
|
202
202
|
* // Using custom levels
|
|
203
203
|
* type MyStrength = "empty" | "slow" | "medium" | "fast";
|
|
204
|
-
* <
|
|
204
|
+
* <InputPassword<MyStrength>
|
|
205
205
|
* dataHook="password"
|
|
206
206
|
* strengthLevels={{
|
|
207
207
|
* empty: { label: "Enter password", value: 0, color: "bg-muted" },
|
|
@@ -217,9 +217,9 @@ export interface InputPasswordRootProps<
|
|
|
217
217
|
* }}
|
|
218
218
|
* >
|
|
219
219
|
* ...
|
|
220
|
-
* </
|
|
220
|
+
* </InputPassword>
|
|
221
221
|
*/
|
|
222
|
-
function
|
|
222
|
+
function InputPassword<T extends string = DefaultPasswordStrength>({
|
|
223
223
|
children,
|
|
224
224
|
dataHook,
|
|
225
225
|
trackingEl,
|
|
@@ -233,7 +233,7 @@ function InputPasswordRoot<T extends string = DefaultPasswordStrength>({
|
|
|
233
233
|
error,
|
|
234
234
|
id,
|
|
235
235
|
className,
|
|
236
|
-
}:
|
|
236
|
+
}: InputPasswordProps<T>) {
|
|
237
237
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
238
238
|
const [internalPassword, setInternalPassword] = React.useState("");
|
|
239
239
|
const [strength, setStrength] = React.useState<string>("meter");
|
|
@@ -323,7 +323,18 @@ function InputPasswordRoot<T extends string = DefaultPasswordStrength>({
|
|
|
323
323
|
);
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
|
|
326
|
+
InputPassword.displayName = "InputPassword";
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* @deprecated Use `InputPassword` instead — family roots are bare names (DS-853).
|
|
330
|
+
*/
|
|
331
|
+
const InputPasswordRoot = InputPassword;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @deprecated Use `InputPasswordProps` instead — family roots are bare names (DS-853).
|
|
335
|
+
*/
|
|
336
|
+
export type InputPasswordRootProps<T extends string = DefaultPasswordStrength> =
|
|
337
|
+
InputPasswordProps<T>;
|
|
327
338
|
|
|
328
339
|
// ============================================================================
|
|
329
340
|
// InputPasswordField
|
|
@@ -501,7 +512,7 @@ export interface InputPasswordStrengthProps {
|
|
|
501
512
|
/**
|
|
502
513
|
* InputPasswordStrength - Password strength indicator
|
|
503
514
|
* Displays a progress bar and optional label showing password strength.
|
|
504
|
-
* Automatically uses the strength levels configured on
|
|
515
|
+
* Automatically uses the strength levels configured on InputPassword.
|
|
505
516
|
*/
|
|
506
517
|
function InputPasswordStrength({
|
|
507
518
|
className,
|
|
@@ -546,6 +557,7 @@ InputPasswordStrength.displayName = "InputPasswordStrength";
|
|
|
546
557
|
// ============================================================================
|
|
547
558
|
|
|
548
559
|
export {
|
|
560
|
+
InputPassword,
|
|
549
561
|
InputPasswordRoot,
|
|
550
562
|
InputPasswordField,
|
|
551
563
|
InputPasswordToggle,
|
|
@@ -442,6 +442,9 @@ interface PaginationControlsProps extends Omit<
|
|
|
442
442
|
* Controlled: the consumer holds `page` and updates it from `onPageChange`.
|
|
443
443
|
* Pass `totalItems` + `pageSize` to get the results caption; the caption sits
|
|
444
444
|
* on the left with the nav pushed right, and without one the nav centres.
|
|
445
|
+
* Below the `sm` viewport breakpoint the caption is removed and the nav
|
|
446
|
+
* centres, and from `sm` up the bar wraps inside narrow containers instead of
|
|
447
|
+
* overflowing — the same responsive rules as `DataTablePagination` (DS-998).
|
|
445
448
|
*
|
|
446
449
|
* There is nothing to navigate on a single page, so the nav hides itself at
|
|
447
450
|
* `totalPages <= 1` and the component renders nothing at all when the caption
|
|
@@ -507,8 +510,12 @@ const PaginationControls = React.forwardRef<
|
|
|
507
510
|
ref
|
|
508
511
|
) => {
|
|
509
512
|
const items = usePagination({ page, totalPages });
|
|
513
|
+
const isMobile = useIsBelowBreakpoint("sm");
|
|
510
514
|
|
|
511
515
|
const caption = (() => {
|
|
516
|
+
// Below `sm` the caption is removed so the page buttons get the full
|
|
517
|
+
// width and centre (DS-998) — same rule as `DataTablePagination`.
|
|
518
|
+
if (isMobile) return null;
|
|
512
519
|
if (renderCaption === null) return null;
|
|
513
520
|
if (totalItems === undefined || pageSize === undefined) return null;
|
|
514
521
|
// A page size that isn't a positive number, or a negative total, can only
|
|
@@ -550,7 +557,7 @@ const PaginationControls = React.forwardRef<
|
|
|
550
557
|
<div
|
|
551
558
|
ref={ref}
|
|
552
559
|
className={cn(
|
|
553
|
-
"flex min-h-9 w-full items-center gap-4",
|
|
560
|
+
"flex min-h-9 w-full flex-wrap items-center gap-x-4 gap-y-2",
|
|
554
561
|
caption == null ? "justify-center" : "justify-between",
|
|
555
562
|
className
|
|
556
563
|
)}
|
|
@@ -562,7 +569,7 @@ const PaginationControls = React.forwardRef<
|
|
|
562
569
|
>
|
|
563
570
|
{caption != null && (
|
|
564
571
|
<span
|
|
565
|
-
className="text-body-sm text-muted-foreground"
|
|
572
|
+
className="text-body-sm text-muted-foreground whitespace-nowrap"
|
|
566
573
|
data-slot="pagination-caption"
|
|
567
574
|
>
|
|
568
575
|
{caption}
|
|
@@ -571,7 +578,7 @@ const PaginationControls = React.forwardRef<
|
|
|
571
578
|
{showNav && (
|
|
572
579
|
<Pagination
|
|
573
580
|
ariaLabel={ariaLabel}
|
|
574
|
-
className={cn(caption != null && "mx-0 w-auto justify-end")}
|
|
581
|
+
className={cn(caption != null && "mx-0 w-auto grow justify-end")}
|
|
575
582
|
dataHook={`${dataHook}-nav`}
|
|
576
583
|
>
|
|
577
584
|
<PaginationContent>
|