-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopNav.js
67 lines (57 loc) · 1.85 KB
/
TopNav.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, {useEffect, useState} from "react";
import styled from "styled-components";
import {Transition} from "react-transition-group";
const NavContainer = styled.div`
position: fixed;
top: 0;
left: 0;
z-index: 990;
backdrop-filter: blur(6px);
transform: translateY(${({state}) => (state === "entering" || state === "entered" ? 0 : '-72px')});
background-color: ${props => (props.backgroundColor ? props.backgroundColor : 'rgb(80, 80, 80, 0.5)')};
width: 90%;
min-height: 64px;
color: $424242;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding-left: 5%;
padding-right: 5%;
font-size: 20px;
transition-delay: 0.2s;
transition-duration: 1s;
@media (min-width: 768px) {
width: 80%;
padding-left: 10%;
padding-right: 10%;
font-size: 32px;
}
`;
const TopNav = (props) => {
const [animate, setAnimate] = useState(false)
const doAnimate = (finalState) => {
setAnimate(finalState);
}
let previousState = 0;
useEffect(() => {
window.addEventListener('scroll', () => {
if (!animate && document.documentElement.scrollTop < previousState) {
doAnimate(true);
} else if (!animate) {
doAnimate(false);
}
previousState = document.documentElement.scrollTop;
});
}, []);
return (
<Transition in={animate} timeout={(props.animationTimeout ? props.animationTimeout : 1000)}>
{(state) => (
<NavContainer className={(props.containerClassName ? props.containerClassName : '')} state={state} backgroundColor={props.backgroundColor}>
{props.children}
</NavContainer>
)}
</Transition>
);
}
export default TopNav;