@brightlocal/ui-components 3.1.0 → 3.2.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 +6 -1
- package/component-meta.json +663 -38
- package/deprecations.json +1 -1
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +32 -3
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +61 -58
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +58 -57
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts +9 -0
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +50 -30
- package/dist/banner.cjs +1 -0
- package/dist/banner.d.ts +81 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/banner.js +176 -0
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +4 -3
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +21 -20
- package/dist/blocks/progress-state.d.ts +2 -2
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +17 -0
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +8 -2
- package/dist/brand-illustration-motif.d.ts +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +86 -6
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +185 -96
- package/dist/chart.cjs +3 -3
- package/dist/chart.d.ts +231 -13
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +466 -306
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.d.ts +1 -1
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +2 -1
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.js +2 -2
- package/dist/command.cjs +1 -1
- package/dist/command.js +1 -1
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +169 -22
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +695 -561
- package/dist/grid.d.ts +24 -1
- package/dist/grid.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.cjs +1 -1
- package/dist/hooks/use-breakpoint.d.ts +1 -1
- package/dist/hooks/use-breakpoint.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +593 -561
- package/dist/info-tooltip.cjs +1 -0
- package/dist/info-tooltip.d.ts +39 -0
- package/dist/info-tooltip.d.ts.map +1 -0
- package/dist/info-tooltip.js +41 -0
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.js +1 -1
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +33 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +167 -54
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.js +9 -9
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +28 -6
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +5 -5
- package/dist/input.cjs +1 -1
- package/dist/input.js +10 -10
- package/dist/lib/block-illustration.cjs +1 -1
- package/dist/lib/block-illustration.d.ts +4 -1
- package/dist/lib/block-illustration.d.ts.map +1 -1
- package/dist/lib/block-illustration.js +12 -11
- package/dist/lib/utils.cjs +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +4 -3
- package/dist/list.cjs +1 -1
- package/dist/list.js +1 -1
- package/dist/multi-select-filter.cjs +1 -0
- package/dist/multi-select-filter.d.ts +178 -0
- package/dist/multi-select-filter.d.ts.map +1 -0
- package/dist/multi-select-filter.js +463 -0
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +123 -16
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +89 -75
- package/dist/rating.cjs +1 -1
- package/dist/rating.js +18 -18
- package/dist/relative-date.cjs +1 -0
- package/dist/relative-date.d.ts +65 -0
- package/dist/relative-date.d.ts.map +1 -0
- package/dist/relative-date.js +128 -0
- package/dist/select.cjs +2 -2
- package/dist/select.d.ts +11 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +97 -81
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +78 -2
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +192 -85
- package/dist/single-select-filter.cjs +1 -0
- package/dist/single-select-filter.d.ts +81 -0
- package/dist/single-select-filter.d.ts.map +1 -0
- package/dist/single-select-filter.js +226 -0
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +22 -22
- package/dist/split-layout.cjs +1 -1
- package/dist/split-layout.d.ts +1 -1
- package/dist/split-layout.js +13 -13
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +45 -4
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +90 -73
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +12 -1
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +148 -126
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.js +1 -1
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts +38 -36
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +262 -73
- package/dist/typography-text.d.ts +1 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography.d.ts +1 -1
- package/package.json +5 -6
- package/src/blocks/empty-state.tsx +8 -3
- package/src/blocks/progress-state.tsx +2 -2
- package/src/blocks/sidebar.tsx +26 -2
- package/src/components/alert-dialog.tsx +50 -5
- package/src/components/alert.tsx +16 -8
- package/src/components/badge.tsx +40 -3
- package/src/components/banner.tsx +288 -0
- package/src/components/brand-illustration-motif.tsx +1 -1
- package/src/components/card.tsx +211 -24
- package/src/components/chart.tsx +523 -35
- package/src/components/checkbox.tsx +1 -1
- package/src/components/combobox.tsx +2 -2
- package/src/components/command.tsx +1 -1
- package/src/components/data-table.tsx +778 -195
- package/src/components/grid.tsx +32 -1
- package/src/components/info-tooltip.tsx +94 -0
- package/src/components/input-chip.tsx +1 -1
- package/src/components/input-group.tsx +246 -11
- package/src/components/input-otp.tsx +1 -1
- package/src/components/input-password.tsx +33 -11
- package/src/components/input.tsx +1 -1
- package/src/components/list.tsx +1 -1
- package/src/components/multi-select-filter.tsx +912 -0
- package/src/components/progress.tsx +190 -31
- package/src/components/rating.tsx +1 -1
- package/src/components/relative-date.tsx +230 -0
- package/src/components/select.tsx +35 -5
- package/src/components/sheet.tsx +240 -4
- package/src/components/single-select-filter.tsx +443 -0
- package/src/components/sonner.tsx +16 -5
- package/src/components/split-layout.tsx +2 -2
- package/src/components/table.tsx +71 -11
- package/src/components/tabs.tsx +93 -46
- package/src/components/textarea.tsx +1 -1
- package/src/components/tooltip.tsx +440 -68
- package/src/components/typography-text.tsx +1 -2
- package/src/components/typography.tsx +1 -1
- package/src/hooks/use-breakpoint.ts +2 -1
- package/src/index.ts +5 -0
- package/src/lib/block-illustration.tsx +5 -1
- package/src/lib/utils.ts +1 -0
package/src/components/sheet.tsx
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import * as SheetPrimitive from "@radix-ui/react-dialog";
|
|
5
5
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
6
|
-
import { X } from "@brightlocal/icons";
|
|
6
|
+
import { ChevronDown, ChevronUp, X } from "@brightlocal/icons";
|
|
7
7
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
+
import { Button } from "@brightlocal/ui-components/button";
|
|
9
10
|
import { ScrollArea } from "@brightlocal/ui-components/scroll-area";
|
|
10
11
|
import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
|
|
11
12
|
|
|
@@ -273,9 +274,18 @@ const SheetContent = React.forwardRef<
|
|
|
273
274
|
{...props}
|
|
274
275
|
>
|
|
275
276
|
{children}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
{/* Ghost icon button (DS-1035) — standard hover/focus states, and its
|
|
278
|
+
36px box at top-6 lines up with a SheetPagination row. */}
|
|
279
|
+
<SheetPrimitive.Close asChild>
|
|
280
|
+
<Button
|
|
281
|
+
iconOnly
|
|
282
|
+
className="absolute top-6 right-4"
|
|
283
|
+
dataHook="sheet-close"
|
|
284
|
+
variant="ghost"
|
|
285
|
+
>
|
|
286
|
+
<X />
|
|
287
|
+
<span className="sr-only">{closeLabel ?? "Close"}</span>
|
|
288
|
+
</Button>
|
|
279
289
|
</SheetPrimitive.Close>
|
|
280
290
|
</SheetPrimitive.Content>
|
|
281
291
|
</SheetPortal>
|
|
@@ -301,6 +311,229 @@ const SheetHeader = React.forwardRef<
|
|
|
301
311
|
));
|
|
302
312
|
SheetHeader.displayName = "SheetHeader";
|
|
303
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Numbers a `SheetPagination` position indicator is built from.
|
|
316
|
+
*/
|
|
317
|
+
interface SheetPaginationPositionInfo {
|
|
318
|
+
/** 1-based position of the item shown in the sheet. */
|
|
319
|
+
current: number;
|
|
320
|
+
/** Total number of items in the list being stepped through. */
|
|
321
|
+
total: number;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Props for the SheetPagination component
|
|
326
|
+
*/
|
|
327
|
+
interface SheetPaginationProps extends Omit<
|
|
328
|
+
React.ComponentProps<"div">,
|
|
329
|
+
"children"
|
|
330
|
+
> {
|
|
331
|
+
/** Called when the user steps to the previous item. */
|
|
332
|
+
onPrevious: () => void;
|
|
333
|
+
/** Called when the user steps to the next item. */
|
|
334
|
+
onNext: () => void;
|
|
335
|
+
/**
|
|
336
|
+
* 1-based position of the item shown in the sheet. Together with `total`,
|
|
337
|
+
* drives the position indicator and the default boundary state.
|
|
338
|
+
*/
|
|
339
|
+
current?: number;
|
|
340
|
+
/** Total number of items in the list being stepped through. */
|
|
341
|
+
total?: number;
|
|
342
|
+
/**
|
|
343
|
+
* Whether a previous item exists. Disables the previous button when false.
|
|
344
|
+
* @default current > 1 (true when `current` is not set)
|
|
345
|
+
*/
|
|
346
|
+
hasPrevious?: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Whether a next item exists. Disables the next button when false.
|
|
349
|
+
* @default current < total (true when either is not set)
|
|
350
|
+
*/
|
|
351
|
+
hasNext?: boolean;
|
|
352
|
+
/**
|
|
353
|
+
* Render the position indicator. Receives the current position and total;
|
|
354
|
+
* you own the wording. Return `null` to hide it.
|
|
355
|
+
* @default Renders "{current} of {total}", or nothing when either is unset.
|
|
356
|
+
*/
|
|
357
|
+
renderPosition?:
|
|
358
|
+
| ((info: SheetPaginationPositionInfo) => React.ReactNode)
|
|
359
|
+
| null;
|
|
360
|
+
/**
|
|
361
|
+
* Accessible label for the item navigation group.
|
|
362
|
+
* @default "Item navigation"
|
|
363
|
+
*/
|
|
364
|
+
ariaLabel?: string;
|
|
365
|
+
/**
|
|
366
|
+
* Accessible label for the previous button.
|
|
367
|
+
* @default "Previous item"
|
|
368
|
+
*/
|
|
369
|
+
prevAriaLabel?: string;
|
|
370
|
+
/**
|
|
371
|
+
* Accessible label for the next button.
|
|
372
|
+
* @default "Next item"
|
|
373
|
+
*/
|
|
374
|
+
nextAriaLabel?: string;
|
|
375
|
+
/**
|
|
376
|
+
* Data hook for automated testing. The buttons get `{dataHook}-previous`
|
|
377
|
+
* and `{dataHook}-next`.
|
|
378
|
+
*/
|
|
379
|
+
dataHook: string;
|
|
380
|
+
/**
|
|
381
|
+
* Tracking element identifier for analytics
|
|
382
|
+
*/
|
|
383
|
+
trackingEl?: string;
|
|
384
|
+
/**
|
|
385
|
+
* Tracking label for analytics context
|
|
386
|
+
*/
|
|
387
|
+
trackingLabel?: string;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Previous/next controls for stepping through a list of items without
|
|
392
|
+
* closing the sheet — e.g. a detail sheet drilled into from a table row.
|
|
393
|
+
* Place it as the first child of SheetContent, above SheetHeader; it shares
|
|
394
|
+
* the close button's row. The arrow keys step while focus is on the controls.
|
|
395
|
+
*/
|
|
396
|
+
const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
|
|
397
|
+
(
|
|
398
|
+
{
|
|
399
|
+
className,
|
|
400
|
+
onPrevious,
|
|
401
|
+
onNext,
|
|
402
|
+
current,
|
|
403
|
+
total,
|
|
404
|
+
hasPrevious,
|
|
405
|
+
hasNext,
|
|
406
|
+
renderPosition,
|
|
407
|
+
ariaLabel,
|
|
408
|
+
prevAriaLabel,
|
|
409
|
+
nextAriaLabel,
|
|
410
|
+
dataHook,
|
|
411
|
+
trackingEl,
|
|
412
|
+
trackingLabel,
|
|
413
|
+
...props
|
|
414
|
+
},
|
|
415
|
+
ref
|
|
416
|
+
) => {
|
|
417
|
+
const canPrevious = hasPrevious ?? (current == null || current > 1);
|
|
418
|
+
const canNext =
|
|
419
|
+
hasNext ?? (current == null || total == null || current < total);
|
|
420
|
+
|
|
421
|
+
const prevRef = React.useRef<HTMLButtonElement>(null);
|
|
422
|
+
const nextRef = React.useRef<HTMLButtonElement>(null);
|
|
423
|
+
// The button that just triggered a step. Set only by our own
|
|
424
|
+
// navigation, consumed on the next commit.
|
|
425
|
+
const pendingRef = React.useRef<HTMLButtonElement | null>(null);
|
|
426
|
+
|
|
427
|
+
// Reaching a boundary disables the button that was just pressed, which
|
|
428
|
+
// drops focus to <body>. Hand it to the sibling instead so keyboard users
|
|
429
|
+
// stay in the control.
|
|
430
|
+
React.useEffect(() => {
|
|
431
|
+
const pending = pendingRef.current;
|
|
432
|
+
pendingRef.current = null;
|
|
433
|
+
if (!pending) return;
|
|
434
|
+
const active = document.activeElement;
|
|
435
|
+
if (active !== pending && active !== document.body) return;
|
|
436
|
+
if (!canPrevious && pending === prevRef.current && canNext) {
|
|
437
|
+
nextRef.current?.focus();
|
|
438
|
+
} else if (!canNext && pending === nextRef.current && canPrevious) {
|
|
439
|
+
prevRef.current?.focus();
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
const handleBlur = (event: React.FocusEvent<HTMLButtonElement>) => {
|
|
444
|
+
// Focus left on purpose (to anything but the sibling) — drop any
|
|
445
|
+
// pending hand-off. A disabled button blurs with a null relatedTarget.
|
|
446
|
+
const next = event.relatedTarget;
|
|
447
|
+
if (next && next !== prevRef.current && next !== nextRef.current) {
|
|
448
|
+
pendingRef.current = null;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const step = (
|
|
453
|
+
direction: "previous" | "next",
|
|
454
|
+
trigger: HTMLButtonElement
|
|
455
|
+
) => {
|
|
456
|
+
if (direction === "previous") {
|
|
457
|
+
if (!canPrevious) return;
|
|
458
|
+
pendingRef.current = trigger;
|
|
459
|
+
onPrevious();
|
|
460
|
+
} else {
|
|
461
|
+
if (!canNext) return;
|
|
462
|
+
pendingRef.current = trigger;
|
|
463
|
+
onNext();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
|
|
468
|
+
if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
|
|
469
|
+
event.preventDefault();
|
|
470
|
+
step("previous", event.currentTarget);
|
|
471
|
+
} else if (event.key === "ArrowDown" || event.key === "ArrowRight") {
|
|
472
|
+
event.preventDefault();
|
|
473
|
+
step("next", event.currentTarget);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
let position: React.ReactNode = null;
|
|
478
|
+
if (renderPosition !== null && current != null && total != null) {
|
|
479
|
+
position = renderPosition
|
|
480
|
+
? renderPosition({ current, total })
|
|
481
|
+
: `${current} of ${total}`;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
return (
|
|
485
|
+
<div
|
|
486
|
+
ref={ref}
|
|
487
|
+
aria-label={ariaLabel ?? "Item navigation"}
|
|
488
|
+
// mb-2 on top of SheetContent's gap-4 gives the 24px Figma gap to
|
|
489
|
+
// the header below.
|
|
490
|
+
className={cn("mb-2 flex items-center gap-1", className)}
|
|
491
|
+
data-hook={dataHook}
|
|
492
|
+
data-slot="sheet-pagination"
|
|
493
|
+
data-tracking-el={trackingEl}
|
|
494
|
+
data-tracking-label={trackingLabel}
|
|
495
|
+
role="group"
|
|
496
|
+
{...props}
|
|
497
|
+
>
|
|
498
|
+
<Button
|
|
499
|
+
ref={prevRef}
|
|
500
|
+
ariaLabel={prevAriaLabel ?? "Previous item"}
|
|
501
|
+
dataHook={`${dataHook}-previous`}
|
|
502
|
+
disabled={!canPrevious}
|
|
503
|
+
variant="ghost"
|
|
504
|
+
onBlur={handleBlur}
|
|
505
|
+
onClick={(event) => step("previous", event.currentTarget)}
|
|
506
|
+
onKeyDown={handleKeyDown}
|
|
507
|
+
>
|
|
508
|
+
<ChevronUp />
|
|
509
|
+
</Button>
|
|
510
|
+
<Button
|
|
511
|
+
ref={nextRef}
|
|
512
|
+
ariaLabel={nextAriaLabel ?? "Next item"}
|
|
513
|
+
dataHook={`${dataHook}-next`}
|
|
514
|
+
disabled={!canNext}
|
|
515
|
+
variant="ghost"
|
|
516
|
+
onBlur={handleBlur}
|
|
517
|
+
onClick={(event) => step("next", event.currentTarget)}
|
|
518
|
+
onKeyDown={handleKeyDown}
|
|
519
|
+
>
|
|
520
|
+
<ChevronDown />
|
|
521
|
+
</Button>
|
|
522
|
+
{position != null && (
|
|
523
|
+
<span
|
|
524
|
+
aria-live="polite"
|
|
525
|
+
className="text-body-sm text-muted-foreground"
|
|
526
|
+
data-slot="sheet-pagination-position"
|
|
527
|
+
>
|
|
528
|
+
{position}
|
|
529
|
+
</span>
|
|
530
|
+
)}
|
|
531
|
+
</div>
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
);
|
|
535
|
+
SheetPagination.displayName = "SheetPagination";
|
|
536
|
+
|
|
304
537
|
/**
|
|
305
538
|
* Props for the SheetBody component
|
|
306
539
|
*/
|
|
@@ -450,6 +683,7 @@ export {
|
|
|
450
683
|
SheetFooter,
|
|
451
684
|
SheetHeader,
|
|
452
685
|
SheetOverlay,
|
|
686
|
+
SheetPagination,
|
|
453
687
|
SheetPortal,
|
|
454
688
|
SheetTitle,
|
|
455
689
|
SheetTrigger,
|
|
@@ -459,6 +693,8 @@ export type {
|
|
|
459
693
|
SheetBodyProps,
|
|
460
694
|
SheetContentProps,
|
|
461
695
|
SheetDescriptionProps,
|
|
696
|
+
SheetPaginationPositionInfo,
|
|
697
|
+
SheetPaginationProps,
|
|
462
698
|
SheetTitleProps,
|
|
463
699
|
SheetTriggerProps,
|
|
464
700
|
};
|