fix(code-highlighter): make light-theme colors fully self-contained - #174
Merged
Conversation
The previous dark-theme fix (#172) added a self-contained `codeLineNumberColorDark` token, but the light-theme line number color still used the global `token.colorTextQuaternary`. The `-light` / `-dark` variants are self-contained color schemes driven by the `theme` prop, so their colors must not follow the app color algorithm. In the mirrored case (app on the dark algorithm + `theme="light"`), `colorTextQuaternary` resolves to `rgba(255, 255, 255, 0.25)` (from `colorTextBase=#fff`), rendered on top of the `#fafafa` light background, making the line numbers nearly invisible. Add a `codeLineNumberColor` component token (light counterpart to `codeLineNumberColorDark`), defaulting to `rgba(0, 0, 0, 0.25)` - the effective color of `colorTextQuaternary` under the light algorithm (`colorTextBase=#000` @ 0.25) - so the common-case appearance is unchanged while the value no longer drifts with the app algorithm.
The previous commit only tokenized the line-number color. The rest of the light-theme chrome still used algorithm-driven global tokens, so in the mirrored case (app on the dark algorithm + `theme="light"`) the language label and action buttons became invisible, the header lost separation from the content, and the borders were wrong. Add the missing light counterparts to the existing dark tokens and wire them in, so `-light` / `-dark` are now fully self-contained and symmetric: - `codeHeaderBg` (was `colorFillSecondary`) - `codeBorderColor` (was `colorBorderSecondary`, used on root / header-bottom / gutter-right) - `codeLangColor` (was `colorTextSecondary`) - `codeBtnColor` (was `colorTextSecondary`) - `codeBtnHoverBg` (light had no hover override; antd Button's algorithm-driven default was used) Also fix the dark-theme root border, which used the global `colorBorder` instead of the existing `codeBorderColorDark` - in the mirrored case (light algorithm + `theme="dark"`) it drew a light `#d9d9d9` outline around the dark card. The light-theme action buttons now mirror the dark side: `!important` plus an explicit hover background, so the override reliably beats antd Button's `.ant-btn-variant-text` color (which is why the dark side already needed `!important`). Defaults preserve the previous common-case appearance: opaque hexes are the equivalent of the prior translucent global tokens composited over white (e.g. `#f0f0f0` == `colorBorderSecondary` / `colorFillSecondary` over white), and the rgba text colors match the prior `colorTextSecondary` under the light algorithm.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤔 This is a ...
🔗 Related Issues
💡 Background and Solution
The
-light/-darkvariants are self-contained color schemes driven by the user-controlledthemeprop, so their colors must not follow the app color algorithm - this is the principle #172 established ("usingcolorTextwould break the mirrored case"). #172 only tokenized the dark side (plus the line-number light token in the first commit here); the rest of the light chrome still used global tokens.Impact of the gap - in the mirrored case (app on the dark algorithm +
theme="light"), the global tokens resolve to dark-algorithm values:#fafafacolorTextSecondary(lang label, buttons)rgba(0,0,0,0.65)rgba(255,255,255,0.65)colorTextQuaternary(line numbers)rgba(0,0,0,0.25)rgba(255,255,255,0.25)colorFillSecondary(header bg)rgba(0,0,0,0.06)rgba(255,255,255,0.12)colorBorderSecondary(borders)#f0f0f0And the dark-theme root border used the global
colorBorderinstead ofcodeBorderColorDark, so in the opposite mirrored case (light algorithm +theme="dark") it drew a light#d9d9d9outline around the dark card.Solution
Add the missing light counterparts to the existing dark tokens and wire them in, so
-light/-darkare now fully self-contained and symmetric:codeLineNumberColorcolorTextQuaternarycodeLineNumberColorDarkcodeHeaderBgcolorFillSecondarycodeHeaderBgDarkcodeBorderColorcolorBorderSecondary(root / header-bottom / gutter-right)codeBorderColorDarkcodeLangColorcolorTextSecondarycodeLangColorDarkcodeBtnColorcolorTextSecondarycodeBtnColorDarkcodeBtnHoverBgcodeBtnHoverBgDarkAlso: dark root border
colorBorder->codeBorderColorDark; light action buttons now mirror the dark side with!important+ explicit hover background (the dark side already needed!importantto beat antd Button.ant-btn-variant-textcolor).Defaults preserve the previous common-case appearance - opaque hexes are the equivalent of the prior translucent global tokens composited over white (e.g.
#f0f0f0==colorBorderSecondary/colorFillSecondaryover white), and the rgba text colors match the priorcolorTextSecondary/colorTextQuaternaryunder the light algorithm. No visual change in the common case; only the mirrored cases are fixed.📝 Change Log
CodeHighlighterrendering in the mirrored case (app color algorithm opposite to the componentthemeprop): line numbers, language label, and action buttons were invisible, the header lost separation, and borders were wrong. All light-theme colors are now self-contained component tokens (codeHeaderBg,codeBorderColor,codeLangColor,codeBtnColor,codeBtnHoverBg,codeLineNumberColor) matching the existing dark counterparts; the dark root border now reusescodeBorderColorDark.CodeHighlighter在镜像场景(应用算法与组件theme相反)下的显示:行号、语言标签、操作按钮不可见,头部背景与内容区糊在一起,边框颜色错误。亮色主题所有颜色改为自包含的组件 token(codeHeaderBg、codeBorderColor、codeLangColor、codeBtnColor、codeBtnHoverBg、codeLineNumberColor),与已有暗色 token 一一对应;暗色根边框改用codeBorderColorDark。