mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 13:13:54 +08:00
[portal][ui] make product navigation appear in mobile menu
This commit is contained in:
@ -4,36 +4,19 @@ import { useRouter } from 'next/router';
|
|||||||
import { signIn, signOut, useSession } from 'next-auth/react';
|
import { signIn, signOut, useSession } from 'next-auth/react';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import { Fragment, useState } from 'react';
|
import { Fragment, useState } from 'react';
|
||||||
import { Dialog, Menu, Transition } from '@headlessui/react';
|
import { Menu, Transition } from '@headlessui/react';
|
||||||
import {
|
import { Bars3BottomLeftIcon } from '@heroicons/react/24/outline';
|
||||||
Bars3BottomLeftIcon,
|
|
||||||
BriefcaseIcon,
|
|
||||||
CurrencyDollarIcon,
|
|
||||||
DocumentTextIcon,
|
|
||||||
HomeIcon,
|
|
||||||
XMarkIcon,
|
|
||||||
} from '@heroicons/react/24/outline';
|
|
||||||
|
|
||||||
|
import GlobalNavigation from '~/components/global/GlobalNavigation';
|
||||||
import HomeNavigation from '~/components/global/HomeNavigation';
|
import HomeNavigation from '~/components/global/HomeNavigation';
|
||||||
import OffersNavigation from '~/components/offers/OffersNavigation';
|
import OffersNavigation from '~/components/offers/OffersNavigation';
|
||||||
import QuestionsNavigation from '~/components/questions/QuestionsNavigation';
|
import QuestionsNavigation from '~/components/questions/QuestionsNavigation';
|
||||||
import ResumesNavigation from '~/components/resumes/ResumesNavigation';
|
import ResumesNavigation from '~/components/resumes/ResumesNavigation';
|
||||||
|
|
||||||
|
import MobileNavigation from './MobileNavigation';
|
||||||
import type { ProductNavigationItems } from './ProductNavigation';
|
import type { ProductNavigationItems } from './ProductNavigation';
|
||||||
import ProductNavigation from './ProductNavigation';
|
import ProductNavigation from './ProductNavigation';
|
||||||
|
|
||||||
const sidebarNavigation = [
|
|
||||||
{ current: false, href: '/', icon: HomeIcon, name: 'Home' },
|
|
||||||
{ current: false, href: '/resumes', icon: DocumentTextIcon, name: 'Resumes' },
|
|
||||||
{
|
|
||||||
current: false,
|
|
||||||
href: '/questions',
|
|
||||||
icon: BriefcaseIcon,
|
|
||||||
name: 'Questions',
|
|
||||||
},
|
|
||||||
{ current: false, href: '/offers', icon: CurrencyDollarIcon, name: 'Offers' },
|
|
||||||
];
|
|
||||||
|
|
||||||
type Props = Readonly<{
|
type Props = Readonly<{
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}>;
|
}>;
|
||||||
@ -157,23 +140,18 @@ export default function AppShell({ children }: Props) {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-6 w-full flex-1 space-y-1 px-2">
|
<div className="mt-6 w-full flex-1 space-y-1 px-2">
|
||||||
{sidebarNavigation.map((item) => (
|
{GlobalNavigation.map((item) => (
|
||||||
<Link
|
<Link
|
||||||
key={item.name}
|
key={item.name}
|
||||||
aria-current={item.current ? 'page' : undefined}
|
|
||||||
className={clsx(
|
className={clsx(
|
||||||
item.current
|
'text-slate-700 hover:bg-slate-100',
|
||||||
? 'bg-primary-50 text-slate-700'
|
|
||||||
: 'text-slate-700 hover:bg-slate-200',
|
|
||||||
'group flex w-full flex-col items-center rounded-md p-3 text-xs font-medium',
|
'group flex w-full flex-col items-center rounded-md p-3 text-xs font-medium',
|
||||||
)}
|
)}
|
||||||
href={item.href}>
|
href={item.href}>
|
||||||
<item.icon
|
<item.icon
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className={clsx(
|
className={clsx(
|
||||||
item.current
|
'text-slate-500 group-hover:text-slate-700',
|
||||||
? 'text-primary-500'
|
|
||||||
: 'text-slate-500 group-hover:text-slate-700',
|
|
||||||
'h-6 w-6',
|
'h-6 w-6',
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@ -185,99 +163,13 @@ export default function AppShell({ children }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile menu */}
|
{/* Mobile menu */}
|
||||||
<Transition.Root as={Fragment} show={mobileMenuOpen}>
|
<MobileNavigation
|
||||||
<Dialog
|
globalNavigationItems={GlobalNavigation}
|
||||||
as="div"
|
isShown={mobileMenuOpen}
|
||||||
className="relative z-20 md:hidden"
|
productNavigationItems={currentProductNavigation.navigation}
|
||||||
onClose={setMobileMenuOpen}>
|
productTitle={currentProductNavigation.title}
|
||||||
<Transition.Child
|
setIsShown={setMobileMenuOpen}
|
||||||
as={Fragment}
|
/>
|
||||||
enter="transition-opacity ease-linear duration-300"
|
|
||||||
enterFrom="opacity-0"
|
|
||||||
enterTo="opacity-100"
|
|
||||||
leave="transition-opacity ease-linear duration-300"
|
|
||||||
leaveFrom="opacity-100"
|
|
||||||
leaveTo="opacity-0">
|
|
||||||
<div className="fixed inset-0 bg-gray-600 bg-opacity-75" />
|
|
||||||
</Transition.Child>
|
|
||||||
|
|
||||||
<div className="fixed inset-0 z-40 flex">
|
|
||||||
<Transition.Child
|
|
||||||
as={Fragment}
|
|
||||||
enter="transition ease-in-out duration-300 transform"
|
|
||||||
enterFrom="-translate-x-full"
|
|
||||||
enterTo="translate-x-0"
|
|
||||||
leave="transition ease-in-out duration-300 transform"
|
|
||||||
leaveFrom="translate-x-0"
|
|
||||||
leaveTo="-translate-x-full">
|
|
||||||
<Dialog.Panel className="relative flex w-full max-w-xs flex-1 flex-col bg-white pt-5 pb-4">
|
|
||||||
<Transition.Child
|
|
||||||
as={Fragment}
|
|
||||||
enter="ease-in-out duration-300"
|
|
||||||
enterFrom="opacity-0"
|
|
||||||
enterTo="opacity-100"
|
|
||||||
leave="ease-in-out duration-300"
|
|
||||||
leaveFrom="opacity-100"
|
|
||||||
leaveTo="opacity-0">
|
|
||||||
<div className="absolute top-1 right-0 -mr-14 p-1">
|
|
||||||
<button
|
|
||||||
className="flex h-12 w-12 items-center justify-center rounded-full focus:outline-none focus:ring-2 focus:ring-white"
|
|
||||||
type="button"
|
|
||||||
onClick={() => setMobileMenuOpen(false)}>
|
|
||||||
<XMarkIcon
|
|
||||||
aria-hidden="true"
|
|
||||||
className="h-6 w-6 text-white"
|
|
||||||
/>
|
|
||||||
<span className="sr-only">Close sidebar</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</Transition.Child>
|
|
||||||
<div className="flex flex-shrink-0 items-center px-4">
|
|
||||||
<Link href="/">
|
|
||||||
<img
|
|
||||||
alt="Tech Interview Handbook"
|
|
||||||
className="h-8 w-auto"
|
|
||||||
src="/logo.svg"
|
|
||||||
/>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
<div className="mt-5 h-0 flex-1 overflow-y-auto px-2">
|
|
||||||
<nav className="flex h-full flex-col">
|
|
||||||
<div className="space-y-1">
|
|
||||||
{sidebarNavigation.map((item) => (
|
|
||||||
<a
|
|
||||||
key={item.name}
|
|
||||||
aria-current={item.current ? 'page' : undefined}
|
|
||||||
className={clsx(
|
|
||||||
item.current
|
|
||||||
? 'bg-primary-50 text-slate-700'
|
|
||||||
: 'text-slate-700 hover:bg-slate-200',
|
|
||||||
'group flex items-center rounded-md py-2 px-3 text-sm font-medium',
|
|
||||||
)}
|
|
||||||
href={item.href}>
|
|
||||||
<item.icon
|
|
||||||
aria-hidden="true"
|
|
||||||
className={clsx(
|
|
||||||
item.current
|
|
||||||
? 'text-primary-500'
|
|
||||||
: 'text-slate-500 group-hover:text-slate-700',
|
|
||||||
'mr-3 h-6 w-6',
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<span>{item.name}</span>
|
|
||||||
</a>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</Dialog.Panel>
|
|
||||||
</Transition.Child>
|
|
||||||
<div aria-hidden="true" className="w-14 flex-shrink-0">
|
|
||||||
{/* Dummy element to force sidebar to shrink to fit close icon */}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Dialog>
|
|
||||||
</Transition.Root>
|
|
||||||
|
|
||||||
{/* Content area */}
|
{/* Content area */}
|
||||||
<div className="flex flex-1 flex-col overflow-hidden">
|
<div className="flex flex-1 flex-col overflow-hidden">
|
||||||
|
24
apps/portal/src/components/global/GlobalNavigation.ts
Normal file
24
apps/portal/src/components/global/GlobalNavigation.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import {
|
||||||
|
BriefcaseIcon,
|
||||||
|
CurrencyDollarIcon,
|
||||||
|
DocumentTextIcon,
|
||||||
|
} from '@heroicons/react/24/outline';
|
||||||
|
|
||||||
|
type GlobalNavigationItem = Readonly<{
|
||||||
|
href: string;
|
||||||
|
icon: (props: React.ComponentProps<'svg'>) => JSX.Element;
|
||||||
|
name: string;
|
||||||
|
}>;
|
||||||
|
export type GlobalNavigationItems = ReadonlyArray<GlobalNavigationItem>;
|
||||||
|
|
||||||
|
const globalNavigation: GlobalNavigationItems = [
|
||||||
|
{ href: '/offers', icon: CurrencyDollarIcon, name: 'Offers' },
|
||||||
|
{
|
||||||
|
href: '/questions',
|
||||||
|
icon: BriefcaseIcon,
|
||||||
|
name: 'Questions',
|
||||||
|
},
|
||||||
|
{ href: '/resumes', icon: DocumentTextIcon, name: 'Resumes' },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default globalNavigation;
|
@ -1,6 +1,8 @@
|
|||||||
import type { ProductNavigationItems } from '~/components/global/ProductNavigation';
|
import type { ProductNavigationItems } from '~/components/global/ProductNavigation';
|
||||||
|
|
||||||
const navigation: ProductNavigationItems = [
|
const navigation: ProductNavigationItems = [
|
||||||
|
{ href: '/offers', name: 'Offers' },
|
||||||
|
{ href: '/questions', name: 'Question Bank' },
|
||||||
{
|
{
|
||||||
children: [
|
children: [
|
||||||
{ href: '/resumes', name: 'View Resumes' },
|
{ href: '/resumes', name: 'View Resumes' },
|
||||||
@ -9,8 +11,6 @@ const navigation: ProductNavigationItems = [
|
|||||||
href: '#',
|
href: '#',
|
||||||
name: 'Resumes',
|
name: 'Resumes',
|
||||||
},
|
},
|
||||||
{ href: '/questions', name: 'Question Bank' },
|
|
||||||
{ href: '/offers', name: 'Offers' },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
132
apps/portal/src/components/global/MobileNavigation.tsx
Normal file
132
apps/portal/src/components/global/MobileNavigation.tsx
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
import clsx from 'clsx';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { Fragment } from 'react';
|
||||||
|
import { Dialog, Transition } from '@headlessui/react';
|
||||||
|
import { XMarkIcon } from '@heroicons/react/24/outline';
|
||||||
|
import { HorizontalDivider } from '@tih/ui';
|
||||||
|
|
||||||
|
import type { GlobalNavigationItems } from './GlobalNavigation';
|
||||||
|
import type { ProductNavigationItems } from './ProductNavigation';
|
||||||
|
|
||||||
|
type Props = Readonly<{
|
||||||
|
globalNavigationItems: GlobalNavigationItems;
|
||||||
|
isShown?: boolean;
|
||||||
|
productNavigationItems: ProductNavigationItems;
|
||||||
|
productTitle: string;
|
||||||
|
setIsShown: (isShown: boolean) => void;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export default function MobileNavigation({
|
||||||
|
globalNavigationItems,
|
||||||
|
isShown,
|
||||||
|
productNavigationItems,
|
||||||
|
productTitle,
|
||||||
|
setIsShown,
|
||||||
|
}: Props) {
|
||||||
|
return (
|
||||||
|
<Transition.Root as={Fragment} show={isShown}>
|
||||||
|
<Dialog as="div" className="relative z-20 md:hidden" onClose={setIsShown}>
|
||||||
|
<Transition.Child
|
||||||
|
as={Fragment}
|
||||||
|
enter="transition-opacity ease-linear duration-300"
|
||||||
|
enterFrom="opacity-0"
|
||||||
|
enterTo="opacity-100"
|
||||||
|
leave="transition-opacity ease-linear duration-300"
|
||||||
|
leaveFrom="opacity-100"
|
||||||
|
leaveTo="opacity-0">
|
||||||
|
<div className="fixed inset-0 bg-gray-600 bg-opacity-75" />
|
||||||
|
</Transition.Child>
|
||||||
|
<div className="fixed inset-0 z-40 flex">
|
||||||
|
<Transition.Child
|
||||||
|
as={Fragment}
|
||||||
|
enter="transition ease-in-out duration-300 transform"
|
||||||
|
enterFrom="-translate-x-full"
|
||||||
|
enterTo="translate-x-0"
|
||||||
|
leave="transition ease-in-out duration-300 transform"
|
||||||
|
leaveFrom="translate-x-0"
|
||||||
|
leaveTo="-translate-x-full">
|
||||||
|
<Dialog.Panel className="relative flex w-full max-w-xs flex-1 flex-col bg-white pt-5 pb-4">
|
||||||
|
<Transition.Child
|
||||||
|
as={Fragment}
|
||||||
|
enter="ease-in-out duration-300"
|
||||||
|
enterFrom="opacity-0"
|
||||||
|
enterTo="opacity-100"
|
||||||
|
leave="ease-in-out duration-300"
|
||||||
|
leaveFrom="opacity-100"
|
||||||
|
leaveTo="opacity-0">
|
||||||
|
<div className="absolute top-1 right-0 -mr-14 p-1">
|
||||||
|
<button
|
||||||
|
className="flex h-12 w-12 items-center justify-center rounded-full focus:outline-none focus:ring-2 focus:ring-white"
|
||||||
|
type="button"
|
||||||
|
onClick={() => setIsShown(false)}>
|
||||||
|
<XMarkIcon
|
||||||
|
aria-hidden="true"
|
||||||
|
className="h-6 w-6 text-white"
|
||||||
|
/>
|
||||||
|
<span className="sr-only">Close sidebar</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Transition.Child>
|
||||||
|
<div className="flex flex-shrink-0 items-center px-4">
|
||||||
|
<Link href="/">
|
||||||
|
<img
|
||||||
|
alt="Tech Interview Handbook"
|
||||||
|
className="h-8 w-auto"
|
||||||
|
src="/logo.svg"
|
||||||
|
/>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div className="mt-5 h-0 flex-1 overflow-y-auto px-2">
|
||||||
|
<div className="mb-2 px-3 py-2 font-medium">{productTitle}</div>
|
||||||
|
<nav className="flex flex-col">
|
||||||
|
<div className="space-y-1">
|
||||||
|
{productNavigationItems.map((item) => (
|
||||||
|
<a
|
||||||
|
key={item.name}
|
||||||
|
className={clsx(
|
||||||
|
'text-slate-700 hover:bg-slate-100',
|
||||||
|
'group flex items-center rounded-md py-2 px-3 text-sm font-medium',
|
||||||
|
)}
|
||||||
|
href={item.href}>
|
||||||
|
<span>{item.name}</span>
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="px-3">
|
||||||
|
<HorizontalDivider />
|
||||||
|
</div>
|
||||||
|
<div className="mb-2 px-3 py-2 text-sm font-medium">
|
||||||
|
Other Products
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
{globalNavigationItems.map((item) => (
|
||||||
|
<a
|
||||||
|
key={item.name}
|
||||||
|
className={clsx(
|
||||||
|
'text-slate-700 hover:bg-slate-100',
|
||||||
|
'group flex items-center rounded-md py-2 px-3 text-sm font-medium',
|
||||||
|
)}
|
||||||
|
href={item.href}>
|
||||||
|
<item.icon
|
||||||
|
aria-hidden="true"
|
||||||
|
className={clsx(
|
||||||
|
'text-slate-500 group-hover:text-slate-700',
|
||||||
|
'mr-3 h-6 w-6',
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<span>{item.name}</span>
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</Dialog.Panel>
|
||||||
|
</Transition.Child>
|
||||||
|
<div aria-hidden="true" className="w-14 flex-shrink-0">
|
||||||
|
{/* Dummy element to force sidebar to shrink to fit close icon */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
</Transition.Root>
|
||||||
|
);
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
import Link from 'next/link';
|
||||||
import { Fragment } from 'react';
|
import { Fragment } from 'react';
|
||||||
import { Menu, Transition } from '@headlessui/react';
|
import { Menu, Transition } from '@headlessui/react';
|
||||||
import { ChevronDownIcon } from '@heroicons/react/20/solid';
|
import { ChevronDownIcon } from '@heroicons/react/20/solid';
|
||||||
@ -18,55 +19,57 @@ type Props = Readonly<{
|
|||||||
|
|
||||||
export default function ProductNavigation({ items, title }: Props) {
|
export default function ProductNavigation({ items, title }: Props) {
|
||||||
return (
|
return (
|
||||||
<nav aria-label="Global" className="flex space-x-10">
|
<nav aria-label="Global" className="flex space-x-8">
|
||||||
<span className="text-primary-700 text-sm font-medium">{title}</span>
|
<span className="text-primary-700 text-sm font-medium">{title}</span>
|
||||||
{items.map((item) =>
|
<div className="hidden space-x-8 md:flex">
|
||||||
item.children != null && item.children.length > 0 ? (
|
{items.map((item) =>
|
||||||
<Menu key={item.name} as="div" className="relative text-left">
|
item.children != null && item.children.length > 0 ? (
|
||||||
<Menu.Button className="focus:ring-primary-600 flex items-center rounded-md text-sm font-medium text-gray-900 focus:outline-none focus:ring-2 focus:ring-offset-2">
|
<Menu key={item.name} as="div" className="relative text-left">
|
||||||
<span>{item.name}</span>
|
<Menu.Button className="focus:ring-primary-600 flex items-center rounded-md text-sm font-medium text-gray-900 focus:outline-none focus:ring-2 focus:ring-offset-2">
|
||||||
<ChevronDownIcon
|
<span>{item.name}</span>
|
||||||
aria-hidden="true"
|
<ChevronDownIcon
|
||||||
className="ml-1 h-5 w-5 text-gray-500"
|
aria-hidden="true"
|
||||||
/>
|
className="ml-1 h-5 w-5 text-gray-500"
|
||||||
</Menu.Button>
|
/>
|
||||||
<Transition
|
</Menu.Button>
|
||||||
as={Fragment}
|
<Transition
|
||||||
enter="transition ease-out duration-100"
|
as={Fragment}
|
||||||
enterFrom="transform opacity-0 scale-95"
|
enter="transition ease-out duration-100"
|
||||||
enterTo="transform opacity-100 scale-100"
|
enterFrom="transform opacity-0 scale-95"
|
||||||
leave="transition ease-in duration-75"
|
enterTo="transform opacity-100 scale-100"
|
||||||
leaveFrom="transform opacity-100 scale-100"
|
leave="transition ease-in duration-75"
|
||||||
leaveTo="transform opacity-0 scale-95">
|
leaveFrom="transform opacity-100 scale-100"
|
||||||
<Menu.Items className="absolute left-0 z-10 mt-2 w-40 origin-top-left rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
|
leaveTo="transform opacity-0 scale-95">
|
||||||
<div className="py-1">
|
<Menu.Items className="absolute left-0 z-10 mt-2 w-40 origin-top-left rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
|
||||||
{item.children.map((child) => (
|
<div className="py-1">
|
||||||
<Menu.Item key={child.name}>
|
{item.children.map((child) => (
|
||||||
{({ active }) => (
|
<Menu.Item key={child.name}>
|
||||||
<a
|
{({ active }) => (
|
||||||
className={clsx(
|
<Link
|
||||||
active ? 'bg-gray-100' : '',
|
className={clsx(
|
||||||
'block px-4 py-2 text-sm text-gray-700',
|
active ? 'bg-gray-100' : '',
|
||||||
)}
|
'block px-4 py-2 text-sm text-gray-700',
|
||||||
href={child.href}>
|
)}
|
||||||
{child.name}
|
href={child.href}>
|
||||||
</a>
|
{child.name}
|
||||||
)}
|
</Link>
|
||||||
</Menu.Item>
|
)}
|
||||||
))}
|
</Menu.Item>
|
||||||
</div>
|
))}
|
||||||
</Menu.Items>
|
</div>
|
||||||
</Transition>
|
</Menu.Items>
|
||||||
</Menu>
|
</Transition>
|
||||||
) : (
|
</Menu>
|
||||||
<a
|
) : (
|
||||||
key={item.name}
|
<Link
|
||||||
className="text-sm font-medium text-gray-900"
|
key={item.name}
|
||||||
href={item.href}>
|
className="hover:text-primary-600 text-sm font-medium text-gray-900"
|
||||||
{item.name}
|
href={item.href}>
|
||||||
</a>
|
{item.name}
|
||||||
),
|
</Link>
|
||||||
)}
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user