modify sidebar

This commit is contained in:
Priyatham Sai Chand 2021-03-29 18:17:28 +05:30
parent 8408889432
commit 950d4a9072
2 changed files with 43 additions and 19 deletions

View file

@ -11,6 +11,9 @@ import { Bullseye } from "@styled-icons/fa-solid";
import { StyledIconBase } from '@styled-icons/styled-icon' import { StyledIconBase } from '@styled-icons/styled-icon'
import Sidebar from './Sidebar'; import Sidebar from './Sidebar';
const Body = styled.div`
`;
const IconStyler = styled.div` const IconStyler = styled.div`
${StyledIconBase} { ${StyledIconBase} {
width: ${props => props.width ? props.width : 26}px; width: ${props => props.width ? props.width : 26}px;
@ -93,7 +96,7 @@ export default function HomePage() {
return ( return (
<div className="HomePage"> <Body>
<ColoredSection > <ColoredSection >
@ -227,7 +230,7 @@ export default function HomePage() {
</ContainerPadded> </ContainerPadded>
</ColoredSection> </ColoredSection>
<Sidebar /> <Sidebar logout="{logout}" />
<NavBar /> <NavBar />
<div id="footer"> <div id="footer">
@ -236,15 +239,7 @@ export default function HomePage() {
</div> </Body>
); );
} }

View file

@ -1,10 +1,12 @@
import React, {useState} from 'react'; import React, {useState, useContext} from 'react';
import { Link } from 'react-router-dom'
import styled from 'styled-components'; import styled from 'styled-components';
import UserContext from '../context/UserContext';
const StyledMenu = styled.nav` const StyledMenu = styled.nav`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
position:fixed !important;
justify-content: center; justify-content: center;
background: #EFFFFA; background: #EFFFFA;
transform: ${({ open }) => open ? 'translateX(0)' : 'translateX(-100%)'}; transform: ${({ open }) => open ? 'translateX(0)' : 'translateX(-100%)'};
@ -41,9 +43,10 @@ const StyledMenu = styled.nav`
} }
` `
const Menu = ({ open }) => { const Menu = (props) => {
const { userData, setUserData } = useContext(UserContext);
return ( return (
<StyledMenu open={open}> <StyledMenu open={props.open}>
<a href="/#about-us"> <a href="/#about-us">
<span role="img" aria-label="about us">💁🏻‍♂️</span> <span role="img" aria-label="about us">💁🏻‍♂️</span>
About us About us
@ -56,12 +59,34 @@ const Menu = ({ open }) => {
<span role="img" aria-label="contact us">📩</span> <span role="img" aria-label="contact us">📩</span>
Contact Contact
</a> </a>
{userData.user ? (
<Link >
<span role="img" aria-label="{userData.user.username}">📩</span>
{userData.user.username}
</Link>
):(
<React.Fragment>
<a href="/user/register">
<span role="img" aria-label="Register">📩</span>
Register
</a>
<a href="/user/login">
<span role="img" aria-label="Login">📩</span>
Login
</a>
</React.Fragment>
)
}
</StyledMenu> </StyledMenu>
) )
} }
const StyledBurger = styled.button` const StyledBurger = styled.button`
position: absolute; position: fixed;
top: 5%; top: 5%;
left: 2rem; left: 2rem;
display: flex; display: flex;
@ -78,6 +103,10 @@ const StyledBurger = styled.button`
&:focus { &:focus {
outline: none; outline: none;
} }
&:hover{
background: transparent;
}
div { div {
width: 2rem; width: 2rem;
@ -117,15 +146,15 @@ const Burger = ({ open, setOpen }) => {
} }
const Sidebar = () => { const Sidebar = (props) => {
const [open, setOpen] = React.useState(false); const [open, setOpen] = useState(false);
const node = React.useRef(); const node = React.useRef();
return ( return (
<div> <div>
<div ref={node}> <div ref={node}>
<Burger open={open} setOpen={setOpen} /> <Burger open={open} setOpen={setOpen} />
<Menu open={open} setOpen={setOpen} /> <Menu open={open} setOpen={setOpen} logout={props.logout} />
</div> </div>
</div> </div>
) )