-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHeader.tsx
More file actions
199 lines (189 loc) · 5.2 KB
/
Copy pathHeader.tsx
File metadata and controls
199 lines (189 loc) · 5.2 KB
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
'use client';
import {
IconArrowNarrowRight,
IconArrowUpRight,
IconChevronDown,
} from '@tabler/icons-react';
import { Burger, Center, Container, Group, Menu } from '@mantine/core';
import Link from 'next/link';
import LitLogo from '../LitLogo/LitLogo';
import {
CAREERS_LINK,
COMMUNITY_LINK,
CONTACT_FORM,
DOCS_LINK,
GITHUB_LINK,
SPARK_LINK,
VINCENT_LINK,
DEVELOPER_CONSTANT_LINK,
COMMUNITY_CONSTANT_LINK,
COMPANY_CONSTANT_LINK,
} from '@/utils/constants';
import { Button } from '../ui/Button';
import SparkleIcon from './assets/SparkleIcon';
import { useState } from 'react';
import SparkleIconFilled from './assets/SparkleIconFilled';
interface LinkItem {
link: string;
label: string;
external?: boolean;
links?: LinkItem[];
}
const links: LinkItem[] = [
{
link: VINCENT_LINK,
label: 'Vincent',
external: false,
},
{
link: DEVELOPER_CONSTANT_LINK,
label: 'Developers',
links: [
{ link: DOCS_LINK, label: 'Documentation', external: true },
{ link: GITHUB_LINK, label: 'Github', external: true },
],
},
{
link: COMMUNITY_CONSTANT_LINK,
label: 'Community',
links: [{ link: COMMUNITY_LINK, label: 'Resources', external: true }],
},
{
link: COMPANY_CONSTANT_LINK,
label: 'Company',
links: [
{ link: SPARK_LINK, label: 'Blog', external: true },
{ link: CAREERS_LINK, label: 'Careers', external: false },
{ link: CONTACT_FORM, label: 'Contact', external: true },
],
},
];
const VincentIcon = ({ hovered }: { hovered: boolean }) => {
return hovered ? (
<SparkleIconFilled size={16} className="transition-all fill-white" />
) : (
<SparkleIcon size={16} className="transition-all" />
);
};
// Individual link component with its own hover state
const NavLink = ({ link }: { link: LinkItem }) => {
const [hovered, setHovered] = useState(false);
const isExternal = link.external === true;
const hasSubLinks = !!link.links?.length;
if (hasSubLinks) {
const menuItems = (link.links ?? []).map(item =>
item.external ? (
<Menu.Item
key={item.link}
component="a"
href={item.link}
target="_blank"
rel="noopener noreferrer"
rightSection={<IconArrowUpRight size={16} />}
>
{item.label}
</Menu.Item>
) : (
<Menu.Item key={item.link} component={Link} href={item.link}>
{item.label}
</Menu.Item>
)
);
return (
<Menu
key={link.label}
trigger="hover"
transitionProps={{ exitDuration: 0 }}
withinPortal
withArrow
offset={16}
>
<Menu.Target>
<a href={link.link}>
<Center
className="group text-off-white font-medium px-[.75rem] py-[.375rem]"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
<span className="mr-[5px]">{link.label}</span>
{link.label === 'Vincent' ? (
<VincentIcon hovered={hovered} />
) : (
<IconChevronDown size={16} stroke={1.5} />
)}
</Center>
</a>
</Menu.Target>
<Menu.Dropdown>{menuItems}</Menu.Dropdown>
</Menu>
);
}
return isExternal ? (
<a
key={link.link}
href={link.link}
target="_blank"
rel="noopener noreferrer"
>
<Center
className="group text-off-white font-medium px-[.75rem] py-[.375rem]"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
<span className="mr-[5px]">{link.label}</span>
{link.label === 'Vincent' && <VincentIcon hovered={hovered} />}
</Center>
</a>
) : (
<Link key={link.link} href={link.link}>
<Center
className="group text-off-white font-medium px-[.75rem] py-[.375rem]"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
<span className="mr-[5px]">{link.label}</span>
{link.label === 'Vincent' && <VincentIcon hovered={hovered} />}
</Center>
</Link>
);
};
export function HeaderMenu({
menuOpen,
toggleMenu,
}: {
menuOpen: boolean;
toggleMenu: () => void;
}) {
const items = links.map(link => <NavLink key={link.label} link={link} />);
return (
<header className="relative w-full top-0 left-0 h-[4.5rem] z-10 bg-coal-950">
<Container size="md">
<div className="flex h-[4.5rem] justify-between items-center">
<Group gap={4}>
<Burger
opened={menuOpen}
onClick={toggleMenu}
size="sm"
hiddenFrom="sm"
color="white"
/>
<LitLogo className="h-[1.5rem] text-lit-orange" />
</Group>
<Group gap={'1.25rem'} visibleFrom="sm">
{items}
</Group>
{menuOpen ? (
<Button className="hidden" />
) : (
<Button
href={DOCS_LINK}
rightIcon={<IconArrowNarrowRight stroke={2} />}
>
Get started
</Button>
)}
</div>
</Container>
</header>
);
}