www: docs: feat: add dark mode (#2820)

- Added CSS vars for dark/light colors.
- Added dark/light theme toggle as Island

Fixes #2648

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
David Monaghan
2025-02-04 11:58:05 +01:00
committed by GitHub
co-authored by Marvin Hagemeister
parent adf8b87a03
commit b1f2a989a5
16 changed files with 320 additions and 46 deletions
+3 -1
View File
@@ -3,7 +3,7 @@ import { define } from "../utils/state.ts";
export default define.page(function App({ Component, state, url }) {
return (
<html lang="en">
<html lang="en" class="dark" data-theme="dark">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -42,6 +42,8 @@ export default define.page(function App({ Component, state, url }) {
</>
)
: null}
<script src="/theme.client.js"></script>
<script type="module" src="/theme-toggle.client.js"></script>
</head>
<body>
<Component />
+9 -9
View File
@@ -152,10 +152,10 @@ export default define.page<typeof handler>(function DocsPage(props) {
<Header title="docs" active="/docs" />
<div f-client-nav={true}>
<MobileSidebar page={page} />
<div class="flex mx-auto max-w-screen-2xl px-0 md:px-4 md:py-0 justify-start bg-gray-100">
<div class="flex mx-auto max-w-screen-2xl px-0 md:px-4 md:py-0 justify-start bg-background-secondary">
<label
for="docs_sidebar"
class="px-4 py-3 lg:hidden flex items-center hover:bg-gray-100 rounded gap-2 cursor-pointer"
class="px-4 py-3 lg:hidden flex items-center rounded gap-2 cursor-pointer"
>
<svg
class="h-6 w-6"
@@ -178,7 +178,7 @@ export default define.page<typeof handler>(function DocsPage(props) {
<div class="fixed top-24 w-[17rem] flex overflow-hidden">
<div class="flex-1 h-[calc(100vh_-_6rem)] overflow-y-auto pb-8">
<SearchButton class="mr-4 sm:mr-0" />
<div class="mb-4">
<div class="mb-4 px-1">
<VersionSelect
selectedVersion={page.version}
versions={page.versionLinks}
@@ -199,7 +199,7 @@ export default define.page<typeof handler>(function DocsPage(props) {
<TableOfContents headings={headings} />
<div class="lg:order-1 min-w-0 max-w-3xl w-full">
<h1 class="text-4xl text-gray-900 tracking-tight font-bold md:mt-0 px-4 md:px-0 mb-4">
<h1 class="text-4xl text-foreground-primary tracking-tight font-bold md:mt-0 px-4 md:px-0 mb-4">
{page.title}
</h1>
<div
@@ -256,7 +256,7 @@ function MobileSidebar({ page }: { page: Page }) {
class="absolute inset-0 bg-gray-600 opacity-75"
for="docs_sidebar"
/>
<div class="relative flex-1 flex flex-col w-[18rem] h-full bg-white border-r-2 border-gray-100">
<div class="relative flex-1 flex flex-col w-[18rem] h-full bg-background-primary border-r-2 border-foreground-secondary">
<nav class="pt-0 pb-16 overflow-x-auto">
<div class="flex-1 h-screen overflow-y-auto pt-4 px-4">
<SearchButton class="mr-4 sm:mr-0" />
@@ -293,9 +293,9 @@ function ForwardBackButtons(props: {
? (
<a
href={prev.href}
class="px-4 py-2 text-left rounded border border-gray-200 grid border-solid w-full hover:border-green-600 transition-colors"
class="px-4 py-2 text-left rounded border border-foreground-secondary/20 grid border-solid w-full hover:border-green-600 transition-colors"
>
<span class="text-sm text-gray-600">
<span class="text-sm text-gray-600 dark:text-gray-500">
Previous page
</span>
<span class="text-green-600 font-medium">
@@ -308,9 +308,9 @@ function ForwardBackButtons(props: {
? (
<a
href={next.href}
class="px-4 py-2 text-right rounded border border-gray-200 border-solid grid w-full hover:border-green-600 transition-colors"
class="px-4 py-2 text-left rounded border border-foreground-secondary/20 grid border-solid w-full hover:border-green-600 transition-colors"
>
<span class="text-sm text-gray-600">
<span class="text-sm text-gray-600 dark:text-gray-500">
Next page
</span>
<span class="text-green-600 font-medium">
+11
View File
@@ -0,0 +1,11 @@
import { PageProps } from "../../../src/context.ts";
export default function Layout({ Component }: PageProps) {
return (
<div class="layout">
<div class="bg-background-primary text-foreground-primary">
<Component />
</div>
</div>
);
}
+95
View File
@@ -0,0 +1,95 @@
import { asset } from "fresh/runtime";
import { page } from "fresh";
import Projects, { type Project } from "../components/Projects.tsx";
import Header from "../components/Header.tsx";
import Footer from "../components/Footer.tsx";
import projects from "../data/showcase.json" with { type: "json" };
import { define } from "../utils/state.ts";
const TITLE = "Showcase | Fresh";
const DESCRIPTION = "Selection of projects that have been built with Fresh.";
export const handler = define.handlers({
GET(ctx) {
ctx.state.title = TITLE;
ctx.state.description = DESCRIPTION;
ctx.state.ogImage = new URL(asset("/og-image.webp"), ctx.url).href;
return page();
},
});
export default define.page<typeof handler>(function ShowcasePage() {
return (
<>
<Header title="showcase" active="/showcase" />
<div class="flex flex-col min-h-screen bg-white text-black">
<div class="flex-1">
<Showcase items={projects} />
<section class="max-w-screen-lg mx-auto my-16 px-4 sm:px-6 md:px-8 space-y-4">
<h2 class="text-3xl text-gray-600 font-bold">
Badge
</h2>
<p class="text-gray-600">
You can add these stylish badges to your project’s README to show
that it was built with Fresh.
</p>
<img
width="197"
height="37"
src="https://fresh.deno.dev/fresh-badge.svg"
alt="Made with Fresh"
/>
<img
width="197"
height="37"
src="https://fresh.deno.dev/fresh-badge-dark.svg"
alt="Made with Fresh"
/>
<p>
<a
href="https://github.com/denoland/fresh#badges"
class="text-blue-600 hover:underline focus:underline"
>
Usage instructions
</a>
</p>
</section>
<img
src="/illustration/deno-plush.svg"
alt="a deno plush is holding a lemon"
class="mx-auto w-48 mt-16"
/>
</div>
<Footer />
</div>
</>
);
});
function Showcase({ items }: { items: Project[] }) {
return (
<section class="max-w-screen-lg mx-auto my-16 px-4 sm:px-6 md:px-8 space-y-4">
<h2 class="text-3xl text-foreground-primary font-bold ">
Showcase
</h2>
<p class="text-foreground-secondary">
Below is a selection of projects that have been built with Fresh.{" "}
<a
href="https://github.com/denoland/fresh/blob/main/www/data/showcase.json"
class="text-blue-600 hover:underline"
>
Add yours!
</a>
</p>
<Projects items={items} class="gap-16" />
</section>
);
}