@brightlocal/ui-components 2.5.0 → 2.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightlocal/ui-components",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "BrightLocal Design System UI Components",
5
5
  "type": "module",
6
6
  "private": false,
@@ -11,6 +11,7 @@ import {
11
11
  Minus,
12
12
  PanelLeft,
13
13
  Ellipsis,
14
+ Menu,
14
15
  } from "@brightlocal/icons";
15
16
 
16
17
  import { cn } from "@brightlocal/ui-components/lib/utils";
@@ -18,6 +19,20 @@ import { Button } from "../components/button";
18
19
  import { Input } from "../components/input";
19
20
  import { Separator } from "../components/separator";
20
21
  import { Sheet, SheetContent } from "../components/sheet";
22
+ import {
23
+ Drawer,
24
+ DrawerContent,
25
+ DrawerDescription,
26
+ DrawerTitle,
27
+ DrawerTrigger,
28
+ } from "../components/drawer";
29
+ import {
30
+ Accordion,
31
+ AccordionItem,
32
+ AccordionContent,
33
+ } from "../components/accordion";
34
+ import * as AccordionPrimitive from "@radix-ui/react-accordion";
35
+ import { ScrollArea } from "../components/scroll-area";
21
36
  import { Skeleton } from "../components/skeleton";
22
37
  import {
23
38
  Tooltip,
@@ -352,6 +367,12 @@ interface SidebarProps extends React.ComponentProps<"div"> {
352
367
  * @default SidebarCollapsible.OFFCANVAS
353
368
  */
354
369
  collapsible?: SidebarCollapsible;
370
+ /**
371
+ * Render in flow layout instead of fixed positioning.
372
+ * Use when the Sidebar is placed inside a layout container (e.g. GlobalLayout).
373
+ * Mobile rendering (Sheet) is skipped — handle mobile navigation separately with Drawer.
374
+ */
375
+ embedded?: boolean;
355
376
  }
356
377
 
357
378
  const Sidebar = React.forwardRef<HTMLDivElement, SidebarProps>(
@@ -363,6 +384,7 @@ const Sidebar = React.forwardRef<HTMLDivElement, SidebarProps>(
363
384
  side = SidebarSide.LEFT,
364
385
  variant = SidebarVariant.SIDEBAR,
365
386
  collapsible = SidebarCollapsible.OFFCANVAS,
387
+ embedded = false,
366
388
  className,
367
389
  children,
368
390
  ...props
@@ -390,6 +412,36 @@ const Sidebar = React.forwardRef<HTMLDivElement, SidebarProps>(
390
412
  );
391
413
  }
392
414
 
415
+ if (embedded) {
416
+ return (
417
+ <div
418
+ ref={ref}
419
+ className={cn(
420
+ "group bg-sidebar text-sidebar-foreground flex h-full shrink-0 flex-col overflow-hidden transition-[width] duration-200 ease-linear",
421
+ state === "expanded" && "w-[var(--sidebar-width)]",
422
+ collapsible === SidebarCollapsible.ICON &&
423
+ state === "collapsed" &&
424
+ "w-[var(--sidebar-width-icon)]",
425
+ collapsible === SidebarCollapsible.OFFCANVAS &&
426
+ state === "collapsed" &&
427
+ "w-0",
428
+ className
429
+ )}
430
+ data-collapsible={state === "collapsed" ? collapsible : ""}
431
+ data-hook={dataHook}
432
+ data-side={side}
433
+ data-slot="sidebar"
434
+ data-state={state}
435
+ data-tracking-el={trackingEl || "sidebar"}
436
+ data-tracking-label={trackingLabel}
437
+ data-variant={variant}
438
+ {...props}
439
+ >
440
+ {children}
441
+ </div>
442
+ );
443
+ }
444
+
393
445
  if (isMobile) {
394
446
  return (
395
447
  <Sheet open={openMobile} onOpenChange={setOpenMobile}>
@@ -605,7 +657,7 @@ const SidebarHeader = React.forwardRef<HTMLDivElement, SidebarHeaderProps>(
605
657
  return (
606
658
  <div
607
659
  ref={ref}
608
- className={cn("flex flex-col gap-2 p-2", className)}
660
+ className={cn("px-section-xs flex flex-col gap-2 pt-2 pb-9", className)}
609
661
  data-hook={dataHook}
610
662
  data-slot="sidebar-header"
611
663
  {...props}
@@ -651,7 +703,7 @@ const SidebarSeparator = React.forwardRef<
651
703
  <Separator
652
704
  ref={ref}
653
705
  className={cn(
654
- "bg-sidebar-border mx-2 w-auto group-data-[collapsible=icon]:mx-0",
706
+ "bg-sidebar-border mx-2 my-2 w-auto group-data-[collapsible=icon]:mx-0",
655
707
  className
656
708
  )}
657
709
  data-slot="sidebar-separator"
@@ -664,24 +716,31 @@ SidebarSeparator.displayName = "SidebarSeparator";
664
716
  /**
665
717
  * Props for the SidebarContent component
666
718
  */
667
- interface SidebarContentProps extends React.ComponentProps<"div"> {
719
+ interface SidebarContentProps extends Omit<React.ComponentProps<"div">, "dir"> {
668
720
  /** Data hook for automated testing */
669
721
  dataHook?: string;
670
722
  }
671
723
 
672
724
  const SidebarContent = React.forwardRef<HTMLDivElement, SidebarContentProps>(
673
- ({ className, dataHook, ...props }, ref) => {
725
+ ({ className, dataHook, children, ...props }, ref) => {
674
726
  return (
675
- <div
727
+ <ScrollArea
676
728
  ref={ref}
677
729
  className={cn(
678
- "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
730
+ "min-h-0 flex-1 group-data-[collapsible=icon]:overflow-hidden [&>[data-slot=scroll-area-viewport]]:p-0",
679
731
  className
680
732
  )}
681
- data-hook={dataHook}
682
- data-slot="sidebar-content"
733
+ dataHook={dataHook ?? "sidebar-content-scroll"}
683
734
  {...props}
684
- />
735
+ >
736
+ <nav
737
+ aria-label="Sidebar"
738
+ className="flex flex-col gap-2"
739
+ data-slot="sidebar-content"
740
+ >
741
+ {children}
742
+ </nav>
743
+ </ScrollArea>
685
744
  );
686
745
  }
687
746
  );
@@ -1003,7 +1062,7 @@ const SidebarCollapseIcon = React.forwardRef<
1003
1062
  SidebarCollapseIcon.displayName = "SidebarCollapseIcon";
1004
1063
 
1005
1064
  const sidebarMenuButtonVariants = cva(
1006
- "peer/menu-button flex w-full items-center gap-3 overflow-hidden rounded-full px-6 py-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 group-data-[collapsible=icon]:rounded-md [&>span:last-child]:truncate [&>svg]:size-4.5 [&>svg]:shrink-0 [&>svg]:stroke-2 [&>svg]:opacity-70 data-[active=true]:[&>svg]:opacity-100 group-data-[collapsible=icon]:[&>span]:hidden group-data-[collapsible=icon]:[&>div]:hidden",
1065
+ "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-full px-6 py-2 text-left text-sm font-medium outline-none ring-sidebar-ring transition-[color,background-color,border-color,box-shadow,opacity,width,height,padding] duration-150 ease-in-out hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-semibold data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 group-data-[collapsible=icon]:rounded-md [&>span:last-child]:truncate [&>svg]:shrink-0 [&>svg]:opacity-70 data-[active=true]:[&>svg]:opacity-100 group-data-[collapsible=icon]:[&>span]:hidden group-data-[collapsible=icon]:[&>div]:hidden",
1007
1066
  {
1008
1067
  variants: {
1009
1068
  variant: {
@@ -1017,7 +1076,7 @@ const sidebarMenuButtonVariants = cva(
1017
1076
  // Tree - has a chevron for tree navigation
1018
1077
  tree: "[&>[data-tree-icon]]:size-4 [&>[data-tree-icon]]:shrink-0 [&>[data-tree-icon]]:opacity-70 [&>[data-tree-icon]]:transition-transform data-[state=open]:[&>[data-tree-icon]]:rotate-90 group-data-[collapsible=icon]:[&>[data-tree-icon]]:hidden",
1019
1078
  // Badge - has a number badge on the right (handled via SidebarMenuBadge)
1020
- badge: "group-has-[[data-sidebar=menu-badge]]/menu-item:pr-8",
1079
+ badge: "group-has-[[data-sidebar=menu-badge]]/menu-item:pr-16",
1021
1080
  // Big Icon - larger icon with title and subtitle
1022
1081
  bigIcon:
1023
1082
  "h-auto flex-col items-start gap-1 rounded-lg p-3 [&>svg]:size-6 [&>svg]:rounded-md [&>svg]:bg-sidebar-foreground [&>svg]:p-1 [&>svg]:text-sidebar [&>svg]:opacity-100 hover:[&>svg]:bg-sidebar-foreground hover:[&>svg]:text-sidebar group-data-[collapsible=icon]:!size-10 group-data-[collapsible=icon]:!p-2 group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:[&>svg]:size-6",
@@ -1026,9 +1085,9 @@ const sidebarMenuButtonVariants = cva(
1026
1085
  "[&>[data-checkbox]]:size-4 [&>[data-checkbox]]:shrink-0 [&>[data-checkbox]]:rounded [&>[data-checkbox]]:border [&>[data-checkbox]]:border-sidebar-foreground/30 data-[checked=true]:[&>[data-checkbox]]:bg-primary data-[checked=true]:[&>[data-checkbox]]:border-primary data-[checked=true]:[&>[data-checkbox]]:text-primary-foreground",
1027
1086
  },
1028
1087
  size: {
1029
- default: "h-8 text-sm",
1030
- sm: "h-7 text-xs",
1031
- lg: "h-12 text-sm group-data-[collapsible=icon]:!p-0",
1088
+ default: "h-12 text-sm/4",
1089
+ sm: "h-7 text-xs/4",
1090
+ lg: "h-12 text-sm/4 group-data-[collapsible=icon]:!p-0",
1032
1091
  },
1033
1092
  },
1034
1093
  defaultVariants: {
@@ -1192,13 +1251,8 @@ const SidebarMenuBadge = React.forwardRef<
1192
1251
  <div
1193
1252
  ref={ref}
1194
1253
  className={cn(
1195
- "text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
1254
+ "text-sidebar-foreground pointer-events-none absolute inset-y-0 right-4 my-auto flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
1196
1255
  "peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
1197
- "peer-data-[size=sm]/menu-button:top-1",
1198
- "peer-data-[size=default]/menu-button:top-1.5",
1199
- "peer-data-[size=lg]/menu-button:top-2.5",
1200
- "peer-data-[size=bigIcon]/menu-button:top-2.5",
1201
- "peer-data-[size=tree]/menu-button:top-1.5",
1202
1256
  "group-data-[collapsible=icon]:hidden",
1203
1257
  className
1204
1258
  )}
@@ -1372,7 +1426,7 @@ const SidebarMenuSubButton = React.forwardRef<
1372
1426
  <Comp
1373
1427
  ref={ref}
1374
1428
  className={cn(
1375
- "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:shrink-0",
1429
+ "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 transition-[color,background-color,box-shadow,opacity] duration-150 ease-in-out outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:shrink-0",
1376
1430
  "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
1377
1431
  size === SidebarMenuSubButtonSize.SM && "text-xs",
1378
1432
  size === SidebarMenuSubButtonSize.MD && "text-sm",
@@ -1390,11 +1444,188 @@ const SidebarMenuSubButton = React.forwardRef<
1390
1444
  );
1391
1445
  SidebarMenuSubButton.displayName = "SidebarMenuSubButton";
1392
1446
 
1447
+ /* -------------------------------------------------------------------------------------------------
1448
+ * SidebarMenuCollapsible (Collapsible menu item with sub-items)
1449
+ * -----------------------------------------------------------------------------------------------*/
1450
+
1451
+ /**
1452
+ * Props for the SidebarMenuCollapsible component
1453
+ */
1454
+ interface SidebarMenuCollapsibleProps {
1455
+ /**
1456
+ * Data hook for automated testing
1457
+ */
1458
+ dataHook?: string;
1459
+ /**
1460
+ * Whether the collapsible is open by default
1461
+ */
1462
+ defaultOpen?: boolean;
1463
+ /**
1464
+ * Controlled open state
1465
+ */
1466
+ open?: boolean;
1467
+ /**
1468
+ * Callback when open state changes
1469
+ */
1470
+ onOpenChange?: (open: boolean) => void;
1471
+ /**
1472
+ * Additional CSS classes
1473
+ */
1474
+ className?: string;
1475
+ children?: React.ReactNode;
1476
+ }
1477
+
1478
+ function SidebarMenuCollapsible({
1479
+ dataHook,
1480
+ className,
1481
+ children,
1482
+ defaultOpen,
1483
+ open,
1484
+ onOpenChange,
1485
+ }: SidebarMenuCollapsibleProps) {
1486
+ return (
1487
+ <SidebarMenuItem>
1488
+ <Accordion
1489
+ collapsible
1490
+ className={className}
1491
+ dataHook={dataHook ?? "sidebar-menu-collapsible"}
1492
+ defaultValue={defaultOpen ? "item" : undefined}
1493
+ type="single"
1494
+ value={open !== undefined ? (open ? "item" : "") : undefined}
1495
+ onValueChange={
1496
+ onOpenChange ? (val) => onOpenChange(val === "item") : undefined
1497
+ }
1498
+ >
1499
+ <AccordionItem className="group/collapsible border-none" value="item">
1500
+ {children}
1501
+ </AccordionItem>
1502
+ </Accordion>
1503
+ </SidebarMenuItem>
1504
+ );
1505
+ }
1506
+ SidebarMenuCollapsible.displayName = "SidebarMenuCollapsible";
1507
+
1508
+ /**
1509
+ * Props for the SidebarMenuCollapsibleTrigger component
1510
+ */
1511
+ type SidebarMenuCollapsibleTriggerProps = Omit<
1512
+ SidebarMenuButtonProps,
1513
+ "variant"
1514
+ >;
1515
+
1516
+ const SidebarMenuCollapsibleTrigger = React.forwardRef<
1517
+ HTMLButtonElement,
1518
+ SidebarMenuCollapsibleTriggerProps
1519
+ >(({ children, className, ...props }, ref) => (
1520
+ <AccordionPrimitive.Trigger asChild>
1521
+ <SidebarMenuButton
1522
+ ref={ref}
1523
+ className={cn("relative", className)}
1524
+ variant={SidebarMenuButtonVariant.COLLAPSIBLE}
1525
+ {...props}
1526
+ >
1527
+ <ChevronRight
1528
+ data-collapse-icon
1529
+ className="absolute left-2.5 !opacity-100 transition-transform duration-200 ease-out group-data-[state=open]/collapsible:rotate-90"
1530
+ size={12}
1531
+ />
1532
+ {children}
1533
+ </SidebarMenuButton>
1534
+ </AccordionPrimitive.Trigger>
1535
+ ));
1536
+ SidebarMenuCollapsibleTrigger.displayName = "SidebarMenuCollapsibleTrigger";
1537
+
1538
+ /**
1539
+ * Props for the SidebarMenuCollapsibleContent component
1540
+ */
1541
+ type SidebarMenuCollapsibleContentProps = SidebarMenuSubProps;
1542
+
1543
+ const SidebarMenuCollapsibleContent = React.forwardRef<
1544
+ HTMLUListElement,
1545
+ SidebarMenuCollapsibleContentProps
1546
+ >(({ dataHook, children, ...props }, ref) => (
1547
+ <AccordionContent className="p-0">
1548
+ <SidebarMenuSub ref={ref} dataHook={dataHook} {...props}>
1549
+ {children}
1550
+ </SidebarMenuSub>
1551
+ </AccordionContent>
1552
+ ));
1553
+ SidebarMenuCollapsibleContent.displayName = "SidebarMenuCollapsibleContent";
1554
+
1555
+ /* -------------------------------------------------------------------------------------------------
1556
+ * SidebarDrawer (Mobile navigation drawer with burger trigger)
1557
+ * -----------------------------------------------------------------------------------------------*/
1558
+
1559
+ interface SidebarDrawerProps extends React.ComponentProps<"div"> {
1560
+ /**
1561
+ * Data hook for automated testing (required)
1562
+ */
1563
+ dataHook: string;
1564
+ /**
1565
+ * Accessible label for the drawer
1566
+ * @default "Navigation"
1567
+ */
1568
+ title?: string;
1569
+ /**
1570
+ * Accessible description for the drawer
1571
+ * @default "Main navigation menu"
1572
+ */
1573
+ description?: string;
1574
+ /**
1575
+ * Tracking element identifier for analytics
1576
+ */
1577
+ trackingEl?: string;
1578
+ /**
1579
+ * Tracking label for analytics context
1580
+ */
1581
+ trackingLabel?: string;
1582
+ }
1583
+
1584
+ function SidebarDrawer({
1585
+ dataHook,
1586
+ title = "Navigation",
1587
+ description = "Main navigation menu",
1588
+ trackingEl,
1589
+ trackingLabel,
1590
+ children,
1591
+ className,
1592
+ ...props
1593
+ }: SidebarDrawerProps) {
1594
+ return (
1595
+ <Drawer direction="left">
1596
+ <DrawerTrigger asChild>
1597
+ <Button
1598
+ iconOnly
1599
+ aria-label="Open menu"
1600
+ dataHook={`${dataHook}-trigger`}
1601
+ size="sm"
1602
+ trackingEl={trackingEl}
1603
+ trackingLabel={trackingLabel}
1604
+ variant="ghost"
1605
+ >
1606
+ <Menu size={24} />
1607
+ </Button>
1608
+ </DrawerTrigger>
1609
+ <DrawerContent
1610
+ className={cn("max-w-96", className)}
1611
+ dataHook={dataHook}
1612
+ {...props}
1613
+ >
1614
+ <DrawerTitle className="sr-only">{title}</DrawerTitle>
1615
+ <DrawerDescription className="sr-only">{description}</DrawerDescription>
1616
+ <div className="flex h-full flex-col p-6">{children}</div>
1617
+ </DrawerContent>
1618
+ </Drawer>
1619
+ );
1620
+ }
1621
+ SidebarDrawer.displayName = "SidebarDrawer";
1622
+
1393
1623
  // Component exports
1394
1624
  export {
1395
1625
  Sidebar,
1396
1626
  SidebarCollapseIcon,
1397
1627
  SidebarContent,
1628
+ SidebarDrawer,
1398
1629
  SidebarFooter,
1399
1630
  SidebarGroup,
1400
1631
  SidebarGroupAction,
@@ -1407,6 +1638,9 @@ export {
1407
1638
  SidebarMenuAction,
1408
1639
  SidebarMenuBadge,
1409
1640
  SidebarMenuButton,
1641
+ SidebarMenuCollapsible,
1642
+ SidebarMenuCollapsibleContent,
1643
+ SidebarMenuCollapsibleTrigger,
1410
1644
  SidebarMenuItem,
1411
1645
  SidebarMenuSkeleton,
1412
1646
  SidebarMenuSub,
@@ -1431,6 +1665,7 @@ export type {
1431
1665
  SidebarFooterProps,
1432
1666
  SidebarSeparatorProps,
1433
1667
  SidebarContentProps,
1668
+ SidebarDrawerProps,
1434
1669
  SidebarGroupProps,
1435
1670
  SidebarGroupLabelProps,
1436
1671
  SidebarGroupActionProps,
@@ -1439,6 +1674,9 @@ export type {
1439
1674
  SidebarMenuItemProps,
1440
1675
  SidebarCollapseIconProps,
1441
1676
  SidebarMenuButtonProps,
1677
+ SidebarMenuCollapsibleProps,
1678
+ SidebarMenuCollapsibleTriggerProps,
1679
+ SidebarMenuCollapsibleContentProps,
1442
1680
  SidebarMenuActionProps,
1443
1681
  SidebarMenuBadgeProps,
1444
1682
  SidebarMenuSkeletonProps,