mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Merge pull request #501 from chriswritescode-dev/feature/app-font-size
feat(frontend): add an app-wide font size preference
This commit is contained in:
9 files changed
+99
-5
No files matched your search
@@ -665,6 +665,7 @@ Retrieve the user's full settings, including all preferences. Stored credentials
|
||||
preferences: {
|
||||
theme: 'dark' | 'light' | 'system',
|
||||
colorTheme?: string, // one of: ${[MANAGER_COLOR_THEME_ID, ...OPENCODE_THEMES.map((theme) => theme.id)].join(', ')}
|
||||
fontSize?: 'small' | 'medium' | 'large' | 'xlarge',
|
||||
mode: 'plan' | 'build',
|
||||
defaultModel?: string,
|
||||
defaultAgent?: string,
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
(function () {
|
||||
try {
|
||||
var snapshot = JSON.parse(localStorage.getItem('ocm-appearance'));
|
||||
var fontSize = localStorage.getItem('ocm-font-size');
|
||||
if (fontSize) document.documentElement.style.fontSize = fontSize;
|
||||
if (!snapshot) return;
|
||||
var root = document.documentElement;
|
||||
if (snapshot.dark) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { MANAGER_COLOR_THEME_ID, OPENCODE_THEMES, isColorThemeId } from '@openco
|
||||
import { UserPreferencesSchema } from '@opencode-manager/shared/schemas'
|
||||
|
||||
const themePreferenceSchema = UserPreferencesSchema.pick({ theme: true })
|
||||
const fontSizePreferenceSchema = UserPreferencesSchema.pick({ fontSize: true })
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
@@ -106,6 +107,34 @@ export function GeneralSettings() {
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="fontSize">Font size</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Scale text and spacing across the app
|
||||
</p>
|
||||
</div>
|
||||
<Select
|
||||
value={preferences?.fontSize ?? 'medium'}
|
||||
onValueChange={(value) => {
|
||||
const parsedFontSize = fontSizePreferenceSchema.safeParse({ fontSize: value })
|
||||
if (parsedFontSize.success && parsedFontSize.data.fontSize) {
|
||||
updateSettings({ fontSize: parsedFontSize.data.fontSize })
|
||||
}
|
||||
}}
|
||||
>
|
||||
<SelectTrigger id="fontSize" className="w-full shrink-0 sm:w-40">
|
||||
<SelectValue placeholder="Select a font size" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="small">Small</SelectItem>
|
||||
<SelectItem value="medium">Default</SelectItem>
|
||||
<SelectItem value="large">Large</SelectItem>
|
||||
<SelectItem value="xlarge">Extra large</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="divide-y divide-border">
|
||||
<div className="flex items-start justify-between gap-4 py-3">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { applyColorTheme, getDocumentThemeMode, type ThemeMode } from '@/lib/theme/colorTheme'
|
||||
import { applyColorTheme, applyFontSize, getDocumentThemeMode, type ThemeMode } from '@/lib/theme/colorTheme'
|
||||
import { ThemeContext } from './theme-context'
|
||||
|
||||
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||
@@ -11,6 +11,13 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||
const hasPreferences = preferences !== undefined
|
||||
const theme = preferences?.theme || 'dark'
|
||||
const colorTheme = preferences?.colorTheme
|
||||
const fontSize = preferences?.fontSize
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasPreferences) return
|
||||
|
||||
applyFontSize(document.documentElement, fontSize)
|
||||
}, [hasPreferences, fontSize])
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasPreferences) return
|
||||
|
||||
@@ -403,12 +403,12 @@ body {
|
||||
input[type="url"],
|
||||
textarea,
|
||||
select {
|
||||
font-size: 16px !important;
|
||||
font-size: max(16px, 1rem) !important;
|
||||
}
|
||||
|
||||
/* ContentEditable elements */
|
||||
[contenteditable="true"] {
|
||||
font-size: 16px !important;
|
||||
font-size: max(16px, 1rem) !important;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
APPEARANCE_STORAGE_KEY,
|
||||
AppearanceSnapshotSchema,
|
||||
FONT_SIZE_STORAGE_KEY,
|
||||
applyColorTheme,
|
||||
applyFontSize,
|
||||
readableTextColor,
|
||||
resolveColorThemeTokens,
|
||||
} from './colorTheme'
|
||||
@@ -148,3 +150,28 @@ describe('applyColorTheme', () => {
|
||||
expect(indexHtml).toContain(APPEARANCE_STORAGE_KEY)
|
||||
})
|
||||
})
|
||||
|
||||
describe('applyFontSize', () => {
|
||||
beforeEach(() => {
|
||||
document.documentElement.removeAttribute('style')
|
||||
window.localStorage.clear()
|
||||
})
|
||||
|
||||
it('applies the scale to the root element and persists it for boot replay', () => {
|
||||
applyFontSize(document.documentElement, 'large')
|
||||
|
||||
expect(document.documentElement.style.fontSize).toBe('112.5%')
|
||||
expect(window.localStorage.getItem(FONT_SIZE_STORAGE_KEY)).toBe('112.5%')
|
||||
})
|
||||
|
||||
it('falls back to the default scale when no preference is set', () => {
|
||||
applyFontSize(document.documentElement, undefined)
|
||||
|
||||
expect(document.documentElement.style.fontSize).toBe('100%')
|
||||
expect(window.localStorage.getItem(FONT_SIZE_STORAGE_KEY)).toBe('100%')
|
||||
})
|
||||
|
||||
it('keeps the boot replay storage key in sync with index.html', () => {
|
||||
expect(indexHtml).toContain(FONT_SIZE_STORAGE_KEY)
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
import { z } from 'zod'
|
||||
import { getOpenCodeTheme, MANAGER_COLOR_THEME_ID } from '@opencode-manager/shared/themes'
|
||||
import type { ColorThemeId, HexColor } from '@opencode-manager/shared/themes'
|
||||
import type { FontSize } from '@opencode-manager/shared/schemas'
|
||||
|
||||
const MANAGER_THEME_TOKENS = [
|
||||
'background',
|
||||
@@ -54,6 +55,15 @@ export type ThemeMode = 'light' | 'dark'
|
||||
|
||||
export const APPEARANCE_STORAGE_KEY = 'ocm-appearance'
|
||||
|
||||
export const FONT_SIZE_STORAGE_KEY = 'ocm-font-size'
|
||||
|
||||
const FONT_SIZE_SCALE: Record<FontSize, string> = {
|
||||
small: '87.5%',
|
||||
medium: '100%',
|
||||
large: '112.5%',
|
||||
xlarge: '125%',
|
||||
}
|
||||
|
||||
export const AppearanceSnapshotSchema = z.object({
|
||||
dark: z.boolean(),
|
||||
tokens: z.record(z.string(), z.string()).nullable(),
|
||||
@@ -165,14 +175,18 @@ export function resolveColorThemeTokens(
|
||||
}
|
||||
}
|
||||
|
||||
function persistAppearance(snapshot: AppearanceSnapshot): void {
|
||||
function persistStorageValue(key: string, value: string): void {
|
||||
try {
|
||||
window.localStorage.setItem(APPEARANCE_STORAGE_KEY, JSON.stringify(snapshot))
|
||||
window.localStorage.setItem(key, value)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function persistAppearance(snapshot: AppearanceSnapshot): void {
|
||||
persistStorageValue(APPEARANCE_STORAGE_KEY, JSON.stringify(snapshot))
|
||||
}
|
||||
|
||||
export function applyColorTheme(
|
||||
root: HTMLElement,
|
||||
colorTheme: ColorThemeId | undefined,
|
||||
@@ -196,3 +210,10 @@ export function applyColorTheme(
|
||||
|
||||
persistAppearance({ dark: isDark, tokens: resolved, themeColor })
|
||||
}
|
||||
|
||||
export function applyFontSize(root: HTMLElement, fontSize: FontSize | undefined): void {
|
||||
const scale = FONT_SIZE_SCALE[fontSize ?? 'medium']
|
||||
|
||||
root.style.fontSize = scale
|
||||
persistStorageValue(FONT_SIZE_STORAGE_KEY, scale)
|
||||
}
|
||||
@@ -102,6 +102,7 @@ export const AssistantSTTPatchSchema = z.object({
|
||||
export const AssistantSettingsPatchSchema = UserPreferencesSchema.pick({
|
||||
theme: true,
|
||||
colorTheme: true,
|
||||
fontSize: true,
|
||||
mode: true,
|
||||
defaultModel: true,
|
||||
walkthroughModel: true,
|
||||
|
||||
@@ -199,6 +199,10 @@ export const DEFAULT_SESSION_DEFAULTS = {
|
||||
permissionMode: 'ask',
|
||||
} satisfies SessionDefaults;
|
||||
|
||||
export const FontSizeSchema = z.enum(['small', 'medium', 'large', 'xlarge']);
|
||||
|
||||
export type FontSize = z.infer<typeof FontSizeSchema>;
|
||||
|
||||
export const DevicePairingPreferencesSchema = z.object({
|
||||
allowPrivateNetworkHttp: z.boolean().optional(),
|
||||
});
|
||||
@@ -208,6 +212,7 @@ export type DevicePairingPreferences = z.infer<typeof DevicePairingPreferencesSc
|
||||
export const UserPreferencesSchema = z.object({
|
||||
theme: z.enum(["dark", "light", "system"]),
|
||||
colorTheme: ColorThemeIdSchema.optional(),
|
||||
fontSize: FontSizeSchema.optional(),
|
||||
mode: z.enum(["plan", "build"]),
|
||||
defaultModel: z.string().optional(),
|
||||
walkthroughModel: z.string().optional(),
|
||||
@@ -269,6 +274,7 @@ export const DEFAULT_STT_CONFIG: STTConfig = {
|
||||
export const DEFAULT_USER_PREFERENCES = {
|
||||
theme: "dark" as const,
|
||||
colorTheme: MANAGER_COLOR_THEME_ID,
|
||||
fontSize: 'medium' as const,
|
||||
mode: "build" as const,
|
||||
activityWindowMinutes: DEFAULT_ACTIVITY_WINDOW_MINUTES,
|
||||
autoScroll: true,
|
||||
|
||||
Reference in new issue
Block a user