import React from 'react' import { StatelessComponent, ReactElement } from 'react'; import { navigate } from "gatsby" import useHierarchy from '../hooks/useHierarchy'; import { DocSearch } from '@docsearch/react'; import '@docsearch/css'; const makeUrlRelative = (url: string) => { // Use an anchor tag to parse the absolute url into a relative url // eslint-disable-next-line no-undef const a = document.createElement(`a`); a.href = url; return `${a.pathname}${a.hash}`; }; const handleClick = (event: Event, url: string) => { event.preventDefault(); navigate(url); } const SearchBox: StatelessComponent = (): ReactElement|null => { const { getCurrentVersion } = useHierarchy(); return ( navigate(makeUrlRelative(itemUrl)), }} // Overrides the link container for search results so we can use gatsby navigation instead of full page loads hitComponent={({ hit, children }) => { const relativeUrl = makeUrlRelative(hit.url); // We can't use a gatsby component here - for some reason it makes the links disappear on hover return handleClick(e, relativeUrl)} href={relativeUrl}>{children} }} /> ); }; export default SearchBox;