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