Skip to content

Commit d09f3ee

Browse files
committed
feat(web): add theme system with light/dark/night modes and compact user messages
- Add theme selector in sidebar with 4 options: light, dark, night, system - Extend useTheme hook to support new theme types - Add CSS variables for dark (balanced) and night (darkest) themes - Make user message cards more compact: - Reduced padding (px-3 py-2) - Smaller text (13px) - Actions appear below card on hover - Update CHANGELOG.md
1 parent 59b0527 commit d09f3ee

5 files changed

Lines changed: 195 additions & 52 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
## [Unreleased]
4+
5+
### Added
6+
- **Theme selector**: Added theme toggle button in sidebar with three theme options:
7+
- **Light**: Light mode
8+
- **Dark**: Balanced dark mode with brighter backgrounds and more visible UI elements
9+
- **Night**: Darkest mode (previously the only dark mode)
10+
- **System**: Follow system preference
11+
12+
### Changed
13+
- **apps/web/src/hooks/useTheme.ts**: Extended theme system to support `light`, `dark`, `night`, and `system` themes. Added `THEME_OPTIONS` export and `Theme` type export.
14+
- **apps/web/src/index.css**: Added CSS variables for the new "dark" middle-ground theme and renamed existing dark theme to "night". The dark theme now uses brighter backgrounds (neutral-800/900 vs neutral-950) and more visible borders/accents.
15+
- **apps/web/src/components/Sidebar.tsx**: Added theme selector menu with icon (Sun/Moon/MoonStar) in the sidebar header, available in both desktop and web modes.
16+
- **apps/web/src/components/ChatView.tsx**: Made user messages more compact:
17+
- Reduced padding (px-3 py-2 instead of px-4 py-3)
18+
- Smaller text (13px instead of 14px)
19+
- Action buttons (copy, rollback) and timestamp moved below the message card
20+
- Actions only appear on hover for cleaner UI

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,10 +5047,10 @@ const MessagesTimeline = memo(function MessagesTimeline({
50475047
const userImages = row.message.attachments ?? [];
50485048
const canRevertAgentWork = revertTurnCountByUserMessageId.has(row.message.id);
50495049
return (
5050-
<div className="flex justify-end">
5051-
<div className="group relative max-w-[80%] rounded-2xl rounded-br-sm border border-border bg-secondary px-4 py-3">
5050+
<div className="group flex flex-col items-end">
5051+
<div className="max-w-[80%] rounded-xl rounded-br-sm border border-border bg-secondary px-3 py-2">
50525052
{userImages.length > 0 && (
5053-
<div className="mb-2 grid max-w-[420px] grid-cols-2 gap-2">
5053+
<div className="mb-1.5 grid max-w-[420px] grid-cols-2 gap-2">
50545054
{userImages.map(
50555055
(image: NonNullable<TimelineMessage["attachments"]>[number]) => (
50565056
<div
@@ -5087,30 +5087,31 @@ const MessagesTimeline = memo(function MessagesTimeline({
50875087
</div>
50885088
)}
50895089
{row.message.text && (
5090-
<pre className="whitespace-pre-wrap wrap-break-word font-mono text-sm leading-relaxed text-foreground">
5090+
<pre className="whitespace-pre-wrap wrap-break-word text-[13px] leading-normal text-foreground">
50915091
{row.message.text}
50925092
</pre>
50935093
)}
5094-
<div className="mt-1.5 flex items-center justify-end gap-2">
5095-
<div className="flex items-center gap-1.5 opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">
5096-
{row.message.text && <MessageCopyButton text={row.message.text} />}
5097-
{canRevertAgentWork && (
5098-
<Button
5099-
type="button"
5100-
size="xs"
5101-
variant="outline"
5102-
disabled={isRevertingCheckpoint || isWorking}
5103-
onClick={() => onRevertUserMessage(row.message.id)}
5104-
title="Revert to this message"
5105-
>
5106-
<Undo2Icon className="size-3" />
5107-
</Button>
5108-
)}
5109-
</div>
5110-
<p className="text-right text-[10px] text-muted-foreground/30">
5111-
{formatTimestamp(row.message.createdAt)}
5112-
</p>
5113-
</div>
5094+
</div>
5095+
<div className="mt-1 flex items-center gap-1.5 opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">
5096+
{row.message.text && <MessageCopyButton text={row.message.text} />}
5097+
{canRevertAgentWork && (
5098+
<Button
5099+
type="button"
5100+
size="xs"
5101+
variant="outline"
5102+
disabled={isRevertingCheckpoint || isWorking}
5103+
onClick={() => onRevertUserMessage(row.message.id)}
5104+
title="Revert to this message"
5105+
>
5106+
<Undo2Icon className="size-3" />
5107+
</Button>
5108+
)}
5109+
<span
5110+
className="text-[10px] text-muted-foreground/40"
5111+
title={formatTimestamp(row.message.createdAt)}
5112+
>
5113+
{formatTimestamp(row.message.createdAt)}
5114+
</span>
51145115
</div>
51155116
</div>
51165117
);

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import {
22
ChevronRightIcon,
33
FolderIcon,
44
GitPullRequestIcon,
5+
MoonIcon,
6+
MoonStarIcon,
57
RocketIcon,
68
SquarePenIcon,
9+
SunIcon,
710
TerminalIcon,
811
} from "lucide-react";
912
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -60,6 +63,14 @@ import {
6063
} from "./ui/sidebar";
6164
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
6265
import { isNonEmpty as isNonEmptyString } from "effect/String";
66+
import { useTheme, THEME_OPTIONS, type Theme } from "../hooks/useTheme";
67+
import {
68+
Menu,
69+
MenuPopup,
70+
MenuRadioGroup,
71+
MenuRadioItem,
72+
MenuTrigger,
73+
} from "./ui/menu";
6374

6475
const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = [];
6576
const THREAD_PREVIEW_LIMIT = 6;
@@ -257,7 +268,14 @@ function ProjectFavicon({ cwd }: { cwd: string }) {
257268
);
258269
}
259270

271+
function ThemeIcon({ theme }: { theme: Theme }) {
272+
if (theme === "light") return <SunIcon className="size-3.5" />;
273+
if (theme === "night") return <MoonStarIcon className="size-3.5" />;
274+
return <MoonIcon className="size-3.5" />;
275+
}
276+
260277
export default function Sidebar() {
278+
const { theme, setTheme } = useTheme();
261279
const projects = useStore((store) => store.projects);
262280
const threads = useStore((store) => store.threads);
263281
const markThreadUnread = useStore((store) => store.markThreadUnread);
@@ -990,36 +1008,79 @@ export default function Sidebar() {
9901008
</div>
9911009
);
9921010

1011+
const themeSelector = (
1012+
<Menu>
1013+
<Tooltip>
1014+
<TooltipTrigger
1015+
render={
1016+
<MenuTrigger
1017+
render={
1018+
<button
1019+
type="button"
1020+
aria-label="Change theme"
1021+
className="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
1022+
>
1023+
<ThemeIcon theme={theme} />
1024+
</button>
1025+
}
1026+
/>
1027+
}
1028+
/>
1029+
<TooltipPopup side="bottom">Theme</TooltipPopup>
1030+
</Tooltip>
1031+
<MenuPopup side="bottom" align="end" className="min-w-[140px]">
1032+
<MenuRadioGroup
1033+
value={theme}
1034+
onValueChange={(value) => setTheme(value as Theme)}
1035+
>
1036+
{THEME_OPTIONS.map((option) => (
1037+
<MenuRadioItem key={option.value} value={option.value}>
1038+
{option.label}
1039+
</MenuRadioItem>
1040+
))}
1041+
</MenuRadioGroup>
1042+
</MenuPopup>
1043+
</Menu>
1044+
);
1045+
9931046
return (
9941047
<>
9951048
{isElectron ? (
9961049
<>
997-
<SidebarHeader className="drag-region h-[52px] flex-row items-center gap-2 px-4 py-0 pl-[82px]">
1050+
<SidebarHeader className="drag-region h-[52px] flex-row items-center gap-1 px-4 py-0 pl-[82px]">
9981051
{wordmark}
999-
{showDesktopUpdateButton && (
1000-
<Tooltip>
1001-
<TooltipTrigger
1002-
render={
1003-
<button
1004-
type="button"
1005-
aria-label={desktopUpdateTooltip}
1006-
aria-disabled={desktopUpdateButtonDisabled || undefined}
1007-
disabled={desktopUpdateButtonDisabled}
1008-
className={`inline-flex size-7 ml-auto mt-2 items-center justify-center rounded-md text-muted-foreground transition-colors ${desktopUpdateButtonInteractivityClasses} ${desktopUpdateButtonClasses}`}
1009-
onClick={handleDesktopUpdateButtonClick}
1010-
>
1011-
<RocketIcon className="size-3.5" />
1012-
</button>
1013-
}
1014-
/>
1015-
<TooltipPopup side="bottom">{desktopUpdateTooltip}</TooltipPopup>
1016-
</Tooltip>
1017-
)}
1052+
<div className="ml-auto mt-2 flex items-center gap-0.5">
1053+
{themeSelector}
1054+
{showDesktopUpdateButton && (
1055+
<Tooltip>
1056+
<TooltipTrigger
1057+
render={
1058+
<button
1059+
type="button"
1060+
aria-label={desktopUpdateTooltip}
1061+
aria-disabled={desktopUpdateButtonDisabled || undefined}
1062+
disabled={desktopUpdateButtonDisabled}
1063+
className={`inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors ${desktopUpdateButtonInteractivityClasses} ${desktopUpdateButtonClasses}`}
1064+
onClick={handleDesktopUpdateButtonClick}
1065+
>
1066+
<RocketIcon className="size-3.5" />
1067+
</button>
1068+
}
1069+
/>
1070+
<TooltipPopup side="bottom">{desktopUpdateTooltip}</TooltipPopup>
1071+
</Tooltip>
1072+
)}
1073+
</div>
10181074
</SidebarHeader>
10191075
</>
10201076
) : (
10211077
<SidebarHeader className="gap-3 px-3 py-2 sm:gap-2.5 sm:px-4 sm:py-3">
1022-
{wordmark}
1078+
<div className="flex items-center gap-2">
1079+
{wordmark}
1080+
<div className="ml-auto">
1081+
{themeSelector}
1082+
</div>
1083+
</div>
10231084
</SidebarHeader>
10241085
)}
10251086

‎apps/web/src/hooks/useTheme.ts‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { useCallback, useEffect, useSyncExternalStore } from "react";
22

3-
type Theme = "light" | "dark" | "system";
3+
type Theme = "light" | "dark" | "night" | "system";
44
type ThemeSnapshot = {
55
theme: Theme;
66
systemDark: boolean;
77
};
88

9+
export const THEME_OPTIONS = [
10+
{ value: "light", label: "Light", description: "Light mode" },
11+
{ value: "dark", label: "Dark", description: "Balanced dark mode" },
12+
{ value: "night", label: "Night", description: "Darkest mode" },
13+
{ value: "system", label: "System", description: "Follow system preference" },
14+
] as const;
15+
916
const STORAGE_KEY = "t3code:theme";
1017
const MEDIA_QUERY = "(prefers-color-scheme: dark)";
1118

@@ -21,16 +28,30 @@ function getSystemDark(): boolean {
2128

2229
function getStored(): Theme {
2330
const raw = localStorage.getItem(STORAGE_KEY);
24-
if (raw === "light" || raw === "dark" || raw === "system") return raw;
31+
if (raw === "light" || raw === "dark" || raw === "night" || raw === "system") return raw;
2532
return "system";
2633
}
2734

2835
function applyTheme(theme: Theme, suppressTransitions = false) {
2936
if (suppressTransitions) {
3037
document.documentElement.classList.add("no-transitions");
3138
}
32-
const isDark = theme === "dark" || (theme === "system" && getSystemDark());
33-
document.documentElement.classList.toggle("dark", isDark);
39+
40+
// Determine which CSS classes to apply
41+
// - "dark" class = dark mode (middle ground)
42+
// - "night" class = darkest mode
43+
// - neither = light mode
44+
const resolvedTheme = theme === "system"
45+
? (getSystemDark() ? "dark" : "light")
46+
: theme;
47+
48+
document.documentElement.classList.remove("dark", "night");
49+
if (resolvedTheme === "dark") {
50+
document.documentElement.classList.add("dark");
51+
} else if (resolvedTheme === "night") {
52+
document.documentElement.classList.add("dark", "night");
53+
}
54+
3455
if (suppressTransitions) {
3556
// Force a reflow so the no-transitions class takes effect before removal
3657
// oxlint-disable-next-line no-unused-expressions
@@ -87,8 +108,14 @@ export function useTheme() {
87108
const snapshot = useSyncExternalStore(subscribe, getSnapshot);
88109
const theme = snapshot.theme;
89110

111+
// resolvedTheme returns "light" or "dark" for components that only care about light/dark distinction
112+
// (night is treated as dark for icon/color purposes)
90113
const resolvedTheme: "light" | "dark" =
91-
theme === "system" ? (snapshot.systemDark ? "dark" : "light") : theme;
114+
theme === "system"
115+
? (snapshot.systemDark ? "dark" : "light")
116+
: theme === "night"
117+
? "dark"
118+
: theme;
92119

93120
const setTheme = useCallback((next: Theme) => {
94121
localStorage.setItem(STORAGE_KEY, next);
@@ -103,3 +130,5 @@ export function useTheme() {
103130

104131
return { theme, setTheme, resolvedTheme } as const;
105132
}
133+
134+
export type { Theme };

‎apps/web/src/index.css‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import "tailwindcss";
22

33
@custom-variant dark (&:is(.dark, .dark *));
4+
@custom-variant night (&:is(.night, .night *));
45

56
@theme inline {
67
--animate-skeleton: skeleton 2s -1s infinite linear;
@@ -90,13 +91,44 @@
9091
--warning: var(--color-amber-500);
9192
--warning-foreground: var(--color-amber-700);
9293

94+
/* Dark mode - balanced dark, between light and night */
9395
@variant dark {
96+
color-scheme: dark;
97+
--background: color-mix(in srgb, var(--color-neutral-900) 97%, var(--color-black));
98+
--foreground: var(--color-neutral-100);
99+
--card: color-mix(in srgb, var(--color-neutral-900) 92%, var(--color-white));
100+
--card-foreground: var(--color-neutral-100);
101+
--popover: color-mix(in srgb, var(--color-neutral-900) 94%, var(--color-white));
102+
--popover-foreground: var(--color-neutral-100);
103+
--primary: oklch(0.588 0.217 264);
104+
--primary-foreground: var(--color-white);
105+
--secondary: --alpha(var(--color-white) / 5%);
106+
--secondary-foreground: var(--color-neutral-100);
107+
--muted: --alpha(var(--color-white) / 6%);
108+
--muted-foreground: color-mix(in srgb, var(--color-neutral-400) 90%, var(--color-white));
109+
--accent: --alpha(var(--color-white) / 6%);
110+
--accent-foreground: var(--color-neutral-100);
111+
--destructive: color-mix(in srgb, var(--color-red-500) 90%, var(--color-white));
112+
--border: --alpha(var(--color-white) / 8%);
113+
--input: --alpha(var(--color-white) / 10%);
114+
--ring: oklch(0.588 0.217 264);
115+
--destructive-foreground: var(--color-red-400);
116+
--info: var(--color-blue-500);
117+
--info-foreground: var(--color-blue-400);
118+
--success: var(--color-emerald-500);
119+
--success-foreground: var(--color-emerald-400);
120+
--warning: var(--color-amber-500);
121+
--warning-foreground: var(--color-amber-400);
122+
}
123+
124+
/* Night mode - darkest */
125+
@variant night {
94126
color-scheme: dark;
95127
--background: color-mix(in srgb, var(--color-neutral-950) 95%, var(--color-white));
96128
--foreground: var(--color-neutral-100);
97-
--card: color-mix(in srgb, var(--background) 98%, var(--color-white));
129+
--card: color-mix(in srgb, var(--color-neutral-950) 98%, var(--color-white));
98130
--card-foreground: var(--color-neutral-100);
99-
--popover: color-mix(in srgb, var(--background) 98%, var(--color-white));
131+
--popover: color-mix(in srgb, var(--color-neutral-950) 98%, var(--color-white));
100132
--popover-foreground: var(--color-neutral-100);
101133
--primary: oklch(0.588 0.217 264);
102134
--primary-foreground: var(--color-white);

0 commit comments

Comments
 (0)