| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 'use client' | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import { useSelectedLayoutSegment } from 'next/navigation' | 
					
						
							|  |  |  | import Link from 'next/link' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import classNames from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2025-02-27 15:11:42 +08:00
										 |  |  | import type { RemixiconComponentType } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | export type NavIcon = React.ComponentType< | 
					
						
							|  |  |  | React.PropsWithoutRef<React.ComponentProps<'svg'>> & { | 
					
						
							|  |  |  |   title?: string | undefined | 
					
						
							|  |  |  |   titleId?: string | undefined | 
					
						
							| 
									
										
										
										
											2025-02-27 15:11:42 +08:00
										 |  |  | }> | RemixiconComponentType | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export type NavLinkProps = { | 
					
						
							|  |  |  |   name: string | 
					
						
							|  |  |  |   href: string | 
					
						
							|  |  |  |   iconMap: { | 
					
						
							|  |  |  |     selected: NavIcon | 
					
						
							|  |  |  |     normal: NavIcon | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |   mode?: string | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export default function NavLink({ | 
					
						
							|  |  |  |   name, | 
					
						
							|  |  |  |   href, | 
					
						
							|  |  |  |   iconMap, | 
					
						
							| 
									
										
										
										
											2023-11-27 11:47:48 +08:00
										 |  |  |   mode = 'expand', | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | }: NavLinkProps) { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const segment = useSelectedLayoutSegment() | 
					
						
							| 
									
										
										
										
											2023-12-18 15:41:24 +08:00
										 |  |  |   const formattedSegment = (() => { | 
					
						
							|  |  |  |     let res = segment?.toLowerCase() | 
					
						
							|  |  |  |     // logs and annotations use the same nav
 | 
					
						
							|  |  |  |     if (res === 'annotations') | 
					
						
							|  |  |  |       res = 'logs' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return res | 
					
						
							|  |  |  |   })() | 
					
						
							|  |  |  |   const isActive = href.toLowerCase().split('/')?.pop() === formattedSegment | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const NavIcon = isActive ? iconMap.selected : iconMap.normal | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <Link | 
					
						
							|  |  |  |       key={name} | 
					
						
							|  |  |  |       href={href} | 
					
						
							|  |  |  |       className={classNames( | 
					
						
							| 
									
										
										
										
											2025-03-19 11:19:57 +08:00
										 |  |  |         isActive ? 'bg-state-accent-active text-text-accent font-semibold' : 'text-components-menu-item-text hover:bg-state-base-hover hover:text-components-menu-item-text-hover', | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |         'group flex items-center h-9 rounded-md py-2 text-sm font-normal', | 
					
						
							|  |  |  |         mode === 'expand' ? 'px-3' : 'px-2.5', | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |       )} | 
					
						
							| 
									
										
										
										
											2024-05-06 11:34:56 +08:00
										 |  |  |       title={mode === 'collapse' ? name : ''} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     > | 
					
						
							|  |  |  |       <NavIcon | 
					
						
							|  |  |  |         className={classNames( | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |           'h-4 w-4 flex-shrink-0', | 
					
						
							|  |  |  |           mode === 'expand' ? 'mr-2' : 'mr-0', | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         )} | 
					
						
							|  |  |  |         aria-hidden="true" | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2023-11-27 11:47:48 +08:00
										 |  |  |       {mode === 'expand' && name} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     </Link> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } |