category.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import exploreI18n from '@/i18n/lang/explore.en'
  7. import type { AppCategory } from '@/models/explore'
  8. const categoryI18n = exploreI18n.category
  9. export type ICategoryProps = {
  10. className?: string
  11. list: AppCategory[]
  12. value: string
  13. onChange: (value: AppCategory | '') => void
  14. }
  15. const Category: FC<ICategoryProps> = ({
  16. className,
  17. list,
  18. value,
  19. onChange,
  20. }) => {
  21. const { t } = useTranslation()
  22. 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')
  23. const itemStyle = (isSelected: boolean) => isSelected ? { boxShadow: '0px 1px 2px rgba(16, 24, 40, 0.05)' } : {}
  24. return (
  25. <div className={cn(className, 'flex space-x-1 text-[13px] flex-wrap')}>
  26. <div
  27. className={itemClassName(value === '')}
  28. style={itemStyle(value === '')}
  29. onClick={() => onChange('')}
  30. >
  31. {t('explore.apps.allCategories')}
  32. </div>
  33. {list.map(name => (
  34. <div
  35. key={name}
  36. className={itemClassName(name === value)}
  37. style={itemStyle(name === value)}
  38. onClick={() => onChange(name)}
  39. >
  40. {categoryI18n[name] ? t(`explore.category.${name}`) : name}
  41. </div>
  42. ))}
  43. </div>
  44. )
  45. }
  46. export default React.memo(Category)