-
Notifications
You must be signed in to change notification settings - Fork 9
/
NavBar.tsx
252 lines (237 loc) · 6.62 KB
/
NavBar.tsx
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import React, { useEffect, useState } from 'react';
import Container from './Container';
import cx from 'classnames';
import MobileMenu from './MobileMenu';
import { motion } from 'framer-motion';
import Logo from './Logo';
import { ClerkProvider } from '@clerk/clerk-react';
import ClerkButton from './ClerkButton';
const CLERK_PUBLISHABLE_KEY = import.meta.env.PUBLIC_VITE_CLERK_PUBLISHABLE_KEY;
if (!CLERK_PUBLISHABLE_KEY) {
throw new Error('Missing Clerk Publishable Key');
}
interface Props {
currentPage: string;
isProgressBar?: boolean;
isBanner?: boolean;
}
const NavBar: React.FC<Props> = ({
currentPage,
isProgressBar = false,
isBanner = false,
}) => {
const [scrollY, setScrollY] = useState(0);
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [progressWidth, setProgressWidth] = useState(101);
const [
isScreenGreaterThanOrEqualTo900px,
setIsScreenGreaterThanOrEqualTo900px,
] = useState(false);
const variants = {
open: {
opacity: 1,
transition: {
ease: 'linear',
duration: 0.15,
},
},
closed: { opacity: 0 },
};
useEffect(() => {
const handleScroll = () => {
if (isProgressBar) {
const blogPost = document.getElementById('tembo-blog-post');
const { top, height } = (
blogPost as any
)?.getBoundingClientRect();
let scrollDistance = -top;
let progressPercentage =
(scrollDistance /
(height - document.documentElement.clientHeight)) *
100;
setProgressWidth(progressPercentage);
}
setScrollY(window.scrollY);
};
handleScroll();
window.addEventListener('scroll', handleScroll);
const handleResize = () => {
const isScreenGreaterThanOrEqualTo900px = window.innerWidth >= 900;
setIsScreenGreaterThanOrEqualTo900px(
isScreenGreaterThanOrEqualTo900px,
);
if (isScreenGreaterThanOrEqualTo900px) {
document.body.style.overflow = 'scroll';
}
};
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
window.removeEventListener('scroll', handleScroll);
};
}, []);
let isActive = progressWidth <= 100;
return (
<div
className={cx(
'fixed top-0 w-full z-50 transition duration-100',
scrollY > 20 ? 'backdrop-blur-lg safari-blur' : '',
isMenuOpen && !isScreenGreaterThanOrEqualTo900px && 'h-screen',
)}
>
{isBanner && !isMenuOpen && (
<a href='/blog/pganalyze'>
<div
className={`flex items-center text-[12px] min-[400px]:text-sm justify-center gap-2 news-banner-container top-0 w-full text-center bg-[#131313] shadow-[0_-20px_36px_0_rgba(240,102,141,0.13)_inset] text-white px-[20px] mobile:px-[95px] py-3.5 sm:py-2.5 z-50`}
>
<span className='truncate'>
Tembo now supports advanced metrics, alerts and more
with pganalyze!
</span>
<span className='bg-gradient-to-r from-salmon via-purple to-lightPurple inline-block text-transparent bg-clip-text font-semibold text-sm whitespace-nowrap'>
Read more
</span>
</div>
</a>
)}
<div className='bg-gradient-rainbow h-[4px] w-full' />
<Container styles='relative'>
<nav
className={cx(
'flex w-full items-center justify-between transition-all duration-100 relative',
scrollY > 20 &&
(!isMenuOpen || isScreenGreaterThanOrEqualTo900px)
? 'py-3 mid:py-4'
: 'py-8',
)}
>
<Logo />
<div className='mid:flex hidden items-center gap-12 m-auto absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2'>
<a
href='/'
className={cx(
'font-secondary font-medium z-10',
currentPage == '/'
? 'text-neon'
: 'text-white opacity-70',
)}
>
Home
</a>
<a
href='/pricing'
className={cx(
'font-secondary font-medium z-10',
currentPage == '/pricing' ||
currentPage == '/pricing/'
? 'text-neon'
: 'text-white opacity-70',
)}
target='_blank'
rel='noreferrer'
>
Pricing
</a>
<a
href='/docs'
className={cx(
'font-secondary font-medium z-10',
currentPage == '/docs' ||
currentPage == '/docs/'
? 'text-neon'
: 'text-white opacity-70',
)}
>
Docs
</a>
<a
href='/blog'
className={cx(
'font-secondary font-medium z-10',
currentPage == '/blog' ||
currentPage == '/blog/'
? 'text-neon'
: 'text-white opacity-70',
)}
>
Blog
</a>
</div>
<div className='hidden mid:flex gap-8 items-center self-end'>
<a
href='https://github.com/tembo-io/tembo'
target='_blank'
className={cx(
'font-secondary font-medium z-10 flex items-center gap-2 ',
'text-white opacity-70',
)}
>
<img
src='/github.svg'
alt='github icon'
className='w-[20px] h-[20px]'
/>
Github
</a>
<ClerkProvider publishableKey={CLERK_PUBLISHABLE_KEY}>
<ClerkButton />
</ClerkProvider>
</div>
<button
onClick={() => {
document.body.style.overflow = !isMenuOpen
? 'hidden'
: 'scroll';
setIsMenuOpen(!isMenuOpen);
}}
className={cx(
'mid:hidden flex flex-col gap-[2.5px] items-center justify-center bg-neon hover:bg-[#D1E278] rounded-full w-[32.57px] h-[32.57px] z-50',
isMenuOpen ? 'p-2' : 'p-2.5',
)}
>
{isMenuOpen ? (
<>
<img src={'/x.svg'} alt='close icon' />
</>
) : (
<>
<div className='bg-[#292D32] rounded-full w-full h-[1.5px]' />
<div className='bg-[#292D32] rounded-full w-full h-[1.5px]' />
<div className='bg-[#292D32] rounded-full w-full h-[1.5px]' />
</>
)}
</button>
</nav>
</Container>
{scrollY > 50 && isProgressBar && (
<div
className={cx(
'w-full flex justify-start relative',
scrollY > 50 && 'h-[2.5px]',
)}
>
<div
className='h-full top-0 bottom-0 right-0 absolute w-screen bg-salmon will-change-transform transition-opacity duration-[40] ease-linear'
style={{
transform: `translate3d(${isActive ? progressWidth - 100 + '%' : '0'},0,0)`,
opacity: isActive ? 1 : 0,
}}
></div>
</div>
)}
<div
className={cx(
'absolute bottom-0 flex h-[1px] w-full flex-row items-center justify-center opacity-100 shine',
scrollY > 20 ? 'flex' : 'hidden',
)}
/>
<motion.div
animate={isMenuOpen ? 'open' : 'closed'}
variants={variants}
>
{isMenuOpen && <MobileMenu />}
</motion.div>
</div>
);
};
export default NavBar;