Skip to content

fix(styles): improve dark mode compatibility for anchor and drag overlay demos#352

Open
SonyLeo wants to merge 4 commits into
opentiny:developfrom
SonyLeo:fix/anchor-drag-overlay-dark-mode
Open

fix(styles): improve dark mode compatibility for anchor and drag overlay demos#352
SonyLeo wants to merge 4 commits into
opentiny:developfrom
SonyLeo:fix/anchor-drag-overlay-dark-mode

Conversation

@SonyLeo
Copy link
Copy Markdown
Collaborator

@SonyLeo SonyLeo commented May 21, 2026

暗色模式适配:

文档效果预览👉

优化前:
image
image
image

优化后:
image
image
image

Summary by CodeRabbit

  • Style
    • Updated demo and component styles to replace hard-coded colors, borders, and backgrounds with design-system CSS variables for consistent theming and improved dark-mode behavior.
    • Added a set of anchor-related CSS custom properties and new bubble/active-background variables to centralize anchor visuals and make anchor UI elements more configurable across light and dark modes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Walkthrough

Replaces hard-coded colors with design-system CSS variables across anchor and drag-overlay demos, adds Anchor CSS variables to root light/dark themes, and updates the Anchor LESS mixin to match the new token structure.

Changes

Design System CSS Variable Migration

Layer / File(s) Summary
Core Anchor theme CSS variables
packages/components/src/styles/variables.css
Introduces the --tr-anchor-* CSS custom properties in both light (:root) and dark ([data-tr-color-mode='dark']) theme blocks.
Anchor component LESS variable mixin
packages/components/src/styles/components/anchor.less
Modifies .tr-anchor-vars() to remove the non-active marker-color and associated tooltip entries while retaining active/hover/item-label and marker-color-active variables.
Anchor demo styling updates
docs/demos/anchor/basic-source.vue, docs/demos/anchor/demo-shell.css, docs/demos/anchor/controlled-search.vue
Replaces hardcoded colors with theme tokens (--tr-text-secondary, --vp-c-divider, --vp-c-bg, --tr-container-bg-default), adds --anchor-section-active-bg and anchor-bubble vars, and updates related animations.
Drag-overlay demo styling updates
docs/demos/drag-overlay/basic.vue, docs/demos/drag-overlay/custom-overlay.vue, docs/demos/drag-overlay/disabled.vue
Replaces hardcoded divider, text, and background colors with theme variables (--vp-c-divider, --vp-c-text-1, --tr-bubble-box-bg, --vp-c-bg) across demo sections, chat UI, upload areas, and overlays.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Possibly related PRs

  • opentiny/tiny-robot#347: Modifies anchor demo styling and touches docs/demos/anchor/demo-shell.css, similar CSS-area changes.

Suggested reviewers

  • gene9831
  • hexqi

Poem

🐰🎨 I swapped old hex for tokens bright and fair,
Demos now wear themes with thoughtful care,
Anchors and overlays hum in tune,
Light and dark both blossom under the moon,
Hop, review, and let the colors share!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main objective of the changeset: improving dark mode compatibility for anchor and drag overlay demo components by migrating hardcoded colors to CSS theme variables.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
docs/demos/drag-overlay/custom-overlay.vue (2)

77-85: ⚡ Quick win

Remaining hardcoded colors will not adapt to dark mode.

The section headings and placeholder text use hardcoded colors (#333, #666) that won't provide proper contrast in dark mode.

♻️ Proposed refactor
 .demo-section h3 {
   margin-top: 0;
-  color: `#333`;
+  color: var(--vp-c-text-1);
 }
 
 .demo-section p {
-  color: `#666`;
+  color: var(--tr-text-secondary);
   margin-bottom: 16px;
 }

 .upload-placeholder {
   text-align: center;
-  color: `#666`;
+  color: var(--tr-text-secondary);
 }

Also applies to: 104-116

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demos/drag-overlay/custom-overlay.vue` around lines 77 - 85, The CSS
uses hardcoded colors in .demo-section h3 and .demo-section p (and similar
blocks at 104-116) which won't adapt to dark mode; change these rules to use
theme-aware CSS variables (e.g., color: var(--text-color, /*fallback*/ ) for
headings and color: var(--muted-text-color, /*fallback*/ ) for paragraphs) or
use currentColor with parent variables so the styles follow the site's
light/dark color tokens instead of fixed hex values.

99-102: ⚡ Quick win

Dragging state uses hardcoded blue color.

Consider using theme primary color for consistency with the design system.

♻️ Optional refactor
 .image-upload-area.dragging {
-  border-color: `#007bff`;
-  background: rgba(0, 123, 255, 0.05);
+  border-color: var(--tr-color-primary);
+  background: var(--tr-color-primary-light);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demos/drag-overlay/custom-overlay.vue` around lines 99 - 102, The
.image-upload-area.dragging rule uses hardcoded blue; update it to use the
theme's primary color instead—replace border-color: `#007bff` and background:
rgba(0, 123, 255, 0.05) with references to your theme CSS variables (e.g.,
border-color: var(--color-primary) and background using an alpha variant like
background: rgba(var(--color-primary-rgb), 0.05) or color-mix()/hsla() depending
on your setup) so the dragging state follows the design system; modify the rule
in custom-overlay.vue where .image-upload-area.dragging is defined.
docs/demos/drag-overlay/basic.vue (2)

246-280: ⚡ Quick win

Remaining hardcoded colors in event log section will not adapt to dark mode.

The event log section still uses hardcoded colors that won't work properly in dark mode: #f8f9fa background, #e9ecef borders, and various text colors (#666, #333, #007bff).

♻️ Proposed refactor to complete dark mode support
 /* 事件日志样式 */
 .event-log {
-  background: `#f8f9fa`;
+  background: var(--tr-container-bg-default-2);
   border-radius: 4px;
   padding: 12px;
   max-height: 200px;
   overflow-y: auto;
 }
 
 .event-item {
   display: flex;
   gap: 12px;
   padding: 4px 0;
-  border-bottom: 1px solid `#e9ecef`;
+  border-bottom: 1px solid var(--vp-c-divider);
   font-size: 14px;
 }
 
 .event-item:last-child {
   border-bottom: none;
 }
 
 .event-time {
-  color: `#666`;
+  color: var(--tr-text-tertiary);
   min-width: 80px;
 }
 
 .event-type {
-  color: `#007bff`;
+  color: var(--tr-color-primary);
   font-weight: bold;
   min-width: 120px;
 }
 
 .event-message {
-  color: `#333`;
+  color: var(--tr-text-secondary);
   flex: 1;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demos/drag-overlay/basic.vue` around lines 246 - 280, Replace the
hardcoded hex colors in the event log styles with theme-aware CSS variables so
the section adapts to dark mode: update .event-log to use a background variable
(e.g., var(--event-log-bg, var(--color-surface))) and border color variable for
.event-item (e.g., var(--event-log-border, var(--color-border))); replace text
colors in .event-time, .event-message and the accent in .event-type with
semantic variables (e.g., var(--color-muted), var(--color-text),
var(--color-primary)) or project-wide tokens so dark-mode overrides apply; touch
the selectors .event-log, .event-item, .event-time, .event-type, and
.event-message to implement these variable fallbacks.

187-191: ⚡ Quick win

Consider using theme primary color for interactive elements.

The drag indicator and button use hardcoded #007bff instead of the theme's primary color variable, which would provide better consistency across light and dark modes.

♻️ Optional refactor for consistency
 .drag-indicator {
-  color: `#007bff`;
+  color: var(--tr-color-primary);
   font-weight: bold;
   animation: pulse 1s infinite;
 }

 .chat-input button {
   padding: 8px 16px;
-  background: `#007bff`;
+  background: var(--tr-color-primary);
   color: white;
   border: none;
   border-radius: 20px;
   cursor: pointer;
 }

Also applies to: 236-243

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demos/drag-overlay/basic.vue` around lines 187 - 191, Replace the
hardcoded color `#007bff` with the project's theme primary color variable in the
CSS for interactive elements: update the .drag-indicator rule (and the button
rule referenced around lines 236–243) to use the theme primary CSS variable
(e.g., var(--primary-color) or your app's equivalent like var(--theme-primary))
so the indicator and button follow light/dark theme changes consistently.
docs/demos/drag-overlay/disabled.vue (1)

30-38: ⚡ Quick win

Remaining hardcoded colors will not adapt to dark mode.

Text colors use hardcoded values (#333, #666) that won't provide proper contrast in dark mode.

♻️ Proposed refactor
 .demo-section h3 {
   margin-top: 0;
-  color: `#333`;
+  color: var(--vp-c-text-1);
 }
 
 .demo-section p {
-  color: `#666`;
+  color: var(--tr-text-secondary);
   margin-bottom: 16px;
 }

 .disabled-content {
   text-align: center;
-  color: `#666`;
+  color: var(--tr-text-secondary);
 }

Also applies to: 56-68

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demos/drag-overlay/disabled.vue` around lines 30 - 38, The hardcoded
colors in the demo CSS (.demo-section h3 and .demo-section p) won't adapt to
dark mode; change them to use theme-aware variables or media queries instead
(e.g., replace `color: `#333`` and `color: `#666`` with CSS custom properties like
`color: var(--text-color)` / `var(--muted-text-color)` or set them inside
`@media (prefers-color-scheme: dark)`), and ensure those variables are defined
in the global/theme stylesheet so both light and dark modes provide appropriate
contrast; apply the same replacement for the other occurrences referenced (lines
~56-68) and any similar selectors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/demos/anchor/basic-source.vue`:
- Line 113: Locate the CSS rule containing the hardcoded declaration "color:
`#191919`;" in basic-source.vue and replace it with the project's theme-aware
token (e.g., a CSS custom property or theme variable like --color-text /
var(--color-text) or the framework's text color token) so the text color adapts
to light/dark modes; update the selector where "color: `#191919`;" appears to use
that theme variable instead of the literal hex value.

---

Nitpick comments:
In `@docs/demos/drag-overlay/basic.vue`:
- Around line 246-280: Replace the hardcoded hex colors in the event log styles
with theme-aware CSS variables so the section adapts to dark mode: update
.event-log to use a background variable (e.g., var(--event-log-bg,
var(--color-surface))) and border color variable for .event-item (e.g.,
var(--event-log-border, var(--color-border))); replace text colors in
.event-time, .event-message and the accent in .event-type with semantic
variables (e.g., var(--color-muted), var(--color-text), var(--color-primary)) or
project-wide tokens so dark-mode overrides apply; touch the selectors
.event-log, .event-item, .event-time, .event-type, and .event-message to
implement these variable fallbacks.
- Around line 187-191: Replace the hardcoded color `#007bff` with the project's
theme primary color variable in the CSS for interactive elements: update the
.drag-indicator rule (and the button rule referenced around lines 236–243) to
use the theme primary CSS variable (e.g., var(--primary-color) or your app's
equivalent like var(--theme-primary)) so the indicator and button follow
light/dark theme changes consistently.

In `@docs/demos/drag-overlay/custom-overlay.vue`:
- Around line 77-85: The CSS uses hardcoded colors in .demo-section h3 and
.demo-section p (and similar blocks at 104-116) which won't adapt to dark mode;
change these rules to use theme-aware CSS variables (e.g., color:
var(--text-color, /*fallback*/ ) for headings and color: var(--muted-text-color,
/*fallback*/ ) for paragraphs) or use currentColor with parent variables so the
styles follow the site's light/dark color tokens instead of fixed hex values.
- Around line 99-102: The .image-upload-area.dragging rule uses hardcoded blue;
update it to use the theme's primary color instead—replace border-color: `#007bff`
and background: rgba(0, 123, 255, 0.05) with references to your theme CSS
variables (e.g., border-color: var(--color-primary) and background using an
alpha variant like background: rgba(var(--color-primary-rgb), 0.05) or
color-mix()/hsla() depending on your setup) so the dragging state follows the
design system; modify the rule in custom-overlay.vue where
.image-upload-area.dragging is defined.

In `@docs/demos/drag-overlay/disabled.vue`:
- Around line 30-38: The hardcoded colors in the demo CSS (.demo-section h3 and
.demo-section p) won't adapt to dark mode; change them to use theme-aware
variables or media queries instead (e.g., replace `color: `#333`` and `color:
`#666`` with CSS custom properties like `color: var(--text-color)` /
`var(--muted-text-color)` or set them inside `@media (prefers-color-scheme:
dark)`), and ensure those variables are defined in the global/theme stylesheet
so both light and dark modes provide appropriate contrast; apply the same
replacement for the other occurrences referenced (lines ~56-68) and any similar
selectors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: aa085ecf-8f62-4d31-80da-45bec9aac92f

📥 Commits

Reviewing files that changed from the base of the PR and between 6b5662c and 5554d14.

📒 Files selected for processing (7)
  • docs/demos/anchor/basic-source.vue
  • docs/demos/anchor/demo-shell.css
  • docs/demos/drag-overlay/basic.vue
  • docs/demos/drag-overlay/custom-overlay.vue
  • docs/demos/drag-overlay/disabled.vue
  • packages/components/src/styles/components/anchor.less
  • packages/components/src/styles/variables.css
💤 Files with no reviewable changes (1)
  • packages/components/src/styles/components/anchor.less

Comment thread docs/demos/anchor/basic-source.vue Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

✅ Preview build completed successfully!

Click the image above to preview.
Preview will be automatically removed when this PR is closed.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

@gene9831
Copy link
Copy Markdown
Collaborator

暗色模式下,item激活的样式过于亮了,优化下

0c414c94283924700be14ac11c674f64_684x558

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/demos/anchor/basic-source.vue (1)

116-118: ⚡ Quick win

Keep .article scoped in the dark-mode override selector.

<style scoped> scoping is bypassed for everything inside :global(...); with :global([data-tr-color-mode='dark'] .article), the .article part can match globally. Keep only the dark-mode root global and move .article outside.

-:global([data-tr-color-mode='dark'] .article) {
+:global([data-tr-color-mode='dark']) .article {
   --anchor-section-active-bg: color-mix(in srgb, `#317af7` 40%, var(--vp-c-bg));
 }

(Also present in docs/demos/anchor/controlled-search.vue for .conversation-list.)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demos/anchor/basic-source.vue` around lines 116 - 118, The dark-mode CSS
selector currently uses :global([data-tr-color-mode='dark'] .article) which
removes scoped scoping from .article; change it so only the root is global and
the component class remains scoped by replacing the selector with
:global([data-tr-color-mode='dark']) .article and keep the rule body the same;
apply the same pattern in docs/demos/anchor/controlled-search.vue for the
.conversation-list selector to preserve scoped styles.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/demos/anchor/controlled-search.vue`:
- Around line 147-150: The dark-mode style selector currently globalizes the
entire selector via :global([data-tr-color-mode='dark'] .conversation-list),
leaking styles outside this SFC; change it so only the mode root is global
(e.g., :global([data-tr-color-mode='dark'])) and then scope the child
.conversation-list normally so variables like --anchor-bubble-bg and
--anchor-bubble-active-bg apply only to this component's .conversation-list;
update the selector around those CSS variables accordingly.

---

Nitpick comments:
In `@docs/demos/anchor/basic-source.vue`:
- Around line 116-118: The dark-mode CSS selector currently uses
:global([data-tr-color-mode='dark'] .article) which removes scoped scoping from
.article; change it so only the root is global and the component class remains
scoped by replacing the selector with :global([data-tr-color-mode='dark'])
.article and keep the rule body the same; apply the same pattern in
docs/demos/anchor/controlled-search.vue for the .conversation-list selector to
preserve scoped styles.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 951a15bf-e10e-438a-bc43-f81f5f5bd381

📥 Commits

Reviewing files that changed from the base of the PR and between b25cb4c and 5d67ae2.

📒 Files selected for processing (2)
  • docs/demos/anchor/basic-source.vue
  • docs/demos/anchor/controlled-search.vue

Comment on lines +147 to +150
:global([data-tr-color-mode='dark'] .conversation-list) {
--anchor-bubble-bg: color-mix(in srgb, #317af7 30%, var(--tr-container-bg-default));
--anchor-bubble-active-bg: color-mix(in srgb, #317af7 40%, var(--tr-container-bg-default));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for the same full-selector :global pattern in this file.
rg -n --type=vue ":global\\(\\[data-tr-color-mode='dark'\\]\\s+\\.[^)]+\\)" docs/demos/anchor/controlled-search.vue

Repository: opentiny/tiny-robot

Length of output: 91


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="docs/demos/anchor/controlled-search.vue"

echo "== Context around lines 130-175 =="
nl -ba "$FILE" | sed -n '120,180p'

echo
echo "== Find :global patterns in this file (no unsupported --type flag) =="
rg -n ":global\\(" "$FILE"

echo
echo "== Find the specific full-selector :global([data-tr-color-mode='dark'] .conversation-list) pattern =="
rg -n ":global\\(\\[data-tr-color-mode='dark'\\]\\s+\\.[^)]+\\)" "$FILE" || true

Repository: opentiny/tiny-robot

Length of output: 159


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="docs/demos/anchor/controlled-search.vue"

echo "== Context around reported lines (130-180) =="
cat -n "$FILE" | sed -n '120,190p'

echo
echo "== All :global( occurrences in file =="
rg -n ":global\\(" "$FILE" || true

echo
echo "== Exact full-selector pattern from the comment (best-effort regex match) =="
rg -n ":global\\(\\[data-tr-color-mode='dark'\\][^)]*\\)" "$FILE" || true

echo
echo "== Specific .conversation-list occurrences (to see what selector wraps it) =="
rg -n "\\.conversation-list" "$FILE"

Repository: opentiny/tiny-robot

Length of output: 2266


Avoid global leakage in the dark-mode selector for .conversation-list

In <style scoped>, :global([data-tr-color-mode='dark'] .conversation-list) makes the whole selector global; globalize only the mode root so .conversation-list remains scoped to this SFC.

Suggested patch
-:global([data-tr-color-mode='dark'] .conversation-list) {
+:global([data-tr-color-mode='dark']) .conversation-list {
   --anchor-bubble-bg: color-mix(in srgb, `#317af7` 30%, var(--tr-container-bg-default));
   --anchor-bubble-active-bg: color-mix(in srgb, `#317af7` 40%, var(--tr-container-bg-default));
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demos/anchor/controlled-search.vue` around lines 147 - 150, The
dark-mode style selector currently globalizes the entire selector via
:global([data-tr-color-mode='dark'] .conversation-list), leaking styles outside
this SFC; change it so only the mode root is global (e.g.,
:global([data-tr-color-mode='dark'])) and then scope the child
.conversation-list normally so variables like --anchor-bubble-bg and
--anchor-bubble-active-bg apply only to this component's .conversation-list;
update the selector around those CSS variables accordingly.

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.

2 participants