2023-09-05 20:53:00 +08:00
|
|
|
import { A, useLocation } from '@solidjs/router'
|
2023-08-24 04:20:53 +08:00
|
|
|
import {
|
|
|
|
IconFileStack,
|
|
|
|
IconGlobe,
|
|
|
|
IconHome,
|
2023-09-22 15:07:13 +08:00
|
|
|
IconLanguage,
|
2023-08-30 00:22:40 +08:00
|
|
|
IconMenu,
|
2023-08-24 04:20:53 +08:00
|
|
|
IconNetwork,
|
2023-08-28 22:28:30 +08:00
|
|
|
IconPalette,
|
2023-08-24 04:20:53 +08:00
|
|
|
IconRuler,
|
|
|
|
IconSettings,
|
|
|
|
} from '@tabler/icons-solidjs'
|
2023-09-06 20:06:26 +08:00
|
|
|
import { For, ParentComponent, Show, createSignal } from 'solid-js'
|
2023-09-22 15:07:13 +08:00
|
|
|
import { Button, LogoText } from '~/components'
|
|
|
|
import { LANG, ROUTES, themes } from '~/constants'
|
2023-09-22 17:14:35 +08:00
|
|
|
import { useI18n } from '~/i18n'
|
2023-09-06 20:06:26 +08:00
|
|
|
import { setCurTheme } 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,
|
|
|
|
}) => (
|
2023-09-02 02:39:02 +08:00
|
|
|
<li class="tooltip tooltip-bottom" data-tip={tooltip}>
|
|
|
|
<A class="rounded-box" href={href}>
|
2023-08-29 00:03:32 +08:00
|
|
|
{children}
|
|
|
|
</A>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
const ThemeSwitcher = () => (
|
|
|
|
<div class="drawer drawer-end w-auto sm:ml-auto">
|
|
|
|
<input id="themes" type="checkbox" class="drawer-toggle" />
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
<div class="drawer-content flex items-center">
|
|
|
|
<label
|
|
|
|
for="themes"
|
|
|
|
class="btn btn-circle btn-primary drawer-button btn-sm"
|
|
|
|
>
|
|
|
|
<IconPalette />
|
|
|
|
</label>
|
|
|
|
</div>
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
<div class="drawer-side">
|
|
|
|
<label for="themes" class="drawer-overlay" />
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-09-10 16:42:00 +08:00
|
|
|
<ul class="menu rounded-l-box gap-2 bg-base-300 p-2">
|
2023-08-30 00:22:40 +08:00
|
|
|
<For each={themes}>
|
|
|
|
{(theme) => (
|
|
|
|
<li
|
|
|
|
data-theme={theme}
|
|
|
|
class="btn btn-xs"
|
|
|
|
onClick={() => setCurTheme(theme)}
|
|
|
|
>
|
|
|
|
{theme}
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
export const Header = () => {
|
2023-09-22 17:14:35 +08:00
|
|
|
const { t, locale } = useI18n()
|
2023-09-06 20:06:26 +08:00
|
|
|
const navs = () => [
|
|
|
|
{
|
|
|
|
href: ROUTES.Overview,
|
|
|
|
name: t('overview'),
|
|
|
|
icon: <IconHome />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: ROUTES.Proxies,
|
|
|
|
name: t('proxies'),
|
|
|
|
icon: <IconGlobe />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: ROUTES.Rules,
|
|
|
|
name: t('rules'),
|
|
|
|
icon: <IconRuler />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: ROUTES.Conns,
|
|
|
|
name: t('connections'),
|
|
|
|
icon: <IconNetwork />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: ROUTES.Log,
|
|
|
|
name: t('logs'),
|
|
|
|
icon: <IconFileStack />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: ROUTES.Config,
|
|
|
|
name: t('config'),
|
|
|
|
icon: <IconSettings />,
|
|
|
|
},
|
|
|
|
]
|
2023-09-01 23:25:37 +08:00
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
const location = useLocation()
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-31 02:21:41 +08:00
|
|
|
const [openedDrawer, setOpenedDrawer] = createSignal(false)
|
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
return (
|
2023-09-10 16:42:00 +08:00
|
|
|
<ul class="navbar sticky inset-x-0 top-0 z-50 flex w-auto items-center justify-center bg-base-300 px-4 shadow-lg">
|
2023-08-31 01:30:08 +08:00
|
|
|
<div class="navbar-start gap-4">
|
2023-09-10 16:42:00 +08:00
|
|
|
<div class="drawer w-auto lg:hidden">
|
2023-08-31 02:21:41 +08:00
|
|
|
<input
|
|
|
|
id="navs"
|
|
|
|
type="checkbox"
|
|
|
|
class="drawer-toggle"
|
|
|
|
onChange={(e) => setOpenedDrawer(e.target.checked)}
|
|
|
|
checked={openedDrawer()}
|
|
|
|
/>
|
2023-08-24 04:20:53 +08:00
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
<div class="drawer-content flex items-center">
|
|
|
|
<label for="navs" class="btn btn-circle drawer-button btn-sm">
|
|
|
|
<IconMenu />
|
|
|
|
</label>
|
|
|
|
</div>
|
2023-08-27 22:25:41 +08:00
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
<div class="drawer-side">
|
|
|
|
<label for="navs" class="drawer-overlay" />
|
2023-08-27 22:25:41 +08:00
|
|
|
|
2023-09-10 16:42:00 +08:00
|
|
|
<ul class="menu rounded-r-box min-h-full w-2/5 gap-2 bg-base-300 pt-20">
|
2023-08-30 00:22:40 +08:00
|
|
|
<For each={navs()}>
|
|
|
|
{({ href, name }) => (
|
2023-08-31 02:21:41 +08:00
|
|
|
<li onClick={() => setOpenedDrawer(false)}>
|
2023-08-30 00:22:40 +08:00
|
|
|
<A href={href}>{name}</A>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-08-27 22:25:41 +08:00
|
|
|
</div>
|
|
|
|
|
2023-09-05 21:09:35 +08:00
|
|
|
<LogoText />
|
2023-08-30 00:22:40 +08:00
|
|
|
</div>
|
|
|
|
|
2023-09-04 13:08:05 +08:00
|
|
|
<Show when={location.pathname !== ROUTES.Setup}>
|
2023-08-30 00:22:40 +08:00
|
|
|
<div class="navbar-center hidden lg:flex">
|
2023-09-05 21:27:31 +08:00
|
|
|
<ul class="menu menu-horizontal menu-lg gap-2 p-0">
|
2023-08-30 00:22:40 +08:00
|
|
|
<For each={navs()}>
|
|
|
|
{({ href, name, icon }) => (
|
|
|
|
<Nav href={href} tooltip={name}>
|
|
|
|
{icon}
|
|
|
|
</Nav>
|
2023-08-27 22:25:41 +08:00
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-08-30 00:22:40 +08:00
|
|
|
</Show>
|
|
|
|
|
|
|
|
<div class="navbar-end">
|
|
|
|
<div class="flex items-center gap-2">
|
2023-09-22 15:07:13 +08:00
|
|
|
<Button
|
|
|
|
class="btn-circle btn-secondary btn-sm"
|
|
|
|
onClick={() => {
|
|
|
|
const curLocale = locale()
|
|
|
|
|
|
|
|
locale(curLocale === LANG.EN ? LANG.ZH : LANG.EN)
|
|
|
|
}}
|
2023-09-22 16:05:36 +08:00
|
|
|
icon={<IconLanguage />}
|
|
|
|
/>
|
2023-09-22 15:07:13 +08:00
|
|
|
|
2023-08-30 00:22:40 +08:00
|
|
|
<ThemeSwitcher />
|
|
|
|
</div>
|
2023-08-27 22:25:41 +08:00
|
|
|
</div>
|
2023-08-28 22:28:30 +08:00
|
|
|
</ul>
|
2023-08-24 04:20:53 +08:00
|
|
|
)
|
|
|
|
}
|