index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import { useCallback, useState } from "react";
  2. import clsx from "clsx";
  3. import Link from "next/link";
  4. import ClickAwayListener from "@mui/base/ClickAwayListener";
  5. export default function Header() {
  6. const [open, setOpen] = useState(false);
  7. const toggleMenu = useCallback(() => {
  8. setOpen((o) => !o);
  9. }, [setOpen]);
  10. const closeMenu = useCallback(() => {
  11. setOpen(false);
  12. }, [setOpen]);
  13. const toggleTheme = function () {
  14. const _html = document.documentElement;
  15. if (_html.classList.contains("dark")) {
  16. _html.classList.remove("dark");
  17. localStorage.setItem("theme", "lite");
  18. } else {
  19. _html.classList.add("dark");
  20. localStorage.setItem("theme", "dark");
  21. }
  22. };
  23. return (
  24. <header className={clsx("header", { open })}>
  25. <ClickAwayListener onClickAway={closeMenu}>
  26. <div className="container">
  27. <Link href="/">
  28. <a className="logo mr-5" title="NovelDit">
  29. {/* eslint-disable-next-line @next/next/no-img-element */}
  30. <img src="/logo.svg" alt="NovelDit" />
  31. <span>NovelDit</span>
  32. </a>
  33. </Link>
  34. <div className="menu">
  35. <nav>
  36. <ul>
  37. <li>
  38. <a className="menu-item" href="" title="Browse">
  39. <svg width="24" height="24">
  40. <use href="/icons.svg#browse"></use>
  41. </svg>
  42. <strong>Browse</strong>
  43. </a>
  44. <div className="sub-menu">
  45. <ul className="sub-menu-sized">
  46. <li>
  47. <a href="/stories/novel" title="Novels">
  48. Novels
  49. </a>
  50. <div className="sub-menu-list">
  51. <p>
  52. <strong>MALE LEAD</strong>
  53. <a href="/stories/novel-urban-male" title="Urban">
  54. Urban
  55. </a>
  56. <a
  57. href="/stories/novel-eastern-male"
  58. title="Eastern"
  59. >
  60. Eastern
  61. </a>
  62. <a href="/stories/novel-games-male" title="Games">
  63. Games
  64. </a>
  65. <a
  66. href="/stories/novel-fantasy-male"
  67. title="Fantasy"
  68. >
  69. Fantasy
  70. </a>
  71. <a href="/stories/novel-scifi-male" title="Sci-fi">
  72. Sci-fi
  73. </a>
  74. <a href="/stories/novel-acg-male" title="ACG">
  75. ACG
  76. </a>
  77. <a href="/stories/novel-horror-male" title="Horror">
  78. Horror
  79. </a>
  80. <a href="/stories/novel-sports-male" title="Sports">
  81. Sports
  82. </a>
  83. <a href="/stories/novel-action-male" title="Action">
  84. Action
  85. </a>
  86. <a href="/stories/novel-war-male" title="War">
  87. War
  88. </a>
  89. <a
  90. href="/stories/novel-realistic-male"
  91. title="Realistic"
  92. >
  93. Realistic
  94. </a>
  95. <a
  96. href="/stories/novel-history-male"
  97. title="History"
  98. >
  99. History
  100. </a>
  101. </p>
  102. <p>
  103. <strong>FEMALE LEAD</strong>
  104. <a href="/stories/novel-urban-female" title="Urban">
  105. Urban
  106. </a>
  107. <a
  108. href="/stories/novel-fantasy-female"
  109. title="Fantasy"
  110. >
  111. Fantasy
  112. </a>
  113. <a
  114. href="/stories/novel-history-female"
  115. title="History"
  116. >
  117. History
  118. </a>
  119. <a href="/stories/novel-teen-female" title="Teen">
  120. Teen
  121. </a>
  122. <a href="/stories/novel-lgbt-female" title="LGBT+">
  123. LGBT+
  124. </a>
  125. <a
  126. href="/stories/novel-scifi-female"
  127. title="Sci-fi"
  128. >
  129. Sci-fi
  130. </a>
  131. <a
  132. href="/stories/novel-general-female"
  133. title="General"
  134. >
  135. General
  136. </a>
  137. </p>
  138. </div>
  139. </li>
  140. <li>
  141. <a href="/stories/fanfic" title="Fan-fic">
  142. Fan-fic
  143. </a>
  144. <div className="sub-menu-list">
  145. <p>
  146. <a
  147. href="/stories/fanfic-anime-comics"
  148. title="Anime &amp; Comics"
  149. >
  150. Anime &amp; Comics
  151. </a>
  152. <a
  153. href="/stories/fanfic-video-games"
  154. title="Video Games"
  155. >
  156. Video Games
  157. </a>
  158. <a
  159. href="/stories/fanfic-celebrities"
  160. title="Celebrities"
  161. >
  162. Celebrities
  163. </a>
  164. <a
  165. href="/stories/fanfic-music-bands"
  166. title="Music &amp; Bands"
  167. >
  168. Music &amp; Bands
  169. </a>
  170. <a href="/stories/fanfic-movies" title="Movies">
  171. Movies
  172. </a>
  173. <a
  174. href="/stories/fanfic-book-literature"
  175. title="Book&amp;Literature"
  176. >
  177. Book&amp;Literature
  178. </a>
  179. <a href="/stories/fanfic-tv" title="TV">
  180. TV
  181. </a>
  182. <a href="/stories/fanfic-theater" title="Theater">
  183. Theater
  184. </a>
  185. <a href="/stories/fanfic-others" title="Others">
  186. Others
  187. </a>
  188. </p>
  189. </div>
  190. </li>
  191. </ul>
  192. </div>
  193. </li>
  194. <li>
  195. <a className="menu-item" href="" title="Rankings">
  196. <svg viewBox="0 0 1024 1024" width="24" height="24">
  197. <use href="/icons.svg#ranking"></use>
  198. </svg>
  199. <strong>Rankings</strong>
  200. </a>
  201. <div className="sub-menu">
  202. <ul>
  203. <li>
  204. <a
  205. href="/ranking/novel/bi_annual/power_rank?timeType=3&amp;sourceType=2&amp;signStatus=1"
  206. title="Novels ranking"
  207. >
  208. Novels ranking
  209. </a>
  210. </li>
  211. <li>
  212. <a
  213. href="/ranking/comic/all_time/comic_power_rank"
  214. title="Comics ranking"
  215. >
  216. Comics ranking
  217. </a>
  218. </li>
  219. <li>
  220. <a
  221. href="/ranking/fanfic/bi_annual/power_rank"
  222. title="Fan-fic ranking"
  223. >
  224. Fan-fic ranking
  225. </a>
  226. </li>
  227. </ul>
  228. </div>
  229. </li>
  230. </ul>
  231. </nav>
  232. <form action="./search" className="search-input">
  233. <svg className="icon-search">
  234. <use href="/icons.svg#search"></use>
  235. </svg>
  236. <input type="search" name="q" placeholder="Search" />
  237. </form>
  238. </div>
  239. <div className="buttons">
  240. <button className="btn" onClick={toggleTheme}>
  241. <svg className="icon-sun" viewBox="0 0 16 16">
  242. <use href="/icons.svg#sun"></use>
  243. </svg>
  244. <svg className="icon-moon" viewBox="0 0 16 16">
  245. <use href="/icons.svg#moon"></use>
  246. </svg>
  247. </button>
  248. <button className="btn menu-btn" onClick={toggleMenu}>
  249. <svg
  250. className="icon-menu"
  251. xmlns="http://www.w3.org/2000/svg"
  252. viewBox="0 0 16 16"
  253. >
  254. <rect
  255. x="1"
  256. y="4"
  257. width="14"
  258. height="1.5"
  259. rx="1"
  260. className="r-1"
  261. ></rect>
  262. <rect
  263. x="1"
  264. y="7.25"
  265. width="14"
  266. height="1.5"
  267. rx="1"
  268. className="r-2"
  269. ></rect>
  270. <rect
  271. x="1"
  272. y="10.5"
  273. width="14"
  274. height="1.5"
  275. rx="1"
  276. className="r-3"
  277. ></rect>
  278. </svg>
  279. </button>
  280. </div>
  281. </div>
  282. </ClickAwayListener>
  283. </header>
  284. );
  285. }