Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion apps/web/src/appSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
normalizeModelSlug,
resolveSelectableModel,
} from "@t3tools/shared/model";
import { useLocalStorage } from "./hooks/useLocalStorage";
import { getLocalStorageItem, useLocalStorage } from "./hooks/useLocalStorage";
import { EnvMode } from "./components/BranchToolbar.logic";

const APP_SETTINGS_STORAGE_KEY = "t3code:app-settings:v1";
const MAX_CUSTOM_MODEL_COUNT = 32;
export const MAX_CUSTOM_MODEL_LENGTH = 256;
export const HIGH_CONTRAST_CLASS_NAME = "high-contrast";

export const TimestampFormat = Schema.Literals(["locale", "12-hour", "24-hour"]);
export type TimestampFormat = typeof TimestampFormat.Type;
Expand Down Expand Up @@ -52,6 +53,7 @@ export const AppSettingsSchema = Schema.Struct({
defaultThreadEnvMode: EnvMode.pipe(withDefaults(() => "local" as const satisfies EnvMode)),
confirmThreadDelete: Schema.Boolean.pipe(withDefaults(() => true)),
enableAssistantStreaming: Schema.Boolean.pipe(withDefaults(() => false)),
highContrastMode: Schema.Boolean.pipe(withDefaults(() => false)),
timestampFormat: TimestampFormat.pipe(withDefaults(() => DEFAULT_TIMESTAMP_FORMAT)),
customCodexModels: Schema.Array(Schema.String).pipe(withDefaults(() => [])),
customClaudeModels: Schema.Array(Schema.String).pipe(withDefaults(() => [])),
Expand Down Expand Up @@ -221,6 +223,20 @@ export function getCustomModelOptionsByProvider(
};
}

export function applyHighContrastMode(enabled: boolean) {
if (typeof document === "undefined") return;
document.documentElement.classList.toggle(HIGH_CONTRAST_CLASS_NAME, enabled);
}

export function getStoredHighContrastMode(): boolean {
try {
const stored = getLocalStorageItem(APP_SETTINGS_STORAGE_KEY, AppSettingsSchema);
return stored?.highContrastMode ?? false;
} catch {
return false;
}
}

export function useAppSettings() {
const [settings, setSettings] = useLocalStorage(
APP_SETTINGS_STORAGE_KEY,
Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@
}
}

:root.high-contrast {
--muted-foreground: color-mix(in srgb, var(--color-neutral-700) 92%, var(--color-black));
--border: --alpha(var(--color-black) / 45%);
--input: --alpha(var(--color-black) / 50%);
}

:root.high-contrast.dark {
--muted-foreground: color-mix(in srgb, var(--color-neutral-300) 92%, var(--color-white));
--border: --alpha(var(--color-white) / 40%);
--input: --alpha(var(--color-white) / 45%);
}

:root.high-contrast ::placeholder {
color: var(--muted-foreground);
opacity: 1;
}

:root.high-contrast [class*="text-muted-foreground/"] {
color: var(--muted-foreground) !important;
}

body {
font-family:
"DM Sans",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createHashHistory, createBrowserHistory } from "@tanstack/react-router"
import "@xterm/xterm/css/xterm.css";
import "./index.css";

import { applyHighContrastMode, getStoredHighContrastMode } from "./appSettings";
import { isElectron } from "./env";
import { getRouter } from "./router";
import { APP_DISPLAY_NAME } from "./branding";
Expand All @@ -16,6 +17,7 @@ const history = isElectron ? createHashHistory() : createBrowserHistory();
const router = getRouter(history);

document.title = APP_DISPLAY_NAME;
applyHighContrastMode(getStoredHighContrastMode());

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useEffect, useRef } from "react";
import { QueryClient, useQueryClient } from "@tanstack/react-query";
import { Throttler } from "@tanstack/react-pacer";

import { applyHighContrastMode, useAppSettings } from "../appSettings";
import { APP_DISPLAY_NAME } from "../branding";
import { Button } from "../components/ui/button";
import { AnchoredToastProvider, ToastProvider, toastManager } from "../components/ui/toast";
Expand All @@ -36,6 +37,12 @@ export const Route = createRootRouteWithContext<{
});

function RootRouteView() {
const { settings } = useAppSettings();

useEffect(() => {
applyHighContrastMode(settings.highContrastMode);
}, [settings.highContrastMode]);

if (!readNativeApi()) {
return (
<div className="flex h-screen flex-col bg-background text-foreground">
Expand Down
35 changes: 35 additions & 0 deletions apps/web/src/routes/_chat.settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ function SettingsRouteView() {
Active theme: <span className="font-medium text-foreground">{resolvedTheme}</span>
</p>

<div className="flex items-center justify-between rounded-lg border border-border bg-background px-3 py-2">
<div>
<p className="text-sm font-medium text-foreground">High contrast mode</p>
<p className="text-xs text-muted-foreground">
Strengthen muted text and low-contrast labels across light and dark mode.
</p>
</div>
<Switch
checked={settings.highContrastMode}
onCheckedChange={(checked) =>
updateSettings({
highContrastMode: Boolean(checked),
})
}
aria-label="High contrast mode"
/>
</div>

<div className="flex items-center justify-between rounded-lg border border-border bg-background px-3 py-2">
<div>
<p className="text-sm font-medium text-foreground">Timestamp format</p>
Expand Down Expand Up @@ -279,6 +297,22 @@ function SettingsRouteView() {
</Button>
</div>
) : null}

{settings.highContrastMode !== defaults.highContrastMode ? (
<div className="flex justify-end">
<Button
size="xs"
variant="outline"
onClick={() =>
updateSettings({
highContrastMode: defaults.highContrastMode,
})
}
>
Restore high contrast default
</Button>
</div>
) : null}
</div>
</section>

Expand Down Expand Up @@ -699,6 +733,7 @@ function SettingsRouteView() {
</div>
) : null}
</section>

<section className="rounded-2xl border border-border bg-card p-5">
<div className="mb-4">
<h2 className="text-sm font-medium text-foreground">About</h2>
Expand Down