Skip to content

Add dark mode / theme system with auto-detection#28

Merged
mortonanalytics merged 1 commit intodevelopfrom
feature/theme-system
Mar 28, 2026
Merged

Add dark mode / theme system with auto-detection#28
mortonanalytics merged 1 commit intodevelopfrom
feature/theme-system

Conversation

@mortonanalytics
Copy link
Copy Markdown
Owner

Summary

  • Adds setTheme(mode = "dark") with WCAG AA-verified dark palette across all chart elements
  • Auto-detection via mode = "auto" — responds to OS prefers-color-scheme and Quarto/Bootstrap data-bs-theme changes in real-time
  • Fully backward compatible: existing setTheme(bg = "#fff") calls still work via nested config normalization

What changed

  • R API: setTheme() gains mode, preset, overrides parameters. Config structure changed from flat dict to nested {mode, preset, values} with JS-side normalization shim for v1.1.0 saved widgets
  • JS: New ThemeManager class (theme-manager.js) with normalizeThemeConfig(), detectEnvironment(), MutationObserver + matchMedia listeners, and lifecycle cleanup. New palettes.js with LIGHT/DARK constants (21 CSS custom properties each)
  • CSS: High-contrast (prefers-contrast: more) and reduced-motion (prefers-reduced-motion: reduce) media queries
  • Existing tests updated: test_options.R, test_e2e_widgets.R, test_setters_extended.R — migrated from flat dict to nested config assertions

Test plan

  • R tests pass: 666/666 (devtools::test())
  • JS tests pass: 183/183 (npx vitest run, 21 test files)
  • 18 R theme contract tests (test_theme_mode.R)
  • 7 JS theme contract tests (theme.test.js)
  • Backward compat: v1.1.0 flat dict config normalized correctly
  • Manual: toggle OS dark mode, verify chart responds
  • Manual: test in Quarto doc with data-bs-theme toggle

🤖 Generated with Claude Code

Adds mode-based theming to setTheme(): "light", "dark", and "auto" modes
with WCAG AA-verified palettes. Auto mode detects OS preference and
Quarto/Bootstrap data-bs-theme via MutationObserver + matchMedia.

R: setTheme() gains mode/preset/overrides params (backward compatible)
JS: ThemeManager class with palettes, auto-detection, lifecycle cleanup
CSS: high-contrast and reduced-motion media queries
Tests: 18 R tests, 7 JS vitest tests (25 total)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mortonanalytics mortonanalytics merged commit 78123f3 into develop Mar 28, 2026
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.

1 participant