Skip to content

fix(client): red peak / green off-peak badge, green pause button - #5

Closed
traderjoe1968 wants to merge 1 commit into
drscrewdriver:mainfrom
traderjoe1968:fix/peak-offpeak-colors
Closed

traderjoe1968 wants to merge 1 commit into
drscrewdriver:mainfrom
traderjoe1968:fix/peak-offpeak-colors

Conversation

@traderjoe1968

Copy link
Copy Markdown

What

Recolor the phase badge and the pause/resume button by peak/off-peak semantics, using only status tokens that actually exist in DSH:

Element Before After
.sg-peak amber #d97706 (fallback — see below) red --dsw-alias-state-error-primary
.sg-off (off-peak) no rule at all → neutral gray green --dsw-alias-state-success-primary
.sg-weekend green green (unchanged, merged into one rule with .sg-off)
.sg-pause (Pause session) neutral gray text/border green text + green border
.sg-pause[aria-pressed='true'] (Resume session) amber green text/border + light green fill

Badges also get an 8% color-mix tint so the state reads at a glance; the pause button uses 8% on hover and 14% when pressed.

Why

  • Off-peak (half price) had no styling at all: .sg-status.sg-off was rendered by status-badge.tsx but never matched in styles.ts, so it looked identical to the neutral state.
  • Peak was amber, which reads as "warning", not "expensive right now"; red is the intended semantic.
  • --dsw-alias-state-warning-primary does not exist in DSH (the real token is state-warn-primary), so [aria-pressed='true'] always fell back to the hardcoded #d97706 and did not follow theme tokens. This PR drops it.

Changes

  • src/client/styles.ts — the CSS above.
  • lib/client.js, lib/client.js.map — rebuilt with pnpm build (build is reproducible; only the CSS string changed).
  • tests/client-styles.test.mjs — 5 new tests pinning the selectors, the two color tokens, and that the non-existent warning token never comes back.

Verification

node --test tests/client-styles.test.mjs   # 5 pass
npm test                                   # 296 pass / 0 fail
npx eslint src tests                       # clean

Visual result is unverified in a running DSH instance (no browser in the environment that produced this PR); the CSS diff is the only behavioral change and is covered by the token-level tests.


中文摘要

峰谷配色修正:

  • 峰时 .sg-peak:橙黄 → 红(--dsw-alias-state-error-primary)。
  • 谷时 .sg-off:此前没有任何规则、一直是中性灰 → 绿(--dsw-alias-state-success-primary)。
  • 周末徽标保持绿色,与谷时合并为同一条规则;徽标加 8% 同色浅底。
  • 「暂停 / 继续会话」按钮:常驻绿字绿边,悬停 8%、按下 14% 绿色浅底。

顺带修掉一处静默回退:旧样式用的 --dsw-alias-state-warning-primary 在 DSH 里不存在(实际是 state-warn-primary),按下态一直吃 #d97706 兜底色,不跟随主题令牌,现已移除。

lib/client.js 由 pnpm build 重新生成(构建可复现,仅 CSS 字符串变化)。新增 5 条样式测试;全量 296 tests / 296 pass,lint 干净。

徽标与按钮按峰谷语义着色,改用 DSH 真实存在的状态令牌:

- 峰时 `.sg-peak`:橙黄 → 红(`--dsw-alias-state-error-primary`)。
- 谷时 `.sg-off`:此前没有规则、一直是中性灰 → 绿(`--dsw-alias-state-success-primary`)。
- 周末 `.sg-weekend`:保持绿色,与谷时合并为同一条规则。
- 「暂停 / 继续会话」按钮:中性灰 / 按下橙黄 → 常驻绿字绿边,按下态用绿色浅底。

顺带修掉一个静默回退:旧样式用的 `--dsw-alias-state-warning-primary` 在 DSH 里并不存在
(实际令牌是 `state-warn-primary`),所以 `[aria-pressed='true']` 一直吃 `#d97706` 兜底色,
主题切换时不会跟随。现在只用 `state-error-primary` / `state-success-primary`。

测试:新增 `tests/client-styles.test.mjs`(5 条)钉住选择器、颜色令牌与「不得再出现
warning 令牌」;全量 296 tests / 296 pass,lint 干净。
@traderjoe1968

Copy link
Copy Markdown
Author

Abandoning this in favor of dsh-save-money — no action needed, sorry for the noise.

@traderjoe1968
traderjoe1968 deleted the fix/peak-offpeak-colors branch November 24, 2026 04:55
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