docs: Enhanced CSR Layout (#1908)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
7d954584a6
commit
eb41b65d4c
@@ -6,6 +6,8 @@ import {
|
||||
import SearchButton from "../islands/SearchButton.tsx";
|
||||
import VersionSelect from "../islands/VersionSelect.tsx";
|
||||
import { type VersionLink } from "../routes/docs/[...slug].tsx";
|
||||
import { Logo } from "$fresh/www/components/Header.tsx";
|
||||
import DocsTitle from "$fresh/www/components/DocsTitle.tsx";
|
||||
|
||||
export default function DocsSidebar(
|
||||
props: {
|
||||
@@ -16,55 +18,29 @@ export default function DocsSidebar(
|
||||
) {
|
||||
return (
|
||||
<>
|
||||
{props.mobile
|
||||
? (
|
||||
<button
|
||||
type="button"
|
||||
class="bg-gray-200 font-bold text-gray-400 rounded-full py-1 px-2 w-full mb-2"
|
||||
>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html:
|
||||
`document.currentScript.parentNode.onclick = function () {
|
||||
document.querySelector(".DocSearch.DocSearch-Button").click()
|
||||
}`,
|
||||
}}
|
||||
<div class="fixed w-[17rem] md:flex h-screen overflow-hidden ">
|
||||
<div class="flex-1 h-screen overflow-y-auto">
|
||||
<div class="sticky mb-4 top-0 bg-white z-10">
|
||||
<div class=" py-4 flex items-center">
|
||||
<Logo />
|
||||
<DocsTitle />
|
||||
</div>
|
||||
<hr />
|
||||
</div>
|
||||
<SearchButton class="mr-4 sm:mr-0" />
|
||||
<div class="mb-4">
|
||||
<VersionSelect
|
||||
selectedVersion={props.selectedVersion}
|
||||
versions={props.versionLinks}
|
||||
/>
|
||||
<span class="DocSearch-Button-Container">
|
||||
<svg
|
||||
width="20"
|
||||
height="20"
|
||||
class="DocSearch-Search-Icon"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path
|
||||
d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
</path>
|
||||
</svg>
|
||||
<span class="DocSearch-Button-Placeholder">Search</span>
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
: <SearchButton />}
|
||||
|
||||
<div class="mb-4">
|
||||
<VersionSelect
|
||||
selectedVersion={props.selectedVersion}
|
||||
versions={props.versionLinks}
|
||||
/>
|
||||
</div>
|
||||
<ul class="list-inside font-semibold nested ml-2.5">
|
||||
{CATEGORIES[props.selectedVersion].map((category) => (
|
||||
<SidebarCategory key={category.href} category={category} />
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="list-inside font-semibold nested ml-2.5">
|
||||
{CATEGORIES[props.selectedVersion].map((category) => (
|
||||
<SidebarCategory key={category.href} category={category} />
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default function DocsTitle(props: { title: string }) {
|
||||
export default function DocsTitle() {
|
||||
return (
|
||||
<>
|
||||
<a
|
||||
|
||||
@@ -17,7 +17,7 @@ const LINKS = [
|
||||
|
||||
export default function Footer() {
|
||||
return (
|
||||
<footer class="border-t-2 border-gray-200 bg-gray-100 md:h-16 flex gap-4 justify-center">
|
||||
<footer class="border-t-2 border-gray-200 md:h-16 flex my-8 justify-center">
|
||||
<div class="flex flex-col sm:flex-row gap-4 justify-between items-center max-w-screen-xl mx-auto w-full px(4 sm:6 md:8) p-4">
|
||||
<div class="text(gray-600 center)">
|
||||
<span>© {new Date().getFullYear()} the Fresh authors</span>
|
||||
@@ -30,27 +30,6 @@ export default function Footer() {
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<ul class="flex justify-center items-center gap-4 md:ml-4 mt-2 mb-4 sm:mt-0 sm:mb-0 flex-wrap">
|
||||
<li class="flex items-center">
|
||||
<a
|
||||
href="https://github.com/denoland/fresh"
|
||||
class="hover:text-green-600 inline-block transition"
|
||||
aria-label="GitHub"
|
||||
>
|
||||
<Icons.GitHub />
|
||||
</a>
|
||||
</li>
|
||||
<li class="flex items-center">
|
||||
<a
|
||||
href="https://discord.com/invite/deno"
|
||||
class="hover:text-green-600 inline-block transition"
|
||||
aria-label="Discord"
|
||||
>
|
||||
<Icons.Discord />
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
|
||||
+33
-14
@@ -3,26 +3,45 @@ import NavigationBar from "./NavigationBar.tsx";
|
||||
|
||||
export default function Header(props: { title: string; active: string }) {
|
||||
const isHome = props.active == "/";
|
||||
const isDocs = props.active == "/docs";
|
||||
|
||||
return (
|
||||
<div>
|
||||
<header
|
||||
class={"mx-auto max-w-screen-xl flex gap-3 items-center " +
|
||||
(isHome ? "justify-end" : "justify-between")}
|
||||
>
|
||||
{!isHome && (
|
||||
<div class="p-4 flex items-center">
|
||||
<Logo />
|
||||
<DocsTitle title={props.title} />
|
||||
</div>
|
||||
<>
|
||||
{isDocs
|
||||
? (
|
||||
<header
|
||||
class={" top-0 w-full bg-white mx-auto max-w-screen-xl flex gap-3 items-center " +
|
||||
"justify-between md:justify-end"}
|
||||
>
|
||||
<div class="p-4 flex items-center md:hidden">
|
||||
<Logo />
|
||||
<DocsTitle />
|
||||
</div>
|
||||
|
||||
<NavigationBar class="hidden md:flex" active={props.active} />
|
||||
</header>
|
||||
)
|
||||
: (
|
||||
<header
|
||||
class={"mx-auto max-w-screen-xl flex gap-3 items-center " +
|
||||
(isHome ? "justify-end" : "justify-between")}
|
||||
>
|
||||
{!isHome && (
|
||||
<div class="p-4 flex items-center">
|
||||
<Logo />
|
||||
<DocsTitle />
|
||||
</div>
|
||||
)}
|
||||
<NavigationBar class="hidden md:flex" active={props.active} />
|
||||
</header>
|
||||
)}
|
||||
<NavigationBar class="hidden md:flex" active={props.active} />
|
||||
</header>
|
||||
|
||||
<NavigationBar class="md:hidden pb-3" active={props.active} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Logo() {
|
||||
export function Logo() {
|
||||
return (
|
||||
<a href="/" class="flex mr-3 items-center" aria-label="Top Page">
|
||||
<img src="/logo.svg" alt="Fresh logo" width={40} height={40} />
|
||||
|
||||
@@ -14,7 +14,7 @@ export default function VersionSelect(
|
||||
|
||||
return (
|
||||
<>
|
||||
<div class="relative">
|
||||
<div class="relative mr-4 sm:mr-0">
|
||||
<label htmlFor="version" class="sr-only">
|
||||
Version
|
||||
</label>
|
||||
|
||||
@@ -155,10 +155,8 @@ export default function DocsPage(props: PageProps<Data>) {
|
||||
<meta property="og:image" content={ogImageUrl} />
|
||||
<meta name="view-transition" content="same-origin" />
|
||||
</Head>
|
||||
<div class="flex flex-col min-h-screen">
|
||||
<Header title="docs" active="/docs" />
|
||||
<div class="flex flex-col min-h-screen mx-auto max-w-screen-xl">
|
||||
<Main page={props.data.page} />
|
||||
<Footer />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
@@ -166,31 +164,8 @@ export default function DocsPage(props: PageProps<Data>) {
|
||||
|
||||
function Main(props: { page: Page }) {
|
||||
return (
|
||||
<div class="flex-1" f-client-nav>
|
||||
<MobileSidebar page={props.page} />
|
||||
<div class="flex mx-auto max-w-screen-xl px-4 md:px-0 md:py-0 justify-end bg-gray-100">
|
||||
<label
|
||||
for="docs_sidebar"
|
||||
class="px-4 py-3 md:hidden flex items-center hover:bg-gray-100 rounded gap-2 cursor-pointer"
|
||||
>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
d="M4 6h16M4 12h16M4 18h7"
|
||||
>
|
||||
</path>
|
||||
</svg>
|
||||
<div>Table of Contents</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="mx-auto max-w-screen-xl flex gap-6 md:gap-8">
|
||||
<div class="flex-1 " f-client-nav>
|
||||
<div class=" md:flex">
|
||||
<DesktopSidebar page={props.page} />
|
||||
<Partial name="docs-main">
|
||||
<Content page={props.page} />
|
||||
@@ -202,7 +177,7 @@ function Main(props: { page: Page }) {
|
||||
|
||||
function MobileSidebar(props: { page: Page }) {
|
||||
return (
|
||||
<>
|
||||
<div class="md:hidden">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="hidden toggle"
|
||||
@@ -215,11 +190,8 @@ function MobileSidebar(props: { page: Page }) {
|
||||
class="absolute inset-0 bg-gray-600 opacity-75"
|
||||
for="docs_sidebar"
|
||||
/>
|
||||
<div class="relative flex-1 flex flex-col w-[16rem] h-full bg-white border(r-2 gray-100)">
|
||||
<div class="p-4 border(b-2 gray-100) bg-green-300">
|
||||
<DocsTitle title="docs" />
|
||||
</div>
|
||||
<nav class="pt-6 pb-16 px-4 overflow-x-auto">
|
||||
<div class="relative flex-1 flex flex-col w-[18rem] h-full bg-white border(r-2 gray-100)">
|
||||
<nav class="pt-0 pb-16 px-4 overflow-x-auto">
|
||||
<DocsSidebar
|
||||
mobile
|
||||
versionLinks={props.page.versionLinks}
|
||||
@@ -228,13 +200,13 @@ function MobileSidebar(props: { page: Page }) {
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DesktopSidebar(props: { page: Page }) {
|
||||
return (
|
||||
<nav class="w-[18rem] flex-shrink-0 hidden md:block py-7 px-4">
|
||||
<nav class="w-[18rem] flex-shrink-0 hidden md:block px-4">
|
||||
<DocsSidebar
|
||||
versionLinks={props.page.versionLinks}
|
||||
selectedVersion={props.page.version}
|
||||
@@ -246,21 +218,48 @@ function DesktopSidebar(props: { page: Page }) {
|
||||
function Content(props: { page: Page }) {
|
||||
const html = renderMarkdown(props.page.markdown);
|
||||
return (
|
||||
<main class="py-6 md:mr-4 lg:mr-32 min-w-0">
|
||||
<h1 class="text(4xl gray-900) tracking-tight font-extrabold md:mt-0 px-4">
|
||||
{props.page.title}
|
||||
</h1>
|
||||
<div
|
||||
class="mt-6 markdown-body"
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
/>
|
||||
<ForwardBackButtons
|
||||
slug={props.page.slug}
|
||||
version={props.page.version}
|
||||
prev={props.page.prevNav}
|
||||
next={props.page.nextNav}
|
||||
/>
|
||||
</main>
|
||||
<div class="w-full min-w-0">
|
||||
<Header title="docs" active="/docs" />
|
||||
<main class="max-w-3xl mt-4 min-w-0 mx-auto">
|
||||
<MobileSidebar page={props.page} />
|
||||
<div class="flex mx-auto max-w-screen-xl px-4 md:px-0 md:py-0 justify-end bg-gray-100">
|
||||
<label
|
||||
for="docs_sidebar"
|
||||
class="px-4 py-3 md:hidden flex items-center hover:bg-gray-100 rounded gap-2 cursor-pointer"
|
||||
>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
d="M4 6h16M4 12h16M4 18h7"
|
||||
>
|
||||
</path>
|
||||
</svg>
|
||||
<div>Table of Contents</div>
|
||||
</label>
|
||||
</div>
|
||||
<h1 class="text(4xl gray-900) tracking-tight font-extrabold md:mt-0 px-4">
|
||||
{props.page.title}
|
||||
</h1>
|
||||
<div
|
||||
class="mt-6 markdown-body"
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
/>
|
||||
<ForwardBackButtons
|
||||
slug={props.page.slug}
|
||||
version={props.page.version}
|
||||
prev={props.page.prevNav}
|
||||
next={props.page.nextNav}
|
||||
/>
|
||||
<Footer />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user