import "@docsearch/css"; import { DocSearchModal, useDocSearchKeyboardEvents } from "@docsearch/react"; import { useTheme } from "next-themes"; import Link from "next/link"; import { useCallback, useEffect, useState } from "react"; import { createPortal } from "react-dom"; const docSearchConfig = { appId: process.env.NEXT_PUBLIC_DOCSEARCH_APP_ID || "", apiKey: process.env.NEXT_PUBLIC_DOCSEARCH_API_KEY || "", indexName: process.env.NEXT_PUBLIC_DOCSEARCH_INDEX_NAME || "", }; interface HitProps { hit: { url: string }; children: React.ReactNode; } const Hit = ({ hit, children }: HitProps) => { return {children}; }; const SearchIcon = (props: any) => { return ( ); }; export const Search = () => { let { resolvedTheme } = useTheme(); let isLightMode = resolvedTheme === "light"; let [isOpen, setIsOpen] = useState(false); let [modifierKey, setModifierKey] = useState(); const onOpen = useCallback(() => { setIsOpen(true); }, [setIsOpen]); const onClose = useCallback(() => { setIsOpen(false); }, [setIsOpen]); useDocSearchKeyboardEvents({ isOpen, onOpen, onClose }); useEffect(() => { setModifierKey(/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) ? "⌘" : "Ctrl "); }, []); useEffect(() => { const style = document.createElement("style"); style.innerHTML = ` :root { --docsearch-primary-color: ${isLightMode ? "#00C4B8" : "#00C4B8"}; --docsearch-modal-background: ${isLightMode ? "#f8fafc" : "#0f172a"}; --docsearch-text-color: ${isLightMode ? "#121212" : "#FFFFFF"}; --docsearch-hit-background: ${isLightMode ? "#FFFFFF" : "#111111"}; --docsearch-footer-background: ${isLightMode ? "#EEEEEE" : "#121212"}; --docsearch-searchbox-focus-background: ${isLightMode ? "#f1f5f9" : "#1e293b"}; --docsearch-modal-shadow: ""; --DocSearch-Input: ${isLightMode ? "#000000" : "#FFFFFF"}; } .DocSearch-Hit-title { color: ${isLightMode ? "#000000" : "#FFFFFF"}; } .DocSearch-Modal { margin: 16rem auto auto; } [type='search']:focus { --tw-ring-color: none; } .DocSearch-Button-Container { width: 200px !important; } .DocSearch-Hit-Container { color: var(--color-text-primary); } .DocSearch-Input { outline: none; } .DocSearch-Screen-Icon { visibility: hidden; } #docsearch-input { background-color: transparent; } .DocSearch-Footer { display: none !important; } `; document.head.appendChild(style); return () => { document.head.removeChild(style); }; }, [isLightMode]); return ( <> {isOpen && createPortal( , document.body )} ); };