on master help sign in
first pass of mobile docs sidebar
commitfc912c008aadaa1a64d58450d8df500fb5c021f2 authorGavin Atkinson <gvnatknsn@protonmail.com> dateFri 9 Jul 2021, 15:17 (5 years ago) parenta7f362f
6 files changed+177−116
components/ContentArea.js+2−2 components/Header.js+53−94 components/MenuTray.js+44 components/Sidebar.js+70−10 pages/docs/[[...slug]].js+5−2 styles/globals.css+3−8
components/ContentArea.js+2−2
@@ -1,7 +1,7 @@
11export default function ContentArea(props) {
22 return (
33 <div className="w-full min-w-0 flex flex-col">
4− <header className="flex justify-between items-center px-24 pt-12 pb-8">
4+ <header className="flex justify-between items-center px-4 md:px-12 lg:px-24 pt-12 pb-8">
55 <div className="type-ui">{props.section}</div>
66 <button
77 onClick={(e) => {
@@ -13,7 +13,7 @@ export default function ContentArea(props) {
1313 Search<div className="ml-4 text-lightGray">⌘K</div>
1414 </button>
1515 </header>
16− <div className="px-24 pb-24 pt-16 flex flex-col w-full max-h-screen h-screen overflow-y-scroll">
16+ <div className="px-4 md:px-12 lg:px-24 pb-24 pt-16 flex flex-col w-full max-h-screen h-screen overflow-y-scroll">
1717 <div className="type-ui text-lightGray">{props.breadcrumbs}</div>
1818 <h2 className="mb-16 mt-4">{props.title}</h2>
1919 {props.children}
components/Header.js+53−94
@@ -3,6 +3,7 @@ import { useRouter } from "next/router";
33import { useState } from "react";
44import classnames from "classnames";
55import path from "path";
6+import MenuTray from "../components/MenuTray";
67
78function ActiveLink({ children, href, className }) {
89 const router = useRouter();
@@ -21,58 +22,10 @@ function ActiveLink({ children, href, className }) {
2122 );
2223}
2324
24−function MenuTray(props) {
25− // Locks document scrolling when menu is open
26− if (typeof document !== "undefined") {
27− if (props.isOpen) {
28− document.body.style.overflow = "hidden";
29− } else {
30− document.body.style.overflow = "visible";
31− }
32− }
33−
34− // Slides the tray in or out from the left
35− const trayClasses = classnames({
36− "tray-menu-open": props.isOpen,
37− "tray-menu-closed": !props.isOpen,
38− });
39−
40− // Fades the background overlay in or out
41− const overlayClasses = classnames({
42− "tray-overlay-open": props.isOpen,
43− "tray-overlay-closed": !props.isOpen,
44− });
45−
46− // Hides or shows the menu
47− const menuClasses = classnames({
48− "menu-open": props.isOpen,
49− "menu-closed": !props.isOpen,
50− });
51−
52− return (
53− <nav className={`z-10 w-screen h-screen top-0 left-0 fixed ${menuClasses}`}>
54− <div
55− onClick={() => props.toggleTray(!props.isOpen)}
56− className={`bg-washedWhite w-screen h-screen ${overlayClasses}`}
57− />
58− <div
59− className={`absolute bg-wall h-screen top-0 left-0 flex flex-col p-4 tray-menu-width ${trayClasses}`}
60− >
61− {props.children}
62− </div>
63− </nav>
64− );
65−}
66−
6725// This is the header for the index page
6826export default function Header(props) {
6927 const [isOpen, toggleTray] = useState(false);
7028
71− const mobileSearchButtonClasses = classnames({
72− visible: isOpen,
73− invisible: !isOpen,
74− });
75−
7629 return (
7730 <header className="layout-wide flex justify-between items-center pt-12">
7831 <Link href="/">
@@ -91,7 +44,9 @@ export default function Header(props) {
9144 <ActiveLink className="mr-5 type-ui" href="/events">
9245 Events
9346 </ActiveLink>
94− <button className="mr-5 text-green type-ui">Download Port</button>
47+ <button className="mr-5 text-green type-ui button-text">
48+ Download Port
49+ </button>
9550 <button
9651 onClick={(e) => {
9752 e.stopPropagation();
@@ -121,51 +76,55 @@ export default function Header(props) {
12176 </ActiveLink>
12277 </MenuTray>
12378
124− <button
125− onClick={(e) => {
126− e.stopPropagation();
127− props.search.toggleSearch(e);
128− }}
129− className={`z-10 fixed px-4 items-center justify-center type-ui rounded-xl h-16 bg-white text-gray left-4 right-4 bottom-4 mobile-search-button-width ${
130− isOpen ? "flex" : "hidden"
131− }`}
132− >
133− Search
134− </button>
135−
136− <button
137− onClick={() => toggleTray(!isOpen)}
138− className="z-10 fixed bottom-4 right-4 w-16 h-16 bg-ultraDeepWall flex items-center justify-center rounded-full"
139− >
140− {isOpen ? (
141− <svg
142− width="16"
143− height="16"
144− viewBox="0 0 16 16"
145− fill="none"
146− xmlns="http://www.w3.org/2000/svg"
147− >
148− <path
149− fill-rule="evenodd"
150− clip-rule="evenodd"
151− d="M0.39382 13.7045C-0.131273 14.2296 -0.131274 15.081 0.39382 15.6061C0.918913 16.1312 1.77026 16.1312 2.29535 15.6061L7.99999 9.90142L13.7047 15.6061C14.2297 16.1312 15.0811 16.1312 15.6062 15.6061C16.1313 15.081 16.1313 14.2296 15.6062 13.7046L9.90152 7.99989L15.6061 2.29535C16.1312 1.77026 16.1312 0.918913 15.6061 0.39382C15.081 -0.131273 14.2296 -0.131273 13.7045 0.39382L7.99999 6.09836L2.29548 0.393844C1.77038 -0.131249 0.919038 -0.13125 0.393945 0.393844C-0.131148 0.918937 -0.131148 1.77028 0.393945 2.29537L6.09846 7.99989L0.39382 13.7045Z"
152− fill="white"
153− />
154− </svg>
155− ) : (
156− <svg
157− width="16"
158− height="16"
159− viewBox="0 0 16 17"
160− fill="none"
161− xmlns="http://www.w3.org/2000/svg"
162− >
163− <rect width="16" height="3" rx="1.5" fill="white" />
164− <rect y="7" width="16" height="3" rx="1.5" fill="white" />
165− <rect y="14" width="16" height="3" rx="1.5" fill="white" />
166− </svg>
167− )}
168− </button>
79+ {
80+ // Mobile menu button and search button
81+ }
82+ <div className="block md:hidden">
83+ <button
84+ onClick={(e) => {
85+ e.stopPropagation();
86+ props.search.toggleSearch(e);
87+ }}
88+ className={`z-10 fixed px-4 items-center justify-center type-ui rounded-xl h-16 bg-white text-gray left-4 right-4 bottom-4 mobile-search-button-width ${
89+ isOpen ? "flex" : "hidden"
90+ }`}
91+ >
92+ Search
93+ </button>
94+ <button
95+ onClick={() => toggleTray(!isOpen)}
96+ className="z-10 fixed bottom-4 right-4 w-16 h-16 bg-ultraDeepWall flex items-center justify-center rounded-full"
97+ >
98+ {isOpen ? (
99+ <svg
100+ width="16"
101+ height="16"
102+ viewBox="0 0 16 16"
103+ fill="none"
104+ xmlns="http://www.w3.org/2000/svg"
105+ >
106+ <path
107+ fill-rule="evenodd"
108+ clip-rule="evenodd"
109+ d="M0.39382 13.7045C-0.131273 14.2296 -0.131274 15.081 0.39382 15.6061C0.918913 16.1312 1.77026 16.1312 2.29535 15.6061L7.99999 9.90142L13.7047 15.6061C14.2297 16.1312 15.0811 16.1312 15.6062 15.6061C16.1313 15.081 16.1313 14.2296 15.6062 13.7046L9.90152 7.99989L15.6061 2.29535C16.1312 1.77026 16.1312 0.918913 15.6061 0.39382C15.081 -0.131273 14.2296 -0.131273 13.7045 0.39382L7.99999 6.09836L2.29548 0.393844C1.77038 -0.131249 0.919038 -0.13125 0.393945 0.393844C-0.131148 0.918937 -0.131148 1.77028 0.393945 2.29537L6.09846 7.99989L0.39382 13.7045Z"
110+ fill="white"
111+ />
112+ </svg>
113+ ) : (
114+ <svg
115+ width="16"
116+ height="16"
117+ viewBox="0 0 16 17"
118+ fill="none"
119+ xmlns="http://www.w3.org/2000/svg"
120+ >
121+ <rect width="16" height="3" rx="1.5" fill="white" />
122+ <rect y="7" width="16" height="3" rx="1.5" fill="white" />
123+ <rect y="14" width="16" height="3" rx="1.5" fill="white" />
124+ </svg>
125+ )}
126+ </button>
127+ </div>
169128 </header>
170129 );
171130}
components/MenuTray.jsnew file+44
@@ -0,0 +1,44 @@
1+import classnames from "classnames";
2+
3+export default function MenuTray(props) {
4+ // Locks document scrolling when menu is open
5+ if (typeof document !== "undefined") {
6+ if (props.isOpen) {
7+ document.body.style.overflow = "hidden";
8+ } else {
9+ document.body.style.overflow = "visible";
10+ }
11+ }
12+
13+ // Slides the tray in or out from the left
14+ const trayClasses = classnames({
15+ "tray-menu-open": props.isOpen,
16+ "tray-menu-closed": !props.isOpen,
17+ });
18+
19+ // Fades the background overlay in or out
20+ const overlayClasses = classnames({
21+ "tray-overlay-open": props.isOpen,
22+ "tray-overlay-closed": !props.isOpen,
23+ });
24+
25+ // Hides or shows the menu
26+ const menuClasses = classnames({
27+ "menu-open": props.isOpen,
28+ "menu-closed": !props.isOpen,
29+ });
30+
31+ return (
32+ <nav className={`z-10 w-screen h-screen top-0 left-0 fixed ${menuClasses}`}>
33+ <div
34+ onClick={() => props.toggleTray(!props.isOpen)}
35+ className={`bg-washedWhite w-screen h-screen ${overlayClasses}`}
36+ />
37+ <div
38+ className={`absolute bg-wall h-screen top-0 left-0 p-4 tray-menu-width overflow-y-scroll ${trayClasses}`}
39+ >
40+ <div className="flex flex-col">{props.children}</div>
41+ </div>
42+ </nav>
43+ );
44+}
components/Sidebar.js+70−10
@@ -1,17 +1,77 @@
11import Link from "next/link";
2+import { useState } from "react";
3+import MenuTray from "./MenuTray";
24
35export default function Sidebar(props) {
6+ const [isOpen, toggleTray] = useState(false);
47 return (
5− <div className="flex flex-col w-96 bg-wall max-h-screen h-screen">
6− <header className="flex flex-shrink-0 justify-between items-center pl-6 pt-12 pb-8">
7− <Link href="/">
8− <a className="type-ui text-gray">Urbit</a>
9− </Link>
10− </header>
11− <div className="overflow-y-scroll p-6 pt-16">
12− {props.children}
13− <div className="pb-32" />
8+ <>
9+ <div className="hidden md:flex flex-col w-96 bg-wall max-h-screen h-screen">
10+ <header className="flex flex-shrink-0 justify-between items-center pl-6 pt-12 pb-8">
11+ <Link href="/">
12+ <a className="type-ui text-gray">Urbit</a>
13+ </Link>
14+ </header>
15+ <div className="overflow-y-scroll p-6 pt-16">
16+ {props.children}
17+ <div className="pb-32" />
18+ </div>
1419 </div>
15− </div>
20+
21+ <div className="block md:hidden">
22+ <MenuTray isOpen={isOpen} toggleTray={toggleTray}>
23+ <header className="flex flex-shrink-0 justify-between items-center pt-8 pb-8">
24+ <Link href="/">
25+ <a className="type-ui text-gray">Urbit</a>
26+ </Link>
27+ </header>
28+ {props.children}
29+ </MenuTray>
30+ <button
31+ onClick={(e) => {
32+ e.stopPropagation();
33+ props.search.toggleSearch(e);
34+ }}
35+ className={`z-10 fixed px-4 items-center justify-center type-ui rounded-xl h-16 bg-white text-gray left-4 right-4 bottom-4 mobile-search-button-width ${
36+ isOpen ? "flex" : "hidden"
37+ }`}
38+ >
39+ Search
40+ </button>
41+ <button
42+ onClick={() => toggleTray(!isOpen)}
43+ className="z-10 fixed bottom-4 right-4 w-16 h-16 bg-ultraDeepWall flex items-center justify-center rounded-full"
44+ >
45+ {isOpen ? (
46+ <svg
47+ width="16"
48+ height="16"
49+ viewBox="0 0 16 16"
50+ fill="none"
51+ xmlns="http://www.w3.org/2000/svg"
52+ >
53+ <path
54+ fill-rule="evenodd"
55+ clip-rule="evenodd"
56+ d="M0.39382 13.7045C-0.131273 14.2296 -0.131274 15.081 0.39382 15.6061C0.918913 16.1312 1.77026 16.1312 2.29535 15.6061L7.99999 9.90142L13.7047 15.6061C14.2297 16.1312 15.0811 16.1312 15.6062 15.6061C16.1313 15.081 16.1313 14.2296 15.6062 13.7046L9.90152 7.99989L15.6061 2.29535C16.1312 1.77026 16.1312 0.918913 15.6061 0.39382C15.081 -0.131273 14.2296 -0.131273 13.7045 0.39382L7.99999 6.09836L2.29548 0.393844C1.77038 -0.131249 0.919038 -0.13125 0.393945 0.393844C-0.131148 0.918937 -0.131148 1.77028 0.393945 2.29537L6.09846 7.99989L0.39382 13.7045Z"
57+ fill="white"
58+ />
59+ </svg>
60+ ) : (
61+ <svg
62+ width="16"
63+ height="16"
64+ viewBox="0 0 16 17"
65+ fill="none"
66+ xmlns="http://www.w3.org/2000/svg"
67+ >
68+ <rect width="16" height="3" rx="1.5" fill="white" />
69+ <rect y="7" width="16" height="3" rx="1.5" fill="white" />
70+ <rect y="14" width="16" height="3" rx="1.5" fill="white" />
71+ </svg>
72+ )}
73+ </button>
74+ </div>
75+ </>
1676 );
1777}
pages/docs/[[...slug]].js+5−2
@@ -30,7 +30,7 @@ const breadcrumbs = (posts, paths) => {
3030};
3131
3232const childPages = (thisLink, children, level = 0) => (
33− <ul className="pl-1">
33+ <ul className="pl-0">
3434 {Object.entries(children).map(([childSlug, child]) => (
3535 <li>{pageTree(join(thisLink, childSlug), child, level)}</li>
3636 ))}
@@ -69,7 +69,7 @@ const pageTree = (thisLink, tree, level = 0) => {
6969 <p className={`${headingItemClasses} cursor-pointer`}>{tree.title}</p>
7070 </span>
7171 <div className={activeClasses}>
72− <ul className={"pl-1"}>
72+ <ul className={""}>
7373 {tree.pages.map(({ title, slug }) => {
7474 const href = join(thisLink, slug);
7575 const isSelected = router.asPath === href;
@@ -97,6 +97,8 @@ const pageTree = (thisLink, tree, level = 0) => {
9797};
9898
9999export default function DocsLayout({ posts, data, params, search, markdown }) {
100+ const [isOpen, toggleTray] = useState(false);
101+
100102 return (
101103 <>
102104 <Head>
@@ -104,6 +106,7 @@ export default function DocsLayout({ posts, data, params, search, markdown }) {
104106 </Head>
105107 <div className="flex w-screen h-screen min-h-screen w-screen">
106108 <Sidebar>{childPages("/docs", posts.children)}</Sidebar>
109+
107110 <ContentArea
108111 breadcrumbs={breadcrumbs(posts, params.slug?.slice(0, -1) || "")}
109112 title={data.title}
styles/globals.css+3−8
@@ -97,14 +97,9 @@ button {
9797 overflow: visible;
9898}
9999
100−.button-sm:hover {
101− opacity: 0.66;
102−}
103−
104−.button-lg:hover {
105− opacity: 0.66;
106−}
107−
100+.button-sm:hover,
101+.button-text:hover,
102+.button-lg:hover,
108103a:hover {
109104 opacity: 0.66;
110105}