forked from bitcoinsearch/bitcoinsearch-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavBar.tsx
More file actions
172 lines (164 loc) · 5.7 KB
/
Copy pathNavBar.tsx
File metadata and controls
172 lines (164 loc) · 5.7 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
import useIsInitialStateWithoutFilter from "@/hooks/useIsInitialStateWithoutFilter";
import Image from "next/image";
import { useEffect, useRef, useState } from "react";
import { AppMenu } from "../appMenu";
import AppsIcon from "../svgs/AppsIcon";
import DayIcon from "../svgs/DayIcon";
import NightIcon from "../svgs/NightIcon";
import SearchBox from "@/components/customSearchbox/SearchBox";
import SearchBoxView from "@/components/customSearchbox/SearchBoxView";
import Link from "next/link";
import useSearchQuery from "@/hooks/useSearchQuery";
import { removeMarkdownCharacters } from "@/utils/elastic-search-ui-functions";
import { useTheme } from "@/context/Theme";
import { Tooltip } from "@chakra-ui/react";
function ThemeSwitcher() {
const { theme, toggleTheme } = useTheme();
const isLight = theme === "light";
const switchStyle = `flex basis-1/2 items-center justify-center rounded-lg transition-[background-color] duration-500`;
return (
<div className="relative w-20 2xl:w-24">
<div className="relative flex overflow-hidden rounded-lg w-20 h-9 2xl:w-24 2xl:h-12 border border-custom-stroke bg-custom-background">
<button
onClick={toggleTheme}
className={`${switchStyle} ${isLight ? "bg-custom-hover-state" : ""}`}
>
<DayIcon className="md:w-4 text-custom-accent dark:text-custom-primary-text" />
</button>
<button
onClick={toggleTheme}
className={`${switchStyle} ${
!isLight ? "bg-custom-hover-state" : ""
}`}
>
<NightIcon
svgProps={{ className: "text-custom-primary-text md:w-4" }}
pathProps={{
className:
"dark:fill-custom-primary-text text-custom-secondary-text",
}}
/>
</button>
</div>
<div
className={`rounded-lg top-0 absolute w-1/2 h-full border border-custom-brightOrange-100 dark:border-custom-stroke transition-all duration-300 ${
isLight ? "left-0" : "left-10 2xl:left-12"
}`}
/>
</div>
);
}
const MenuSwitcher = () => {
const popoverRef = useRef<HTMLDivElement>(null);
const buttonRef = useRef<HTMLButtonElement>(null);
const [open, setIsOpen] = useState(false);
useEffect(() => {
const handleClickOutside = (event) => {
if (
popoverRef.current &&
!popoverRef.current.contains(event.target) &&
buttonRef.current &&
!buttonRef.current.contains(event.target)
) {
setIsOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, []);
return (
<div className="relative flex flex-col">
<button ref={buttonRef} onClick={() => setIsOpen((v) => !v)} className="">
<Tooltip
color="#fafafa"
hasArrow
label="All Tools by the Bitcoin Dev Project"
className="bg-custom-black text-custom-primary-text text-center text-sm font-medium"
padding="16px"
borderRadius="8px"
maxW="180px"
mx="4px"
isDisabled={open}
bgColor="var(--black)"
placement="bottom-end"
>
<div
className={`flex flex-col rounded-lg border border-custom-brightOrange-100 dark:border-custom-stroke w-9 h-9 2xl:w-12 2xl:h-12 items-center justify-center transition-[background-color] duration-200 ${
open
? "bg-custom-hover-state shadow-custom-sm"
: "bg-custom-background"
}`}
>
<div data-freeze-body={open}>
<AppsIcon className="md:w-7" />
</div>
</div>
</Tooltip>
</button>
<div className="relative">
<div
data-is-open={open}
ref={popoverRef}
className="hidden data-[is-open=true]:block absolute top-0 right-0 mt-3 md:mt-4"
>
<AppMenu />
</div>
</div>
</div>
);
};
const NavBar = () => {
const { hiddenHomeFacet } = useIsInitialStateWithoutFilter();
const { makeQuery } = useSearchQuery();
const handleSubmit = (input: string) => {
makeQuery(input);
};
const handleAutoCompleteSelect = (selection) => {
if (!selection.suggestion) return;
makeQuery(removeMarkdownCharacters(selection.suggestion));
};
return (
<nav
className={`navBar pointer-events-auto fixed top-0 text-left md:text-center w-full text-xs md:text-base 2xl:text-xl leading-normal z-40 ${
hiddenHomeFacet ? "bg-custom-hover-state shadow-md" : ""
}`}
>
<div
className={`flex items-center justify-between p-3 md:p-5 2xl:p-7 w-full max-w-[1920px] m-auto ${
!hiddenHomeFacet ? "flex-row-reverse" : ""
}`}
>
<Link className={hiddenHomeFacet ? "" : "hidden"} href="/">
<Image
src="/btc-main.png"
className="max-w-[140px] lg:max-w-[240px] 2xl:max-w-[300px] "
alt="bitcoin logo"
width={459}
height={69}
priority
/>
</Link>
{hiddenHomeFacet && (
<div className="hidden md:block w-[45vw]">
<SearchBox
autocompleteMinimumCharacters={3}
view={SearchBoxView}
autocompleteSuggestions={true}
debounceLength={0}
onSubmit={handleSubmit}
className="w-auto mx-10"
onSelectAutocomplete={handleAutoCompleteSelect}
/>
</div>
)}
<div className="flex items-center gap-3 md:gap-4">
<ThemeSwitcher />
<MenuSwitcher />
</div>
</div>
</nav>
);
};
export default NavBar;