import React, { StatelessComponent, ReactElement } from 'react'; import SearchBox from './SearchBox'; import { Link, navigate } from 'gatsby'; import logo from '../images/silverstripe-logo.svg'; import useDocContext from '../hooks/useDocContext'; import useHierarchy from '../hooks/useHierarchy'; interface HeaderProps { handleSidebarToggle(e: EventTarget): void } const Header: StatelessComponent = ({ handleSidebarToggle }): ReactElement => { const { getHomePage, getCurrentNode, getCurrentVersion, getVersionPath } = useHierarchy(); const home = getHomePage(); const currentNode = getCurrentNode() || home; const context = useDocContext(); const handleNavigate = (e: any): void => { if (typeof window === 'undefined') { return; } const ver = e.target.value; if (currentNode) { const newPath = getVersionPath(currentNode, ver); // This has to be a hard refresh, because the sidebar and searchbar need to unmount navigate(newPath); } }; const title = context === 'user' ? 'CMS Help' : 'CMS Docs'; return (
Silverstripe CMS Documentation {title}
{process.env.GATSBY_DOCSEARCH_API_KEY && }
); }; export default Header;