Skip to content

feat(viewer): dark mode + system monospace font (#304)#312

Merged
lizhengfeng101 merged 1 commit into
alibaba:mainfrom
chethanuk:fix/issue-304-dark-mode
Jul 8, 2026
Merged

feat(viewer): dark mode + system monospace font (#304)#312
lizhengfeng101 merged 1 commit into
alibaba:mainfrom
chethanuk:fix/issue-304-dark-mode

Conversation

@chethanuk

Copy link
Copy Markdown
Contributor

Closes #304.

What

Enhances the embedded viewer stylesheet (internal/viewer/static/style.css) to add a dark theme and use the system monospace font, as requested in #304. CSS-only — no JS, no Go, no template changes.

Dark mode

  • Automatic via @media (prefers-color-scheme: dark) — follows the OS setting, no toggle/JS/state to persist.
  • Palette extracted into :root CSS variables; the dark block overrides only the variables, so light-mode colors are unchanged. A small extra dark block handles the badge tints (model/tokens/duration/error) that need alpha rather than a flat variable swap.
  • color-scheme: light dark declared so native scrollbars/form controls theme correctly in dark (the response/tool-output scroll regions).

System monospace font

  • Replaces the hardcoded SFMono-Regular, Consolas, … stacks with a --mono variable led by ui-monospace, so the OS's UI monospace font is used across platforms.

Accessibility

Dark tokens chosen to clear WCAG AA (≥4.5:1) for small text — measured: file-count badge 6.17:1, faint labels 4.64:1, muted labels 5.62:1.

How it was verified

Built and ran ocr viewer, then rendered all three pages (repos / sessions / session) in both light and dark with a headless browser emulating prefers-color-scheme, using a fixture that exercises every themed element (token/duration/error badges, markdown code-blocks, inline-code, tool-call panes, overflow scroll regions). Programmatically asserted computed colors, color-scheme, and contrast ratios; visually confirmed no light-mode regression.

Light Dark
pastel badges, white surfaces, unchanged GitHub-dark palette (#0d1117 bg, #58a6ff links)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ 1 posted as inline comment(s)
  • 📝 0 posted as summary

Comment thread internal/viewer/static/style.css Outdated
Comment on lines +514 to +525
/* Dark-mode badge tints (need alpha, not a flat var swap) */
@media (prefers-color-scheme: dark) {
.badge-model { background: rgba(56,139,253,0.15); color: #79c0ff; }
.badge-tokens { background: rgba(46,160,67,0.15); color: #7ee787; }
.badge-duration { background: rgba(187,128,9,0.15); color: #e3b341; }
.badge-error { background: rgba(248,81,73,0.15); color: #ff7b72; }
.file-count-badge { color: #adbac7; } /* lift off --badge-neutral-bg to clear WCAG AA */
.tool-call-error { border-left-color: #f85149; }
.tool-name { color: #d2a8ff; }
.task-plan .card { border-left-color: #d2a8ff; }
.task-plan .task-type-dot { background: #d2a8ff; }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent theming: hardcoded colors in dark-mode overrides.

The entire file has been refactored to use CSS custom properties, but this dark-mode block reverts to hardcoded rgba() and hex values. CSS custom properties can absolutely hold rgba() values — you could define semantic variables like --badge-model-bg, --badge-model-color, --tool-name-color, etc. in both the light and dark :root blocks. This would:

  1. Keep the theming system consistent and maintainable.
  2. Allow future theme customization via variable overrides.
  3. Avoid the disconnect noted in the comment "need alpha, not a flat var swap" — alpha values work fine in custom properties.

Additionally, several light-mode selectors still use hardcoded colors that lack dark-mode overrides here:

  • .task-main .card { border-left: 3px solid #0366d6; } — no dark override
  • .task-relocation .card { border-left: 3px solid #e36209; } — no dark override
  • .task-memory .card { border-left: 3px solid #8b949e; } — no dark override
  • .task-default .card / .task-default .task-type-dot — no dark override
  • .task-main .task-type-dot, .task-memory .task-type-dot, .task-relocation .task-type-dot — no dark overrides
  • .badge-model/tokens/duration/error light-mode definitions (lines 342–345) still use hardcoded colors
  • .tool-name { color: #8250df; } (line 439) still hardcoded in light mode

Consider defining all these as CSS variables in both :root blocks for full consistency.

Enhance the embedded viewer stylesheet per alibaba#304:

- Add automatic dark mode via `prefers-color-scheme` (no JS/toggle).
  The full colour palette — surfaces, text, borders, accents, task/badge
  brand colours — lives in `:root` custom properties, with a single dark
  block overriding the values. Light-mode colours are unchanged.
- Declare `color-scheme: light dark` so native scrollbars and form
  controls follow the active theme.
- Use the system monospace stack (`ui-monospace, ...`) via a `--mono`
  variable, replacing the hardcoded font stacks.
- Dark tokens chosen to clear WCAG AA (>=4.5:1) for small text, and dim
  brand colours (task-main, task-default) lifted for the dark surface.

Verified by rendering all three viewer pages in light and dark with a
headless browser: computed colours, contrast ratios, resolved theme
variables, and `color-scheme` asserted programmatically.
@chethanuk chethanuk force-pushed the fix/issue-304-dark-mode branch from 10fa7e8 to 8a89896 Compare July 6, 2026 13:59

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101 lizhengfeng101 merged commit 14f1c22 into alibaba:main Jul 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dark mode for WebUI and system monospace font

2 participants