Skip to content

Commit b9d2a29

Browse files
committed
style: implement theme toggle and update layout styles
1 parent 548322d commit b9d2a29

7 files changed

Lines changed: 91 additions & 139 deletions

File tree

TODO.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
- [ ] add gitee to remote
2-
- [ ] autoscroll to active index
1+
# TODO
32

3+
- [ ] feat: autoscroll to active/highlighted index
4+
- [ ] fix: handle overflow text in the browser component on smaller screens
5+
- [ ] fix: handle longer "file" names to prevent multiple lines
6+
- [ ] style: handle "hover" and "active" states highlight for the browser component

src/components/Bar.astro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
import ThemeToggle from "./ThemeToggle.astro";
23
import Clock from "./svelte/Clock.svelte";
34
45
const pathname = new URL(Astro.request.url).pathname;
@@ -27,11 +28,11 @@ const isHighlighted = function (tab: Tab) {
2728
};
2829
---
2930

30-
<nav class="flex justify-center w-full border px-2 lg:w-full lg:grid lg:grid-cols-2 bg-black/50">
31-
<ul class="hidden lg:flex">
31+
<nav class="flex w-full justify-between border border-black/70 bg-white/50 px-2 text-black transition-colors dark:border-white/70 dark:bg-black/50 dark:text-white">
32+
<ul class="flex">
3233
{
3334
tabs.map((tab) => (
34-
<li class={"w-[26px] flex justify-center " + (isHighlighted(tab) ? "bg-white text-black" : "")}>
35+
<li class={"flex w-[26px] justify-center " + (isHighlighted(tab) ? "bg-black text-white hover:text-white/90 dark:bg-white dark:text-black dark:hover:text-black/80" : "hover:text-black/70 dark:hover:text-white/70")}>
3536
<a
3637
class={"w-[18px] " + tab.padding}
3738
rel="prefetch"
@@ -44,8 +45,9 @@ const isHighlighted = function (tab: Tab) {
4445
}
4546
</ul>
4647

47-
<div class="text-end">
48+
<div class="flex justify-end gap-2 text-end">
4849
<Clock client:only="svelte" />
50+
<ThemeToggle />
4951
</div>
5052

5153
<script is:inline define:vars={{ tabs }}>

src/components/Main.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<main class="w-full h-full border flex flex-col items-center px-2 pb-2 overflow-hidden bg-black/50 font-mono">
1+
<main class="flex h-full w-full flex-col items-center overflow-hidden border border-black/70 bg-white/50 px-2 pb-2 font-mono transition-colors dark:border-white/70 dark:bg-black/50">
22
<slot />
33
</main>

src/components/ThemeToggle.astro

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<button
2+
id="themeToggle"
3+
aria-label="Toggle theme"
4+
class="cursor-pointer text-black transition-colors hover:text-black/70 dark:text-white dark:hover:text-white"
5+
>
6+
<svg
7+
aria-hidden="true"
8+
class="size-5"
9+
xmlns="http://www.w3.org/2000/svg"
10+
viewBox="0 0 24 24"
11+
>
12+
<path
13+
class="fill-current dark:fill-transparent"
14+
fill-rule="evenodd"
15+
d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"
16+
></path>
17+
<path
18+
class="fill-transparent dark:fill-current"
19+
fill-rule="evenodd"
20+
d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"
21+
></path>
22+
</svg>
23+
</button>
24+
25+
<script is:inline>
26+
const theme = (() => {
27+
const localStorageTheme = localStorage?.getItem("theme") ?? "";
28+
if (["dark", "light"].includes(localStorageTheme)) {
29+
return localStorageTheme;
30+
}
31+
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
32+
return "dark";
33+
}
34+
return "light";
35+
})();
36+
37+
if (theme === "light") {
38+
document.documentElement.classList.remove("dark");
39+
} else {
40+
document.documentElement.classList.add("dark");
41+
}
42+
43+
window.localStorage.setItem("theme", theme);
44+
45+
const handleToggleClick = () => {
46+
const element = document.documentElement;
47+
element.classList.toggle("dark");
48+
49+
isDark = element.classList.contains("dark");
50+
localStorage.setItem("theme", isDark ? "dark" : "light");
51+
};
52+
53+
document.getElementById("themeToggle")?.addEventListener("click", handleToggleClick);
54+
</script>

src/components/svelte/Browser.svelte

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<script lang="ts">
22
import { mod } from "../lib/math.ts";
33
4+
type Entry = {
5+
name: string;
6+
icon?: string;
7+
href?: string;
8+
description?: string;
9+
search?: string;
10+
shortcut?: string;
11+
dialog?: boolean;
12+
content?: Array<Entry>;
13+
};
14+
415
interface Props {
516
prompt: string;
617
files: Entry[];
@@ -110,14 +121,14 @@
110121
/>
111122

112123
<div class="w-full">
113-
<span class="text-grey">{prompt}</span>
124+
<span class="text-black/70 dark:text-white/70">{prompt}</span>
114125
<span>~/{files[activeIndexes[0]].name}</span>
115126
</div>
116127
<div class="h-full w-full grid grid-cols-[minmax(140px,max-content)_minmax(140px,max-content)_1fr] border">
117128
<div class="p-2 lf-pane-left">
118129
<ul>
119130
{#each files as { name, icon, href, content }, index}
120-
<li class={"px-2 leading-snug " + (index === activeIndexes[0] ? "bg-white text-black" : "")}>
131+
<li class={"px-2 leading-snug " + (index === activeIndexes[0] ? "bg-black text-white dark:bg-white dark:text-black" : "")}>
121132
{#if href}
122133
<a {href}
123134
><span class="text-sm mr-0.5">{icon || (href && "") || (content && "") || ""}</span>
@@ -134,10 +145,10 @@
134145
<div class="p-2 border-x">
135146
<ul>
136147
{#if files[activeIndexes[0]].content?.length == 0}
137-
<li class={"px-2 leading-snug text-red"}>EMPTY</li>
148+
<li class={"px-2 leading-snug text-red-700 dark:text-red-400"}>EMPTY</li>
138149
{:else if files[activeIndexes[0]].content?.length}
139150
{#each files[activeIndexes[0]].content ?? [] as { name, icon, href, content }, index}
140-
<li class={"px-2 leading-snug " + (index === activeIndexes[1] ? "bg-white text-black" : "")}>
151+
<li class={"px-2 leading-snug " + (index === activeIndexes[1] ? "bg-black text-white dark:bg-white dark:text-black" : "")}>
141152
<span class="text-sm mr-0.5">{icon || (href && "") || (content && "") || ""}</span>
142153
{name}
143154
</li>
@@ -177,7 +188,7 @@
177188
</div>
178189
<dialog
179190
bind:this={dialog}
180-
class="m-auto bg-black text-white border fixed inset-0"
191+
class="fixed inset-0 m-auto border border-black/70 bg-white text-black backdrop:bg-black/5 dark:border-white/70 dark:bg-black dark:text-white dark:backdrop:bg-black/60"
181192
onclick={onDialogClick}
182193
>
183194
<form
@@ -189,13 +200,13 @@
189200
<label for="input"> {files[activeIndexes[0]].name}</label>
190201
<input
191202
id="input"
192-
class="bg-black text-white ml-1 w-96"
203+
class="ml-1 w-96"
193204
bind:value={query}
194205
/>
195206
<input
196207
type="submit"
197208
value="󰘌"
198-
class="cursor-pointer w-6"
209+
class="w-6 cursor-pointer"
199210
onclick={handleSubmit}
200211
/>
201212
</p>

src/layouts/Layout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { title } = Astro.props;
1414
<head>
1515
<Head title={title} />
1616
</head>
17-
<body>
17+
<body class="grid h-screen min-h-screen grid-rows-[auto_1fr] place-items-center gap-2 bg-white p-2 font-mono leading-[1.6] text-black transition-colors dark:bg-black dark:text-white">
1818
<Bar />
1919
<Main>
2020
<slot />

src/styles/global.css

Lines changed: 6 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,16 @@
11
@import "tailwindcss";
2-
@plugin "@tailwindcss/typography";
32

4-
@theme {
5-
--color-black: #000000;
6-
--color-red: #E64A29;
7-
--color-green: #5AC55A;
8-
--color-yellow: #FFCE29;
9-
--color-blue: #5AADFF;
10-
--color-magenta: #C583CD;
11-
--color-cyan: #63C5C5;
12-
--color-white: #fdfdfd;
13-
--color-grey: #C5C5C5;
14-
}
3+
@custom-variant dark (&:where(.dark, .dark *));
154

165
@theme inline {
176
--font-mono: var(--font-jetbrains-mono), var(--font-noto-sans-cjk), var(--font-symbols-nerd-font), monospace;
187
}
198

20-
@utility prose-grey {
21-
--tw-prose-body: #fdfdfd;
22-
--tw-prose-headings: #fdfdfd;
23-
--tw-prose-links: #fdfdfd;
24-
--tw-prose-pre-code: #fdfdfd;
25-
--tw-prose-pre-bg: #000000;
26-
}
27-
28-
@layer base {
29-
30-
*,
31-
*::before,
32-
*::after {
33-
box-sizing: border-box;
34-
}
35-
36-
*:focus-visible,
37-
input:focus-visible {
38-
outline: none;
39-
}
40-
41-
body,
42-
h1,
43-
h2,
44-
h3,
45-
h4,
46-
p,
47-
figure,
48-
blockquote,
49-
dl,
50-
dd {
51-
margin: 0;
52-
}
53-
54-
ul,
55-
ol {
56-
list-style: none;
57-
margin: 0;
58-
padding: 0;
59-
}
60-
61-
a {
62-
text-decoration: none;
63-
color: inherit;
64-
}
65-
}
66-
67-
:root {
68-
--color-background: black;
69-
--color-text: #fdfdfd;
70-
--color-grey: #a5a5a5;
71-
}
72-
73-
body {
74-
min-height: 100vh;
75-
height: 100vh;
76-
display: grid;
77-
grid-template-areas: "nav" "main";
78-
grid-template-rows: auto 1fr;
79-
place-items: center;
80-
padding: 0.5em;
81-
gap: 0.5em;
82-
color: var(--color-text);
83-
background-color: var(--color-background);
84-
font-family: var(--font-mono);
85-
font-size: 16px;
86-
line-height: 1.6;
87-
}
88-
89-
pre {
90-
font-family: var(--font-mono);
91-
}
92-
93-
.prose h2 {
94-
text-align: center;
95-
font-size: 1.125rem;
96-
color: var(--color-text);
97-
}
98-
99-
.prose h3 {
100-
text-align: center;
101-
font-size: 1rem;
102-
font-weight: 300;
103-
}
104-
105-
.prose p:has(strong) {
106-
margin-top: 1rem;
107-
}
108-
109-
.prose details {
110-
padding: 6px 10px;
111-
border: 1px solid var(--color-text);
112-
}
113-
114-
.prose details>summary {
115-
padding: 2px 0;
116-
cursor: pointer;
117-
line-height: 1.2;
118-
}
119-
120-
.prose details>summary::marker {
121-
content: " ";
122-
color: var(--color-grey);
123-
font-size: 1.2em;
124-
}
125-
126-
.prose details>p {
127-
margin: 2px 0;
128-
cursor: pointer;
9+
@theme {
10+
--color-black: #020202;
11+
--color-white: #fdfdfd;
12912
}
13013

131-
div {
132-
scrollbar-width: thin;
133-
scrollbar-color: var(--color-grey) #0000;
14+
a, input, button {
15+
@apply outline-none focus-visible:outline-none
13416
}

0 commit comments

Comments
 (0)