jevstrudel.git / website / src / docs / MobileNav.jsx
MobileNav.jsx57 lines · 2.2 KB · raw
1import { Disclosure } from '@headlessui/react';
2import Bars3Icon from '@heroicons/react/24/outline/Bars3Icon';
3import XMarkIcon from '@heroicons/react/24/outline/XMarkIcon';
4
5function classNames(...classes) {
6  return classes.filter(Boolean).join(' ');
7}
8
9export default function MobileNav({ sidebar }) {
10  return (
11    <Disclosure as="nav">
12      {({ open }) => (
13        <>
14          <Disclosure.Button className="inline-flex items-center justify-center rounded-md p-2 text-gray-400 hover:bg-gray-700 hover:text-white focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white">
15            <span className="sr-only">Open main menu</span>
16            {open ? (
17              <XMarkIcon className="block h-6 w-6" aria-hidden="true" />
18            ) : (
19              <Bars3Icon className="block h-6 w-6" aria-hidden="true" />
20            )}
21          </Disclosure.Button>
22          <Disclosure.Panel className="md:hidden absolute top-14 right-0 max-h-screen pb-14 overflow-auto z-[100] w-full">
23            <div className="space-y-1 px-4 py-4 bg-[#161616]">
24              <a
25                href=".."
26                className="py-2 flex cursor-pointer items-center space-x-1 hover:bg-background hover:px-2 rounded-md"
27              >
28                <span>go to REPL</span>
29              </a>
30              {Object.entries(sidebar).map(([group, items], i) => (
31                <div key={i} className="space-y-2">
32                  <div>{group}</div>
33                  {items.map((item, j) => (
34                    <Disclosure.Button
35                      key={j}
36                      as="a"
37                      href={`/${item.link}`}
38                      className={classNames(
39                        item.current
40                          ? 'bg-background text-white'
41                          : 'text-gray-300 hover:bg-lineHighlight hover:text-white',
42                        'block px-3 py-2 rounded-md text-base font-medium',
43                      )}
44                      aria-current={item.current ? 'page' : undefined}
45                    >
46                      {item.text}
47                    </Disclosure.Button>
48                  ))}
49                </div>
50              ))}
51            </div>
52          </Disclosure.Panel>
53        </>
54      )}
55    </Disclosure>
56  );
57}