@brightlocal/ui-components 3.3.0 → 3.5.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 +22 -3
- package/README.md +177 -109
- package/component-meta.json +1307 -113
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +13 -2
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +4 -3
- package/dist/banner.cjs +1 -1
- package/dist/banner.d.ts +47 -11
- package/dist/banner.d.ts.map +1 -1
- package/dist/banner.js +156 -79
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +40 -5
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +59 -52
- package/dist/blocks/input-list.cjs +1 -1
- package/dist/blocks/input-list.d.ts +1 -0
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/input-list.js +39 -39
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +12 -6
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +64 -63
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +47 -43
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +12 -0
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +115 -97
- package/dist/chart.cjs +6 -6
- package/dist/chart.d.ts +6 -10
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +281 -296
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +430 -343
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +23 -2
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +212 -207
- package/dist/count-indicator.cjs +1 -0
- package/dist/count-indicator.d.ts +85 -0
- package/dist/count-indicator.d.ts.map +1 -0
- package/dist/count-indicator.js +72 -0
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +101 -11
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +593 -523
- package/dist/description-list.cjs +1 -0
- package/dist/description-list.d.ts +142 -0
- package/dist/description-list.d.ts.map +1 -0
- package/dist/description-list.js +173 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +26 -3
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +62 -47
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +8 -4
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +37 -38
- package/dist/file-upload.cjs +1 -0
- package/dist/file-upload.d.ts +546 -0
- package/dist/file-upload.d.ts.map +1 -0
- package/dist/file-upload.js +1103 -0
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +7 -2
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +52 -52
- package/dist/hooks/use-file-dropzone.cjs +1 -0
- package/dist/hooks/use-file-dropzone.d.ts +75 -0
- package/dist/hooks/use-file-dropzone.d.ts.map +1 -0
- package/dist/hooks/use-file-dropzone.js +133 -0
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +29 -16
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +153 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +681 -623
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +30 -1
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +131 -115
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +37 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +131 -114
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.js +6 -6
- package/dist/lib/empty-canvas.cjs +1 -1
- package/dist/lib/empty-canvas.d.ts +27 -1
- package/dist/lib/empty-canvas.d.ts.map +1 -1
- package/dist/lib/empty-canvas.js +27 -23
- package/dist/lib/empty-chip.cjs +1 -1
- package/dist/lib/empty-chip.d.ts +19 -2
- package/dist/lib/empty-chip.d.ts.map +1 -1
- package/dist/lib/empty-chip.js +14 -9
- package/dist/lib/field-aria.cjs +1 -1
- package/dist/lib/field-aria.d.ts +4 -4
- package/dist/lib/field-aria.d.ts.map +1 -1
- package/dist/lib/field-aria.js +7 -5
- package/dist/lib/media-viewer-content.cjs +1 -1
- package/dist/lib/media-viewer-content.js +1 -1
- package/dist/lib/motion.cjs +1 -1
- package/dist/lib/motion.js +15 -10
- package/dist/lib/table-internal.cjs +1 -1
- package/dist/lib/table-internal.d.ts +19 -0
- package/dist/lib/table-internal.d.ts.map +1 -1
- package/dist/lib/table-internal.js +22 -7
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts +230 -40
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +301 -66
- package/dist/logo-mark.cjs +1 -1
- package/dist/logo-mark.d.ts +18 -2
- package/dist/logo-mark.d.ts.map +1 -1
- package/dist/logo-mark.js +159 -79
- package/dist/media-empty.cjs +1 -1
- package/dist/media-empty.d.ts +50 -7
- package/dist/media-empty.d.ts.map +1 -1
- package/dist/media-empty.js +14 -13
- package/dist/media-viewer.cjs +1 -1
- package/dist/media-viewer.js +6 -6
- package/dist/multi-select-filter.cjs +1 -1
- package/dist/multi-select-filter.d.ts.map +1 -1
- package/dist/multi-select-filter.js +92 -101
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +11 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +17 -17
- package/dist/relative-date.d.ts +6 -0
- package/dist/relative-date.d.ts.map +1 -1
- package/dist/resizable.d.ts +1 -1
- package/dist/result-count.cjs +1 -1
- package/dist/result-count.d.ts +13 -16
- package/dist/result-count.d.ts.map +1 -1
- package/dist/result-count.js +24 -33
- package/dist/route-progress.cjs +1 -1
- package/dist/route-progress.js +24 -23
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +22 -3
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +152 -125
- package/dist/single-select-filter.cjs +1 -1
- package/dist/single-select-filter.d.ts.map +1 -1
- package/dist/single-select-filter.js +67 -76
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +77 -76
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +39 -3
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +127 -76
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.d.ts +34 -0
- package/dist/textarea.d.ts.map +1 -1
- package/dist/textarea.js +115 -19
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +137 -131
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +6 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +14 -13
- package/package.json +2 -3
- package/src/blocks/empty-state.tsx +108 -48
- package/src/blocks/input-list.tsx +15 -9
- package/src/blocks/sidebar.tsx +39 -16
- package/src/components/alert-dialog.tsx +18 -2
- package/src/components/banner.tsx +247 -68
- package/src/components/button.tsx +27 -10
- package/src/components/card.tsx +89 -7
- package/src/components/chart.tsx +47 -67
- package/src/components/combobox.tsx +221 -12
- package/src/components/command.tsx +83 -37
- package/src/components/count-indicator.tsx +188 -0
- package/src/components/data-table.tsx +506 -159
- package/src/components/description-list.tsx +445 -0
- package/src/components/dialog.tsx +74 -5
- package/src/components/drawer.tsx +52 -32
- package/src/components/file-upload.tsx +2574 -0
- package/src/components/global-layout.tsx +18 -5
- package/src/components/hover-card.tsx +395 -65
- package/src/components/input-chip.tsx +67 -2
- package/src/components/input-group.tsx +89 -6
- package/src/components/list.tsx +720 -72
- package/src/components/logo-mark.tsx +109 -25
- package/src/components/media-empty.tsx +62 -7
- package/src/components/multi-select-filter.tsx +9 -16
- package/src/components/pagination.tsx +15 -2
- package/src/components/relative-date.tsx +6 -0
- package/src/components/result-count.tsx +27 -54
- package/src/components/sheet.tsx +86 -8
- package/src/components/single-select-filter.tsx +9 -16
- package/src/components/table.tsx +16 -1
- package/src/components/tabs.tsx +223 -41
- package/src/components/textarea.tsx +271 -4
- package/src/components/tooltip.tsx +29 -2
- package/src/components/typography-text.tsx +7 -2
- package/src/hooks/use-file-dropzone.ts +325 -0
- package/src/index.ts +4 -0
- package/src/lib/empty-canvas.tsx +47 -20
- package/src/lib/empty-chip.tsx +38 -3
- package/src/lib/field-aria.tsx +11 -6
- package/src/lib/table-internal.ts +38 -0
package/src/components/sheet.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { ChevronDown, ChevronUp, X } from "@brightlocal/icons";
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
9
|
import { Button } from "@brightlocal/ui-components/button";
|
|
10
10
|
import { ScrollArea } from "@brightlocal/ui-components/scroll-area";
|
|
11
|
+
import { Spinner } from "@brightlocal/ui-components/spinner";
|
|
11
12
|
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -26,8 +27,10 @@ export type SheetSide = "top" | "right" | "bottom" | "left";
|
|
|
26
27
|
* partly visible behind it on phones (used by the Sidebar mobile nav)
|
|
27
28
|
* - lg: Panel fills 75% of the viewport up to 512px — detail panels with
|
|
28
29
|
* dense content (date pickers, thumbnail rows)
|
|
30
|
+
* - xl: Full width on phones, 480px from the `sm` breakpoint and 640px from
|
|
31
|
+
* `xl` — edit forms with a table or a row of selects (DS-1245)
|
|
29
32
|
*/
|
|
30
|
-
export type SheetSize = "default" | "sm" | "lg";
|
|
33
|
+
export type SheetSize = "default" | "sm" | "lg" | "xl";
|
|
31
34
|
|
|
32
35
|
const sheetContentVariants = cva(
|
|
33
36
|
[
|
|
@@ -90,6 +93,7 @@ const sheetContentVariants = cva(
|
|
|
90
93
|
default: [],
|
|
91
94
|
sm: [],
|
|
92
95
|
lg: [],
|
|
96
|
+
xl: [],
|
|
93
97
|
},
|
|
94
98
|
},
|
|
95
99
|
compoundVariants: [
|
|
@@ -119,6 +123,15 @@ const sheetContentVariants = cva(
|
|
|
119
123
|
size: "lg",
|
|
120
124
|
className: ["w-3/4", "sm:max-w-lg"],
|
|
121
125
|
},
|
|
126
|
+
// xl side panels are the form width (DS-1245): full width on phones,
|
|
127
|
+
// where 75% is too narrow for fields, then two fixed steps on the DS
|
|
128
|
+
// breakpoints — 480px from sm, 640px from xl — so the panel does not
|
|
129
|
+
// shift as the window resizes.
|
|
130
|
+
{
|
|
131
|
+
side: ["left", "right"],
|
|
132
|
+
size: "xl",
|
|
133
|
+
className: ["w-full", "sm:w-120", "xl:w-160"],
|
|
134
|
+
},
|
|
122
135
|
],
|
|
123
136
|
defaultVariants: {
|
|
124
137
|
side: "right",
|
|
@@ -223,7 +236,8 @@ interface SheetContentProps
|
|
|
223
236
|
/**
|
|
224
237
|
* Width preset for side panels. `sm` hugs the content between 288 and
|
|
225
238
|
* 320px; `default` keeps the classic 75%-up-to-384px drawer width; `lg`
|
|
226
|
-
* widens to 75%-up-to-512px for dense detail panels
|
|
239
|
+
* widens to 75%-up-to-512px for dense detail panels; `xl` is the form
|
|
240
|
+
* width — full width on phones, 480px from `sm`, 640px from `xl`.
|
|
227
241
|
* Ignored for top/bottom sheets.
|
|
228
242
|
* @default "default"
|
|
229
243
|
*/
|
|
@@ -367,6 +381,22 @@ interface SheetPaginationProps extends Omit<
|
|
|
367
381
|
*/
|
|
368
382
|
renderPosition?:
|
|
369
383
|
((info: SheetPaginationPositionInfo) => React.ReactNode) | null;
|
|
384
|
+
/**
|
|
385
|
+
* Marks the step the user just requested as in flight — e.g. the next item
|
|
386
|
+
* sits on a page that is still being fetched. The button that requested
|
|
387
|
+
* the step (by click or arrow key) swaps its chevron for a spinner and sets
|
|
388
|
+
* `aria-busy`; both buttons ignore clicks and arrow keys until the flag
|
|
389
|
+
* clears, without a disabled look, so focus stays where it is. Screen
|
|
390
|
+
* readers hear `loadingLabel`. Keep `hasPrevious` / `hasNext` describing
|
|
391
|
+
* the list, not the fetch.
|
|
392
|
+
* @default false
|
|
393
|
+
*/
|
|
394
|
+
loading?: boolean;
|
|
395
|
+
/**
|
|
396
|
+
* Text announced to screen readers while `loading` is true.
|
|
397
|
+
* @default "Loading item"
|
|
398
|
+
*/
|
|
399
|
+
loadingLabel?: string;
|
|
370
400
|
/**
|
|
371
401
|
* Accessible label for the item navigation group.
|
|
372
402
|
* @default "Item navigation"
|
|
@@ -414,6 +444,8 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
414
444
|
hasPrevious,
|
|
415
445
|
hasNext,
|
|
416
446
|
renderPosition,
|
|
447
|
+
loading = false,
|
|
448
|
+
loadingLabel,
|
|
417
449
|
ariaLabel,
|
|
418
450
|
prevAriaLabel,
|
|
419
451
|
nextAriaLabel,
|
|
@@ -433,11 +465,30 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
433
465
|
// The button that just triggered a step. Set only by our own
|
|
434
466
|
// navigation, consumed on the next commit.
|
|
435
467
|
const pendingRef = React.useRef<HTMLButtonElement | null>(null);
|
|
468
|
+
// The direction of the last requested step — the button that owns the
|
|
469
|
+
// spinner while `loading` (an arrow key on Previous can request Next).
|
|
470
|
+
const [requested, setRequested] = React.useState<
|
|
471
|
+
"previous" | "next" | null
|
|
472
|
+
>(null);
|
|
473
|
+
|
|
474
|
+
// Once the step lands (the position or a boundary changes, or `loading`
|
|
475
|
+
// finishes), forget the requester so a later refetch raised from outside
|
|
476
|
+
// does not spin the old button. Adjusted during render, not in an effect.
|
|
477
|
+
const settleKey = `${loading}|${current}|${total}|${canPrevious}|${canNext}`;
|
|
478
|
+
const [prevSettleKey, setPrevSettleKey] = React.useState(settleKey);
|
|
479
|
+
if (settleKey !== prevSettleKey) {
|
|
480
|
+
setPrevSettleKey(settleKey);
|
|
481
|
+
if (!loading) setRequested(null);
|
|
482
|
+
}
|
|
436
483
|
|
|
437
484
|
// Reaching a boundary disables the button that was just pressed, which
|
|
438
485
|
// drops focus to <body>. Hand it to the sibling instead so keyboard users
|
|
439
|
-
// stay in the control.
|
|
486
|
+
// stay in the control. While a step is loading the boundary is not known
|
|
487
|
+
// yet — keep the pending hand-off until it lands. Runs only when the
|
|
488
|
+
// position, a boundary or `loading` changes, so the render caused by
|
|
489
|
+
// recording a request does not consume the hand-off early.
|
|
440
490
|
React.useEffect(() => {
|
|
491
|
+
if (loading) return;
|
|
441
492
|
const pending = pendingRef.current;
|
|
442
493
|
pendingRef.current = null;
|
|
443
494
|
if (!pending) return;
|
|
@@ -448,7 +499,7 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
448
499
|
} else if (!canNext && pending === nextRef.current && canPrevious) {
|
|
449
500
|
prevRef.current?.focus();
|
|
450
501
|
}
|
|
451
|
-
});
|
|
502
|
+
}, [loading, current, total, canPrevious, canNext]);
|
|
452
503
|
|
|
453
504
|
const handleBlur = (event: React.FocusEvent<HTMLButtonElement>) => {
|
|
454
505
|
// Focus left on purpose (to anything but the sibling) — drop any
|
|
@@ -463,17 +514,26 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
463
514
|
direction: "previous" | "next",
|
|
464
515
|
trigger: HTMLButtonElement
|
|
465
516
|
) => {
|
|
517
|
+
// Inert while a step is in flight — prevents a double fetch.
|
|
518
|
+
if (loading) return;
|
|
466
519
|
if (direction === "previous") {
|
|
467
520
|
if (!canPrevious) return;
|
|
468
521
|
pendingRef.current = trigger;
|
|
522
|
+
setRequested("previous");
|
|
469
523
|
onPrevious();
|
|
470
524
|
} else {
|
|
471
525
|
if (!canNext) return;
|
|
472
526
|
pendingRef.current = trigger;
|
|
527
|
+
setRequested("next");
|
|
473
528
|
onNext();
|
|
474
529
|
}
|
|
475
530
|
};
|
|
476
531
|
|
|
532
|
+
// Without a recorded request (loading set from outside), no button gets
|
|
533
|
+
// the spinner — the status still announces busy and input is ignored.
|
|
534
|
+
const previousBusy = loading && requested === "previous";
|
|
535
|
+
const nextBusy = loading && requested === "next";
|
|
536
|
+
|
|
477
537
|
const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
|
|
478
538
|
if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
|
|
479
539
|
event.preventDefault();
|
|
@@ -496,8 +556,8 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
496
556
|
ref={ref}
|
|
497
557
|
aria-label={ariaLabel ?? "Item navigation"}
|
|
498
558
|
// mb-2 on top of SheetContent's gap-4 gives the 24px Figma gap to
|
|
499
|
-
// the header below.
|
|
500
|
-
className={cn("mb-2 flex items-center gap-1", className)}
|
|
559
|
+
// the header below. `relative` anchors the sr-only status below.
|
|
560
|
+
className={cn("relative mb-2 flex items-center gap-1", className)}
|
|
501
561
|
data-hook={dataHook}
|
|
502
562
|
data-slot="sheet-pagination"
|
|
503
563
|
data-tracking-el={trackingEl}
|
|
@@ -507,6 +567,7 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
507
567
|
>
|
|
508
568
|
<Button
|
|
509
569
|
ref={prevRef}
|
|
570
|
+
aria-busy={previousBusy ? "true" : undefined}
|
|
510
571
|
ariaLabel={prevAriaLabel ?? "Previous item"}
|
|
511
572
|
dataHook={`${dataHook}-previous`}
|
|
512
573
|
disabled={!canPrevious}
|
|
@@ -515,10 +576,15 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
515
576
|
onClick={(event) => step("previous", event.currentTarget)}
|
|
516
577
|
onKeyDown={handleKeyDown}
|
|
517
578
|
>
|
|
518
|
-
|
|
579
|
+
{previousBusy ? (
|
|
580
|
+
<Spinner dataHook={`${dataHook}-previous-loading`} />
|
|
581
|
+
) : (
|
|
582
|
+
<ChevronUp />
|
|
583
|
+
)}
|
|
519
584
|
</Button>
|
|
520
585
|
<Button
|
|
521
586
|
ref={nextRef}
|
|
587
|
+
aria-busy={nextBusy ? "true" : undefined}
|
|
522
588
|
ariaLabel={nextAriaLabel ?? "Next item"}
|
|
523
589
|
dataHook={`${dataHook}-next`}
|
|
524
590
|
disabled={!canNext}
|
|
@@ -527,7 +593,11 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
527
593
|
onClick={(event) => step("next", event.currentTarget)}
|
|
528
594
|
onKeyDown={handleKeyDown}
|
|
529
595
|
>
|
|
530
|
-
|
|
596
|
+
{nextBusy ? (
|
|
597
|
+
<Spinner dataHook={`${dataHook}-next-loading`} />
|
|
598
|
+
) : (
|
|
599
|
+
<ChevronDown />
|
|
600
|
+
)}
|
|
531
601
|
</Button>
|
|
532
602
|
{position != null && (
|
|
533
603
|
<span
|
|
@@ -538,6 +608,14 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
|
538
608
|
{position}
|
|
539
609
|
</span>
|
|
540
610
|
)}
|
|
611
|
+
{/* Always mounted so the announcement fires when loading starts. */}
|
|
612
|
+
<span
|
|
613
|
+
className="sr-only"
|
|
614
|
+
data-slot="sheet-pagination-status"
|
|
615
|
+
role="status"
|
|
616
|
+
>
|
|
617
|
+
{loading ? (loadingLabel ?? "Loading item") : null}
|
|
618
|
+
</span>
|
|
541
619
|
</div>
|
|
542
620
|
);
|
|
543
621
|
}
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
InputGroupInput,
|
|
24
24
|
} from "@brightlocal/ui-components/input-group";
|
|
25
25
|
import { Label } from "@brightlocal/ui-components/label";
|
|
26
|
-
import {
|
|
26
|
+
import { EmptyState } from "../blocks/empty-state";
|
|
27
27
|
import {
|
|
28
28
|
RadioGroup,
|
|
29
29
|
RadioGroupItem,
|
|
@@ -384,21 +384,14 @@ function SingleSelectFilterInner<Value extends string = string>({
|
|
|
384
384
|
) : null}
|
|
385
385
|
<DrawerBody className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pt-1 pb-2">
|
|
386
386
|
{searching && visibleOptions.length === 0 ? (
|
|
387
|
-
<
|
|
388
|
-
className="
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
<
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
slot="single-select-filter-empty-icon"
|
|
396
|
-
/>
|
|
397
|
-
<p>{emptyLabel ?? "No options found."}</p>
|
|
398
|
-
<p className="text-muted-foreground">
|
|
399
|
-
{emptyDescription ?? "Try another search."}
|
|
400
|
-
</p>
|
|
401
|
-
</div>
|
|
387
|
+
<EmptyState
|
|
388
|
+
className="py-6"
|
|
389
|
+
dataHook={`${dataHook}-empty`}
|
|
390
|
+
description={emptyDescription ?? "Try another search."}
|
|
391
|
+
icon={<SearchX />}
|
|
392
|
+
size="sm"
|
|
393
|
+
title={emptyLabel ?? "No options found."}
|
|
394
|
+
/>
|
|
402
395
|
) : (
|
|
403
396
|
<RadioGroup
|
|
404
397
|
className="grid grid-cols-2 gap-x-4 gap-y-3"
|
package/src/components/table.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
scrollRegionProps,
|
|
12
12
|
type TableFrame,
|
|
13
13
|
type TableSize,
|
|
14
|
+
useTableViewInlineSize,
|
|
14
15
|
} from "../lib/table-internal";
|
|
15
16
|
|
|
16
17
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -187,9 +188,14 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
|
|
|
187
188
|
) => {
|
|
188
189
|
const ownsScroll = scrollOwner === "self";
|
|
189
190
|
const ownFrame = frame === "own";
|
|
191
|
+
// DS-1105: as the scroll container, publish the visible width TableEmpty
|
|
192
|
+
// caps its message at.
|
|
193
|
+
const wrapperRef = React.useRef<HTMLDivElement>(null);
|
|
194
|
+
useTableViewInlineSize(wrapperRef, ownsScroll);
|
|
190
195
|
return (
|
|
191
196
|
<TableSizeContext.Provider value={size}>
|
|
192
197
|
<div
|
|
198
|
+
ref={wrapperRef}
|
|
193
199
|
className={cn(
|
|
194
200
|
"relative w-full",
|
|
195
201
|
// `overflow-x-auto` makes the wrapper a scroll container in BOTH
|
|
@@ -568,7 +574,16 @@ const TableEmpty = React.forwardRef<HTMLTableRowElement, TableEmptyProps>(
|
|
|
568
574
|
{/* Polite live region: the outcome of the reader's own query. */}
|
|
569
575
|
<div
|
|
570
576
|
aria-live="polite"
|
|
571
|
-
className={cn(
|
|
577
|
+
className={cn(
|
|
578
|
+
!isLine && "py-6",
|
|
579
|
+
// DS-1105: pinned to the visible part of a table that scrolls
|
|
580
|
+
// sideways. The scroll container publishes its visible width as
|
|
581
|
+
// `--table-view-inline-size` (useTableViewInlineSize); capped at
|
|
582
|
+
// it, this block is exactly one viewport wide, so its centred
|
|
583
|
+
// content sits in view at any scroll offset. Unset (nothing
|
|
584
|
+
// measuring) the cap is `none` — the plain full-width row.
|
|
585
|
+
"sticky left-0 max-w-(--table-view-inline-size,none)"
|
|
586
|
+
)}
|
|
572
587
|
data-slot="table-empty-message"
|
|
573
588
|
role="status"
|
|
574
589
|
>
|
package/src/components/tabs.tsx
CHANGED
|
@@ -29,24 +29,79 @@ const TabsContext = React.createContext<TabsContextValue>({
|
|
|
29
29
|
variant: "default",
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Horizontal alignment of triggers inside the tab list.
|
|
34
|
+
* - `"start"` — triggers sit at the left edge (default for underline)
|
|
35
|
+
* - `"center"` — triggers are centred; falls back to start on overflow
|
|
36
|
+
* (default for pill)
|
|
37
|
+
*
|
|
38
|
+
* @deprecated No consumer uses this — the variant-aware defaults cover every
|
|
39
|
+
* real case. Will be removed in a future major. Use `className="justify-center"`
|
|
40
|
+
* if you need to override.
|
|
41
|
+
*/
|
|
42
|
+
type TabsListAlign = "start" | "center";
|
|
43
|
+
|
|
44
|
+
const tabsListVariants = cva(
|
|
45
|
+
[
|
|
46
|
+
"inline-flex max-w-full items-center",
|
|
47
|
+
// A row wider than its container scrolls sideways instead of widening
|
|
48
|
+
// the page (six tabs on a phone). Only an overflowing list becomes a
|
|
49
|
+
// scroll container (data-overflowing), because a scroll container clips
|
|
50
|
+
// the focus ring of a list that fits. The scrollbar stays hidden; touch,
|
|
51
|
+
// trackpad and arrow keys scroll the row. overscroll-x-contain is scoped
|
|
52
|
+
// to the list, so the page keeps its back/forward swipe gestures.
|
|
53
|
+
"overscroll-x-contain [scrollbar-width:none]",
|
|
54
|
+
"data-overflowing:overflow-x-auto data-overflowing:overflow-y-hidden",
|
|
55
|
+
],
|
|
56
|
+
{
|
|
57
|
+
variants: {
|
|
58
|
+
variant: {
|
|
59
|
+
default: "h-9 w-fit bg-muted rounded-lg p-1",
|
|
60
|
+
// The bottom rule is an inset shadow, not a border: a scrolling list
|
|
61
|
+
// clips at its padding box, so a border would cut the active
|
|
62
|
+
// underline in half.
|
|
63
|
+
underline:
|
|
64
|
+
"w-full gap-1 rounded-none shadow-[inset_0_-1px_0_var(--border)]",
|
|
65
|
+
},
|
|
66
|
+
align: {
|
|
67
|
+
start: "justify-start",
|
|
68
|
+
center: "justify-center-safe",
|
|
69
|
+
},
|
|
70
|
+
fullWidth: {
|
|
71
|
+
// Triggers share the row equally (basis-0 + grow) and wrap long labels
|
|
72
|
+
// inside their cell instead of overflowing or truncating.
|
|
73
|
+
true: [
|
|
74
|
+
"flex w-full items-stretch",
|
|
75
|
+
// wrap-anywhere breaks a single long word too, so it never spills
|
|
76
|
+
// into the next trigger.
|
|
77
|
+
"*:min-w-0 *:flex-1 *:basis-0 *:whitespace-normal *:wrap-anywhere *:text-center",
|
|
78
|
+
],
|
|
79
|
+
false: "",
|
|
80
|
+
},
|
|
37
81
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
82
|
+
compoundVariants: [
|
|
83
|
+
// The pill row grows with wrapped labels instead of clipping at 36px.
|
|
84
|
+
// py-0.5 keeps a one-line row at h-9: stretched triggers (30px tall)
|
|
85
|
+
// fit the 32px content box instead of pushing the row to 38px.
|
|
86
|
+
{
|
|
87
|
+
variant: "default",
|
|
88
|
+
fullWidth: true,
|
|
89
|
+
className: "h-auto min-h-9 py-0.5",
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
defaultVariants: {
|
|
93
|
+
variant: "default",
|
|
94
|
+
fullWidth: false,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
);
|
|
43
98
|
|
|
44
99
|
const tabsTriggerVariants = cva(
|
|
45
100
|
[
|
|
46
101
|
"inline-flex items-center justify-center gap-2",
|
|
47
102
|
"text-label whitespace-nowrap",
|
|
48
103
|
"cursor-pointer",
|
|
49
|
-
"
|
|
104
|
+
"outline-none",
|
|
50
105
|
"disabled:pointer-events-none disabled:opacity-50",
|
|
51
106
|
],
|
|
52
107
|
{
|
|
@@ -64,13 +119,15 @@ const tabsTriggerVariants = cva(
|
|
|
64
119
|
"dark:data-[state=active]:border-white/15 dark:data-[state=active]:bg-white/5",
|
|
65
120
|
],
|
|
66
121
|
underline: [
|
|
67
|
-
"
|
|
122
|
+
"px-3 py-1.5",
|
|
68
123
|
"rounded-none border-b-2 border-transparent bg-transparent",
|
|
69
124
|
"first:rounded-l-none last:rounded-r-none",
|
|
70
125
|
"text-muted-foreground hover:bg-transparent hover:text-foreground",
|
|
71
126
|
"data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground",
|
|
72
127
|
"transition-[color,border-color,box-shadow] duration-fast ease-out",
|
|
73
128
|
"focus-visible:rounded-md focus-visible:shadow-default",
|
|
129
|
+
"[&:focus:not(:focus-visible)]:shadow-none",
|
|
130
|
+
"[&[data-pointer-focus]:focus-visible]:shadow-none [&[data-pointer-focus]:focus-visible]:rounded-none",
|
|
74
131
|
],
|
|
75
132
|
},
|
|
76
133
|
},
|
|
@@ -100,9 +157,18 @@ interface TabsProps<T extends string = string> extends Omit<
|
|
|
100
157
|
* @default "default"
|
|
101
158
|
*/
|
|
102
159
|
variant?: TabsVariant;
|
|
103
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Only mount a panel when its tab is first activated; once visited it stays
|
|
162
|
+
* mounted (hidden while inactive) unless `unmountOnExit` is also set.
|
|
163
|
+
* @default false
|
|
164
|
+
*/
|
|
104
165
|
lazyMount?: boolean;
|
|
105
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* Unmount a panel's content when its tab becomes inactive. Off by default:
|
|
168
|
+
* inactive panels stay mounted and hidden, so form edits, scroll position
|
|
169
|
+
* and other local state survive a tab switch.
|
|
170
|
+
* @default false
|
|
171
|
+
*/
|
|
106
172
|
unmountOnExit?: boolean;
|
|
107
173
|
/** The controlled value of the active tab */
|
|
108
174
|
value?: T;
|
|
@@ -136,20 +202,20 @@ function TabsInner<T extends string = string>(
|
|
|
136
202
|
() => new Set(activeValue != null ? [activeValue] : [])
|
|
137
203
|
);
|
|
138
204
|
|
|
205
|
+
// Record the active tab as visited however it became active: a trigger
|
|
206
|
+
// click or a parent changing the controlled `value`. Updating state during
|
|
207
|
+
// render (guarded, so it settles in one pass) keeps the panel from being
|
|
208
|
+
// dropped when it is left.
|
|
209
|
+
if (lazyMount && activeValue != null && !visitedTabs.has(activeValue)) {
|
|
210
|
+
setVisitedTabs(new Set(visitedTabs).add(activeValue));
|
|
211
|
+
}
|
|
212
|
+
|
|
139
213
|
const handleValueChange = React.useCallback(
|
|
140
214
|
(newValue: string) => {
|
|
141
215
|
setInternalValue(newValue as T);
|
|
142
|
-
if (lazyMount) {
|
|
143
|
-
setVisitedTabs((prev) => {
|
|
144
|
-
if (prev.has(newValue)) return prev;
|
|
145
|
-
const next = new Set(prev);
|
|
146
|
-
next.add(newValue);
|
|
147
|
-
return next;
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
216
|
onValueChange?.(newValue as T);
|
|
151
217
|
},
|
|
152
|
-
[
|
|
218
|
+
[onValueChange]
|
|
153
219
|
);
|
|
154
220
|
|
|
155
221
|
const contextValue = React.useMemo(
|
|
@@ -167,7 +233,11 @@ function TabsInner<T extends string = string>(
|
|
|
167
233
|
<TabsContext.Provider value={contextValue}>
|
|
168
234
|
<TabsPrimitive.Root
|
|
169
235
|
ref={ref}
|
|
170
|
-
className={cn(
|
|
236
|
+
className={cn(
|
|
237
|
+
"flex max-w-full min-w-0 flex-col",
|
|
238
|
+
variant === "underline" ? "gap-6" : "gap-2",
|
|
239
|
+
className
|
|
240
|
+
)}
|
|
171
241
|
data-hook={dataHook}
|
|
172
242
|
data-slot="tabs"
|
|
173
243
|
data-tracking-el={trackingEl}
|
|
@@ -192,6 +262,44 @@ const Tabs = React.forwardRef(TabsInner) as <T extends string = string>(
|
|
|
192
262
|
|
|
193
263
|
(Tabs as React.FC).displayName = "Tabs";
|
|
194
264
|
|
|
265
|
+
/**
|
|
266
|
+
* True while an element's children are wider than the element itself.
|
|
267
|
+
* Re-measures when the element or any child resizes, and when children are
|
|
268
|
+
* added or removed.
|
|
269
|
+
*/
|
|
270
|
+
function useHorizontalOverflow(element: HTMLElement | null) {
|
|
271
|
+
const [overflowing, setOverflowing] = React.useState(false);
|
|
272
|
+
|
|
273
|
+
React.useLayoutEffect(() => {
|
|
274
|
+
if (!element || typeof ResizeObserver === "undefined") return;
|
|
275
|
+
|
|
276
|
+
const measure = () =>
|
|
277
|
+
setOverflowing(element.scrollWidth > element.clientWidth + 1);
|
|
278
|
+
|
|
279
|
+
const resize = new ResizeObserver(measure);
|
|
280
|
+
const observeAll = () => {
|
|
281
|
+
resize.disconnect();
|
|
282
|
+
resize.observe(element);
|
|
283
|
+
for (const child of Array.from(element.children)) resize.observe(child);
|
|
284
|
+
};
|
|
285
|
+
const mutation = new MutationObserver(() => {
|
|
286
|
+
observeAll();
|
|
287
|
+
measure();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
observeAll();
|
|
291
|
+
mutation.observe(element, { childList: true });
|
|
292
|
+
measure();
|
|
293
|
+
|
|
294
|
+
return () => {
|
|
295
|
+
resize.disconnect();
|
|
296
|
+
mutation.disconnect();
|
|
297
|
+
};
|
|
298
|
+
}, [element]);
|
|
299
|
+
|
|
300
|
+
return overflowing;
|
|
301
|
+
}
|
|
302
|
+
|
|
195
303
|
/**
|
|
196
304
|
* Props for the TabsList component
|
|
197
305
|
*/
|
|
@@ -204,26 +312,72 @@ interface TabsListProps extends React.ComponentProps<
|
|
|
204
312
|
trackingEl?: string;
|
|
205
313
|
/** Tracking label for analytics context */
|
|
206
314
|
trackingLabel?: string;
|
|
315
|
+
/**
|
|
316
|
+
* Horizontal alignment of triggers inside the list.
|
|
317
|
+
* Defaults to `"start"` for the underline variant and `"center"` for the
|
|
318
|
+
* pill variant.
|
|
319
|
+
*
|
|
320
|
+
* @deprecated No consumer uses this — the variant-aware defaults cover every
|
|
321
|
+
* real case. Will be removed in a future major. Use `className` if you need
|
|
322
|
+
* to override alignment.
|
|
323
|
+
*/
|
|
324
|
+
align?: TabsListAlign;
|
|
325
|
+
/**
|
|
326
|
+
* Stretch the list to its container and give every trigger an equal share
|
|
327
|
+
* of the width. Long labels wrap inside their trigger; they never truncate.
|
|
328
|
+
* @default false
|
|
329
|
+
*/
|
|
330
|
+
fullWidth?: boolean;
|
|
207
331
|
}
|
|
208
332
|
|
|
209
333
|
const TabsList = React.forwardRef<
|
|
210
334
|
React.ComponentRef<typeof TabsPrimitive.List>,
|
|
211
335
|
TabsListProps
|
|
212
|
-
>(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
336
|
+
>(
|
|
337
|
+
(
|
|
338
|
+
{
|
|
339
|
+
className,
|
|
340
|
+
dataHook,
|
|
341
|
+
trackingEl,
|
|
342
|
+
trackingLabel,
|
|
343
|
+
align: alignProp,
|
|
344
|
+
fullWidth = false,
|
|
345
|
+
...props
|
|
346
|
+
},
|
|
347
|
+
ref
|
|
348
|
+
) => {
|
|
349
|
+
const { variant } = React.useContext(TabsContext);
|
|
350
|
+
const resolvedAlign =
|
|
351
|
+
alignProp ?? (variant === "underline" ? "start" : "center");
|
|
352
|
+
const [list, setList] = React.useState<HTMLDivElement | null>(null);
|
|
353
|
+
const overflowing = useHorizontalOverflow(list);
|
|
354
|
+
|
|
355
|
+
const setRefs = React.useCallback(
|
|
356
|
+
(node: HTMLDivElement | null) => {
|
|
357
|
+
setList(node);
|
|
358
|
+
if (typeof ref === "function") ref(node);
|
|
359
|
+
else if (ref) ref.current = node;
|
|
360
|
+
},
|
|
361
|
+
[ref]
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
return (
|
|
365
|
+
<TabsPrimitive.List
|
|
366
|
+
ref={setRefs}
|
|
367
|
+
className={cn(
|
|
368
|
+
tabsListVariants({ variant, align: resolvedAlign, fullWidth }),
|
|
369
|
+
className
|
|
370
|
+
)}
|
|
371
|
+
data-hook={dataHook}
|
|
372
|
+
data-overflowing={overflowing ? "" : undefined}
|
|
373
|
+
data-slot="tabs-list"
|
|
374
|
+
data-tracking-el={trackingEl}
|
|
375
|
+
data-tracking-label={trackingLabel}
|
|
376
|
+
{...props}
|
|
377
|
+
/>
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
);
|
|
227
381
|
|
|
228
382
|
TabsList.displayName = "TabsList";
|
|
229
383
|
|
|
@@ -252,12 +406,30 @@ function TabsTriggerInner<T extends string = string>(
|
|
|
252
406
|
dataHook,
|
|
253
407
|
trackingEl,
|
|
254
408
|
trackingLabel,
|
|
409
|
+
onPointerDown: onPointerDownProp,
|
|
410
|
+
onBlur: onBlurProp,
|
|
255
411
|
...props
|
|
256
412
|
}: TabsTriggerProps<T>,
|
|
257
413
|
ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Trigger>>
|
|
258
414
|
) {
|
|
259
415
|
const { variant } = React.useContext(TabsContext);
|
|
260
416
|
|
|
417
|
+
const handlePointerDown = React.useCallback(
|
|
418
|
+
(e: React.PointerEvent<HTMLButtonElement>) => {
|
|
419
|
+
e.currentTarget.setAttribute("data-pointer-focus", "");
|
|
420
|
+
onPointerDownProp?.(e);
|
|
421
|
+
},
|
|
422
|
+
[onPointerDownProp]
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
const handleBlur = React.useCallback(
|
|
426
|
+
(e: React.FocusEvent<HTMLButtonElement>) => {
|
|
427
|
+
e.currentTarget.removeAttribute("data-pointer-focus");
|
|
428
|
+
onBlurProp?.(e);
|
|
429
|
+
},
|
|
430
|
+
[onBlurProp]
|
|
431
|
+
);
|
|
432
|
+
|
|
261
433
|
return (
|
|
262
434
|
<TabsPrimitive.Trigger
|
|
263
435
|
ref={ref}
|
|
@@ -266,6 +438,8 @@ function TabsTriggerInner<T extends string = string>(
|
|
|
266
438
|
data-slot="tabs-trigger"
|
|
267
439
|
data-tracking-el={trackingEl}
|
|
268
440
|
data-tracking-label={trackingLabel}
|
|
441
|
+
onBlur={handleBlur}
|
|
442
|
+
onPointerDown={handlePointerDown}
|
|
269
443
|
{...props}
|
|
270
444
|
/>
|
|
271
445
|
);
|
|
@@ -315,7 +489,7 @@ function TabsContentInner<T extends string = string>(
|
|
|
315
489
|
|
|
316
490
|
const isActive = value === activeValue;
|
|
317
491
|
|
|
318
|
-
if (lazyMount && !visitedTabs.has(value)) {
|
|
492
|
+
if (lazyMount && !isActive && !visitedTabs.has(value)) {
|
|
319
493
|
return null;
|
|
320
494
|
}
|
|
321
495
|
|
|
@@ -326,11 +500,18 @@ function TabsContentInner<T extends string = string>(
|
|
|
326
500
|
return (
|
|
327
501
|
<TabsPrimitive.Content
|
|
328
502
|
ref={ref}
|
|
329
|
-
className={cn(
|
|
503
|
+
className={cn(
|
|
504
|
+
"flex-1 outline-none data-[state=inactive]:hidden",
|
|
505
|
+
className
|
|
506
|
+
)}
|
|
330
507
|
data-hook={dataHook}
|
|
331
508
|
data-slot="tabs-content"
|
|
332
509
|
data-tracking-el={trackingEl}
|
|
333
510
|
data-tracking-label={trackingLabel}
|
|
511
|
+
// Radix unmounts inactive content unless forceMount. Keep it mounted
|
|
512
|
+
// (unless unmountOnExit); the class above hides it with display: none,
|
|
513
|
+
// which also takes it out of the accessibility tree and the tab order.
|
|
514
|
+
forceMount={unmountOnExit ? undefined : true}
|
|
334
515
|
value={value}
|
|
335
516
|
{...props}
|
|
336
517
|
/>
|
|
@@ -351,6 +532,7 @@ export { Tabs, TabsList, TabsTrigger, TabsContent };
|
|
|
351
532
|
export type {
|
|
352
533
|
TabsProps,
|
|
353
534
|
TabsListProps,
|
|
535
|
+
TabsListAlign,
|
|
354
536
|
TabsTriggerProps,
|
|
355
537
|
TabsContentProps,
|
|
356
538
|
TabsVariant,
|