-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathHeader.js
More file actions
89 lines (80 loc) · 3.2 KB
/
Header.js
File metadata and controls
89 lines (80 loc) · 3.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
import { Navbar, Container } from "react-bootstrap";
import "./Header.css";
import { useContext, useState, useEffect, useRef } from "react";
import logo from "./../logo.png";
import logo_white from "./../logo-white.png";
import { useDebouncedCallback } from "use-debounce";
// Context
import { ThemeContext } from "../Context/themeContext";
import Darkmode from "./Buttons/Darkmode";
import CustomSelect from "./Buttons/Language";
const Header = ({ language, setLanguage, setInputSearch }) => {
const { theme, changeTheme } = useContext(ThemeContext);
const [input, setInput] = useState(""); // Mirrors inputSearch and setInputSearch
const debouncedInput = useDebouncedCallback(
(value) => {
setInputSearch(value);
},
// delay in ms
1000
);
const handleInputSearch = (inputValue) => {
setInputExpanded(true); // Keep input expanded while typing
setInput(inputValue);
debouncedInput(inputValue);
};
useEffect(() => {
setInputSearch(input);
}, [input, setInputSearch]);
const [inputExpanded, setInputExpanded] = useState(false); // Control input expansion state
const handleSearchClick = () => {
setInputExpanded((prev) => !prev); // Expand input when clicked
};
return (
<Navbar id="header" expand="lg" variant="light">
<Container className=" flex lg:flex-row flex-col justify-center items-center w-full px-4">
<Navbar.Brand href="/" className="d-none d-sm-block ">
{theme.mode === "light" ? (
<img src={logo_white} alt="Logo" className="w-24 h-24"></img>
) : (
<img src={logo} alt="Logo" className="w-24 h-24"></img>
)}
</Navbar.Brand>
<div className="flex justify-around items-center gap-11 w-full">
<label
className={`${
theme.mode === "light" ? "bg-slate-200" : "bg-slate-500"
} flex rounded-3xl p-2 h-11 w-full md:w-[40rem]`}
>
<CustomSelect
theme={theme} // Correctly pass theme directly
language={language} // Correctly pass language
setLanguage={setLanguage} // Correctly pass setLanguage
/>
{/* Project Search Bar */}
<input
type="text"
className={`transition-all h-7 ml-2 border-solid border-l-2 border-l-violet-950 pl-2 duration-1000 ease-in-out focus:outline-none outline-none ${
inputExpanded ? "w-1/2 pl-5 border-b-slate-300 border-b-2 border-solid" : "w-1/2"
} bg-transparent ${theme.mode === "dark" ? "opacity-100 text-slate-200" : "opacity-70 text-slate-800"}`}
placeholder="Search"
autoComplete="off"
onMouseEnter={handleSearchClick}
onMouseLeave={handleSearchClick}
onKeyUp={(e) => handleInputSearch(e.target.value)}
/>
</label>
<div
onClick={changeTheme}
className={"cursor-pointer max-lg:!hidden hover:scale-105 transition-all ease-linear duration-200"}
style={{ fontSize: "1.5rem" }}
aria-hidden="true"
>
<Darkmode />
</div>
</div>
</Container>
</Navbar>
);
};
export default Header;