feat: allow external links in navbar and sidebar

This commit is contained in:
Kim, Jimin 2023-06-26 00:58:52 +09:00
parent 12c246dcd3
commit 3af0fd7056
2 changed files with 38 additions and 14 deletions

View file

@ -18,11 +18,17 @@ const Nav = styled.div`
export default () => {
return (
<Nav>
{NavbarData.map((item, index) => (
<Link key={index} to={item.path}>
<HeaderButton>{item.title}</HeaderButton>
</Link>
))}
{NavbarData.map(({ path, title }, index) => {
return path.at(0) === "/" ? (
<Link key={index} to={path}>
<HeaderButton>{title}</HeaderButton>
</Link>
) : (
<a key={index} target="_blank" href={path}>
<HeaderButton>{title}</HeaderButton>
</a>
)
})}
</Nav>
)
}

View file

@ -6,11 +6,11 @@ import type { Item } from "../../data/NavbarData"
import { useCallback, useState } from "react"
import { Link } from "react-router-dom"
import styled from "styled-components"
import styled, { css } from "styled-components"
import button from "../../styles/button"
const SidebarLink = styled(Link)`
const sharedStyle = css`
${button};
display: flex;
width: 100%;
@ -31,6 +31,14 @@ const SidebarLink = styled(Link)`
}
`
const SidebarLink = styled(Link)`
${sharedStyle}
`
const SidebarAnchor = styled.a`
${sharedStyle}
`
const SidebarLabel = styled.span`
margin-left: 1rem;
`
@ -39,21 +47,31 @@ interface Props {
item: Item
}
const SubMenu = (props: Props) => {
const SubMenu = ({ item }: Props) => {
const { path, icon, title } = item
const [isSubNavOpen, setSubNavOpen] = useState(false)
const handleSidebarLinkClick = useCallback(() => {
setSubNavOpen((prev) => !prev)
}, [isSubNavOpen])
return (
<>
<SidebarLink to={props.item.path} onClick={handleSidebarLinkClick}>
if (path.at(0) == "/") {
return (
<SidebarLink to={path} onClick={handleSidebarLinkClick}>
<div>
{props.item.icon}
<SidebarLabel>{props.item.title}</SidebarLabel>
{icon}
<SidebarLabel>{title}</SidebarLabel>
</div>
</SidebarLink>
</>
)
}
return (
<SidebarAnchor target="_blank" href={path} onClick={handleSidebarLinkClick}>
<div>
{icon}
<SidebarLabel>{title}</SidebarLabel>
</div>
</SidebarAnchor>
)
}