| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 'use client' | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import s from './style.module.css' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | type Item = { | 
					
						
							|  |  |  |   id: string | 
					
						
							|  |  |  |   name: string | 
					
						
							|  |  |  |   isRight?: boolean | 
					
						
							|  |  |  |   extra?: React.ReactNode | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export type ITabHeaderProps = { | 
					
						
							|  |  |  |   items: Item[] | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   value: string | 
					
						
							|  |  |  |   onChange: (value: string) => void | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const TabHeader: FC<ITabHeaderProps> = ({ | 
					
						
							|  |  |  |   items, | 
					
						
							|  |  |  |   value, | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  |   onChange, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | }) => { | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  |   const renderItem = ({ id, name, extra }: Item) => ( | 
					
						
							|  |  |  |     <div | 
					
						
							|  |  |  |       key={id} | 
					
						
							|  |  |  |       className={cn(id === value ? `${s.itemActive} text-gray-900` : 'text-gray-500', 'relative flex items-center pb-1.5 leading-6 cursor-pointer')} | 
					
						
							|  |  |  |       onClick={() => onChange(id)} | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <div className='text-base font-semibold'>{name}</div> | 
					
						
							|  |  |  |       {extra || ''} | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  |     <div className='flex justify-between border-b border-gray-200 '> | 
					
						
							|  |  |  |       <div className='flex space-x-4'> | 
					
						
							|  |  |  |         {items.filter(item => !item.isRight).map(renderItem)} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <div className='flex space-x-4'> | 
					
						
							|  |  |  |         {items.filter(item => item.isRight).map(renderItem)} | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default React.memo(TabHeader) |