Skip to content

Commit dd213e2

Browse files
committed
menghapus hamburger menu dan memanjangkan input ketika device mobile
1 parent 1e16a44 commit dd213e2

File tree

2 files changed

+17
-71
lines changed

2 files changed

+17
-71
lines changed

src/components/Input/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { memo } from "react";
22

33
const Input = ({ width, ...props }) => (
44
<input
5-
className={`search-input truncate outline-none px-5 py-1 rounded-full bg-slate-800 text-base ring-2 focus:ring-4 focus:ring-sky-500 transition-all selection:bg-rose-700 selection:text-rose-300 font-bold ${width}`}
5+
className={`search-input truncate outline-none px-5 py-2 md:py-1 rounded-full bg-slate-800 text-base ring-2 focus:ring-4 focus:ring-sky-500 transition-all selection:bg-rose-700 selection:text-rose-300 font-bold ${width}`}
66
{...props}
77
/>
88
);

src/components/Navbar/index.js

+16-70
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1+
import Input from "@/components/Input";
12
import Link from "next/link";
2-
import { memo } from "react";
33
import { useRouter } from "next/router";
4-
import { useEffect, useState } from "react";
5-
import createRoute from "@/helper/createRoute";
6-
import { For } from "@/utils";
7-
import Input from "@/components/Input";
8-
9-
const routes = [
10-
createRoute("/", "Home"),
11-
createRoute("/genre", "Genre List"),
12-
createRoute("/season", "Season Anime"),
13-
];
4+
import { memo, useEffect, useState } from "react";
145

156
const Navbar = () => {
167
const router = useRouter();
@@ -22,24 +13,12 @@ const Navbar = () => {
2213
e.preventDefault();
2314
if (inputValue.length === 0) return;
2415
router.push(`/search/${inputValue.split(" ").join("+")}`);
25-
setInputValue("");
2616
};
2717

2818
useEffect(() => {
29-
const toggle = document.getElementById("toggle");
3019
const navUl = document.querySelector("nav ul");
3120
const searchInput = document.querySelector("form input.search-input");
3221

33-
const openNavMenu = () => {
34-
toggle.classList.add("hamburger-active");
35-
navUl.classList.remove("hidden");
36-
navUl.classList.add("flex");
37-
38-
setTimeout(() => {
39-
navUl.classList.add("slide");
40-
}, 10);
41-
};
42-
4322
const closeNavMenu = () => {
4423
toggle.classList.remove("hamburger-active");
4524
navUl.classList.remove("slide");
@@ -50,11 +29,6 @@ const Navbar = () => {
5029
}, 100);
5130
};
5231

53-
const toggleFunc = () => {
54-
if (!navUl.classList.contains("slide")) openNavMenu();
55-
else closeNavMenu();
56-
};
57-
5832
const searchInputKeypressFunc = (e) => {
5933
if (e.key === "Enter") closeNavMenu();
6034
};
@@ -64,20 +38,18 @@ const Navbar = () => {
6438
closeNavMenu();
6539
};
6640

67-
toggle.addEventListener("click", toggleFunc);
6841
searchInput.addEventListener("keypress", searchInputKeypressFunc);
6942
window.addEventListener("click", windowClickFunc);
7043

7144
return () => {
72-
toggle.removeEventListener("click", toggleFunc);
7345
searchInput.removeEventListener("keypress", searchInputKeypressFunc);
7446
window.removeEventListener("click", windowClickFunc);
7547
};
7648
}, []);
7749

7850
return (
7951
<header>
80-
<nav className="bg-gray-900 py-2.5 2xl:py-3 z-[999] w-full transition-all duration-300 text-white border-b relative border-b-slate-700">
52+
<nav className="bg-gray-900 py-1.5 md:py-2.5 2xl:py-3 z-[999] w-full transition-all duration-300 text-white border-b relative border-b-slate-700">
8153
<div className="container flex justify-between items-center py-1 relative">
8254
<div>
8355
<h1 className="text-center bg-gradient-to-r from-sky-500 to-indigo-500 bg-clip-text text-transparent font-bold text-3xl 2xl:text-4xl hidden md:block">
@@ -87,36 +59,7 @@ const Navbar = () => {
8759
</a>
8860
</Link>
8961
</h1>
90-
<form onSubmit={submitHandler} className="md:hidden">
91-
<Input
92-
type="search"
93-
name="search"
94-
placeholder="Search Anime Here ..."
95-
autoComplete="off"
96-
width="w-11/12"
97-
value={inputValue}
98-
onChange={searchFunc}
99-
/>
100-
</form>
10162
</div>
102-
<ul className="absolute text-lg font-semibold right-0 flex-col bg-slate-800 backdrop-blur-lg h-[50vh] md:h-[30vh] xl:h-[40vh] top-[75px] bottom-0 justify-evenly items-center -z-[199] w-[65%] md:w-[30%] lg:w-[20%] transition-all duration-200 rounded-md border border-slate-600 navbar-nav px-8 md:px-0 hidden">
103-
<For
104-
each={routes}
105-
render={({ path, name }, index) => (
106-
<li key={index}>
107-
<Link href={path}>
108-
<a
109-
className={`transition-all duration-200 py-1 border-b-2 border-transparent hover:border-b-slate-200 selection:bg-emerald-500 selection:text-emerald-900 ${
110-
currentPath === path.split("/")[1] ? "active" : ""
111-
}`}
112-
>
113-
{name}
114-
</a>
115-
</Link>
116-
</li>
117-
)}
118-
/>
119-
</ul>
12063
<div className="flex items-center justify-center">
12164
<div className="hidden md:block mr-4">
12265
<form onSubmit={submitHandler}>
@@ -130,18 +73,21 @@ const Navbar = () => {
13073
/>
13174
</form>
13275
</div>
133-
<div className="relative">
134-
<input
135-
type="checkbox"
136-
id="toggle"
137-
className="absolute w-[30px] h-[30px] z-[999] opacity-0 cursor-pointer"
138-
/>
139-
<span className="hamburger-line origin-top-right"></span>
140-
<span className="hamburger-line"></span>
141-
<span className="hamburger-line origin-bottom-right"></span>
142-
</div>
14376
</div>
14477
</div>
78+
<div className="container pb-2 md:hidden">
79+
<form onSubmit={submitHandler} className="md:hidden">
80+
<Input
81+
type="search"
82+
name="search"
83+
placeholder="Search Anime Here ..."
84+
autoComplete="off"
85+
width="w-full"
86+
value={inputValue}
87+
onChange={searchFunc}
88+
/>
89+
</form>
90+
</div>
14591
</nav>
14692
</header>
14793
);

0 commit comments

Comments
 (0)