feat(frontend): improved settings menu design for mobile

pull/165/head
sct 4 years ago
parent 46d99b02b1
commit 16221a46a7

@ -2,6 +2,45 @@ import React from 'react';
import Link from 'next/link'; import Link from 'next/link';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
interface SettingsRoute {
text: string;
route: string;
regex: RegExp;
}
const settingsRoutes: SettingsRoute[] = [
{
text: 'General Settings',
route: '/settings/main',
regex: /^\/settings(\/main)?$/,
},
{
text: 'Plex',
route: '/settings/plex',
regex: /^\/settings\/plex/,
},
{
text: 'Services',
route: '/settings/services',
regex: /^\/settings\/services/,
},
{
text: 'Logs',
route: '/settings/logs',
regex: /^\/settings\/logs/,
},
{
text: 'Jobs',
route: '/settings/jobs',
regex: /^\/settings\/jobs/,
},
{
text: 'About',
route: '/settings/about',
regex: /^\/settings\/about/,
},
];
const SettingsLayout: React.FC = ({ children }) => { const SettingsLayout: React.FC = ({ children }) => {
const router = useRouter(); const router = useRouter();
const activeLinkColor = const activeLinkColor =
@ -10,50 +49,71 @@ const SettingsLayout: React.FC = ({ children }) => {
const inactiveLinkColor = const inactiveLinkColor =
'border-transparent text-cool-gray-500 hover:text-cool-gray-400 hover:border-cool-gray-300 focus:outline-none focus:text-cool-gray-4700 focus:border-cool-gray-300'; 'border-transparent text-cool-gray-500 hover:text-cool-gray-400 hover:border-cool-gray-300 focus:outline-none focus:text-cool-gray-4700 focus:border-cool-gray-300';
const settingsLink = ({ const SettingsLink: React.FC<{
text,
route,
regex,
}: {
text: string;
route: string; route: string;
regex: RegExp; regex: RegExp;
}) => { isMobile?: boolean;
}> = ({ children, route, regex, isMobile = false }) => {
if (isMobile) {
return <option value={route}>{children}</option>;
}
return ( return (
<Link href={route}> <Link href={route}>
<a <a
className={`whitespace-no-wrap pb-4 px-1 border-b-2 font-medium text-sm leading-5 ${ className={`whitespace-no-wrap ml-8 first:ml-0 py-4 px-1 border-b-2 border-transparent font-medium text-sm leading-5 ${
!!router.pathname.match(regex) ? activeLinkColor : inactiveLinkColor !!router.pathname.match(regex) ? activeLinkColor : inactiveLinkColor
}`} }`}
aria-current="page" aria-current="page"
> >
{text} {children}
</a> </a>
</Link> </Link>
); );
}; };
return ( return (
<> <>
<div className="border-b border-cool-gray-600 mt-10"> <div className="mt-6">
<div className="space-y-4 sm:flex sm:items-baseline sm:space-y-0 sm:space-x-10"> <div className="sm:hidden">
<h3 className="text-lg leading-6 font-medium text-white">Settings</h3> <select
<div> onChange={(e) => {
<nav className="-mb-px flex space-x-8"> router.push(e.target.value);
{settingsLink({ }}
text: 'General Settings', onBlur={(e) => {
route: '/settings/main', router.push(e.target.value);
regex: /^\/settings(\/main)?$/, }}
})} defaultValue={
{settingsLink({ settingsRoutes.find(
text: 'Plex', (route) => !!router.pathname.match(route.regex)
route: '/settings/plex', )?.route
regex: /^\/settings\/plex/, }
})} aria-label="Selected tab"
{settingsLink({ className="bg-cool-gray-800 text-white mt-1 form-select block w-full pl-3 pr-10 py-2 text-base leading-6 border-cool-gray-700 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 sm:text-sm sm:leading-5 transition ease-in-out duration-150"
text: 'Services', >
route: '/settings/services', {settingsRoutes.map((route, index) => (
regex: /^\/settings\/services/, <SettingsLink
})} route={route.route}
regex={route.regex}
isMobile
key={`mobile-settings-link-${index}`}
>
{route.text}
</SettingsLink>
))}
</select>
</div>
<div className="hidden sm:block">
<div className="border-b border-cool-gray-600">
<nav className="-mb-px flex">
{settingsRoutes.map((route, index) => (
<SettingsLink
route={route.route}
regex={route.regex}
key={`standard-settings-link-${index}`}
>
{route.text}
</SettingsLink>
))}
</nav> </nav>
</div> </div>
</div> </div>

@ -13,6 +13,7 @@ module.exports = {
variants: { variants: {
padding: ['first', 'last'], padding: ['first', 'last'],
borderWidth: ['first', 'last'], borderWidth: ['first', 'last'],
margin: ['first', 'last', 'responsive'],
boxShadow: ['group-focus'], boxShadow: ['group-focus'],
opacity: ['disabled'], opacity: ['disabled'],
}, },

Loading…
Cancel
Save