-
Notifications
You must be signed in to change notification settings - Fork 12
/
Header.tsx
282 lines (267 loc) · 8.18 KB
/
Header.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { ArrowRightIcon } from "@heroicons/react/20/solid";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/router";
import React, {
type MouseEventHandler,
type PropsWithChildren,
useState,
} from "react";
import { shorten } from "@/utils/formatter";
import { Button } from "./Button";
import { ConnectedButton } from "./ConnectedButton";
import OpenMenuIcon from "./icons/OpenMenuIcon";
const NavItem: React.FC<
PropsWithChildren<{
className?: string;
href: string;
active?: boolean;
external?: boolean;
}>
> = ({ className, href, active, external, children }) => {
if (external) {
return (
<a
href={href}
target="_blank"
rel="noreferrer"
className={`cursor-pointer font-roboto-mono text-xl font-medium uppercase tracking-wide transition-all lg:text-lg ${
active ? "text-neutral-100" : "text-neutral-500 hover:text-blue"
} ${className ? className : ""}`}
>
{children}
</a>
);
}
return (
<Link
href={href}
className={`cursor-pointer font-roboto-mono text-xl font-medium uppercase tracking-wide transition-all lg:text-lg ${
active ? "text-neutral-100" : "text-neutral-500 hover:text-blue"
}`}
>
{children}
</Link>
);
};
const NavItemDivider: React.FC = () => {
return (
<p className="interact cursor-default font-roboto-mono text-xl font-medium uppercase tracking-wide text-neutral-600">
/
</p>
);
};
type HeaderProps = {
logoHref: string;
onDepositWithdrawClick?: MouseEventHandler<HTMLButtonElement>;
onWalletButtonClick?: MouseEventHandler<HTMLButtonElement>;
};
export function Header({
logoHref,
onDepositWithdrawClick,
onWalletButtonClick,
}: HeaderProps) {
const { account } = useWallet();
const router = useRouter();
return (
<>
<header className="hidden border-b border-neutral-600 lg:block">
<nav className="flex items-center justify-between py-5 pl-[29.19px] pr-[20.02px]">
<div className="my-auto flex items-center gap-[29.95px]">
<Link href={logoHref}>
<Image
className=""
alt="Econia Logo"
src="/econia.svg"
width={117}
height={19}
priority
/>
</Link>
<div className="flex flex-1 items-center justify-center gap-6">
<NavItem
href="/market"
active={router.pathname.startsWith("/market")}
>
Trade
</NavItem>
<NavItemDivider />
<NavItem
href="/faucet"
active={router.pathname.startsWith("/faucet")}
>
Faucet
</NavItem>
<NavItemDivider />
<NavItem
className="flex items-center gap-1"
href="https://econia.dev"
external
>
<p>Docs</p>
<ArrowRightIcon className="inline-block h-3 w-3 -rotate-45" />
</NavItem>
</div>
</div>
<div className="flex flex-1 justify-end">
<ConnectedButton className="py-[7px]">
<div className="flex items-center gap-4">
{onDepositWithdrawClick && (
<Button
variant="secondary"
className="whitespace-nowrap px-[15px] pb-2 pt-[10px] uppercase !leading-[18px] tracking-[0.32px]"
onClick={onDepositWithdrawClick}
>
Deposit/Withdraw
</Button>
)}
<Button
variant="primary"
onClick={onWalletButtonClick}
className="whitespace-nowrap px-[17.5px] pb-2 pt-[10px] uppercase !leading-[18px] tracking-[0.32px]"
>
{shorten(account?.address)}
</Button>
</div>
</ConnectedButton>
</div>
</nav>
</header>
<HeaderMobile
logoHref={logoHref}
onDepositWithdrawClick={onDepositWithdrawClick}
onWalletButtonClick={onWalletButtonClick}
/>
</>
);
}
const SlidingMenu = ({
isOpen,
onWalletButtonClick,
onDepositWithdrawClick,
}: {
isOpen: boolean;
toggleMenu: () => void;
onWalletButtonClick?: MouseEventHandler<HTMLButtonElement>;
onDepositWithdrawClick?: MouseEventHandler<HTMLButtonElement>;
}) => {
const { account } = useWallet();
const router = useRouter();
return (
<div
className={`transition-width fixed right-0 top-16 z-30 flex h-full flex-col overflow-x-hidden bg-neutral-800 bg-noise pt-4 duration-300 ease-in-out ${
isOpen ? "w-full" : "w-0"
}`}
>
<div className="mb-8 flex flex-col items-start justify-between gap-[23.68px] px-[29.28px]">
<NavItem
href="/market"
active={router.pathname.startsWith("/market")}
className=""
>
Trade
</NavItem>
<NavItem
href="/faucet"
active={router.pathname.startsWith("/faucet")}
className=""
>
Faucet
</NavItem>
<NavItem
href="https://econia.dev"
className="flex items-center gap-1"
external={true}
>
<p>Docs</p>
<ArrowRightIcon className="inline-block h-3 w-3 -rotate-45" />
</NavItem>
</div>
<div className="px-[29.28px]">
<ConnectedButton className="w-[182px] py-[7px] uppercase leading-[22px]">
<div className="flex flex-col gap-[29.37px]">
<Button
variant="primary"
onClick={onWalletButtonClick}
className="w-fit whitespace-nowrap py-[7px] !font-bold uppercase leading-[22px] tracking-[0.32px]"
>
{shorten(account?.address, 12)}
</Button>
{onDepositWithdrawClick && (
<Button
variant="secondary"
className="h-9 w-[189px] whitespace-nowrap font-roboto-mono !text-base font-medium uppercase leading-[18px] tracking-[0.32px]"
onClick={onDepositWithdrawClick}
>
Deposit/Withdraw
</Button>
)}
</div>
</ConnectedButton>
</div>
</div>
);
};
const HeaderMobile = ({
logoHref,
onDepositWithdrawClick,
onWalletButtonClick,
}: HeaderProps) => {
const [isOpen, setIsOpen] = useState(false);
const toggleMenu = () => {
if (!isOpen) {
window.scrollTo({
behavior: "smooth",
top: 0,
});
document.body.classList.add("overflow-hidden");
} else {
document.body.classList.remove("overflow-hidden");
}
setIsOpen(!isOpen);
};
const closeMenu = () => {
setIsOpen(false);
};
return (
<header
className={`flex h-[76px] items-center justify-between border-b border-neutral-600 py-4 pl-[29.28px] pr-[30.85px] lg:hidden ${
isOpen && ""
}`}
>
<div className="flex items-center">
<Link
href={logoHref}
onClick={closeMenu}
className="scale-101 hover:scale-96 transform transition duration-300"
>
<Image src="/econia.svg" alt="logo" width={117} height={19} />
</Link>
</div>
<div className="flex h-[69px] items-center gap-5">
<div
className="flex flex-col items-end gap-[8px] text-white"
onClick={toggleMenu}
>
<OpenMenuIcon
className={`transition duration-300 ease-in-out ${
isOpen ? "translate-y-[6px] rotate-[135deg]" : ""
}`}
/>
<OpenMenuIcon
className={`transition duration-300 ease-in-out ${
isOpen ? "-translate-y-[6.5px] rotate-45" : ""
}`}
/>
</div>
</div>
<SlidingMenu
isOpen={isOpen}
toggleMenu={toggleMenu}
onWalletButtonClick={onWalletButtonClick}
onDepositWithdrawClick={onDepositWithdrawClick}
/>
</header>
);
};