Adds hero component
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { chakra } from '@chakra-ui/react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
|
||||
const ChakraLink = chakra(Link);
|
||||
|
||||
type NavLinkProps = React.ComponentProps<typeof ChakraLink>;
|
||||
|
||||
export default function NavLink({ children, ...props }: NavLinkProps) {
|
||||
return (
|
||||
<ChakraLink
|
||||
textTransform="uppercase"
|
||||
fontWeight="300"
|
||||
fontSize="0.72rem"
|
||||
letterSpacing="0.22em"
|
||||
position="relative"
|
||||
display="inline-block"
|
||||
py="2"
|
||||
mx="4"
|
||||
css={{
|
||||
'&::after': {
|
||||
content: '""',
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
bottom: 0,
|
||||
width: '100%',
|
||||
height: '1px',
|
||||
bg: 'currentColor',
|
||||
transform: 'scaleX(0)',
|
||||
transformOrigin: 'right',
|
||||
transition: 'transform 0.45s cubic-bezier(.22,.61,.36,1)',
|
||||
},
|
||||
'&:hover::after, &:focus-visible::after, &[aria-current="page"]::after':
|
||||
{
|
||||
transform: 'scaleX(1)',
|
||||
transformOrigin: 'left',
|
||||
},
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</ChakraLink>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import { Flex, HStack, chakra, Image, Box, Container } from '@chakra-ui/react';
|
||||
import NavLink from './NavLink';
|
||||
import useScrolledPast from '@/hooks/useScrolledPast';
|
||||
import { useState } from 'react';
|
||||
import { useRouterState } from '@tanstack/react-router';
|
||||
|
||||
// Images
|
||||
import logoLight from '../../assets/logo-light.png';
|
||||
import logoDark from '../../assets/logo-dark.png';
|
||||
|
||||
export default function NavigationBar() {
|
||||
let [open, setOpen] = useState(false);
|
||||
|
||||
const pastHero = useScrolledPast(() => 150);
|
||||
const isHome = useRouterState({
|
||||
select: (state) => state.location.pathname === '/',
|
||||
});
|
||||
const isSolid = pastHero || !isHome;
|
||||
|
||||
return (
|
||||
<chakra.header
|
||||
position="fixed"
|
||||
top={0}
|
||||
insetX={0}
|
||||
zIndex="docked"
|
||||
bg={isSolid ? 'white' : 'transparent'}
|
||||
color={isSolid ? 'fg' : 'white'}
|
||||
boxShadow={isSolid ? 'sm' : 'none'}
|
||||
border="none"
|
||||
px={{ base: 4, md: 8 }}
|
||||
py={4}
|
||||
transition="background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease"
|
||||
>
|
||||
<Container>
|
||||
<Flex
|
||||
gap={6}
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
>
|
||||
<Box
|
||||
flexBasis="auto"
|
||||
flexGrow={1}
|
||||
flexShrink={0}
|
||||
aspectRatio="square"
|
||||
maxW="50px"
|
||||
>
|
||||
<Image src={isSolid ? logoDark : logoLight} />
|
||||
</Box>
|
||||
<HStack
|
||||
as="ul"
|
||||
gap={6}
|
||||
listStyleType="none"
|
||||
flexBasis="100%"
|
||||
flexGrow={0}
|
||||
flexShrink={1}
|
||||
justifyContent="center"
|
||||
>
|
||||
<chakra.li>
|
||||
<NavLink to="/">Home</NavLink>
|
||||
</chakra.li>
|
||||
<chakra.li>
|
||||
<NavLink to="/over-mij">Over mij</NavLink>
|
||||
</chakra.li>
|
||||
</HStack>
|
||||
<chakra.div flexBasis="auto" flexGrow={1} flexShrink={0}>
|
||||
<chakra.button
|
||||
onClick={() => {
|
||||
setOpen(!open);
|
||||
console.log('Clicked menu button, open:', open);
|
||||
}}
|
||||
auria-label="{open ? 'Sluit menu' : 'Open menu'}"
|
||||
aria-expanded={open}
|
||||
data-open={open || undefined}
|
||||
position="relative"
|
||||
w="32px"
|
||||
h="32px"
|
||||
cursor="pointer"
|
||||
zIndex="modal"
|
||||
css={{
|
||||
'& > span': {
|
||||
position: 'absolute',
|
||||
left: '4px',
|
||||
width: '24px',
|
||||
height: '2px',
|
||||
bg: 'currentColor',
|
||||
borderRadius: '1px',
|
||||
transition:
|
||||
'transform 0.3s ease, opacity 0.2s ease, top 0.3s ease',
|
||||
},
|
||||
'& > span:nth-of-type(1)': { top: '9px' },
|
||||
'& > span:nth-of-type(2)': { top: '15px' },
|
||||
'& > span:nth-of-type(3)': { top: '21px' },
|
||||
|
||||
// open kruisje
|
||||
'&[data-open] > span:nth-of-type(1)': {
|
||||
top: '15px',
|
||||
transform: 'rotate(45deg)',
|
||||
},
|
||||
'&[data-open] > span:nth-of-type(2)': {
|
||||
opacity: 0,
|
||||
top: '15px',
|
||||
transform: 'rotate(45deg)',
|
||||
},
|
||||
'&[data-open] > span:nth-of-type(3)': {
|
||||
top: '15px',
|
||||
transform: 'rotate(-45deg)',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<span />
|
||||
<span />
|
||||
<span />
|
||||
</chakra.button>
|
||||
</chakra.div>
|
||||
</Flex>
|
||||
</Container>
|
||||
</chakra.header>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user