diff options
Diffstat (limited to 'docs/src/components/Header/Search.tsx')
-rw-r--r-- | docs/src/components/Header/Search.tsx | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/docs/src/components/Header/Search.tsx b/docs/src/components/Header/Search.tsx index 6236b5806..8f2cfe649 100644 --- a/docs/src/components/Header/Search.tsx +++ b/docs/src/components/Header/Search.tsx @@ -6,88 +6,88 @@ import '@docsearch/css/dist/style.css'; import './Search.css'; const { DocSearchModal, useDocSearchKeyboardEvents } = - (docsearch as unknown as { default: typeof docsearch }).default || docsearch; + (docsearch as unknown as { default: typeof docsearch }).default || docsearch; export default function Search(props) { - const [isOpen, setIsOpen] = useState(false); - const searchButtonRef = useRef(); - const [initialQuery, setInitialQuery] = useState(null); - const { lang = 'en' } = props; + const [isOpen, setIsOpen] = useState(false); + const searchButtonRef = useRef(); + const [initialQuery, setInitialQuery] = useState(null); + const { lang = 'en' } = props; - const onOpen = useCallback(() => { - setIsOpen(true); - }, [setIsOpen]); + const onOpen = useCallback(() => { + setIsOpen(true); + }, [setIsOpen]); - const onClose = useCallback(() => { - setIsOpen(false); - }, [setIsOpen]); + const onClose = useCallback(() => { + setIsOpen(false); + }, [setIsOpen]); - const onInput = useCallback( - (e) => { - setIsOpen(true); - setInitialQuery(e.key); - }, - [setIsOpen, setInitialQuery] - ); + const onInput = useCallback( + (e) => { + setIsOpen(true); + setInitialQuery(e.key); + }, + [setIsOpen, setInitialQuery] + ); - useDocSearchKeyboardEvents({ - isOpen, - onOpen, - onClose, - onInput, - searchButtonRef, - }); + useDocSearchKeyboardEvents({ + isOpen, + onOpen, + onClose, + onInput, + searchButtonRef, + }); - return ( - <> - <button - type="button" - ref={searchButtonRef} - onClick={onOpen} - className="search-input" - > - <svg width="24" height="24" fill="none"> - <path - d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" - stroke="currentColor" - strokeWidth="2" - strokeLinecap="round" - strokeLinejoin="round" - /> - </svg> - <span className="search-placeholder">Search</span> - <span className="search-hint"> - <span className="sr-only">Press </span> - <kbd>/</kbd> - <span className="sr-only"> to search</span> - </span> - </button> - {isOpen && - createPortal( - <DocSearchModal - initialQuery={initialQuery} - initialScrollY={window.scrollY} - onClose={onClose} - indexName="astro" - apiKey="0f387260ad74f9cbf4353facd29c919c" - // Set facetFilters once Astro docs have been indexed by language - // searchParameters={{ facetFilters: [`lang:${lang}`] }} - transformItems={(items) => { - return items.map((item) => { - // We transform the absolute URL into a relative URL to - // work better on localhost, preview URLS. - const a = document.createElement('a'); - a.href = item.url; - const hash = a.hash === '#overview' ? '' : a.hash; - return { - ...item, - url: `${a.pathname}${hash}`, - }; - }); - }} - />, - document.body - )} - </> - ); + return ( + <> + <button + type="button" + ref={searchButtonRef} + onClick={onOpen} + className="search-input" + > + <svg width="24" height="24" fill="none"> + <path + d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" + stroke="currentColor" + strokeWidth="2" + strokeLinecap="round" + strokeLinejoin="round" + /> + </svg> + <span className="search-placeholder">Search</span> + <span className="search-hint"> + <span className="sr-only">Press </span> + <kbd>/</kbd> + <span className="sr-only"> to search</span> + </span> + </button> + {isOpen && + createPortal( + <DocSearchModal + initialQuery={initialQuery} + initialScrollY={window.scrollY} + onClose={onClose} + indexName="astro" + apiKey="0f387260ad74f9cbf4353facd29c919c" + // Set facetFilters once Astro docs have been indexed by language + // searchParameters={{ facetFilters: [`lang:${lang}`] }} + transformItems={(items) => { + return items.map((item) => { + // We transform the absolute URL into a relative URL to + // work better on localhost, preview URLS. + const a = document.createElement('a'); + a.href = item.url; + const hash = a.hash === '#overview' ? '' : a.hash; + return { + ...item, + url: `${a.pathname}${hash}`, + }; + }); + }} + />, + document.body + )} + </> + ); } |