Removes Headless UI from the sidenav (#935)

Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
This commit is contained in:
Alex van Andel 2021-10-13 15:00:40 +01:00 committed by GitHub
parent dc4331ed17
commit cf92deb145
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 129 additions and 167 deletions

View file

@ -1,4 +1,3 @@
import { Menu, Transition } from "@headlessui/react";
import { SelectorIcon } from "@heroicons/react/outline"; import { SelectorIcon } from "@heroicons/react/outline";
import { import {
CalendarIcon, CalendarIcon,
@ -25,6 +24,12 @@ import { trpc } from "@lib/trpc";
import { HeadSeo } from "@components/seo/head-seo"; import { HeadSeo } from "@components/seo/head-seo";
import Avatar from "@components/ui/Avatar"; import Avatar from "@components/ui/Avatar";
import Dropdown, {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@components/ui/Dropdown";
import Logo from "./Logo"; import Logo from "./Logo";
@ -66,12 +71,12 @@ export function ShellSubHeading(props: {
return ( return (
<div className={classNames("block sm:flex justify-between mb-3", props.className)}> <div className={classNames("block sm:flex justify-between mb-3", props.className)}>
<div> <div>
<h2 className="text-lg font-bold text-gray-900 flex items-center content-center space-x-2"> <h2 className="flex items-center content-center space-x-2 text-lg font-bold text-gray-900">
{props.title} {props.title}
</h2> </h2>
{props.subtitle && <p className="text-sm text-neutral-500 mr-4">{props.subtitle}</p>} {props.subtitle && <p className="mr-4 text-sm text-neutral-500">{props.subtitle}</p>}
</div> </div>
{props.actions && <div className="mb-4 flex-shrink-0">{props.actions}</div>} {props.actions && <div className="flex-shrink-0 mb-4">{props.actions}</div>}
</div> </div>
); );
} }
@ -159,17 +164,17 @@ export default function Shell(props: {
<Toaster position="bottom-right" /> <Toaster position="bottom-right" />
</div> </div>
<div className="h-screen flex overflow-hidden bg-gray-100"> <div className="flex h-screen overflow-hidden bg-gray-100">
<div className="hidden md:flex md:flex-shrink-0"> <div className="hidden md:flex md:flex-shrink-0">
<div className="flex flex-col w-56"> <div className="flex flex-col w-56">
<div className="flex flex-col h-0 flex-1 border-r border-gray-200 bg-white"> <div className="flex flex-col flex-1 h-0 bg-white border-r border-gray-200">
<div className="flex-1 flex flex-col pt-5 pb-4 overflow-y-auto"> <div className="flex flex-col flex-1 pt-5 pb-4 overflow-y-auto">
<Link href="/event-types"> <Link href="/event-types">
<a className="px-4"> <a className="px-4">
<Logo small /> <Logo small />
</a> </a>
</Link> </Link>
<nav className="mt-5 flex-1 px-2 bg-white space-y-1"> <nav className="flex-1 px-2 mt-5 space-y-1 bg-white">
{navigation.map((item) => ( {navigation.map((item) => (
<Link key={item.name} href={item.href}> <Link key={item.name} href={item.href}>
<a <a
@ -194,49 +199,47 @@ export default function Shell(props: {
))} ))}
</nav> </nav>
</div> </div>
<div className="flex-shrink-0 flex p-4"> <div className="p-4 pt-2 pr-2">
<UserDropdown /> <UserDropdown />
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div className="flex flex-col w-0 flex-1 overflow-hidden"> <div className="flex flex-col flex-1 w-0 overflow-hidden">
<main className="flex-1 relative z-0 overflow-y-auto focus:outline-none max-w-[1700px]"> <main className="flex-1 relative z-0 overflow-y-auto focus:outline-none max-w-[1700px]">
{/* show top navigation for md and smaller (tablet and phones) */} {/* show top navigation for md and smaller (tablet and phones) */}
<nav className="md:hidden bg-white shadow p-4 flex justify-between items-center"> <nav className="flex items-center justify-between p-4 bg-white shadow md:hidden">
<Link href="/event-types"> <Link href="/event-types">
<a> <a>
<Logo /> <Logo />
</a> </a>
</Link> </Link>
<div className="flex gap-3 items-center self-center"> <div className="flex items-center self-center gap-3">
<button className="bg-white p-2 rounded-full text-gray-400 hover:text-gray-500 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black"> <button className="p-2 text-gray-400 bg-white rounded-full hover:text-gray-500 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black">
<span className="sr-only">View notifications</span> <span className="sr-only">View notifications</span>
<Link href="/settings/profile"> <Link href="/settings/profile">
<a> <a>
<CogIcon className="h-6 w-6" aria-hidden="true" /> <CogIcon className="w-6 h-6" aria-hidden="true" />
</a> </a>
</Link> </Link>
</button> </button>
<div className="mt-1"> <UserDropdown small />
<UserDropdown small bottom />
</div>
</div> </div>
</nav> </nav>
<div className={classNames(props.centered && "md:max-w-5xl mx-auto", "py-8")}> <div className={classNames(props.centered && "md:max-w-5xl mx-auto", "py-8")}>
<div className="block sm:flex justify-between px-4 sm:px-6 md:px-8 min-h-[80px]"> <div className="block sm:flex justify-between px-4 sm:px-6 md:px-8 min-h-[80px]">
<div className="mb-8 w-full"> <div className="w-full mb-8">
<h1 className="font-cal text-xl font-bold text-gray-900 tracking-wide mb-1"> <h1 className="mb-1 text-xl font-bold tracking-wide text-gray-900 font-cal">
{props.heading} {props.heading}
</h1> </h1>
<p className="text-sm text-neutral-500 mr-4">{props.subtitle}</p> <p className="mr-4 text-sm text-neutral-500">{props.subtitle}</p>
</div> </div>
<div className="mb-4 flex-shrink-0">{props.CTA}</div> <div className="flex-shrink-0 mb-4">{props.CTA}</div>
</div> </div>
<div className="px-4 sm:px-6 md:px-8">{props.children}</div> <div className="px-4 sm:px-6 md:px-8">{props.children}</div>
{/* show bottom navigation for md and smaller (tablet and phones) */} {/* show bottom navigation for md and smaller (tablet and phones) */}
<nav className="bottom-nav md:hidden flex fixed bottom-0 bg-white w-full shadow"> <nav className="fixed bottom-0 flex w-full bg-white shadow bottom-nav md:hidden">
{/* note(PeerRich): using flatMap instead of map to remove settings from bottom nav */} {/* note(PeerRich): using flatMap instead of map to remove settings from bottom nav */}
{navigation.flatMap((item, itemIdx) => {navigation.flatMap((item, itemIdx) =>
item.name === "Settings" ? ( item.name === "Settings" ? (
@ -265,7 +268,7 @@ export default function Shell(props: {
)} )}
</nav> </nav>
{/* add padding to content for mobile navigation*/} {/* add padding to content for mobile navigation*/}
<div className="block md:hidden pt-12" /> <div className="block pt-12 md:hidden" />
</div> </div>
<LicenseBanner /> <LicenseBanner />
</main> </main>
@ -275,134 +278,97 @@ export default function Shell(props: {
); );
} }
function UserDropdown({ small, bottom }: { small?: boolean; bottom?: boolean }) { function UserDropdown({ small }: { small?: boolean }) {
const query = useMeQuery(); const query = useMeQuery();
const user = query.data; const user = query.data;
return ( return (
<Menu as="div" className="w-full relative inline-block text-left"> !!user && (
{({ open }) => ( <Dropdown>
<> <DropdownMenuTrigger asChild>
<div> <div className="flex items-center space-x-2 cursor-pointer group">
{user && ( <Avatar
<Menu.Button className="group w-full rounded-md text-sm text-left font-medium text-gray-700 focus:outline-none"> imageSrc={user.avatar}
<span className="flex w-full justify-between items-center"> alt={user.username}
<span className="flex min-w-0 items-center justify-between space-x-3"> className={classNames(
<Avatar small ? "w-8 h-8" : "w-10 h-10",
imageSrc={user.avatar} "bg-gray-300 rounded-full flex-shrink-0"
alt={user.username} )}
className={classNames( />
small ? "w-8 h-8" : "w-10 h-10", {!small && (
"bg-gray-300 rounded-full flex-shrink-0" <>
)} <span className="flex-grow text-sm">
/> <span className="block font-medium text-gray-900 truncate">{user.name}</span>
{!small && ( <span className="block font-normal truncate text-neutral-500">/{user.username}</span>
<span className="flex-1 flex flex-col min-w-0">
<span className="text-gray-900 text-sm font-medium truncate">{user.name}</span>
<span className="text-neutral-500 font-normal text-sm truncate">
/{user.username}
</span>
</span>
)}
</span>
{!small && (
<SelectorIcon
className="flex-shrink-0 h-5 w-5 text-gray-400 group-hover:text-gray-500"
aria-hidden="true"
/>
)}
</span> </span>
</Menu.Button> <SelectorIcon
className="flex-shrink-0 w-5 h-5 text-gray-400 group-hover:text-gray-500"
aria-hidden="true"
/>
</>
)} )}
</div> </div>
<Transition </DropdownMenuTrigger>
show={open} <DropdownMenuContent>
as={Fragment} <DropdownMenuItem>
enter="transition ease-out duration-100" <a
enterFrom="transform opacity-0 scale-95" target="_blank"
enterTo="transform opacity-100 scale-100" rel="noopener noreferrer"
leave="transition ease-in duration-75" href={`${process.env.NEXT_PUBLIC_APP_URL}/${user?.username || ""}`}
leaveFrom="transform opacity-100 scale-100" className="flex px-4 py-2 text-sm text-neutral-500">
leaveTo="transform opacity-0 scale-95"> View public page <ExternalLinkIcon className="w-3 h-3 mt-1 ml-1 text-neutral-400" />
<Menu.Items </a>
static </DropdownMenuItem>
className={classNames( <DropdownMenuSeparator className="h-px bg-gray-200" />
bottom ? "origin-top top-1 right-0" : "origin-bottom bottom-14 left-0", <DropdownMenuItem>
"w-64 z-10 absolute mt-1 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 divide-y divide-gray-200 focus:outline-none" <a
)}> href="https://cal.com/slack"
<div className="py-1"> target="_blank"
<a rel="noreferrer"
target="_blank" className="flex px-4 py-2 text-sm font-medium text-neutral-700 hover:bg-gray-100 hover:text-gray-900">
rel="noopener noreferrer" <svg
href={`${process.env.NEXT_PUBLIC_APP_URL}/${user?.username || ""}`} viewBox="0 0 2447.6 2452.5"
className="flex px-4 py-2 text-sm text-neutral-500"> className={classNames(
View public page <ExternalLinkIcon className="ml-1 mt-1 w-3 h-3 text-neutral-400" /> "text-neutral-400 group-hover:text-neutral-500",
</a> "mt-0.5 mr-3 flex-shrink-0 h-4 w-4"
</div> )}
<div className="py-1"> xmlns="http://www.w3.org/2000/svg">
<Menu.Item> <g clipRule="evenodd" fillRule="evenodd">
{({ active }) => ( <path
<a d="m897.4 0c-135.3.1-244.8 109.9-244.7 245.2-.1 135.3 109.5 245.1 244.8 245.2h244.8v-245.1c.1-135.3-109.5-245.1-244.9-245.3.1 0 .1 0 0 0m0 654h-652.6c-135.3.1-244.9 109.9-244.8 245.2-.2 135.3 109.4 245.1 244.7 245.3h652.7c135.3-.1 244.9-109.9 244.8-245.2.1-135.4-109.5-245.2-244.8-245.3z"
href="https://cal.com/slack" fill="#9BA6B6"></path>
target="_blank" <path
rel="noreferrer" d="m2447.6 899.2c.1-135.3-109.5-245.1-244.8-245.2-135.3.1-244.9 109.9-244.8 245.2v245.3h244.8c135.3-.1 244.9-109.9 244.8-245.3zm-652.7 0v-654c.1-135.2-109.4-245-244.7-245.2-135.3.1-244.9 109.9-244.8 245.2v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.3z"
className={classNames( fill="#9BA6B6"></path>
active ? "bg-gray-100 text-gray-900" : "text-neutral-700", <path
"flex px-4 py-2 text-sm font-medium" d="m1550.1 2452.5c135.3-.1 244.9-109.9 244.8-245.2.1-135.3-109.5-245.1-244.8-245.2h-244.8v245.2c-.1 135.2 109.5 245 244.8 245.2zm0-654.1h652.7c135.3-.1 244.9-109.9 244.8-245.2.2-135.3-109.4-245.1-244.7-245.3h-652.7c-135.3.1-244.9 109.9-244.8 245.2-.1 135.4 109.4 245.2 244.7 245.3z"
)}> fill="#9BA6B6"></path>
<svg <path
viewBox="0 0 2447.6 2452.5" d="m0 1553.2c-.1 135.3 109.5 245.1 244.8 245.2 135.3-.1 244.9-109.9 244.8-245.2v-245.2h-244.8c-135.3.1-244.9 109.9-244.8 245.2zm652.7 0v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.2v-653.9c.2-135.3-109.4-245.1-244.7-245.3-135.4 0-244.9 109.8-244.8 245.1 0 0 0 .1 0 0"
className={classNames( fill="#9BA6B6"></path>
"text-neutral-400 group-hover:text-neutral-500", </g>
"mt-0.5 mr-3 flex-shrink-0 h-4 w-4" </svg>
)} Join our Slack
xmlns="http://www.w3.org/2000/svg"> </a>
<g clipRule="evenodd" fillRule="evenodd"> </DropdownMenuItem>
<path <HelpMenuItemDynamic />
d="m897.4 0c-135.3.1-244.8 109.9-244.7 245.2-.1 135.3 109.5 245.1 244.8 245.2h244.8v-245.1c.1-135.3-109.5-245.1-244.9-245.3.1 0 .1 0 0 0m0 654h-652.6c-135.3.1-244.9 109.9-244.8 245.2-.2 135.3 109.4 245.1 244.7 245.3h652.7c135.3-.1 244.9-109.9 244.8-245.2.1-135.4-109.5-245.2-244.8-245.3z" <DropdownMenuSeparator className="h-px bg-gray-200" />
fill="#9BA6B6"></path> <DropdownMenuItem>
<path <a
d="m2447.6 899.2c.1-135.3-109.5-245.1-244.8-245.2-135.3.1-244.9 109.9-244.8 245.2v245.3h244.8c135.3-.1 244.9-109.9 244.8-245.3zm-652.7 0v-654c.1-135.2-109.4-245-244.7-245.2-135.3.1-244.9 109.9-244.8 245.2v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.3z" onClick={() => signOut({ callbackUrl: "/auth/logout" })}
fill="#9BA6B6"></path> className="flex px-4 py-2 text-sm font-medium cursor-pointer hover:bg-gray-100 hover:text-gray-900">
<path <LogoutIcon
d="m1550.1 2452.5c135.3-.1 244.9-109.9 244.8-245.2.1-135.3-109.5-245.1-244.8-245.2h-244.8v245.2c-.1 135.2 109.5 245 244.8 245.2zm0-654.1h652.7c135.3-.1 244.9-109.9 244.8-245.2.2-135.3-109.4-245.1-244.7-245.3h-652.7c-135.3.1-244.9 109.9-244.8 245.2-.1 135.4 109.4 245.2 244.7 245.3z" className={classNames(
fill="#9BA6B6"></path> "text-neutral-400 group-hover:text-neutral-500",
<path "mr-2 flex-shrink-0 h-5 w-5"
d="m0 1553.2c-.1 135.3 109.5 245.1 244.8 245.2 135.3-.1 244.9-109.9 244.8-245.2v-245.2h-244.8c-135.3.1-244.9 109.9-244.8 245.2zm652.7 0v654c-.2 135.3 109.4 245.1 244.7 245.3 135.3-.1 244.9-109.9 244.8-245.2v-653.9c.2-135.3-109.4-245.1-244.7-245.3-135.4 0-244.9 109.8-244.8 245.1 0 0 0 .1 0 0" )}
fill="#9BA6B6"></path> aria-hidden="true"
</g> />
</svg> Sign out
Join our Slack </a>
</a> </DropdownMenuItem>
)} </DropdownMenuContent>
</Menu.Item> </Dropdown>
<HelpMenuItemDynamic /> )
</div>
<div className="py-1">
<Menu.Item>
{({ active }) => (
<a
onClick={() => signOut({ callbackUrl: "/auth/logout" })}
className={classNames(
active ? "bg-gray-100 text-gray-900" : "text-gray-700",
"flex px-4 py-2 text-sm font-medium"
)}>
<LogoutIcon
className={classNames(
"text-neutral-400 group-hover:text-neutral-500",
"mr-2 flex-shrink-0 h-5 w-5"
)}
aria-hidden="true"
/>
Sign out
</a>
)}
</Menu.Item>
</div>
</Menu.Items>
</Transition>
</>
)}
</Menu>
); );
} }

View file

@ -1,34 +1,30 @@
import { Menu } from "@headlessui/react";
import { ChatAltIcon } from "@heroicons/react/solid"; import { ChatAltIcon } from "@heroicons/react/solid";
import { useIntercom } from "react-use-intercom"; import { useIntercom } from "react-use-intercom";
import classNames from "@lib/classNames"; import classNames from "@lib/classNames";
import { DropdownMenuItem } from "@components/ui/Dropdown";
const HelpMenuItem = () => { const HelpMenuItem = () => {
const { boot, show } = useIntercom(); const { boot, show } = useIntercom();
return ( return (
<Menu.Item> <DropdownMenuItem>
{({ active }) => ( <button
<button onClick={() => {
onClick={() => { boot();
boot(); show();
show(); }}
}} className="flex w-full px-4 py-2 text-sm font-medium text-neutral-700 hover:bg-gray-100 hover:text-gray-900">
<ChatAltIcon
className={classNames( className={classNames(
active ? "bg-gray-100 text-gray-900" : "text-neutral-700", "text-neutral-400 group-hover:text-neutral-500",
"w-full flex px-4 py-2 text-sm font-medium" "mr-2 flex-shrink-0 h-5 w-5"
)}> )}
<ChatAltIcon aria-hidden="true"
className={classNames( />
"text-neutral-400 group-hover:text-neutral-500", Help
"mr-2 flex-shrink-0 h-5 w-5" </button>
)} </DropdownMenuItem>
aria-hidden="true"
/>
Help
</button>
)}
</Menu.Item>
); );
}; };