@brightlocal/ui-components 2.12.0 → 2.14.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.
Files changed (48) hide show
  1. package/component-meta.json +316 -19
  2. package/dist/blocks/sidebar.cjs +1 -1
  3. package/dist/blocks/sidebar.d.ts +203 -4
  4. package/dist/blocks/sidebar.d.ts.map +1 -1
  5. package/dist/blocks/sidebar.js +667 -393
  6. package/dist/card.cjs +1 -1
  7. package/dist/card.d.ts +5 -1
  8. package/dist/card.d.ts.map +1 -1
  9. package/dist/card.js +48 -31
  10. package/dist/combobox.cjs +3 -3
  11. package/dist/combobox.d.ts +8 -0
  12. package/dist/combobox.d.ts.map +1 -1
  13. package/dist/combobox.js +227 -226
  14. package/dist/dropdown-menu.cjs +1 -1
  15. package/dist/dropdown-menu.js +1 -1
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.js +450 -441
  18. package/dist/list.cjs +1 -1
  19. package/dist/list.d.ts +25 -4
  20. package/dist/list.d.ts.map +1 -1
  21. package/dist/list.js +71 -53
  22. package/dist/popover.cjs +1 -1
  23. package/dist/popover.js +7 -7
  24. package/dist/rating.cjs +1 -1
  25. package/dist/rating.js +13 -13
  26. package/dist/select.cjs +2 -2
  27. package/dist/select.d.ts +10 -2
  28. package/dist/select.d.ts.map +1 -1
  29. package/dist/select.js +36 -30
  30. package/dist/table.cjs +1 -1
  31. package/dist/table.d.ts +14 -0
  32. package/dist/table.d.ts.map +1 -1
  33. package/dist/table.js +57 -39
  34. package/dist/tabs.cjs +1 -1
  35. package/dist/tabs.d.ts +25 -9
  36. package/dist/tabs.d.ts.map +1 -1
  37. package/dist/tabs.js +128 -113
  38. package/package.json +2 -2
  39. package/src/blocks/sidebar.tsx +596 -9
  40. package/src/components/card.tsx +23 -0
  41. package/src/components/combobox.tsx +10 -0
  42. package/src/components/dropdown-menu.tsx +1 -1
  43. package/src/components/list.tsx +45 -2
  44. package/src/components/popover.tsx +1 -1
  45. package/src/components/rating.tsx +1 -1
  46. package/src/components/select.tsx +24 -2
  47. package/src/components/table.tsx +39 -2
  48. package/src/components/tabs.tsx +195 -146
@@ -18,6 +18,15 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
18
18
  import { Button } from "../components/button";
19
19
  import { Input } from "../components/input";
20
20
  import { Separator } from "../components/separator";
21
+ import {
22
+ DropdownMenu,
23
+ DropdownMenuContent,
24
+ DropdownMenuItem,
25
+ DropdownMenuLabel,
26
+ DropdownMenuSeparator,
27
+ DropdownMenuTrigger,
28
+ } from "../components/dropdown-menu";
29
+ import { Popover, PopoverContent, PopoverTrigger } from "../components/popover";
21
30
  import {
22
31
  Sheet,
23
32
  SheetContent,
@@ -40,6 +49,9 @@ import {
40
49
  } from "../components/tooltip";
41
50
  import { useIsBelowBreakpoint } from "../hooks/use-breakpoint";
42
51
 
52
+ const SIDEBAR_FOCUS_RING =
53
+ "focus-visible:[box-shadow:0_0_0_1px_color-mix(in_srgb,var(--color-sidebar-ring)_50%,transparent),0_0_0_3px_rgba(0,0,0,0.1)]";
54
+
43
55
  /**
44
56
  * Sidebar position variants
45
57
  */
@@ -631,7 +643,8 @@ const SidebarInput = React.forwardRef<
631
643
  <Input
632
644
  ref={ref}
633
645
  className={cn(
634
- "bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",
646
+ "bg-background h-8 w-full shadow-none",
647
+ SIDEBAR_FOCUS_RING,
635
648
  className
636
649
  )}
637
650
  data-slot="sidebar-input"
@@ -729,11 +742,24 @@ interface SidebarContentProps extends Omit<React.ComponentProps<"div">, "dir"> {
729
742
  const SidebarContent = React.forwardRef<HTMLDivElement, SidebarContentProps>(
730
743
  ({ className, dataHook, ariaLabel = "Sidebar", children, ...props }, ref) => {
731
744
  const { isMobile } = useSidebar();
745
+
746
+ const scrollAreaRef = React.useCallback(
747
+ (node: HTMLDivElement | null) => {
748
+ const viewport = node?.querySelector<HTMLElement>(
749
+ '[data-slot="scroll-area-viewport"]'
750
+ );
751
+ if (viewport) viewport.tabIndex = -1;
752
+ if (typeof ref === "function") ref(node);
753
+ else if (ref) ref.current = node;
754
+ },
755
+ [ref]
756
+ );
757
+
732
758
  return (
733
759
  <ScrollArea
734
- ref={ref}
760
+ ref={scrollAreaRef}
735
761
  className={cn(
736
- "min-h-0 flex-1 group-data-[collapsible=icon]:overflow-hidden *:data-[slot=scroll-area-viewport]:p-0 [&_[data-slot=scroll-area-viewport]>div]:block!",
762
+ "min-h-0 flex-1 group-data-[collapsible=icon]:overflow-hidden [&_[data-slot=scroll-area-viewport]>div]:block!",
737
763
  className
738
764
  )}
739
765
  dataHook={dataHook ?? "sidebar-content-scroll"}
@@ -777,7 +803,10 @@ const SidebarGroup = React.forwardRef<HTMLDivElement, SidebarGroupProps>(
777
803
  SidebarGroup.displayName = "SidebarGroup";
778
804
 
779
805
  const sidebarGroupLabelVariants = cva(
780
- "flex h-8 shrink-0 items-center rounded-md px-2 font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:shrink-0 group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
806
+ [
807
+ "flex h-8 shrink-0 items-center rounded-md px-2 font-medium text-sidebar-foreground/70 outline-none transition-[margin,opacity] duration-200 ease-linear [&>svg]:shrink-0 group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
808
+ SIDEBAR_FOCUS_RING,
809
+ ],
781
810
  {
782
811
  variants: {
783
812
  size: {
@@ -933,7 +962,8 @@ const SidebarGroupAction = React.forwardRef<
933
962
  <Comp
934
963
  ref={ref}
935
964
  className={cn(
936
- "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:shrink-0",
965
+ "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none [&>svg]:shrink-0",
966
+ SIDEBAR_FOCUS_RING,
937
967
  // Increases the hit area of the button on mobile.
938
968
  "after:absolute after:-inset-2 after:md:hidden",
939
969
  "group-data-[collapsible=icon]:hidden",
@@ -1069,7 +1099,10 @@ const SidebarCollapseIcon = React.forwardRef<
1069
1099
  SidebarCollapseIcon.displayName = "SidebarCollapseIcon";
1070
1100
 
1071
1101
  const sidebarMenuButtonVariants = cva(
1072
- "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-of-type]: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",
1102
+ [
1103
+ "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 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 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-of-type]: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",
1104
+ SIDEBAR_FOCUS_RING,
1105
+ ],
1073
1106
  {
1074
1107
  variants: {
1075
1108
  variant: {
@@ -1224,7 +1257,8 @@ const SidebarMenuAction = React.forwardRef<
1224
1257
  <Comp
1225
1258
  ref={ref}
1226
1259
  className={cn(
1227
- "text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:shrink-0",
1260
+ "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none [&>svg]:shrink-0",
1261
+ SIDEBAR_FOCUS_RING,
1228
1262
  // Increases the hit area of the button on mobile.
1229
1263
  "after:absolute after:-inset-2 after:md:hidden",
1230
1264
  "peer-data-[size=sm]/menu-button:top-1",
@@ -1320,7 +1354,7 @@ const SidebarMenuSkeleton = React.forwardRef<
1320
1354
  SidebarMenuSkeleton.displayName = "SidebarMenuSkeleton";
1321
1355
 
1322
1356
  const sidebarMenuSubVariants = cva(
1323
- "flex min-w-0 flex-col items-start gap-1 py-0.5 group-data-[collapsible=icon]:hidden",
1357
+ "flex min-w-0 flex-col items-start gap-1 py-1 group-data-[collapsible=icon]:hidden",
1324
1358
  {
1325
1359
  variants: {
1326
1360
  variant: {
@@ -1430,7 +1464,8 @@ const SidebarMenuSubButton = React.forwardRef<
1430
1464
  <Comp
1431
1465
  ref={ref}
1432
1466
  className={cn(
1433
- "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 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-of-type]:truncate [&>svg]:shrink-0",
1467
+ "text-sidebar-foreground 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 items-center gap-2 overflow-hidden rounded-md px-2 transition-[color,background-color,box-shadow,opacity] duration-150 ease-in-out outline-none disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-of-type]:truncate [&>svg]:shrink-0",
1468
+ SIDEBAR_FOCUS_RING,
1434
1469
  "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
1435
1470
  size === SidebarMenuSubButtonSize.SM && "text-xs",
1436
1471
  size === SidebarMenuSubButtonSize.MD && "text-sm",
@@ -1625,9 +1660,548 @@ const SidebarDrawer = React.forwardRef<HTMLDivElement, SidebarDrawerProps>(
1625
1660
  );
1626
1661
  SidebarDrawer.displayName = "SidebarDrawer";
1627
1662
 
1663
+ /* -------------------------------------------------------------------------------------------------
1664
+ * SidebarHeaderButton (Small icon button for sidebar header actions)
1665
+ * -----------------------------------------------------------------------------------------------*/
1666
+
1667
+ /**
1668
+ * Props for the SidebarHeaderButton component
1669
+ */
1670
+ interface SidebarHeaderButtonProps extends Omit<
1671
+ React.ComponentProps<typeof Button>,
1672
+ "dataHook"
1673
+ > {
1674
+ /**
1675
+ * Data hook for automated testing
1676
+ * @default "sidebar-header-button"
1677
+ */
1678
+ dataHook?: string;
1679
+ /**
1680
+ * Accessible label for the button
1681
+ */
1682
+ "aria-label": string;
1683
+ }
1684
+
1685
+ const SidebarHeaderButton = React.forwardRef<
1686
+ React.ComponentRef<typeof Button>,
1687
+ SidebarHeaderButtonProps
1688
+ >(
1689
+ (
1690
+ { className, dataHook = "sidebar-header-button", children, ...props },
1691
+ ref
1692
+ ) => {
1693
+ return (
1694
+ <Button
1695
+ ref={ref}
1696
+ {...props}
1697
+ iconOnly
1698
+ className={cn(
1699
+ "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground size-7 rounded-md shadow-none",
1700
+ SIDEBAR_FOCUS_RING,
1701
+ className
1702
+ )}
1703
+ data-slot="sidebar-header-button"
1704
+ dataHook={dataHook}
1705
+ size="sm"
1706
+ variant="ghost"
1707
+ >
1708
+ {children}
1709
+ </Button>
1710
+ );
1711
+ }
1712
+ );
1713
+ SidebarHeaderButton.displayName = "SidebarHeaderButton";
1714
+
1715
+ /* -------------------------------------------------------------------------------------------------
1716
+ * SidebarPopoverTrigger (Compact trigger for workspace/team switcher)
1717
+ * -----------------------------------------------------------------------------------------------*/
1718
+
1719
+ /**
1720
+ * Props for the SidebarPopoverTrigger component
1721
+ */
1722
+ interface SidebarPopoverTriggerProps extends React.ComponentProps<"button"> {
1723
+ /**
1724
+ * Data hook for automated testing
1725
+ * @default "sidebar-popover-trigger"
1726
+ */
1727
+ dataHook?: string;
1728
+ /**
1729
+ * Icon element displayed in the trigger
1730
+ */
1731
+ icon?: React.ReactNode;
1732
+ /**
1733
+ * Accessible label for the trigger button.
1734
+ * @default "Switch workspace"
1735
+ */
1736
+ triggerAriaLabel?: string;
1737
+ }
1738
+
1739
+ const SidebarPopoverTrigger = React.forwardRef<
1740
+ HTMLButtonElement,
1741
+ SidebarPopoverTriggerProps
1742
+ >(
1743
+ (
1744
+ {
1745
+ className,
1746
+ dataHook = "sidebar-popover-trigger",
1747
+ icon,
1748
+ triggerAriaLabel,
1749
+ children,
1750
+ ...props
1751
+ },
1752
+ ref
1753
+ ) => {
1754
+ return (
1755
+ <button
1756
+ ref={ref}
1757
+ aria-label={triggerAriaLabel ?? "Switch workspace"}
1758
+ className={cn(
1759
+ "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground flex items-center gap-2 rounded-md px-1.5 py-2 text-sm font-semibold transition-colors duration-200 ease-out outline-none",
1760
+ SIDEBAR_FOCUS_RING,
1761
+ className
1762
+ )}
1763
+ data-hook={dataHook}
1764
+ data-slot="sidebar-popover-trigger"
1765
+ type="button"
1766
+ {...props}
1767
+ >
1768
+ {icon && (
1769
+ <span className="bg-sidebar-primary text-sidebar-primary-foreground flex size-5 shrink-0 items-center justify-center rounded-md">
1770
+ {icon}
1771
+ </span>
1772
+ )}
1773
+ <span className="truncate">{children}</span>
1774
+ <ChevronDown className="shrink-0 opacity-50" size={16} />
1775
+ </button>
1776
+ );
1777
+ }
1778
+ );
1779
+ SidebarPopoverTrigger.displayName = "SidebarPopoverTrigger";
1780
+
1781
+ /* -------------------------------------------------------------------------------------------------
1782
+ * SidebarPopoverMenuItem (Menu item inside the popover menu)
1783
+ * -----------------------------------------------------------------------------------------------*/
1784
+
1785
+ /**
1786
+ * Props for the SidebarPopoverMenuItem component
1787
+ */
1788
+ interface SidebarPopoverMenuItemProps extends React.ComponentProps<"button"> {
1789
+ /**
1790
+ * Data hook for automated testing
1791
+ */
1792
+ dataHook?: string;
1793
+ /**
1794
+ * Icon element displayed in the icon box
1795
+ */
1796
+ icon?: React.ReactNode;
1797
+ /**
1798
+ * Keyboard shortcut text shown on the right
1799
+ */
1800
+ shortcut?: string;
1801
+ }
1802
+
1803
+ const SidebarPopoverMenuItem = React.forwardRef<
1804
+ HTMLButtonElement,
1805
+ SidebarPopoverMenuItemProps
1806
+ >(({ className, dataHook, icon, shortcut, children, ...props }, ref) => {
1807
+ return (
1808
+ <button
1809
+ ref={ref}
1810
+ className={cn(
1811
+ "text-popover-foreground hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground flex h-10 w-full items-center gap-2 rounded-xs p-2 text-sm transition-colors duration-150 ease-in-out outline-none",
1812
+ SIDEBAR_FOCUS_RING,
1813
+ className
1814
+ )}
1815
+ data-hook={dataHook}
1816
+ data-slot="sidebar-popover-menu-item"
1817
+ type="button"
1818
+ {...props}
1819
+ >
1820
+ {icon && (
1821
+ <span className="border-border flex size-6 shrink-0 items-center justify-center rounded-xs border [&_svg]:size-4">
1822
+ {icon}
1823
+ </span>
1824
+ )}
1825
+ <span className="min-w-px flex-1 truncate text-left">{children}</span>
1826
+ {shortcut && (
1827
+ <span className="text-popover-foreground/60 shrink-0 text-xs">
1828
+ {shortcut}
1829
+ </span>
1830
+ )}
1831
+ </button>
1832
+ );
1833
+ });
1834
+ SidebarPopoverMenuItem.displayName = "SidebarPopoverMenuItem";
1835
+
1836
+ /* -------------------------------------------------------------------------------------------------
1837
+ * SidebarPopoverMenu (Dropdown panel for workspace/team switcher)
1838
+ * -----------------------------------------------------------------------------------------------*/
1839
+
1840
+ /**
1841
+ * Props for the SidebarPopoverMenu component
1842
+ */
1843
+ interface SidebarPopoverMenuProps extends React.ComponentProps<"div"> {
1844
+ /**
1845
+ * Data hook for automated testing
1846
+ * @default "sidebar-popover-menu"
1847
+ */
1848
+ dataHook?: string;
1849
+ /**
1850
+ * Group title displayed at the top of the menu.
1851
+ * @default "Teams"
1852
+ */
1853
+ groupTitle?: string;
1854
+ /**
1855
+ * Items to render in the menu
1856
+ */
1857
+ items?: Array<{
1858
+ label: string;
1859
+ icon?: React.ReactNode;
1860
+ shortcut?: string;
1861
+ onClick?: () => void;
1862
+ }>;
1863
+ /**
1864
+ * Label for the add action at the bottom.
1865
+ * @default "Add team"
1866
+ */
1867
+ addActionLabel?: string;
1868
+ /**
1869
+ * Icon for the add action
1870
+ */
1871
+ addActionIcon?: React.ReactNode;
1872
+ /**
1873
+ * Callback when add action is clicked
1874
+ */
1875
+ onAddAction?: () => void;
1876
+ }
1877
+
1878
+ const SidebarPopoverMenu = React.forwardRef<
1879
+ HTMLDivElement,
1880
+ SidebarPopoverMenuProps
1881
+ >(
1882
+ (
1883
+ {
1884
+ className,
1885
+ dataHook = "sidebar-popover-menu",
1886
+ groupTitle = "Teams",
1887
+ items,
1888
+ addActionLabel,
1889
+ addActionIcon,
1890
+ onAddAction,
1891
+ children,
1892
+ ...props
1893
+ },
1894
+ ref
1895
+ ) => {
1896
+ return (
1897
+ <div
1898
+ ref={ref}
1899
+ className={cn("flex flex-col", className)}
1900
+ data-hook={dataHook}
1901
+ data-slot="sidebar-popover-menu"
1902
+ {...props}
1903
+ >
1904
+ {children || (
1905
+ <>
1906
+ <div className="flex flex-col items-start p-1">
1907
+ {groupTitle && (
1908
+ <div className="flex w-full items-center px-2 py-1.5">
1909
+ <span className="text-muted-foreground flex-1 text-xs font-medium">
1910
+ {groupTitle}
1911
+ </span>
1912
+ </div>
1913
+ )}
1914
+ {items?.map((item, index) => (
1915
+ <SidebarPopoverMenuItem
1916
+ key={index}
1917
+ icon={item.icon}
1918
+ shortcut={item.shortcut}
1919
+ onClick={item.onClick}
1920
+ >
1921
+ {item.label}
1922
+ </SidebarPopoverMenuItem>
1923
+ ))}
1924
+ </div>
1925
+ {onAddAction && (
1926
+ <>
1927
+ <Separator />
1928
+ <div className="flex flex-col items-start p-1">
1929
+ <SidebarPopoverMenuItem
1930
+ icon={addActionIcon || <Plus size={16} />}
1931
+ onClick={onAddAction}
1932
+ >
1933
+ {addActionLabel ?? "Add team"}
1934
+ </SidebarPopoverMenuItem>
1935
+ </div>
1936
+ </>
1937
+ )}
1938
+ </>
1939
+ )}
1940
+ </div>
1941
+ );
1942
+ }
1943
+ );
1944
+ SidebarPopoverMenu.displayName = "SidebarPopoverMenu";
1945
+
1946
+ /* -------------------------------------------------------------------------------------------------
1947
+ * SidebarSwitcher (Composed PopoverTrigger + PopoverMenu using DS Popover)
1948
+ * -----------------------------------------------------------------------------------------------*/
1949
+
1950
+ /**
1951
+ * Props for the SidebarSwitcher component
1952
+ */
1953
+ interface SidebarSwitcherProps {
1954
+ /**
1955
+ * Data hook for automated testing
1956
+ * @default "sidebar-switcher"
1957
+ */
1958
+ dataHook?: string;
1959
+ /**
1960
+ * Icon for the trigger
1961
+ */
1962
+ icon?: React.ReactNode;
1963
+ /**
1964
+ * Label displayed in the trigger
1965
+ */
1966
+ label: string;
1967
+ /**
1968
+ * Accessible label for the trigger button.
1969
+ * @default "Switch workspace"
1970
+ */
1971
+ triggerAriaLabel?: string;
1972
+ /**
1973
+ * Additional CSS classes for the trigger
1974
+ */
1975
+ triggerClassName?: string;
1976
+ children?: React.ReactNode;
1977
+ }
1978
+
1979
+ function SidebarSwitcher({
1980
+ dataHook = "sidebar-switcher",
1981
+ icon,
1982
+ label,
1983
+ triggerAriaLabel,
1984
+ triggerClassName,
1985
+ children,
1986
+ }: SidebarSwitcherProps) {
1987
+ return (
1988
+ <Popover>
1989
+ <PopoverTrigger asChild>
1990
+ <SidebarPopoverTrigger
1991
+ className={triggerClassName}
1992
+ dataHook={`${dataHook}-trigger`}
1993
+ icon={icon}
1994
+ triggerAriaLabel={triggerAriaLabel}
1995
+ >
1996
+ {label}
1997
+ </SidebarPopoverTrigger>
1998
+ </PopoverTrigger>
1999
+ <PopoverContent
2000
+ align="start"
2001
+ className="w-[316px] p-0"
2002
+ dataHook={`${dataHook}-content`}
2003
+ side="bottom"
2004
+ sideOffset={4}
2005
+ >
2006
+ {children}
2007
+ </PopoverContent>
2008
+ </Popover>
2009
+ );
2010
+ }
2011
+ SidebarSwitcher.displayName = "SidebarSwitcher";
2012
+
2013
+ /* -------------------------------------------------------------------------------------------------
2014
+ * SidebarAccountDropdown (Account menu dropdown)
2015
+ * -----------------------------------------------------------------------------------------------*/
2016
+
2017
+ /**
2018
+ * Props for the SidebarAccountDropdown component
2019
+ */
2020
+ interface SidebarAccountDropdownProps {
2021
+ /**
2022
+ * Data hook for automated testing
2023
+ * @default "sidebar-account-dropdown"
2024
+ */
2025
+ dataHook?: string;
2026
+ /**
2027
+ * User's display name
2028
+ */
2029
+ name: string;
2030
+ /**
2031
+ * User's email address
2032
+ */
2033
+ email: string;
2034
+ /**
2035
+ * Avatar element (use DS Avatar component)
2036
+ */
2037
+ avatar?: React.ReactNode;
2038
+ /**
2039
+ * Menu items to render. Each group is separated by a divider.
2040
+ */
2041
+ menuGroups?: Array<
2042
+ Array<{
2043
+ label: string;
2044
+ onClick?: () => void;
2045
+ icon?: React.ReactNode;
2046
+ }>
2047
+ >;
2048
+ /**
2049
+ * Accessible label for the account menu trigger.
2050
+ * @default "Account menu"
2051
+ */
2052
+ triggerAriaLabel?: string;
2053
+ /**
2054
+ * Dropdown alignment
2055
+ * @default "end"
2056
+ */
2057
+ align?: "start" | "center" | "end";
2058
+ /**
2059
+ * Dropdown side
2060
+ * @default "top"
2061
+ */
2062
+ side?: "top" | "right" | "bottom" | "left";
2063
+ children?: React.ReactNode;
2064
+ }
2065
+
2066
+ function SidebarAccountDropdown({
2067
+ dataHook = "sidebar-account-dropdown",
2068
+ name,
2069
+ email,
2070
+ avatar,
2071
+ menuGroups,
2072
+ triggerAriaLabel,
2073
+ align = "end",
2074
+ side = "top",
2075
+ children,
2076
+ }: SidebarAccountDropdownProps) {
2077
+ return (
2078
+ <DropdownMenu>
2079
+ <DropdownMenuTrigger asChild>
2080
+ <SidebarMenuButton
2081
+ aria-label={triggerAriaLabel ?? "Account menu"}
2082
+ className="h-auto py-1.5"
2083
+ dataHook={`${dataHook}-button`}
2084
+ size={SidebarMenuButtonSize.LG}
2085
+ >
2086
+ {avatar}
2087
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5 leading-none">
2088
+ <span className="truncate text-sm font-semibold">{name}</span>
2089
+ <span className="truncate text-xs font-normal">{email}</span>
2090
+ </div>
2091
+ </SidebarMenuButton>
2092
+ </DropdownMenuTrigger>
2093
+ <DropdownMenuContent
2094
+ align={align}
2095
+ className="w-56"
2096
+ dataHook={`${dataHook}-content`}
2097
+ side={side}
2098
+ sideOffset={4}
2099
+ >
2100
+ {children || (
2101
+ <>
2102
+ <DropdownMenuLabel className="flex items-center gap-2 px-1 py-1.5">
2103
+ {avatar}
2104
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5 leading-none">
2105
+ <span className="truncate text-sm font-semibold">{name}</span>
2106
+ <span className="truncate text-xs font-normal">{email}</span>
2107
+ </div>
2108
+ </DropdownMenuLabel>
2109
+ {menuGroups?.map((group, groupIndex) => (
2110
+ <React.Fragment key={groupIndex}>
2111
+ <DropdownMenuSeparator />
2112
+ {group.map((item, itemIndex) => (
2113
+ <DropdownMenuItem key={itemIndex} onClick={item.onClick}>
2114
+ {item.icon}
2115
+ {item.label}
2116
+ </DropdownMenuItem>
2117
+ ))}
2118
+ </React.Fragment>
2119
+ ))}
2120
+ </>
2121
+ )}
2122
+ </DropdownMenuContent>
2123
+ </DropdownMenu>
2124
+ );
2125
+ }
2126
+ SidebarAccountDropdown.displayName = "SidebarAccountDropdown";
2127
+
2128
+ /* -------------------------------------------------------------------------------------------------
2129
+ * SidebarInboxItem (Notification/inbox item)
2130
+ * -----------------------------------------------------------------------------------------------*/
2131
+
2132
+ /**
2133
+ * Props for the SidebarInboxItem component
2134
+ */
2135
+ interface SidebarInboxItemProps extends React.ComponentProps<"button"> {
2136
+ /**
2137
+ * Data hook for automated testing
2138
+ */
2139
+ dataHook?: string;
2140
+ /**
2141
+ * Sender or person name
2142
+ */
2143
+ senderName: string;
2144
+ /**
2145
+ * Notification title
2146
+ */
2147
+ title: string;
2148
+ /**
2149
+ * Preview description text
2150
+ */
2151
+ description?: string;
2152
+ /**
2153
+ * Timestamp string
2154
+ */
2155
+ timestamp?: string;
2156
+ }
2157
+
2158
+ const SidebarInboxItem = React.forwardRef<
2159
+ HTMLButtonElement,
2160
+ SidebarInboxItemProps
2161
+ >(
2162
+ (
2163
+ {
2164
+ className,
2165
+ dataHook,
2166
+ senderName,
2167
+ title,
2168
+ description,
2169
+ timestamp,
2170
+ ...props
2171
+ },
2172
+ ref
2173
+ ) => {
2174
+ return (
2175
+ <button
2176
+ ref={ref}
2177
+ className={cn(
2178
+ "border-sidebar-border text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent flex w-full flex-col gap-2 border-b p-4 text-left transition-colors duration-150 ease-in-out outline-none",
2179
+ SIDEBAR_FOCUS_RING,
2180
+ className
2181
+ )}
2182
+ data-hook={dataHook}
2183
+ data-slot="sidebar-inbox-item"
2184
+ type="button"
2185
+ {...props}
2186
+ >
2187
+ <div className="flex w-full items-center justify-between text-sm">
2188
+ <span>{senderName}</span>
2189
+ {timestamp && <span>{timestamp}</span>}
2190
+ </div>
2191
+ <p className="w-full text-sm font-medium">{title}</p>
2192
+ {description && (
2193
+ <p className="w-full truncate text-xs">{description}</p>
2194
+ )}
2195
+ </button>
2196
+ );
2197
+ }
2198
+ );
2199
+ SidebarInboxItem.displayName = "SidebarInboxItem";
2200
+
1628
2201
  // Component exports
1629
2202
  export {
1630
2203
  Sidebar,
2204
+ SidebarAccountDropdown,
1631
2205
  SidebarCollapseIcon,
1632
2206
  /** @deprecated Use `SidebarTrigger` instead */
1633
2207
  SidebarDrawer,
@@ -1638,6 +2212,8 @@ export {
1638
2212
  SidebarGroupContent,
1639
2213
  SidebarGroupLabel,
1640
2214
  SidebarHeader,
2215
+ SidebarHeaderButton,
2216
+ SidebarInboxItem,
1641
2217
  SidebarInput,
1642
2218
  SidebarInset,
1643
2219
  SidebarMenu,
@@ -1652,15 +2228,20 @@ export {
1652
2228
  SidebarMenuSub,
1653
2229
  SidebarMenuSubButton,
1654
2230
  SidebarMenuSubItem,
2231
+ SidebarPopoverMenu,
2232
+ SidebarPopoverMenuItem,
2233
+ SidebarPopoverTrigger,
1655
2234
  SidebarProvider,
1656
2235
  SidebarRail,
1657
2236
  SidebarSeparator,
2237
+ SidebarSwitcher,
1658
2238
  SidebarTrigger,
1659
2239
  useSidebar,
1660
2240
  };
1661
2241
 
1662
2242
  // Type exports
1663
2243
  export type {
2244
+ SidebarAccountDropdownProps,
1664
2245
  SidebarProviderProps,
1665
2246
  SidebarProps,
1666
2247
  /** @deprecated Use `SidebarTriggerProps` instead */
@@ -1670,6 +2251,8 @@ export type {
1670
2251
  SidebarInsetProps,
1671
2252
  SidebarInputProps,
1672
2253
  SidebarHeaderProps,
2254
+ SidebarHeaderButtonProps,
2255
+ SidebarInboxItemProps,
1673
2256
  SidebarFooterProps,
1674
2257
  SidebarSeparatorProps,
1675
2258
  SidebarContentProps,
@@ -1690,4 +2273,8 @@ export type {
1690
2273
  SidebarMenuSubProps,
1691
2274
  SidebarMenuSubItemProps,
1692
2275
  SidebarMenuSubButtonProps,
2276
+ SidebarPopoverMenuProps,
2277
+ SidebarPopoverMenuItemProps,
2278
+ SidebarPopoverTriggerProps,
2279
+ SidebarSwitcherProps,
1693
2280
  };