category.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use client'
  2. import React, { FC } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import exploreI18n from '@/i18n/lang/explore.en'
  5. import cn from 'classnames'
  6. const categoryI18n = exploreI18n.category
  7. export interface ICategoryProps {
  8. className?: string
  9. list: string[]
  10. value: string
  11. onChange: (value: string) => void
  12. }
  13. const Category: FC<ICategoryProps> = ({
  14. className,
  15. list,
  16. value,
  17. onChange
  18. }) => {
  19. const { t } = useTranslation()
  20. const itemClassName = (isSelected: boolean) => cn(isSelected ? 'bg-white text-primary-600 border-gray-200 font-semibold' : 'border-transparent font-medium','flex items-center h-7 px-3 border cursor-pointer rounded-lg')
  21. const itemStyle = (isSelected: boolean) => isSelected ? {boxShadow: '0px 1px 2px rgba(16, 24, 40, 0.05)'} : {}
  22. return (
  23. <div className={cn(className, 'flex space-x-1 text-[13px]')}>
  24. <div
  25. className={itemClassName('' === value)}
  26. style={itemStyle('' === value)}
  27. onClick={() => onChange('')}
  28. >
  29. {t('explore.apps.allCategories')}
  30. </div>
  31. {list.map(name => (
  32. <div
  33. key={name}
  34. className={itemClassName(name === value)}
  35. style={itemStyle(name === value)}
  36. onClick={() => onChange(name)}
  37. >
  38. {(categoryI18n as any)[name] ? t(`explore.category.${name}`) : name}
  39. </div>
  40. ))}
  41. </div>
  42. )
  43. }
  44. export default React.memo(Category)