menu refactoring
This commit is contained in:
1 parent
8a41a895fb
commit
b07def3eee
2 files changed
+41
-18
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import cx from 'classnames'
|
||||
import { useRouter } from 'next/router'
|
||||
import { ActiveLink } from './ActiveLink'
|
||||
|
||||
export type MenuItemProps = {
|
||||
href: string
|
||||
layout: 'desktop' | 'mobile'
|
||||
}
|
||||
|
||||
export const MenuItem: React.FC<MenuItemProps> = props => {
|
||||
const router = useRouter()
|
||||
const current = router.asPath === props.href
|
||||
const href = current ? null : props.href
|
||||
|
||||
return (
|
||||
<li
|
||||
className={cx('menuItem', props.layout, {
|
||||
selected: current,
|
||||
})}
|
||||
>
|
||||
<ActiveLink
|
||||
href={href}
|
||||
activeStyle={{
|
||||
fontWeight: 'bold'
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</ActiveLink>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user