--- trunk/docs/components/Searching/Search.tsx 2024/08/30 10:10:56 625 +++ trunk/docs/components/Searching/Search.tsx 2024/09/07 09:38:45 626 @@ -2,16 +2,18 @@ import useIsDesktop from "@/hooks/useIsDesktop"; import usePlatform from "@/hooks/usePlatform"; -import styles from "@/styles/Search.module.css"; import { Button } from "@mui/material"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { MdSearch } from "react-icons/md"; -import SearchModal from "./SearchModal"; +import SearchInput from "./SearchInput"; +import SearchResults from "./SearchResults"; export default function Search() { const platform = usePlatform(); const isDesktop = useIsDesktop(); - const [modalOpen, setModalOpen] = useState(false); + const ref = useRef(null); + const [query, setQuery] = useState(null); + const [toggled, setToggled] = useState(false); useEffect(() => { const callback = (event: KeyboardEvent) => { @@ -21,46 +23,59 @@ event.code === "KeyK") ) { event.preventDefault(); - setTimeout(() => setModalOpen(true), 120); - } else if (event.code === "Escape" && modalOpen) { - event.preventDefault(); - setModalOpen(false); + ref.current?.focus(); } }; window.addEventListener("keydown", callback); return () => window.removeEventListener("keydown", callback); - }, [modalOpen]); + }, [platform]); return ( <> -
+
+ {isDesktop && } + + {query && isDesktop && ( + setQuery(null)} + /> + )} + {!isDesktop && ( )} - {isDesktop && } - {isDesktop && ( + + {!isDesktop && toggled && (
setModalOpen(true)} + className="fixed top-0 left-0 w-screen h-screen bg-black/30 z-[100000005]" + onClick={() => setToggled(false)} > - Search anything +
event.stopPropagation()} + > + + + {query && ( + setQuery(null)} + /> + )} +
)} - {isDesktop && ( - - {platform === "darwin" ? "⌘" : "Ctrl +"} K - - )}
- {modalOpen && setModalOpen(false)} />} ); }