2023-05-25 16:59:47 +08:00
|
|
|
'use client'
|
2023-06-01 23:19:36 +08:00
|
|
|
import type { FC } from 'react'
|
|
|
|
import React from 'react'
|
2023-05-25 16:59:47 +08:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-07-09 15:05:40 +08:00
|
|
|
import cn from '@/utils/classnames'
|
2024-02-23 14:31:06 +08:00
|
|
|
import exploreI18n from '@/i18n/en-US/explore'
|
2023-08-28 19:48:53 +08:00
|
|
|
import type { AppCategory } from '@/models/explore'
|
2024-04-08 18:51:46 +08:00
|
|
|
import { ThumbsUp } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback'
|
2023-05-25 16:59:47 +08:00
|
|
|
|
|
|
|
const categoryI18n = exploreI18n.category
|
|
|
|
|
2023-06-01 23:19:36 +08:00
|
|
|
export type ICategoryProps = {
|
2023-05-25 16:59:47 +08:00
|
|
|
className?: string
|
2023-08-28 19:48:53 +08:00
|
|
|
list: AppCategory[]
|
2023-05-25 16:59:47 +08:00
|
|
|
value: string
|
2024-03-02 17:11:25 +08:00
|
|
|
onChange: (value: AppCategory | string) => void
|
|
|
|
/**
|
|
|
|
* default value for searchparam 'category' in en
|
|
|
|
*/
|
|
|
|
allCategoriesEn: string
|
2023-05-25 16:59:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Category: FC<ICategoryProps> = ({
|
|
|
|
className,
|
|
|
|
list,
|
|
|
|
value,
|
2023-06-01 23:19:36 +08:00
|
|
|
onChange,
|
2024-03-02 17:11:25 +08:00
|
|
|
allCategoriesEn,
|
2023-05-25 16:59:47 +08:00
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
2024-03-02 17:11:25 +08:00
|
|
|
const isAllCategories = !list.includes(value)
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
const itemClassName = (isSelected: boolean) => cn(
|
|
|
|
'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',
|
|
|
|
isSelected && 'bg-white border-gray-200 shadow-xs text-primary-600 hover:bg-white',
|
|
|
|
)
|
2023-05-25 16:59:47 +08:00
|
|
|
|
|
|
|
return (
|
2023-08-22 13:39:52 +08:00
|
|
|
<div className={cn(className, 'flex space-x-1 text-[13px] flex-wrap')}>
|
2023-06-01 23:19:36 +08:00
|
|
|
<div
|
2024-03-02 17:11:25 +08:00
|
|
|
className={itemClassName(isAllCategories)}
|
|
|
|
onClick={() => onChange(allCategoriesEn)}
|
2023-06-01 23:19:36 +08:00
|
|
|
>
|
2024-07-09 15:05:40 +08:00
|
|
|
<ThumbsUp className='mr-1 w-3.5 h-3.5' />
|
2023-06-01 23:19:36 +08:00
|
|
|
{t('explore.apps.allCategories')}
|
|
|
|
</div>
|
2023-05-25 16:59:47 +08:00
|
|
|
{list.map(name => (
|
2023-06-01 23:19:36 +08:00
|
|
|
<div
|
2023-05-25 16:59:47 +08:00
|
|
|
key={name}
|
|
|
|
className={itemClassName(name === value)}
|
|
|
|
onClick={() => onChange(name)}
|
|
|
|
>
|
2023-08-28 19:48:53 +08:00
|
|
|
{categoryI18n[name] ? t(`explore.category.${name}`) : name}
|
2023-05-25 16:59:47 +08:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2024-03-02 17:11:25 +08:00
|
|
|
|
2023-05-25 16:59:47 +08:00
|
|
|
export default React.memo(Category)
|