Spaces:
Running
Running
import React from 'react'; | |
import styled from 'styled-components'; | |
import { Link } from 'react-router-dom'; | |
import ThemeToggle from '../UI/ThemeToggle'; | |
import { useAuth } from '../../hooks/useAuth'; | |
const HeaderContainer = styled.header` | |
background: ${({ theme }) => theme.colors.primary}; | |
color: white; | |
padding: 1rem 2rem; | |
box-shadow: ${({ theme }) => theme.shadows.medium}; | |
`; | |
const Nav = styled.nav` | |
display: flex; | |
justify-content: space-between; | |
align-items: center; | |
max-width: 1200px; | |
margin: 0 auto; | |
`; | |
const Logo = styled(Link)` | |
font-size: ${({ theme }) => theme.fontSizes.xxlarge}; | |
font-weight: bold; | |
color: white; | |
text-decoration: none; | |
font-family: ${({ theme }) => theme.fonts.secondary}; | |
`; | |
const NavLinks = styled.div` | |
display: flex; | |
gap: 2rem; | |
align-items: center; | |
`; | |
const NavLink = styled(Link)` | |
color: white; | |
text-decoration: none; | |
font-weight: 500; | |
transition: opacity 0.3s ease; | |
&:hover { | |
opacity: 0.8; | |
} | |
`; | |
const Header = () => { | |
const { isAuthenticated } = useAuth(); | |
return ( | |
<HeaderContainer> | |
<Nav> | |
<Logo to="/">EnlightenQalb</Logo> | |
<NavLinks> | |
<NavLink to="/">Home</NavLink> | |
{isAuthenticated && <NavLink to="/dashboard">Dashboard</NavLink>} | |
<NavLink to="/about">About</NavLink> | |
<ThemeToggle /> | |
{isAuthenticated ? <LogoutButton /> : <LoginButton />} | |
</NavLinks> | |
</Nav> | |
</HeaderContainer> | |
); | |
}; | |
const LoginButton = () => ( | |
<NavLink to="/login">Login</NavLink> | |
); | |
const LogoutButton = () => { | |
const { logout } = useAuth(); | |
return ( | |
<NavLink as="button" onClick={logout} style={{ background: 'none', border: 'none' }}> | |
Logout | |
</NavLink> | |
); | |
}; | |
export default Header; |