Skip to content

Commit ba64124

Browse files
committed
feat: implement collapse/expand UI for category tags
1 parent efdc10e commit ba64124

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

components/Hero.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import dynamic from 'next/dynamic'
21
import { NextSeo } from 'next-seo'
2+
import dynamic from 'next/dynamic'
3+
import { useState } from 'react'
34

45
import {
56
botCategories,
@@ -13,6 +14,7 @@ const Tag = dynamic(() => import('@components/Tag'))
1314
const Search = dynamic(() => import('@components/Search'))
1415

1516
const Hero: React.FC<HeroProps> = ({ type = 'all', header, description }) => {
17+
const [showAllCategories, setShowAllCategories] = useState(false)
1618
const link = `/${type}/categories`
1719
return (
1820
<>
@@ -109,32 +111,35 @@ const Hero: React.FC<HeroProps> = ({ type = 'all', header, description }) => {
109111
bigger
110112
href={type === 'bots' ? '/bots/list/votes' : '/servers/list/votes'}
111113
/>
112-
{(type === 'bots' ? botCategories : serverCategories).slice(0, 4).map((t) => (
113-
<Tag
114-
key={t}
115-
text={
116-
<>
117-
<i
118-
className={(type === 'bots' ? botCategoryIcon : serverCategoryIcon)[t]}
119-
/>{' '}
120-
{t}
121-
</>
122-
}
123-
dark
124-
bigger
125-
href={`${link}/${t}`}
126-
/>
127-
))}
114+
{(type === 'bots' ? botCategories : serverCategories)
115+
.slice(0, showAllCategories ? undefined : 4)
116+
.map((t) => (
117+
<Tag
118+
key={t}
119+
text={
120+
<>
121+
<i
122+
className={(type === 'bots' ? botCategoryIcon : serverCategoryIcon)[t]}
123+
/>{' '}
124+
{t}
125+
</>
126+
}
127+
dark
128+
bigger
129+
href={`${link}/${t}`}
130+
/>
131+
))}
128132
<Tag
129133
key='tag'
130134
text={
131135
<>
132-
<i className='fas fa-tag' /> 카테고리 더보기
136+
<i className='fas fa-tag' />{' '}
137+
{showAllCategories ? '간략히 보기' : '카테고리 더보기'}
133138
</>
134139
}
135140
dark
136141
bigger
137-
href={link}
142+
onClick={() => setShowAllCategories(!showAllCategories)}
138143
/>
139144
</>
140145
)}

0 commit comments

Comments
 (0)