index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Badge, Menu } from 'ui'
  2. import type { ProductMenuGroup } from './ProductMenu.types'
  3. import { ProductMenuItem } from './ProductMenuItem'
  4. interface ProductMenuProps {
  5. page?: string
  6. menu: ProductMenuGroup[]
  7. /** Called when a menu item link is clicked (e.g. to close a sheet on navigation) */
  8. onItemClick?: () => void
  9. }
  10. export const ProductMenu = ({ page, menu, onItemClick }: ProductMenuProps) => {
  11. return (
  12. <div className="flex flex-col space-y-4">
  13. <Menu type="pills">
  14. {menu.map((group, idx) => (
  15. <div key={group.key || group.title}>
  16. <div className="my-4 space-y-4">
  17. <div className="md:mx-3">
  18. <Menu.Group
  19. title={
  20. group.title ? (
  21. <div className="flex flex-col space-y-2 uppercase font-mono">
  22. <span>{group.title}</span>
  23. {group.isPreview && <Badge variant="warning">Not production ready</Badge>}
  24. </div>
  25. ) : null
  26. }
  27. />
  28. <div>
  29. {group.items.map((item) => {
  30. const isActive = !!item.pages
  31. ? item.pages.includes(page ?? '')
  32. : page === item.key
  33. return (
  34. <ProductMenuItem
  35. key={item.key}
  36. item={item}
  37. isActive={isActive}
  38. target={item.isExternal ? '_blank' : '_self'}
  39. onClick={onItemClick}
  40. />
  41. )
  42. })}
  43. </div>
  44. </div>
  45. </div>
  46. {idx !== menu.length - 1 && (
  47. <div className="h-px w-[calc(100%-1.5rem)] mx-auto md:w-full bg-border-overlay" />
  48. )}
  49. </div>
  50. ))}
  51. </Menu>
  52. </div>
  53. )
  54. }