Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(site): remove switch theme button #2995

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Mar 3, 2025

PR

移除官网页面上的,切换主题的按钮。
开发时需要切暗色主题,手动在 html 标签上添加 class="dark"

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Introduced a button for users to toggle the dark theme, enhancing the user interface.
    • Enabled dark theme support for the footer rendering in the application.
  • Bug Fixes
    • Removed outdated dark theme styles from various components, ensuring a cleaner visual presentation.
  • Refactor
    • Removed the dark mode toggle option, so users will no longer be able to switch between dark and light themes.

Copy link

coderabbitai bot commented Mar 3, 2025

Walkthrough

The pull request removes the dark mode toggle functionality from the layout.vue component. The <div> containing the <tiny-button> for toggling dark mode and its associated logic using useDark and useToggle have been deleted. As a result, the isDark and toggleDark variables have been removed both from the component setup and its return object. The component’s overall structure remains unchanged aside from this removal. Additional changes include updates to CSS for dark mode styling and the removal of a related LESS file.

Changes

File(s) Change Summary
examples/.../layout.vue Removed dark mode toggle button markup and the associated logic (useDark, useToggle, and related vars)
examples/.../custom-markdown.css Added new CSS rules for dark mode styling of .markdown-body and its child elements
examples/.../markdown.less Deleted file containing styles for .tiny-huicharts
examples/.../main.js Commented out import of default CSS from highlight.js and removed import of markdown.less
examples/.../components-doc/components/demo.vue Replaced global style for .dark .pc-demo-container.pc-demo-container with scoped styles
examples/.../docs/docs.vue Removed several CSS rules related to dark theme styling for .markdown-body within .docs-container
examples/.../components-doc/common.vue Updated instantiation of TDCommon to include allowDarkTheme: true
examples/.../overview.vue Updated instantiation of TDCommon to include allowDarkTheme: true
examples/.../public/static/js/design-common.js Introduced a button for toggling dark theme with an event listener to switch the theme

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

In a meadow of code, I hop with delight,
Leaving behind the dark mode night.
My paws tap keys, swift and light,
For clean code paths shining bright.
A rabbit's joy in every byte!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/sites/public/static/js/design-common.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the bug Something isn't working label Mar 3, 2025
Copy link

Walkthrough

此PR移除了官网页面上的切换主题按钮。开发者需要在开发时手动在HTML标签上添加class="dark"来切换到暗色主题。

Changes

文件 概要
examples/sites/src/views/layout/layout.vue 移除了切换主题按钮的相关代码,包括按钮的HTML结构和相关的useDarkuseToggle函数调用。

@@ -2,9 +2,6 @@
<div class="main-layout ti-hp100 ti-f-c ti-f-box-stretch">
<div class="content-layout ti-fi-1" :has-sider="!isFrame">
<div id="layoutSider" class="layout-sider" :class="{ 'saas-border': templateModeState.isSaas }" v-if="!isFrame">
<div style="padding: 10px 0; text-align: center">
<tiny-button :reset-time="0" type="info" @click="toggleDark()">{{ isDark ? 'dark' : 'light' }}</tiny-button>
</div>
<tiny-tree-menu

Choose a reason for hiding this comment

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

移除了切换主题按钮的代码,这意味着用户将无法通过UI切换主题。确保这是预期的行为,并且在文档中有说明如何手动切换主题。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Walkthrough

This PR removes the Toggle Theme button on the official website page. Developers need to manually add `class="dark" on HTML tags during development to switch to dark themes.

Changes

Documents Summary
examples/sites/src/views/layout/layout.vue Removed the relevant code for toggle the theme button, including the HTML structure of the button and the related useDark and useToggle function calls.

Copy link

github-actions bot commented Mar 3, 2025

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

Copy link

@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: 0

🧹 Nitpick comments (1)
examples/sites/src/assets/custom-markdown.css (1)

110-120: Consider using CSS variables for consistent color theming

While you're using var(--tv-color-text) for the code text color, the nested selectors use hardcoded color values. Consider using CSS variables for all colors to maintain consistency and make future theme adjustments easier.

.dark.dark .markdown-body code {
  color: var(--tv-color-text);

  .token.operator {
    background-color: transparent;
  }

  .hljs-string {
-    color: #6f42c1;
+    color: var(--color-prettylights-syntax-entity, #6f42c1);
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe2122 and bf6472a.

⛔ Files ignored due to path filters (1)
  • examples/sites/src/assets/images/leftMenu/directives-custom-instruction.svg is excluded by !**/*.svg
📒 Files selected for processing (5)
  • examples/sites/src/assets/custom-markdown.css (1 hunks)
  • examples/sites/src/assets/markdown.less (0 hunks)
  • examples/sites/src/main.js (1 hunks)
  • examples/sites/src/views/components-doc/components/demo.vue (1 hunks)
  • examples/sites/src/views/docs/docs.vue (0 hunks)
💤 Files with no reviewable changes (2)
  • examples/sites/src/assets/markdown.less
  • examples/sites/src/views/docs/docs.vue
✅ Files skipped from review due to trivial changes (1)
  • examples/sites/src/views/components-doc/components/demo.vue
🔇 Additional comments (4)
examples/sites/src/main.js (1)

10-10:

✅ Verification successful

Removing default highlight.js styling might affect code highlighting appearance

This change comments out the import for highlight.js default styles, which aligns with the PR objective of removing the theme switch button. However, it's important to verify that code highlighting still appears correctly in light mode without these default styles.


🏁 Script executed:

#!/bin/bash
# Check if highlight.js styling is handled elsewhere in the codebase
echo "Checking for other highlight.js style imports:"
rg -i "highlight.js.*style" --type css --type less
rg -i "highlight.js.*css" --type js --type vue

echo -e "\nChecking for custom highlighting styles that might replace the default:"
rg -i "\.hljs" --type css --type less

Length of output: 4335


Verified: Custom Highlighting Styles in Place

  • The removal of the default highlight.js style import (i.e., commenting out import 'highlight.js/styles/default.css') aligns with the PR’s objective and is acceptable.
  • Verification shows that custom styling for code highlighting (using .hljs selectors) is defined in the codebase (e.g., in examples/sites/src/assets/custom-markdown.css and within the Less files under packages/theme/src/rich-text-editor and packages/theme-saas/src/rich-text-editor).
  • These custom styles should ensure that code highlighting remains consistent in light mode despite the removal of the default styles.
examples/sites/src/assets/custom-markdown.css (3)

98-100: Removing text shadows from code elements improves readability

This change ensures code elements in the markdown body don't have text shadows, which improves readability, especially in dark mode. The use of !important ensures this style takes precedence over any other conflicting styles.


106-108: Dark mode pre element styling enhances code block readability

Setting the background color of pre elements to a dark gray (#1a1a1a) in dark mode provides good contrast for code blocks. This improves readability for code samples when in dark mode.


102-104:

❓ Verification inconclusive

Verify the double class selector .dark.dark is intentional

The double class selector .dark.dark is unusual and might be a typo. If intentional, it suggests a need for higher specificity to override other styles. Consider using a single .dark class with higher specificity selectors if needed.


🏁 Script executed:

#!/bin/bash
# Check for other occurrences of .dark.dark in the codebase
echo "Checking for double .dark.dark class usage:"
rg "\.dark\.dark" --type css --type less --type vue

echo -e "\nChecking for relevant dark theme class usage in Vue components:"
rg "class=\".*dark.*\"" --type vue

Length of output: 384


Action: Verify the usage of the double class selector .dark.dark

The initial script encountered issues searching Vue files (the --type vue flag wasn’t recognized). This makes it unclear whether .dark.dark is used elsewhere or if this occurrence in examples/sites/src/assets/custom-markdown.css is accidental. To clarify this, please run the following updated script that uses glob patterns instead:

#!/bin/bash
echo "Checking for .dark.dark in CSS, LESS, and Vue files using updated glob patterns:"
rg "\.dark\.dark" --glob "*.{css,less,vue}"

echo -e "\nChecking for relevant dark theme class usage in Vue components using updated glob patterns:"
rg "class=\".*dark.*\"" --glob "*.vue"

Once you’ve confirmed whether the double class selector appears intentionally elsewhere or is unique to this file, please update the CSS accordingly—either by documenting the intentional higher specificity or by refactoring it if it was a typo.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf6472a and 1799218.

📒 Files selected for processing (4)
  • examples/sites/src/App.vue (1 hunks)
  • examples/sites/src/views/components-doc/common.vue (1 hunks)
  • examples/sites/src/views/docs/docs.vue (1 hunks)
  • examples/sites/src/views/overview.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/sites/src/views/docs/docs.vue
🔇 Additional comments (3)
examples/sites/src/App.vue (1)

34-34: Support for dark theme added

The allowDarkTheme: true parameter is added to the TDCommon configuration to support the dark mode styling. This aligns with the PR objective of removing the theme switch button and managing themes through manually adding class="dark" to HTML tags during development.

examples/sites/src/views/overview.vue (1)

162-162: Dark theme support added to footer

The allowDarkTheme: true parameter is added to the TDCommon configuration for the footer component, which aligns with the PR objective of supporting dark theme while removing the toggle functionality.

examples/sites/src/views/components-doc/common.vue (1)

165-165: Consistent dark theme implementation

The addition of allowDarkTheme: true parameter is consistent with changes in other files and supports the PR's goal of implementing dark theme styling while removing the theme toggle button.

@@ -162,7 +162,7 @@ watch(
onMounted(() => {
loadPage()
// 加载公共尾部
const common = new window.TDCommon(['#footer'], {})
const common = new window.TDCmmon(['#footer'], { allowDarkTheme: true })
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in constructor name

There's a typo in the constructor name - TDCmmon should be TDCommon. This will cause the footer to not render correctly.

Apply this fix:

-  const common = new window.TDCmmon(['#footer'], { allowDarkTheme: true })
+  const common = new window.TDCommon(['#footer'], { allowDarkTheme: true })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const common = new window.TDCmmon(['#footer'], { allowDarkTheme: true })
const common = new window.TDCommon(['#footer'], { allowDarkTheme: true })

Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1799218 and 3677496.

📒 Files selected for processing (1)
  • examples/sites/public/static/js/design-common.js (2 hunks)

@@ -27,6 +27,7 @@ const headerHtml = `
<span class="header-detail-name">TinyVue</span>

<div class="nav-menus nav-menus-left"></div>
<button id="switchTheme" style="margin-left:150px">切换主题</button>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

This button addition contradicts the PR objective to remove the theme switch.

According to the PR objective, the goal is to remove the theme switch button from the official website, but this code is adding a new one instead. Additionally, I see the following issues with this button:

  1. It uses hardcoded inline styling (margin-left:150px) which is generally not recommended for maintainability
  2. The button text is in Chinese ("切换主题") without internationalization support
  3. The button lacks accessibility attributes (like aria-label)

If the intent is to remove theme switching as stated in the PR objectives, consider removing this button:

-      <button id="switchTheme" style="margin-left:150px">切换主题</button>

If theme switching should be kept but implemented differently, consider proper styling and accessibility:

-      <button id="switchTheme" style="margin-left:150px">切换主题</button>
+      <button id="switchTheme" class="theme-toggle-button" aria-label="Toggle dark/light theme">切换主题</button>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<button id="switchTheme" style="margin-left:150px">切换主题</button>

Comment on lines +151 to +154

document.getElementById('switchTheme').addEventListener('click', () => {
document.querySelector('html').classList.toggle('dark')
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Theme toggle logic contradicts PR objective and lacks persistence.

The PR objective states that the theme switch functionality should be removed, requiring developers to "manually add class='dark' to HTML tags during development." However, this event listener is adding automated theme toggling that affects all users.

Additionally, this implementation doesn't persist the user's theme preference across page reloads, which leads to a poor user experience if this is intended as a user-facing feature.

If the intent is to remove theme switching as stated in the PR objectives, this event listener should be removed:

-    document.getElementById('switchTheme').addEventListener('click', () => {
-      document.querySelector('html').classList.toggle('dark')
-    })

If theme switching should be kept, consider adding persistence:

     document.getElementById('switchTheme').addEventListener('click', () => {
-      document.querySelector('html').classList.toggle('dark')
+      const html = document.querySelector('html');
+      const isDark = html.classList.toggle('dark');
+      localStorage.setItem('theme-preference', isDark ? 'dark' : 'light');
     })
+    
+    // Apply saved theme preference on load
+    const savedTheme = localStorage.getItem('theme-preference');
+    if (savedTheme === 'dark') {
+      document.querySelector('html').classList.add('dark');
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
document.getElementById('switchTheme').addEventListener('click', () => {
document.querySelector('html').classList.toggle('dark')
})
// Theme toggling functionality removed per PR objective.
Suggested change
document.getElementById('switchTheme').addEventListener('click', () => {
document.querySelector('html').classList.toggle('dark')
})
document.getElementById('switchTheme').addEventListener('click', () => {
const html = document.querySelector('html');
const isDark = html.classList.toggle('dark');
localStorage.setItem('theme-preference', isDark ? 'dark' : 'light');
});
// Apply saved theme preference on load
const savedTheme = localStorage.getItem('theme-preference');
if (savedTheme === 'dark') {
document.querySelector('html').classList.add('dark');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants