index.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import s from './style.module.css'
  5. import cn from '@/utils/classnames'
  6. type Item = {
  7. id: string
  8. name: string
  9. isRight?: boolean
  10. extra?: React.ReactNode
  11. }
  12. export type ITabHeaderProps = {
  13. items: Item[]
  14. value: string
  15. onChange: (value: string) => void
  16. }
  17. const TabHeader: FC<ITabHeaderProps> = ({
  18. items,
  19. value,
  20. onChange,
  21. }) => {
  22. const renderItem = ({ id, name, extra }: Item) => (
  23. <div
  24. key={id}
  25. className={cn(id === value ? `${s.itemActive} text-gray-900` : 'text-gray-500', 'relative flex items-center pb-1.5 leading-6 cursor-pointer')}
  26. onClick={() => onChange(id)}
  27. >
  28. <div className='text-base font-semibold'>{name}</div>
  29. {extra || ''}
  30. </div>
  31. )
  32. return (
  33. <div className='flex justify-between border-b border-gray-200 '>
  34. <div className='flex space-x-4'>
  35. {items.filter(item => !item.isRight).map(renderItem)}
  36. </div>
  37. <div className='flex space-x-4'>
  38. {items.filter(item => item.isRight).map(renderItem)}
  39. </div>
  40. </div>
  41. )
  42. }
  43. export default React.memo(TabHeader)