Skip to content

Commit 669e98c

Browse files
Merge pull request #5 from DataResponsibly/accessible-frontend
added light/dark mode
2 parents 445e1bd + 4428bba commit 669e98c

3 files changed

Lines changed: 80 additions & 15 deletions

File tree

client/src/App.jsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useMemo, useRef, useState } from "react";
1+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import ChatInput from "./components/ChatInput.jsx";
33
import ChatOutput from "./components/ChatOutput.jsx";
44
import SettingsPanel from "./components/SettingsPanel.jsx";
@@ -48,6 +48,20 @@ function resolveMaxNewTokens(input) {
4848
}
4949

5050
export default function App() {
51+
const [isDark, setIsDark] = useState(() => {
52+
const saved = localStorage.getItem("theme");
53+
return saved ? saved === "dark" : false;
54+
});
55+
56+
useEffect(() => {
57+
if (isDark) {
58+
document.documentElement.classList.add("dark");
59+
} else {
60+
document.documentElement.classList.remove("dark");
61+
}
62+
localStorage.setItem("theme", isDark ? "dark" : "light");
63+
}, [isDark]);
64+
5165
const [prompt, setPrompt] = useState("");
5266
const [settings, setSettings] = useState(DEFAULT_SETTINGS);
5367
const [tokens, setTokens] = useState([]);
@@ -243,6 +257,15 @@ export default function App() {
243257
)}
244258
</div>
245259
<div className="flex items-center gap-2 shrink-0">
260+
<button
261+
type="button"
262+
className="border border-border px-2 min-h-[36px] hover:bg-panel active:bg-panel touch-manipulation"
263+
onClick={() => setIsDark((d) => !d)}
264+
title={isDark ? "Switch to light mode" : "Switch to dark mode"}
265+
aria-label={isDark ? "Switch to light mode" : "Switch to dark mode"}
266+
>
267+
{isDark ? <SunIcon /> : <MoonIcon />}
268+
</button>
246269
<button
247270
type="button"
248271
className="border border-border px-3 min-h-[36px] uppercase text-xs tracking-wider hover:bg-panel active:bg-panel disabled:opacity-40 disabled:cursor-not-allowed touch-manipulation"
@@ -403,6 +426,30 @@ function MobileDrawer({ title, onClose, children }) {
403426
);
404427
}
405428

429+
function SunIcon() {
430+
return (
431+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
432+
<circle cx="12" cy="12" r="5" />
433+
<line x1="12" y1="1" x2="12" y2="3" />
434+
<line x1="12" y1="21" x2="12" y2="23" />
435+
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64" />
436+
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78" />
437+
<line x1="1" y1="12" x2="3" y2="12" />
438+
<line x1="21" y1="12" x2="23" y2="12" />
439+
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36" />
440+
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22" />
441+
</svg>
442+
);
443+
}
444+
445+
function MoonIcon() {
446+
return (
447+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
448+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
449+
</svg>
450+
);
451+
}
452+
406453
function DesktopBarplotPanel({ barplotData, safenudgeActive, onTokenEdit }) {
407454
return (
408455
<div className="flex flex-col h-full min-h-0 p-3 overflow-hidden">

client/src/index.css

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
@tailwind components;
33
@tailwind utilities;
44

5+
/* Light mode (default) */
6+
:root {
7+
--color-bg: 245 246 250;
8+
--color-panel: 225 232 237;
9+
--color-input: 213 221 227;
10+
--color-border: 127 140 141;
11+
--color-fg: 33 33 33;
12+
}
13+
14+
/* Dark mode */
15+
.dark {
16+
--color-bg: 33 33 33;
17+
--color-panel: 32 44 51;
18+
--color-input: 42 57 66;
19+
--color-border: 127 140 141;
20+
--color-fg: 245 246 250;
21+
}
22+
523
html,
624
body,
725
#root {
@@ -10,8 +28,8 @@ body,
1028

1129
body {
1230
margin: 0;
13-
background-color: #212121;
14-
color: #f5f6fa;
31+
background-color: rgb(var(--color-bg));
32+
color: rgb(var(--color-fg));
1533
font-family: "Andale Mono", AndaleMono, ui-monospace, SFMono-Regular, Menlo,
1634
monospace;
1735
letter-spacing: 0px;
@@ -55,14 +73,14 @@ input[type="number"] {
5573
font-family: "Andale Mono", AndaleMono, monospace;
5674
letter-spacing: 1px;
5775
font-size: 12px;
58-
fill: #f5f6fa;
76+
fill: rgb(var(--color-fg));
5977
cursor: pointer;
6078
}
6179
.barplot-svg .bar {
6280
fill: rgb(39, 174, 96);
6381
}
6482
.barplot-svg .label {
65-
fill: #ffffff;
83+
fill: rgb(var(--color-fg));
6684
font-size: 12px;
6785
}
6886

@@ -117,8 +135,8 @@ input[type="number"] {
117135
text-indent: -20px;
118136
word-spacing: 20px;
119137
white-space: nowrap;
120-
background: #f5f6fa;
121-
color: #f5f6fa;
138+
background: rgb(var(--color-fg));
139+
color: rgb(var(--color-fg));
122140
transition: transform cubic-bezier(0.3, 1.5, 0.7, 1) 0.2s;
123141
}
124142
.toggle:checked {
@@ -142,12 +160,12 @@ input[type="number"] {
142160
appearance: none;
143161
width: 25px;
144162
height: 25px;
145-
background: #f5f6fa;
163+
background: rgb(var(--color-fg));
146164
cursor: pointer;
147165
}
148166
.slider::-moz-range-thumb {
149167
width: 25px;
150168
height: 25px;
151-
background: #f5f6fa;
169+
background: rgb(var(--color-fg));
152170
cursor: pointer;
153171
}

client/tailwind.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/** @type {import('tailwindcss').Config} */
22
export default {
3+
darkMode: "class",
34
content: ["./index.html", "./src/**/*.{js,jsx}"],
45
theme: {
56
extend: {
67
colors: {
7-
// Match the existing dark terminal aesthetic
8-
bg: "#212121",
9-
panel: "#202c33",
10-
input: "#2a3942",
11-
border: "#7f8c8d",
12-
fg: "#f5f6fa",
8+
bg: "rgb(var(--color-bg) / <alpha-value>)",
9+
panel: "rgb(var(--color-panel) / <alpha-value>)",
10+
input: "rgb(var(--color-input) / <alpha-value>)",
11+
border: "rgb(var(--color-border) / <alpha-value>)",
12+
fg: "rgb(var(--color-fg) / <alpha-value>)",
1313
accent: "#27ae60",
1414
danger: "#c0392b",
1515
},

0 commit comments

Comments
 (0)