category.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from '@/utils/classnames'
  6. import exploreI18n from '@/i18n/en-US/explore'
  7. import type { AppCategory } from '@/models/explore'
  8. import { ThumbsUp } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback'
  9. const categoryI18n = exploreI18n.category
  10. export type ICategoryProps = {
  11. className?: string
  12. list: AppCategory[]
  13. value: string
  14. onChange: (value: AppCategory | string) => void
  15. /**
  16. * default value for search param 'category' in en
  17. */
  18. allCategoriesEn: string
  19. }
  20. const Category: FC<ICategoryProps> = ({
  21. className,
  22. list,
  23. value,
  24. onChange,
  25. allCategoriesEn,
  26. }) => {
  27. const { t } = useTranslation()
  28. const isAllCategories = !list.includes(value as AppCategory)
  29. const itemClassName = (isSelected: boolean) => cn(
  30. 'flex items-center px-3 py-[7px] h-[32px] rounded-lg border-[0.5px] border-transparent text-gray-700 font-medium leading-[18px] cursor-pointer hover:bg-gray-200',
  31. isSelected && 'bg-white border-gray-200 shadow-xs text-primary-600 hover:bg-white',
  32. )
  33. return (
  34. <div className={cn(className, 'flex space-x-1 text-[13px] flex-wrap')}>
  35. <div
  36. className={itemClassName(isAllCategories)}
  37. onClick={() => onChange(allCategoriesEn)}
  38. >
  39. <ThumbsUp className='mr-1 w-3.5 h-3.5' />
  40. {t('explore.apps.allCategories')}
  41. </div>
  42. {list.map(name => (
  43. <div
  44. key={name}
  45. className={itemClassName(name === value)}
  46. onClick={() => onChange(name)}
  47. >
  48. {categoryI18n[name] ? t(`explore.category.${name}`) : name}
  49. </div>
  50. ))}
  51. </div>
  52. )
  53. }
  54. export default React.memo(Category)