forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: app-wide theming with presets, fonts, and contrast #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
e291899
feat: add comprehensive theming support (colors, fonts, contrast, tra…
aaditagrawal 631a87a
feat: redesign appearance settings with theme presets, fix Gemini ico…
aaditagrawal c3cb2b2
fix: handle comma-separated font stacks in buildFontStack
aaditagrawal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import type { AppSettings } from "./appSettings"; | ||
| import { isValidAccentColor, normalizeAccentColor } from "./accentColor"; | ||
|
|
||
| // ── Default values ────────────────────────────────────────────────────────── | ||
| export const DEFAULT_UI_FONT = ""; | ||
| export const DEFAULT_CODE_FONT = ""; | ||
| export const DEFAULT_UI_FONT_SIZE = 0; // 0 = use CSS default | ||
| export const DEFAULT_CODE_FONT_SIZE = 0; | ||
| export const DEFAULT_CONTRAST = 0; // 0 = no adjustment | ||
| export const MIN_UI_FONT_SIZE = 10; | ||
| export const MAX_UI_FONT_SIZE = 24; | ||
| export const MIN_CODE_FONT_SIZE = 8; | ||
| export const MAX_CODE_FONT_SIZE = 24; | ||
| export const MIN_CONTRAST = -100; | ||
| export const MAX_CONTRAST = 100; | ||
|
|
||
| // ── Font families ─────────────────────────────────────────────────────────── | ||
| const DEFAULT_UI_FONT_STACK = | ||
| '"DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif'; | ||
| const DEFAULT_CODE_FONT_STACK = | ||
| '"Geist Mono", "SF Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace'; | ||
|
|
||
| function buildFontStack(userFont: string, fallback: string): string { | ||
| const trimmed = userFont.trim(); | ||
| if (!trimmed) return fallback; | ||
| // If the user provided a comma-separated stack, keep it as-is | ||
| if (trimmed.includes(",")) { | ||
| return `${trimmed}, ${fallback}`; | ||
| } | ||
| // If the single font family contains spaces and isn't already quoted, quote it | ||
| const quoted = | ||
| trimmed.includes(" ") && !trimmed.startsWith('"') && !trimmed.startsWith("'") | ||
| ? `"${trimmed}"` | ||
| : trimmed; | ||
| return `${quoted}, ${fallback}`; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function clampFontSize(size: number, min: number, max: number): number { | ||
| if (!Number.isFinite(size) || size <= 0) return 0; | ||
| return Math.min(max, Math.max(min, Math.round(size))); | ||
| } | ||
|
|
||
| function clampContrast(contrast: number): number { | ||
| if (!Number.isFinite(contrast)) return 0; | ||
| return Math.min(MAX_CONTRAST, Math.max(MIN_CONTRAST, Math.round(contrast))); | ||
| } | ||
|
|
||
| // ── Apply to document ─────────────────────────────────────────────────────── | ||
|
|
||
| export function applyThemeConfigToDocument(settings: AppSettings): void { | ||
| if (typeof document === "undefined") return; | ||
|
|
||
| const root = document.documentElement.style; | ||
|
|
||
| // Fonts | ||
| const uiFontStack = buildFontStack(settings.uiFont, DEFAULT_UI_FONT_STACK); | ||
| const codeFontStack = buildFontStack(settings.codeFont, DEFAULT_CODE_FONT_STACK); | ||
| root.setProperty("--theme-ui-font", uiFontStack); | ||
| root.setProperty("--theme-code-font", codeFontStack); | ||
|
|
||
| // Font sizes | ||
| const uiSize = clampFontSize(settings.uiFontSize, MIN_UI_FONT_SIZE, MAX_UI_FONT_SIZE); | ||
| const codeSize = clampFontSize(settings.codeFontSize, MIN_CODE_FONT_SIZE, MAX_CODE_FONT_SIZE); | ||
| if (uiSize > 0) { | ||
| root.setProperty("--theme-ui-font-size", `${uiSize}px`); | ||
| } else { | ||
| root.removeProperty("--theme-ui-font-size"); | ||
| } | ||
| if (codeSize > 0) { | ||
| root.setProperty("--theme-code-font-size", `${codeSize}px`); | ||
| } else { | ||
| root.removeProperty("--theme-code-font-size"); | ||
| } | ||
|
|
||
| // Background/foreground overrides | ||
| if (settings.backgroundColorOverride && isValidAccentColor(settings.backgroundColorOverride)) { | ||
| root.setProperty( | ||
| "--theme-background-override", | ||
| normalizeAccentColor(settings.backgroundColorOverride), | ||
| ); | ||
| } else { | ||
| root.removeProperty("--theme-background-override"); | ||
| } | ||
| if (settings.foregroundColorOverride && isValidAccentColor(settings.foregroundColorOverride)) { | ||
| root.setProperty( | ||
| "--theme-foreground-override", | ||
| normalizeAccentColor(settings.foregroundColorOverride), | ||
| ); | ||
| } else { | ||
| root.removeProperty("--theme-foreground-override"); | ||
| } | ||
|
|
||
| // Contrast adjustment | ||
| const contrast = clampContrast(settings.contrast); | ||
| if (contrast !== 0) { | ||
| root.setProperty("--theme-contrast", String(contrast)); | ||
| } else { | ||
| root.removeProperty("--theme-contrast"); | ||
| } | ||
|
|
||
| // Translucency | ||
| if (settings.translucency) { | ||
| document.documentElement.classList.add("theme-translucent"); | ||
| } else { | ||
| document.documentElement.classList.remove("theme-translucent"); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 91
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 579
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 89
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 118
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 3684
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 2682
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 45
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 788
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 1101
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 6624
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 2840
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 576
🏁 Script executed:
Repository: aaditagrawal/t3code
Length of output: 557
Add CSS rules for
sidebar-translucentgated by.theme-translucent.The
sidebar-translucentclass is applied unconditionally in line 291, but has no CSS definition. When styling is added, it must be scoped so translucency only applies when the root element has thetheme-translucentclass (set conditionally in themeConfig.ts based onsettings.translucency).🤖 Prompt for AI Agents