2022-09-29 01:59:28 +00:00
|
|
|
import Link from 'next/link'
|
2022-09-30 21:15:06 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2022-09-29 01:59:28 +00:00
|
|
|
import GitHub from './GitHub'
|
|
|
|
import { LineChart } from './LineChart'
|
|
|
|
import ThemeSwitcher from './ThemeSwitcher'
|
|
|
|
|
|
|
|
type HeaderProps = {
|
|
|
|
name: string
|
|
|
|
darkMode: boolean
|
|
|
|
setDarkMode: (state: boolean) => void
|
2022-10-01 20:32:01 +00:00
|
|
|
searchIndex: SearchIndex
|
2022-09-29 01:59:28 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 21:15:06 +00:00
|
|
|
import * as React from 'react'
|
2022-10-01 20:32:01 +00:00
|
|
|
import Search from './Search'
|
2023-02-26 01:12:11 +00:00
|
|
|
import { SearchIndex, SearchItem } from '../utils/search'
|
|
|
|
import Fuse from 'fuse.js'
|
2022-09-30 21:15:06 +00:00
|
|
|
|
|
|
|
interface NavLinkProps {
|
|
|
|
href: string
|
|
|
|
name: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const NavLink: React.FunctionComponent<NavLinkProps> = (props) => {
|
|
|
|
const router = useRouter()
|
|
|
|
const bg = router.asPath.startsWith(props.href)
|
|
|
|
? 'bg-rose-100 dark:bg-rose-900'
|
|
|
|
: ''
|
|
|
|
return (
|
2023-02-26 01:12:11 +00:00
|
|
|
<Link
|
|
|
|
href={props.href}
|
|
|
|
className={`m-0.5 p-1 self-end hover:ring-1 ring-black dark:ring-white hover:bg-rose-300 dark:hover:bg-rose-700 ${bg} rounded`}
|
|
|
|
>
|
|
|
|
{props.name}
|
2022-09-30 21:15:06 +00:00
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-10-01 20:32:01 +00:00
|
|
|
export default function Header({
|
|
|
|
name,
|
|
|
|
darkMode,
|
|
|
|
setDarkMode,
|
|
|
|
searchIndex,
|
|
|
|
}: HeaderProps) {
|
2022-09-30 21:15:06 +00:00
|
|
|
const router = useRouter()
|
2023-02-26 01:12:11 +00:00
|
|
|
const fuse = React.useMemo(() => {
|
|
|
|
const options: Fuse.IFuseOptions<SearchItem> = {}
|
|
|
|
return new Fuse(
|
|
|
|
searchIndex.list,
|
|
|
|
options,
|
|
|
|
Fuse.parseIndex(searchIndex.index)
|
|
|
|
)
|
|
|
|
}, [searchIndex])
|
|
|
|
|
2022-09-29 01:59:28 +00:00
|
|
|
return (
|
|
|
|
<div className="border-b-1 backdrop-blur-lg bg-white dark:bg-black bg-opacity-20 dark:bg-opacity-20 transition">
|
2022-09-30 21:15:06 +00:00
|
|
|
<header className="max-w-3xl mx-auto m-0 p-1 grow flex w-full">
|
2022-09-29 01:59:28 +00:00
|
|
|
<h1 className="px-2 text-3xl dark:text-white self-end">
|
2023-02-26 14:37:41 +00:00
|
|
|
<Link href="/" className="font-bold" data-cy="top-link">
|
|
|
|
{name}
|
2022-09-29 01:59:28 +00:00
|
|
|
</Link>
|
|
|
|
</h1>
|
2022-09-30 21:15:06 +00:00
|
|
|
{router.asPath != '/' && (
|
|
|
|
<div className="flex text-md items-stretch self-stretch mx-1">
|
|
|
|
<NavLink href="/variables" name="Vars" />
|
|
|
|
<NavLink href="/config_settings" name="Config" />
|
|
|
|
<NavLink href="/lua" name="Lua" />
|
|
|
|
</div>
|
|
|
|
)}
|
2022-10-05 01:55:32 +00:00
|
|
|
<LineChart width={380} height={40} darkMode={darkMode} />
|
2023-02-26 01:12:11 +00:00
|
|
|
<Search fuse={fuse} />
|
2022-09-30 21:15:06 +00:00
|
|
|
<div className="flex">
|
2022-09-29 01:59:28 +00:00
|
|
|
<div className="border-r mx-1 px-1 border-slate-700">
|
|
|
|
<a href="https://github.com/brndnmtthws/conky">
|
|
|
|
<GitHub />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div className="mx-1 px-1 flex place-content-center place-items-center">
|
|
|
|
<ThemeSwitcher setDarkMode={setDarkMode} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|