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'
|
|
|
|
import cn from 'classnames'
|
2023-06-01 23:19:36 +08:00
|
|
|
import exploreI18n from '@/i18n/lang/explore.en'
|
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
|
|
|
|
list: string[]
|
|
|
|
value: string
|
|
|
|
onChange: (value: string) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const Category: FC<ICategoryProps> = ({
|
|
|
|
className,
|
|
|
|
list,
|
|
|
|
value,
|
2023-06-01 23:19:36 +08:00
|
|
|
onChange,
|
2023-05-25 16:59:47 +08:00
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2023-06-01 23:19:36 +08:00
|
|
|
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')
|
|
|
|
const itemStyle = (isSelected: boolean) => isSelected ? { boxShadow: '0px 1px 2px rgba(16, 24, 40, 0.05)' } : {}
|
2023-05-25 16:59:47 +08:00
|
|
|
return (
|
|
|
|
<div className={cn(className, 'flex space-x-1 text-[13px]')}>
|
2023-06-01 23:19:36 +08:00
|
|
|
<div
|
|
|
|
className={itemClassName(value === '')}
|
|
|
|
style={itemStyle(value === '')}
|
|
|
|
onClick={() => onChange('')}
|
|
|
|
>
|
|
|
|
{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)}
|
|
|
|
style={itemStyle(name === value)}
|
|
|
|
onClick={() => onChange(name)}
|
|
|
|
>
|
|
|
|
{(categoryI18n as any)[name] ? t(`explore.category.${name}`) : name}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default React.memo(Category)
|