Skip to content

Conversation

@zzcr
Copy link
Member

@zzcr zzcr commented Feb 17, 2025

官网添加动态切换明暗主题功能

PR

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 dark mode toggle, enabling users to seamlessly switch between light and dark themes.
  • Style

    • Refined visual elements with dynamic tooltips and enhanced dark theme styling for a more intuitive and consistent interface.

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2025

Walkthrough

This pull request adds a new dependency to support enhanced theme functionality and updates multiple Vue components. The changes include incorporating the @vueuse/core library for dark mode toggling, refining tooltip messages and icon bindings in a demo component, and introducing a dark mode toggle button in the layout. Additionally, the theme styling is modified by scoping dark theme variables and activating relevant style imports.

Changes

File(s) Change Summary
examples/sites/package.json Added dependency @vueuse/core version ^12.7.0.
examples/sites/src/views/components-doc/components/demo.vue Updated tooltip content, revised icon class bindings, streamlined demo code toggle functionality, and modified dark theme selector in style.
examples/sites/src/views/layout/layout.vue Introduced a dark mode toggle feature with new imports (useDark, useToggle), reactive property (isDark), and method (toggleDark).
packages/theme/src/base/dark-theme.less
packages/theme/src/base/index.less
Changed the CSS selector from :root to :root.dark for dark theme styling and activated the import of dark-theme.less by uncommenting its import in index.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant L as Layout Component
    participant T as Theme Handler (@vueuse/core)
    
    U->>L: Clicks dark mode toggle button
    L->>T: Calls toggleDark() to update theme state
    T-->>L: Returns updated isDark value
    L->>U: Renders view with updated theme (dark/light)
Loading

Possibly related PRs

Suggested labels

enhancement

Poem

I hopped through the modules in the code,
Added a core that lightens the load.
A toggle for dark, a theme refined,
Each change woven, seamlessly aligned.
With whiskers twitching in delight, I cheer—
For every line makes our project dear! 🐰✨

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/src/views/components-doc/components/demo.vue

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.

examples/sites/src/views/layout/layout.vue

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.


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. (Beta)
  • @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 enhancement New feature or request (功能增强) label Feb 17, 2025
@petercat-assistant
Copy link

Walkthrough

This pull request introduces a feature that allows the official website to dynamically switch between light and dark themes. The changes include updates to the layout and style files to support theme toggling.

Changes

Files Summary
examples/sites/package.json Updated dependencies for theme support.
examples/sites/src/views/components-doc/components/demo.vue Modified CSS selectors for dark theme compatibility.
examples/sites/src/views/layout/layout.vue Added a button to toggle between light and dark themes using @vueuse/core.
packages/theme/src/base/dark-theme.less Updated dark theme styles to use a new root selector.
packages/theme/src/base/index.less Enabled the import of dark theme styles.

<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>

Choose a reason for hiding this comment

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

Ensure that the toggleDark() function is correctly handling the theme switch to avoid any potential UI inconsistencies.

@github-actions
Copy link

[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 (2)
examples/sites/src/views/components-doc/components/demo.vue (1)

358-360: Consider using a softer background color for dark theme.

Pure black (#000) backgrounds can be harsh on the eyes. Consider using a softer dark color like #1a1a1a or #121212 for better user experience.

 :global(html.dark .pc-demo-container) {
-  background: #000;
+  background: #121212;
 }
examples/sites/src/views/layout/layout.vue (1)

5-7: Consider improving the toggle button's accessibility.

While the implementation works, the button could benefit from better accessibility.

Apply this diff to enhance the user experience:

-<div style="padding: 10px 0; text-align: center">
-  <tiny-button :reset-time="0" type="info" @click="toggleDark()">{{ isDark ? 'dark' : 'light' }}</tiny-button>
+<div style="padding: 10px 0; text-align: center">
+  <tiny-button
+    :reset-time="0"
+    type="info"
+    @click="toggleDark()"
+    :aria-label="`Switch to ${isDark ? 'light' : 'dark'} theme`"
+    :title="`Switch to ${isDark ? 'light' : 'dark'} theme`"
+  >
+    {{ isDark ? 'dark' : 'light' }}
+  </tiny-button>
+</div>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2215cb and 45ccd5f.

📒 Files selected for processing (5)
  • examples/sites/package.json (1 hunks)
  • examples/sites/src/views/components-doc/components/demo.vue (1 hunks)
  • examples/sites/src/views/layout/layout.vue (4 hunks)
  • packages/theme/src/base/dark-theme.less (1 hunks)
  • packages/theme/src/base/index.less (1 hunks)
🔇 Additional comments (8)
examples/sites/src/views/components-doc/components/demo.vue (3)

32-36: LGTM! Improved user feedback through dynamic tooltips and icons.

The dynamic tooltip content and icon classes provide clear visual feedback about the code visibility state.


126-126: LGTM! Proper theme integration with playground functionality.

The theme integration is well-implemented, ensuring the playground opens with the correct theme context.

Also applies to: 252-252


358-358: LGTM! Simplified dark theme selector.

The selector change from dark-theme to dark aligns with standard dark theme implementations.

examples/sites/package.json (1)

53-53:

✅ Verification successful

Verify the compatibility of @vueuse/core version.

Let's check if version 12.7.0 is the latest stable version and verify its compatibility with the project's Vue version (3.4.31).


🌐 Web query:

What is the latest stable version of @vueuse/core and its Vue compatibility requirements?

💡 Result:

The latest stable version of @vueuse/core is v12.7.0 (released 18 hours before February 17, 2025)[7]. Its compatibility requirements are:

Vue Version Support

  • Vue 3.x: Fully supported starting from v12.0+[4][8]
  • Vue 2.x: Not supported in v12+ - requires @vueuse/core@11.x instead[4][5][9]

Key Compatibility Details

  1. Vue 3 Requirements

    • Requires Vue.js ≥3.x[2][8]
    • Requires Composition API (native in Vue 3)[5]
    • Compatible with Nuxt 3 via @vueuse/nuxt module[10]
  2. Vue 2 Limitations

    • Final supported version: @vueuse/core@11.x[4][9]
    • Requires @vue/composition-api polyfill[5]
    • Officially deprecated since Vue 2 reached EOL on December 31, 2023[9]

Installation Requirements

# For Vue 3
npm install @vueuse/core@latest

# For legacy Vue 2
npm install @vueuse/core@11.x @vue/composition-api

The library follows semantic versioning with weekly canary releases from main branch[1][7]. TypeScript ≥4.4 is recommended but optional[2][8].

Citations:


@vueuse/core v12.7.0 is correctly used and fully compatible with Vue 3.4.31

  • Verified that v12.7.0 is the latest stable release and is specifically designed for Vue 3.x.
  • The project's Vue version (3.4.31) meets the dependency requirements.
packages/theme/src/base/index.less (1)

17-17: LGTM! Dark theme import enabled.

The dark theme import is correctly positioned after the base variables import.

packages/theme/src/base/dark-theme.less (1)

2-2: LGTM! Well-structured dark theme implementation.

The :root.dark selector is the correct approach for theme switching, as it:

  • Ensures dark theme styles are only applied when the .dark class is present
  • Allows for smooth transitions between themes
  • Follows the principle of CSS specificity
examples/sites/src/views/layout/layout.vue (2)

71-71: LGTM! Appropriate use of @vueuse/core utilities.

The imports from @vueuse/core provide a clean way to implement dark mode functionality.


110-111: LGTM! Clean implementation of dark mode toggle.

The dark mode implementation using useDark and useToggle is clean and follows Vue Composition API best practices.

Also applies to: 200-201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request (功能增强)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants