2022-05-12 15:07:10 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
|
|
|
|
import { Row } from '../layout/row'
|
|
|
|
import { CATEGORIES, CATEGORY_LIST } from '../../../common/categories'
|
|
|
|
|
|
|
|
export function CategorySelector(props: {
|
2022-05-16 02:57:50 +00:00
|
|
|
category: string
|
|
|
|
setCategory: (category: string) => void
|
2022-05-12 15:07:10 +00:00
|
|
|
className?: string
|
|
|
|
}) {
|
2022-06-01 02:23:36 +00:00
|
|
|
const { className, category, setCategory } = props
|
2022-05-12 15:07:10 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Row
|
|
|
|
className={clsx(
|
2022-05-17 17:56:10 +00:00
|
|
|
'carousel mr-2 items-center space-x-2 space-y-2 overflow-x-scroll pb-4 sm:flex-wrap',
|
2022-05-12 15:07:10 +00:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<div />
|
|
|
|
<CategoryButton
|
2022-05-16 02:57:50 +00:00
|
|
|
key="all"
|
2022-05-12 15:07:10 +00:00
|
|
|
category="All"
|
2022-05-16 02:57:50 +00:00
|
|
|
isFollowed={category === 'all'}
|
2022-06-01 02:23:36 +00:00
|
|
|
toggle={() => {
|
2022-05-16 02:57:50 +00:00
|
|
|
setCategory('all')
|
2022-05-12 15:07:10 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{CATEGORY_LIST.map((cat) => (
|
|
|
|
<CategoryButton
|
2022-05-16 02:57:50 +00:00
|
|
|
key={cat}
|
2022-05-12 15:07:10 +00:00
|
|
|
category={CATEGORIES[cat].split(' ')[0]}
|
2022-05-16 02:57:50 +00:00
|
|
|
isFollowed={cat === category}
|
2022-06-01 02:23:36 +00:00
|
|
|
toggle={() => {
|
2022-05-16 02:57:50 +00:00
|
|
|
setCategory(cat)
|
2022-05-12 15:07:10 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function CategoryButton(props: {
|
|
|
|
category: string
|
|
|
|
isFollowed: boolean
|
|
|
|
toggle: () => void
|
|
|
|
}) {
|
|
|
|
const { toggle, category, isFollowed } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2022-05-12 17:47:07 +00:00
|
|
|
'rounded-full border-2 px-4 py-1 shadow-md hover:bg-gray-200',
|
2022-05-12 16:07:44 +00:00
|
|
|
'cursor-pointer select-none',
|
2022-05-12 15:07:10 +00:00
|
|
|
isFollowed ? 'border-gray-300 bg-gray-300' : 'bg-white'
|
|
|
|
)}
|
|
|
|
onClick={toggle}
|
|
|
|
>
|
|
|
|
<span className="text-sm text-gray-500">{category}</span>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|