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 16 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
34 changes: 30 additions & 4 deletions _components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Searcher from "lume/core/searcher.ts";
import SidebarTopNav from "./SidebarTopNav.tsx";
import {
Sidebar as Sidebar_,
SidebarCategory as SidebarCategory_,
Expand All @@ -20,12 +21,23 @@ export default function Sidebar(
class="p-2 pt-0 pr-0 overflow-y-auto overflow-x-hidden"
style={{ scrollbarGutter: "stable", scrollbarWidth: "thin" }}
>
{props.url !== "/" &&
(
<ul className="xl:hidden">
<SidebarTopNav name="Runtime" url="/runtime/" />
<SidebarTopNav name="API reference" url="/api/deno" />
<SidebarTopNav name="Examples" url="/examples/" />
<SidebarTopNav name="Deploy" url="/deploy/" />
<SidebarTopNav name="Subhosting" url="/subhosting/" />
</ul>
)}
<ul>
{props.sidebar.map((section) => (
<SidebarSection
section={section}
search={props.search}
url={props.url}
headerPath={props.headerPath}
/>
))}
</ul>
Expand All @@ -45,8 +57,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 Down Expand Up @@ -145,7 +157,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,7 +188,21 @@ 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>
</>
Expand Down
12 changes: 12 additions & 0 deletions _components/SidebarTopNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function SidebarTopNav(props: { name: string; url: string }) {
return (
<li class="mx-2">
<a
class="block px-3 py-1.5 text-[.8125rem] leading-4 font-normal text-foreground-secondary rounded-md ring-1 ring-transparent hover:ring-background-tertiary hover:bg-background-secondary current:bg-background-secondary current:text-blue-500 current:font-semibold transition-colors duration-200 ease-in-out select-none"
href={props.url}
>
{props.name}
</a>
</li>
);
}
12 changes: 12 additions & 0 deletions _components/ToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function ToTop() {
return (
<a href="#" className="top docs-cta runtime-cta">
<span>
&#8679;
</span>
<span>
To top
</span>
</a>
);
}
22 changes: 3 additions & 19 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 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
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
30 changes: 28 additions & 2 deletions overrides.css
Original file line number Diff line number Diff line change
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,29 @@ 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;
}

.top {
@apply text-xs flex flex-col items-center;
position: fixed;
bottom: 1rem;
right: 1rem;
animation-name: showToTop;
animation-duration: 1ms; /* Firefox requires this to apply the animation */
animation-timeline: --showScrollTop;
}

html {
scroll-timeline: --showScrollTop y;
/* Firefox supports the older "vertical" syntax */
scroll-timeline: --showScrollTop vertical;
}

@keyframes showToTop {
0% {
opacity: 0;
}

10% {
opacity: 1;
}
}
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