Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding header links to sidebar on mobile #1211

Merged
merged 27 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b35d00
initial commit, adding header links to sidebar on mobile
thisisjofrank Nov 29, 2024
4f8fff8
make it happen at tablet too
thisisjofrank Nov 29, 2024
99753fd
style like homepage sidenav
thisisjofrank Nov 29, 2024
1c37e72
Merge branch 'main' into add-header-links-in-sidebar
thisisjofrank Dec 9, 2024
1e743aa
Merge branch 'main' into add-header-links-in-sidebar
thisisjofrank Dec 11, 2024
ff0df6d
update sidebar order
thisisjofrank Dec 11, 2024
57e98f0
add sidear to api ref
thisisjofrank Dec 11, 2024
24b7dd0
fmt
thisisjofrank Dec 11, 2024
a0842b3
Merge branch 'main' into add-header-links-in-sidebar
thisisjofrank Dec 11, 2024
de58f2f
add scroll to top
thisisjofrank Dec 11, 2024
b0d8790
Merge branch 'add-header-links-in-sidebar' of https://github.com/deno…
thisisjofrank Dec 11, 2024
45d0415
fmt
thisisjofrank Dec 11, 2024
a300383
remove colour
thisisjofrank Dec 11, 2024
17843ce
Merge branch 'main' into add-header-links-in-sidebar
thisisjofrank Dec 11, 2024
a515935
add totop
thisisjofrank Dec 11, 2024
c6038e0
Merge branch 'add-header-links-in-sidebar' of https://github.com/deno…
thisisjofrank Dec 11, 2024
81e8add
Style section switcher
josh-collinsworth Dec 11, 2024
2b017ff
update header on homepage, update back to top styles
thisisjofrank Dec 12, 2024
971031f
fmt
thisisjofrank Dec 12, 2024
665c2b2
styles button
thisisjofrank Dec 12, 2024
2f6e474
Merge branch 'main' of https://github.com/denoland/docs into add-head…
thisisjofrank Dec 12, 2024
d6f5015
styles button
thisisjofrank Dec 12, 2024
3100786
styles button
thisisjofrank Dec 12, 2024
3d46677
Merge branch 'main' into add-header-links-in-sidebar
thisisjofrank Dec 12, 2024
73dc575
Minor styling updates; add aliases
josh-collinsworth Dec 12, 2024
a912608
fix styles for active deploy and subhosting
thisisjofrank Dec 12, 2024
97b849a
Merge branch 'add-header-links-in-sidebar' of https://github.com/deno…
thisisjofrank Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 70 additions & 9 deletions _components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,43 @@ export default function Sidebar(
) {
return (
<nav
class="p-2 pt-0 pr-0 overflow-y-auto overflow-x-hidden"
class="overflow-y-auto overflow-x-hidden"
style={{ scrollbarGutter: "stable", scrollbarWidth: "thin" }}
>
<ul className="xl:hidden border-bg-tertiary relative bg-background-secondary m-2 mt-0 mb-4 py-2 rounded-md border border-background-tertiary">
<SidebarTopNav
name="Runtime"
url="/runtime/"
currentPath={props.url}
/>
<SidebarTopNav
name="API reference"
url="/api/deno/"
currentPath={props.url}
/>
<SidebarTopNav
name="Examples"
url="/examples/"
currentPath={props.url}
/>
<SidebarTopNav
name="Deploy"
url="/deploy/"
currentPath={props.url}
/>
<SidebarTopNav
name="Subhosting"
url="/subhosting/"
currentPath={props.url}
/>
</ul>
<ul>
{props.sidebar.map((section) => (
{props.sidebar.map((section, idx) => (
<SidebarSection
section={section}
search={props.search}
url={props.url}
headerPath={props.headerPath}
/>
))}
</ul>
Expand All @@ -45,8 +73,8 @@ function SidebarSection(
str.replaceAll(/[\s_]/g, "-")
.replaceAll(/[^a-zA-Z0-9-]/g, "")
.toLowerCase();
const slug = slugify(props.section.title ?? "");
const categoryTitle = `sidebar-category-${slug}`;
const slug = "-" + slugify(props.section.title ?? "");
const categoryTitle = `sidebar-category${slug}`;
const headingLink = props.section.href;

return (
Expand All @@ -57,7 +85,7 @@ function SidebarSection(
<a href={headingLink}>
<h2
id={categoryTitle}
class="border-b border-foreground-tertiary pt-2 pb-1.5 -mx-5 px-8 mt-4 mb-2 text-sm font-semibold hover:bg-background-secondary current:bg-background-secondary current:text-blue-500 text-foreground-primary capitalize"
class="border-b border-foreground-tertiary pt-2 pb-1.5 -mx-5 px-8 mb-2 text-sm font-semibold hover:bg-background-secondary current:bg-background-secondary current:text-blue-500 text-foreground-primary capitalize"
aria-current={props.url === headingLink ? "page" : undefined}
>
{props.section.title}
Expand All @@ -67,13 +95,13 @@ function SidebarSection(
: (
<h2
id={categoryTitle}
class="border-b border-foreground-tertiary pt-2 pb-0.5 -mx-5 px-8 mt-4 mb-3 text-sm font-semibold text-foreground-primary capitalize"
class="border-b border-foreground-tertiary pt-2 pb-0.5 -mx-5 px-8 mb-3 text-sm font-semibold text-foreground-primary capitalize"
>
{props.section.title}
</h2>
)
)}{" "}
<ul aria-labelledby={categoryTitle}>
<ul aria-labelledby={categoryTitle} class="mb-4">
{props.section.items.map((item) => (
<li class="mx-2">
{typeof item === "object" && "items" in item
Expand Down Expand Up @@ -145,7 +173,7 @@ function SidebarCategory(props: {
if (typeof item === "string") {
return item === props.url;
}
return item.id === props.url;
return typeof item === "object" && "id" in item && item.id === props.url;
});

return (
Expand Down Expand Up @@ -176,9 +204,42 @@ function SidebarCategory(props: {
data-accordion-content
>
{props.item.items.map((item) => (
<SidebarItem item={item} search={props.search} url={props.url} />
typeof item === "object" && "items" in item
? (
<SidebarCategory
item={item}
url={props.url}
search={props.search}
/>
)
: (
<SidebarItem
item={item}
search={props.search}
url={props.url}
/>
)
))}
</ul>
</>
);
}

function SidebarTopNav(
props: { name: string; url: string; currentPath: string },
) {
const isCurrentlyActivePath = props.currentPath.startsWith(props.url);
return (
<li class="mx-2">
<a
class={`relative block py-1.5 px-1.5 text-base text-foreground-primary leading-snug rounded ring-1 ring-transparent hover:ring-background-tertiary hover:bg-background-secondary transition-colors duration-200 ease-in-out select-none current:bg-background-tertiary ${
isCurrentlyActivePath ? "font-semibold" : "font-normal"
}`}
href={props.url}
aria-current={isCurrentlyActivePath ? "page" : undefined}
>
{props.name}
</a>
</li>
);
}
9 changes: 9 additions & 0 deletions _components/ToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function ToTop() {
return (
<a href="#" className="totop">
<span className="sr-only">
Back to top
</span>
</a>
);
}
10 changes: 5 additions & 5 deletions _includes/doc.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Breadcrumbs } from "../_components/Breadcrumbs.tsx";
import Logo from "../_components/Logo.tsx";
import { NavigationButton } from "../_components/NavigationButton.tsx";
import { TableOfContentsItem } from "../_components/TableOfContentsItem.tsx";
import { TableOfContentsItemMobile } from "../_components/TableOfContentsItemMobile.tsx";
import {
Sidebar as Sidebar_,
SidebarItem,
TableOfContentsItem as TableOfContentsItem_,
} from "../types.ts";
import { Breadcrumbs } from "../_components/Breadcrumbs.tsx";
import { NavigationButton } from "../_components/NavigationButton.tsx";
import { TableOfContentsItem } from "../_components/TableOfContentsItem.tsx";
import { TableOfContentsItemMobile } from "../_components/TableOfContentsItemMobile.tsx";
import renderCommand from "./renderCommand.tsx";

export const layout = "layout.tsx";
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function Page(props: Lume.Data, helpers: Lume.Helpers) {
id="sidebar"
data-open="false"
>
<div class="xl:hidden p-4 shadow-sm flex justify-between h-16">
<div class="xl:hidden p-4 flex justify-between h-16">
<a class="flex items-center gap-3 mr-6" href="/">
<Logo />
</a>
Expand Down
24 changes: 4 additions & 20 deletions _includes/raw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ export const layout = "layout.tsx";
export default function Raw(props: Lume.Data, helpers: Lume.Helpers) {
const reference = props.url.startsWith("/api");

if (reference) {
return (
<div>
{props.children}
</div>
);
}

return (
<>
{props.sidebar && (
Expand All @@ -20,7 +12,7 @@ export default function Raw(props: Lume.Data, helpers: Lume.Helpers) {
id="sidebar"
data-open="false"
>
<div class="p-4 shadow-sm flex justify-between h-16">
<div class="p-4 flex justify-between h-16">
<a class="flex items-center gap-3 mr-6" href="/">
<img
src="/img/logo.svg"
Expand Down Expand Up @@ -55,20 +47,12 @@ export default function Raw(props: Lume.Data, helpers: Lume.Helpers) {
url={props.url}
/>
</aside>
<div
class="absolute inset-0 backdrop-brightness-50 z-40 hidden sidebar-open:block sidebar-open:xl:hidden"
id="sidebar-cover"
data-open="false"
>
</div>
</>
)}
<div
class="absolute top-16 bottom-0 left-0 right-0 overflow-y-auto"
style={{ scrollbarGutter: "stable" }}
>
<div style={{ scrollbarGutter: "stable" }}>
{props.children}
<props.comp.Footer />
{reference && <props.comp.ToTop />}
{!reference && <props.comp.Footer />}
</div>
</>
);
Expand Down
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"tailwindcss": "npm:tailwindcss@^3.4.9"
},
"tasks": {
"build": "deno run -A lume.ts",
"serve": "deno run -A lume.ts -s",
"start": "deno task serve",
"dev": "deno task serve",
"build": "deno run -A lume.ts",
"debug": "deno task build && deno task prod",
"prod": "cd _site && deno run --allow-read --allow-env --allow-net server.ts",
"reference": "cd reference_gen && deno task types && deno task doc",
Expand Down
27 changes: 1 addition & 26 deletions examples/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
export const layout = "raw.tsx";
export const sidebar = [
{
items: [
{
label: "Runtime",
id: "/runtime/",
},
{
label: "API Reference",
id: "/api/deno/",
},
{
label: "Examples",
id: "/examples/",
},
{
label: "Deploy",
id: "/deploy/",
},
{
label: "Subhosting",
id: "/subhosting/",
},
],
},
];
export const sidebar = [];

export const toc = [];

Expand Down
20 changes: 0 additions & 20 deletions index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@ export const url = "/";
export const sidebar = [
{
items: [
{
label: "Runtime Manual",
id: "/runtime/",
},
{
label: "API reference",
id: "/api/deno",
},
{
label: "Examples",
id: "/examples/",
},
{
label: "Deploy",
id: "/deploy/manual/",
},
{
label: "Subhosting",
id: "/subhosting/manual/",
},
{
label: "deno.com",
id: "https://deno.com",
Expand Down
36 changes: 33 additions & 3 deletions overrides.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This file exists to provide CSS overrides to styles that exist on the pages
/* This file exists to provide CSS overrides to styles that exist on the pages
that are generated by deno_doc, the tool that powers the API reference documentation */

#content > main > section + div {
Expand Down Expand Up @@ -63,8 +63,8 @@ that are generated by deno_doc, the tool that powers the API reference documenta
@apply ml-1 !important;
}

.doc .toc :not(.documentNavigation) > a {
@apply text-xl !important;
.ddoc .z-50 {
z-index: 49 !important;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for this hack, I can't edit the z-50 on the reference doc that is generated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you isolate it instead? May be a little cleaner. https://tailwindcss.com/docs/isolation

}

.ddoc .usageContent {
Expand Down Expand Up @@ -115,3 +115,33 @@ that are generated by deno_doc, the tool that powers the API reference documenta
.ddoc .space-y-7 > .section .markdown-body {
@apply mb-6 !important;
}

.totop {
@apply block fixed p-3 bg-background-secondary rounded-md border
border-background-tertiary bottom-4 right-4 text-transparent;
animation-name: showToTop;
animation-duration: 1ms;
animation-timeline: --showScrollTop;
}

.totop::after {
@apply block w-4 h-4 border-2 border-primary border-l-0 border-t-0;
content: "";
transform: translate(0, 25%) rotate(225deg);
}

html {
scroll-timeline: --showScrollTop y;
scroll-timeline: --showScrollTop vertical;
}

@keyframes showToTop {
0% {
opacity: 0;
transform: translateY(300%);
}
10% {
opacity: 1;
transform: translateY(0%);
}
}
19 changes: 19 additions & 0 deletions reference.page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ import entityList from "@std/html/named-entity-list.json" with { type: "json" };

export const layout = "raw.tsx";

export const sidebar = [
{
items: [
{
label: "Deno APIs",
id: "/api/deno/",
},
{
label: "Web APIs",
id: "/api/web/",
},
{
label: "Node APIs",
id: "/api/node/",
},
],
},
];

const resetRegexp =
/<link id="ddocResetStylesheet" rel="stylesheet" href=".*?reset\.css">\s*/;
const titleRegexp = /<title>(.+?)<\/title>\s*/s;
Expand Down
2 changes: 2 additions & 0 deletions sidebar.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ for (const el of document.querySelectorAll("[data-accordion-trigger]")) {
}

const sidebar = document.getElementById("sidebar");
console.log(sidebar);

if (sidebar) {
const sidebarNav = sidebar.querySelector("nav")!;
const sidebarOpen = document.getElementById("sidebar-open");
Expand Down
4 changes: 4 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
}
}

html {
scroll-behavior: smooth;
}

/* Scrollbar colors that look good on light and dark theme */
* {
scrollbar-color: hsla(0deg, 0%, 50%, 0.5) hsla(0deg, 0%, 50%, 0.1) !important;
Expand Down
Loading