feat(header): responsive layout

This commit is contained in:
kunish 2023-08-30 00:22:40 +08:00
parent 69edb487de
commit 2d9daa96cc
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430

View File

@ -1,10 +1,11 @@
import { A, useLocation, useNavigate } from '@solidjs/router' import { A, useLocation, useNavigate } from '@solidjs/router'
import { import {
IconArrowsExchange,
IconFileStack, IconFileStack,
IconGlobe, IconGlobe,
IconHome, IconHome,
IconMenu,
IconNetwork, IconNetwork,
IconNetworkOff,
IconPalette, IconPalette,
IconRuler, IconRuler,
IconSettings, IconSettings,
@ -20,7 +21,7 @@ const Nav: ParentComponent<{ href: string; tooltip: string }> = ({
}) => ( }) => (
<li> <li>
<A <A
class="tooltiptooltip-bottom rounded-full" class="tooltip tooltip-bottom rounded-full"
href={href} href={href}
data-tip={tooltip} data-tip={tooltip}
> >
@ -29,81 +30,142 @@ const Nav: ParentComponent<{ href: string; tooltip: string }> = ({
</li> </li>
) )
const ThemeSwitcher = () => (
<div class="drawer drawer-end w-auto sm:ml-auto">
<input id="themes" type="checkbox" class="drawer-toggle" />
<div class="drawer-content flex items-center">
<label
for="themes"
class="btn btn-circle btn-primary drawer-button btn-sm"
>
<IconPalette />
</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>
)
const navs = () => [
{
href: '/',
name: 'Overview',
icon: <IconHome />,
},
{
href: '/proxies',
name: 'Proxies',
icon: <IconGlobe />,
},
{
href: '/rules',
name: 'Rules',
icon: <IconRuler />,
},
{
href: '/conns',
name: 'Connections',
icon: <IconNetwork />,
},
{
href: '/logs',
name: 'Logs',
icon: <IconFileStack />,
},
{
href: '/config',
name: 'Config',
icon: <IconSettings />,
},
]
export const Header = () => { export const Header = () => {
const location = useLocation() const location = useLocation()
const navigate = useNavigate() const navigate = useNavigate()
const onSwitchEndpointClick = () => {
setSelectedEndpoint('')
navigate('/setup')
}
return ( return (
<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"> <ul class="navbar rounded-box sticky inset-x-0 top-2 z-10 mx-2 mt-2 flex w-auto items-center justify-center bg-base-200 p-2 sm:gap-2">
<Show when={location.pathname !== '/setup'}> <div class="navbar-start">
<Nav href="/" tooltip="Overview"> <div class="drawer w-auto lg:hidden">
<IconHome /> <input id="navs" type="checkbox" class="drawer-toggle" />
</Nav>
<Nav href="/proxies" tooltip="Proxies"> <div class="drawer-content flex items-center">
<IconGlobe /> <label for="navs" class="btn btn-circle drawer-button btn-sm">
</Nav> <IconMenu />
</label>
</div>
<Nav href="/rules" tooltip="Rules"> <div class="drawer-side">
<IconRuler /> <label for="navs" class="drawer-overlay" />
</Nav>
<Nav href="/conns" tooltip="Connections"> <ul class="menu rounded-box z-50 gap-2 bg-base-300 p-2 shadow">
<IconNetwork /> <For each={navs()}>
</Nav> {({ href, name }) => (
<li>
<Nav href="/logs" tooltip="Logs"> <A href={href}>{name}</A>
<IconFileStack /> </li>
</Nav> )}
</For>
<Nav href="/config" tooltip="Config"> </ul>
<IconSettings /> </div>
</Nav>
<li>
<button
class="tooltip tooltip-bottom rounded-full"
data-tip="Switch Endpoint"
onClick={() => {
setSelectedEndpoint('')
navigate('/setup')
}}
>
<IconNetworkOff />
</button>
</li>
</Show>
<div class="drawer drawer-end w-auto sm:ml-auto">
<input id="themes" type="checkbox" class="drawer-toggle" />
<div class="drawer-content flex items-center">
<label
for="themes"
class="btn btn-circle btn-primary drawer-button btn-sm"
>
<IconPalette />
</label>
</div> </div>
<div class="drawer-side"> <a
<label for="themes" class="drawer-overlay" /> class="btn btn-ghost text-xl normal-case"
href="https://github.com/metacubex/metacubexd"
target="_blank"
>
metacubexd
</a>
</div>
<ul class="menu rounded-box z-50 gap-2 bg-base-300 p-2 shadow"> <Show when={location.pathname !== '/setup'}>
<For each={themes}> <div class="navbar-center hidden lg:flex">
{(theme) => ( <ul class="menu menu-horizontal px-1">
<li <For each={navs()}>
data-theme={theme} {({ href, name, icon }) => (
class="btn btn-xs" <Nav href={href} tooltip={name}>
onClick={() => setCurTheme(theme)} {icon}
> </Nav>
{theme}
</li>
)} )}
</For> </For>
</ul> </ul>
</div> </div>
</Show>
<div class="navbar-end">
<div class="flex items-center gap-2">
<ThemeSwitcher />
<button
class="btn btn-circle btn-secondary btn-sm"
onClick={onSwitchEndpointClick}
>
<IconArrowsExchange />
</button>
</div>
</div> </div>
</ul> </ul>
) )