SidebarItem.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { MoreHorizontal } from 'lucide-react'
  2. import Link from 'next/link'
  3. import { type MouseEventHandler } from 'react'
  4. import { Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from 'ui'
  5. type Props = {
  6. label: string
  7. icon?: React.ReactNode
  8. dropdownItems?: React.ReactNode
  9. href: string
  10. isActive: boolean
  11. onClick?: MouseEventHandler<HTMLAnchorElement>
  12. }
  13. export function LogsSidebarItem({ label, icon, dropdownItems, href, isActive, onClick }: Props) {
  14. return (
  15. <div
  16. className={cn(
  17. {
  18. 'bg-foreground-lighter/10': isActive,
  19. },
  20. 'relative flex [&:has([data-state=open])]:bg-foreground-lighter/10 [&:has([data-state=open])]:text-foreground hover:text-foreground hover:bg-foreground-lighter/10 transition-all text-foreground-light group'
  21. )}
  22. >
  23. <Link
  24. onClick={onClick}
  25. href={href}
  26. className={'h-7 flex-1 text-sm px-4 flex items-center gap-2 truncate'}
  27. >
  28. {icon && <span>{icon}</span>}
  29. <span className="truncate">{label}</span>
  30. </Link>
  31. {dropdownItems && (
  32. <DropdownMenu>
  33. <DropdownMenuTrigger
  34. asChild
  35. onClick={(e) => {
  36. // Prevents clicking the dropdown from also clicking the parent link and navigating to it
  37. e.preventDefault()
  38. }}
  39. >
  40. <Button
  41. type="text"
  42. title="Actions"
  43. className="space-x-0 h-7 px-1.5 opacity-0 group-hover:opacity-100 bg-transparent! data-open:opacity-100"
  44. icon={<MoreHorizontal size={14} />}
  45. >
  46. <div className="sr-only">Actions</div>
  47. </Button>
  48. </DropdownMenuTrigger>
  49. <DropdownMenuContent className="w-48" align="end">
  50. {dropdownItems}
  51. </DropdownMenuContent>
  52. </DropdownMenu>
  53. )}
  54. </div>
  55. )
  56. }