mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(dashboard): keep savings profile visible in light mode (#2544)
## Description The active savings-profile badge uses `text-cyan-100`, which is readable in dark mode but has insufficient contrast against the light-mode badge background. This change adds a light-mode-specific cyan text color so statuses such as `coding` remain visible. Closes #2528 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - Added a light-mode override for the `text-cyan-100` utility used by the active savings-profile badge. - Selected `#155e75` to provide readable contrast against the light-mode badge background. - Added a regression test that verifies the badge color meets the WCAG AA contrast requirement of 4.5:1. ## Testing - [x] Unit tests pass (targeted pytest command below) - [x] Linting passes (targeted Ruff command below) - [ ] Type checking passes (`mypy headroom`) — not run - [x] New tests added for the fix - [x] Manual testing performed ### Test Output ```text $ uv run --frozen --with pytest==8.3.4 python -m pytest tests/test_dashboard_light_mode_contrast.py tests/test_dashboard_token_savings.py -q collected 2 items tests/test_dashboard_light_mode_contrast.py . [50%] tests/test_dashboard_token_savings.py . [100%] 2 passed, 1 warning in 0.14s $ uv run --frozen --with ruff==0.15.17 ruff check tests/test_dashboard_light_mode_contrast.py All checks passed! $ uv run --frozen --with ruff==0.15.17 ruff format --check tests/test_dashboard_light_mode_contrast.py 1 file already formatted ``` The pytest warning was an `asyncio_mode` configuration warning caused by running the lightweight targeted environment without the optional asyncio plugin. It is unrelated to this change. ## Real Behavior Proof - Environment: macOS, Python 3.13.5, patched dashboard served locally in a Chromium-based browser. - Exact command / steps: Served the patched dashboard with `savings_profile: coding`, opened it locally, switched to light mode, and inspected the rendered badge and computed styles. - Observed result: The `coding` status remained visible with computed color `rgb(21, 94, 117)` (`#155e75`) and approximately `6.64:1` contrast, exceeding the WCAG AA requirement of `4.5:1`. - Not tested: Full repository test suite, `mypy headroom`, and manual browser verification on Windows or Linux. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented the non-obvious contrast requirement - [x] Documentation changes are not required for this CSS-only bug fix - [x] My changes generate no new warnings - [x] I have added a test that proves my fix is effective - [x] New and relevant existing unit tests pass locally with my changes - [x] I did **not** edit `CHANGELOG.md` ## Screenshots <img width="1180" height="170" alt="issue-2528-light-mode-after" src="https://github.com/user-attachments/assets/8ccb7c57-466e-45fc-8d30-0e41559a6539" /> ## Additional Notes The fix is intentionally scoped to the existing `text-cyan-100` light-mode behavior and does not change dark-mode styling. I enjoyed working on this issue and learning more about Headroom. I hope this fix is useful, and I’d be happy to address any review feedback. It would mean a lot to make a small contribution to this project. Thank you for taking the time to review the PR! <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/2544" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a> <!-- devin-review-badge-end --> Co-authored-by: JD Davis <mxjerrett@gmail.com>
This commit is contained in:
@@ -102,6 +102,8 @@
|
||||
html:not(.dark) .ring-white\/5 { --tw-ring-color: rgba(0,0,0,0.08); }
|
||||
html:not(.dark) .border-red-900\/30 { border-color: rgba(239,68,68,0.25); }
|
||||
html:not(.dark) .border-emerald-900\/30 { border-color: rgba(16,185,129,0.25); }
|
||||
/* Light mode: keep the active savings-profile badge readable */
|
||||
html:not(.dark) .text-cyan-100 { color: #155e75; }
|
||||
/* Light mode: TTL card color adjustments */
|
||||
html:not(.dark) .text-cyan-50 { color: #164e63; }
|
||||
html:not(.dark) .text-violet-50 { color: #4c1d95; }
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
"""Regression tests for light-mode dashboard contrast."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
from headroom.dashboard import get_dashboard_html
|
||||
|
||||
|
||||
def _relative_luminance(hex_color: str) -> float:
|
||||
channels = [int(hex_color[index : index + 2], 16) / 255 for index in (1, 3, 5)]
|
||||
linear = [
|
||||
value / 12.92 if value <= 0.04045 else ((value + 0.055) / 1.055) ** 2.4
|
||||
for value in channels
|
||||
]
|
||||
return 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2]
|
||||
|
||||
|
||||
def _contrast_ratio(foreground: str, background: str) -> float:
|
||||
lighter, darker = sorted(
|
||||
(_relative_luminance(foreground), _relative_luminance(background)),
|
||||
reverse=True,
|
||||
)
|
||||
return (lighter + 0.05) / (darker + 0.05)
|
||||
|
||||
|
||||
def test_savings_profile_badge_is_readable_in_light_mode() -> None:
|
||||
html = get_dashboard_html()
|
||||
|
||||
assert 'class="text-xs text-cyan-100"' in html
|
||||
override = re.search(
|
||||
r"html:not\(\.dark\) \.text-cyan-100 \{ color: (#[0-9a-fA-F]{6}); \}",
|
||||
html,
|
||||
)
|
||||
assert override is not None
|
||||
|
||||
# The badge is Tailwind cyan-500 at 10% opacity over the white light-mode
|
||||
# surface (#e6f8fb when composited). WCAG AA requires at least 4.5:1
|
||||
# contrast for normal-sized text.
|
||||
assert _contrast_ratio(override.group(1), "#e6f8fb") >= 4.5
|
||||
Reference in New Issue
Block a user