metacubexd/src/components/Header.tsx

111 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-08-27 22:25:41 +08:00
import { A, useLocation, useNavigate } from '@solidjs/router'
2023-08-24 04:20:53 +08:00
import {
IconFileStack,
IconGlobe,
IconHome,
IconNetwork,
IconNetworkOff,
2023-08-28 22:28:30 +08:00
IconPalette,
2023-08-24 04:20:53 +08:00
IconRuler,
IconSettings,
} from '@tabler/icons-solidjs'
2023-08-29 00:03:32 +08:00
import { For, ParentComponent, Show } from 'solid-js'
2023-08-27 22:25:41 +08:00
import { themes } from '~/constants'
import { setCurTheme, setSelectedEndpoint } from '~/signals'
2023-08-24 04:20:53 +08:00
2023-08-29 00:03:32 +08:00
const Nav: ParentComponent<{ href: string; tooltip: string }> = ({
href,
tooltip,
children,
}) => (
<li>
<A
class="tooltiptooltip-bottom rounded-full"
href={href}
data-tip={tooltip}
>
{children}
</A>
</li>
)
2023-08-24 04:20:53 +08:00
export const Header = () => {
2023-08-27 22:25:41 +08:00
const location = useLocation()
2023-08-24 04:20:53 +08:00
const navigate = useNavigate()
return (
2023-08-29 00:03:32 +08:00
<ul class="menu menu-horizontal sticky left-0 top-0 z-10 flex items-center justify-center gap-2 rounded-full bg-base-200 p-2">
2023-08-27 22:25:41 +08:00
<Show when={location.pathname !== '/setup'}>
2023-08-29 00:03:32 +08:00
<Nav href="/" tooltip="Overview">
<IconHome />
</Nav>
2023-08-24 04:20:53 +08:00
2023-08-29 00:03:32 +08:00
<Nav href="/proxies" tooltip="Proxies">
<IconGlobe />
</Nav>
2023-08-24 04:20:53 +08:00
2023-08-29 00:03:32 +08:00
<Nav href="/rules" tooltip="Rules">
<IconRuler />
</Nav>
2023-08-24 04:20:53 +08:00
2023-08-29 00:03:32 +08:00
<Nav href="/conns" tooltip="Connections">
<IconNetwork />
</Nav>
2023-08-24 04:20:53 +08:00
2023-08-29 00:03:32 +08:00
<Nav href="/logs" tooltip="Logs">
<IconFileStack />
</Nav>
2023-08-24 04:20:53 +08:00
2023-08-29 00:03:32 +08:00
<Nav href="/config" tooltip="Config">
<IconSettings />
</Nav>
2023-08-24 04:20:53 +08:00
2023-08-28 22:28:30 +08:00
<li>
<button
2023-08-29 00:03:32 +08:00
class="tooltip tooltip-bottom rounded-full"
2023-08-28 22:28:30 +08:00
data-tip="Switch Endpoint"
onClick={() => {
setSelectedEndpoint('')
2023-08-24 04:20:53 +08:00
2023-08-28 22:28:30 +08:00
navigate('/setup')
}}
>
<IconNetworkOff />
</button>
</li>
2023-08-27 22:25:41 +08:00
</Show>
2023-08-28 22:28:30 +08:00
<div class="drawer drawer-end w-auto sm:ml-auto">
2023-08-27 22:25:41 +08:00
<input id="themes" type="checkbox" class="drawer-toggle" />
2023-08-28 22:53:29 +08:00
<div class="drawer-content flex items-center">
2023-08-29 00:03:32 +08:00
<label
for="themes"
class="btn btn-circle btn-primary drawer-button btn-sm"
>
2023-08-28 22:28:30 +08:00
<IconPalette />
2023-08-27 22:25:41 +08:00
</label>
</div>
<div class="drawer-side">
<label for="themes" class="drawer-overlay" />
<ul class="menu rounded-box z-50 gap-2 bg-base-300 p-2 shadow">
<For each={themes}>
{(theme) => (
<li
data-theme={theme}
class="btn btn-xs"
onClick={() => setCurTheme(theme)}
>
{theme}
</li>
)}
</For>
</ul>
</div>
</div>
2023-08-28 22:28:30 +08:00
</ul>
2023-08-24 04:20:53 +08:00
)
}