code quality and css update

- simplified navbar styling
- more readable code structure
This commit is contained in:
Kim, Jimin 2022-01-22 12:30:12 +09:00
parent adb809ed88
commit 1839805a79
4 changed files with 81 additions and 46 deletions

View file

@ -1,7 +1,6 @@
import styled from "styled-components"
import { Link } from "react-router-dom"
import ReactTooltip from "react-tooltip"
import { isMobile } from "react-device-detect"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faSearch } from "@fortawesome/free-solid-svg-icons"
@ -36,8 +35,7 @@ const StyledContainer = styled.div`
margin: 0 auto;
align-items: center;
display: flex;
height: 2rem;
padding: 1rem;
height: 4rem;
/* account for 20px scrollbar width */
@media only screen and (min-width: calc(${theming.size
@ -51,53 +49,70 @@ const StyledContainer = styled.div`
`
const StyledNavLinks = styled.div`
display: flex;
height: 100%;
@media only screen and (max-width: ${theming.size.screen_size1}) {
display: none;
}
`
const StyledImg = styled.img`
height: 2rem;
height: 2.5rem;
display: block;
margin: 1rem;
`
const StyledLink = styled(Link)`
const StyledLink = styled.div`
${theming.styles.navbarButtonStyle}
margin: 0 0.2rem 0 0.2rem;
`
const SearchButton = () => {
return (
<>
<div style={{ height: "100%" }}>
<Link
data-tip
data-for="search"
to={`${process.env.PUBLIC_URL}/search`}
>
<StyledLink>
<FontAwesomeIcon icon={faSearch} />
</StyledLink>
</Link>
</div>
<ReactTooltip id="search" type="dark" effect="solid">
<span>Search</span>
</ReactTooltip>
</>
)
}
const Navbar = () => {
return (
<StyledNav>
<StyledContainer>
{/* icon */}
<Link to="/">
<StyledImg src={process.env.PUBLIC_URL + "/icon/icon_circle.svg"} />
</Link>
{/* nav links */}
<StyledNavLinks>
{NavbarData.map((item, index) => (
<StyledLink key={index} to={item.path}>
{item.title}
</StyledLink>
<Link key={index} to={item.path}>
<StyledLink>{item.title}</StyledLink>
</Link>
))}
</StyledNavLinks>
{/* right buttons */}
<ThemeToggleButton />
<StyledLink
data-tip
data-for="search"
to={`${process.env.PUBLIC_URL}/search`}
>
<FontAwesomeIcon icon={faSearch} />
</StyledLink>
{!isMobile && (
<ReactTooltip id="search" type="dark" effect="solid">
<span>Search</span>
</ReactTooltip>
)}
<SearchButton />
<Sidebar />
</StyledContainer>
<ReadProgress />

View file

@ -21,17 +21,20 @@ const CommonSidebarToggleButtonStyle = css`
}
`
const StyledToggleSidebarButton = styled.div`
const SidebarOpenButton = styled.div`
${CommonSidebarToggleButtonStyle}
`
const StyledToggleSidebarButton2 = styled.div`
const SidebarCloseButton = styled.div`
${CommonSidebarToggleButtonStyle}
border-radius: 0;
margin: auto;
width: 90%;
height: 2rem;
height: 4rem;
font-size: 1.1rem;
svg {
margin-top: 0.2rem;
margin-right: 0.5rem;
}
`
const StyledOverlay = styled.div<{ isSidebarOpen: boolean }>`
@ -89,24 +92,25 @@ const Sidebar = () => {
<>
<StyledOverlay isSidebarOpen={isSidebarOpen} onClick={toggleSidebar} />
<StyledToggleSidebarButton
data-tip
data-for="sidebar"
onClick={toggleSidebar}
>
<SidebarOpenButton data-tip data-for="sidebar" onClick={toggleSidebar}>
<FontAwesomeIcon icon={faEllipsisV}></FontAwesomeIcon>
{!isMobile && (
<ReactTooltip id="sidebar" type="dark" effect="solid">
<span>open sidebar</span>
</ReactTooltip>
)}
</StyledToggleSidebarButton>
</SidebarOpenButton>
<SidebarNav isSidebarOpen={isSidebarOpen}>
<SidebarWrap>
<StyledToggleSidebarButton2 onClick={toggleSidebar}>
<FontAwesomeIcon icon={faTimes}></FontAwesomeIcon> Close
</StyledToggleSidebarButton2>
{/* close sidebar button */}
<SidebarCloseButton onClick={toggleSidebar}>
<FontAwesomeIcon icon={faTimes}></FontAwesomeIcon>Close
</SidebarCloseButton>
{/* sidebar items */}
{NavbarData.map((item: Item, index) => {
return <SubMenu item={item} key={index} />
})}

View file

@ -23,7 +23,7 @@ const SidebarLink = styled(Link)`
`
const SidebarLabel = styled.span`
margin-left: 16px;
margin-left: 1rem;
`
interface Props {

View file

@ -61,13 +61,26 @@ const theming = {
}
`,
navbarButtonStyle: css`
cursor: pointer; /* so it can be applies to divs too */
font-size: 1rem;
border-radius: 0.5rem;
float: left;
padding: 14px 16px;
/* style */
display: flex;
cursor: pointer;
align-items: center;
justify-content: center;
/* size */
height: 100%;
min-width: 3rem;
margin: 0;
padding: 0 1rem 0 1rem;
/* text */
text-decoration: none;
transition: transform 0.1s linear;
/* color */
color: ${(props) =>
theme(props.theme.currentTheme, {
light: "black",
@ -79,10 +92,13 @@ const theming = {
dark: "#202225",
})};
/* animation */
transition: transform 0.1s linear;
&:hover {
background-color: ${(props) =>
theme(props.theme.currentTheme, {
light: "lightgrey",
light: "#EEEEEE",
dark: "#36393F",
})};
}