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): the aurora-theme switch function is added to the official website #2604

Merged
merged 4 commits into from
Dec 4, 2024

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Dec 4, 2024

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

Release Notes

  • New Features

    • Introduced the "AuroraTheme" for enhanced theme customization.
    • Added detailed guidance on using the TinyThemeTool for custom themes.
    • Expanded examples for dynamic theme switching.
    • Enhanced tooltip padding flexibility through updated CSS variables.
  • Documentation

    • Updated theme documentation for clarity on old and new theme configurations.
    • Provided best practices for custom CSS variable definitions.
  • Bug Fixes

    • Improved handling of theme parameters in routing.

These updates enhance user experience by providing more customization options and clearer instructions for implementing themes.

@github-actions github-actions bot added the bug Something isn't working label Dec 4, 2024
Copy link

coderabbitai bot commented Dec 4, 2024

Walkthrough

The pull request introduces updates to theme customization for the @opentiny/vue component library. It adds a section on custom themes in the theme.md document, defines the ThemeData interface, and enhances theme management in the useTheme.js file by incorporating the tinyAuroraTheme. The build process is updated to compile the new Aurora theme, and a new JavaScript file for the Aurora theme is created. The changes improve documentation and functionality related to theme management.

Changes

File Change Summary
examples/sites/demos/pc/webdoc/theme.md Added a section on custom themes, defined ThemeData interface, updated old theme section, and expanded theme handling instructions.
examples/sites/src/tools/useTheme.js Updated import statement to include tinyAuroraTheme and added logic to handle the new theme based on route parameters.
packages/theme/build/gulp-dist.js Modified concatOldTheme to include aurora-theme.less and updated the gulp.task('compile') to compile the new theme.
packages/theme/build/release.js Added functionality to handle the Aurora theme, writing its configuration to JavaScript files.
packages/theme/src/aurora-theme-index.js Introduced a new file exporting an object with theme configuration, including CSS variables.
packages/theme/src/aurora-theme-index.less Added import statement for aurora-theme.less to include its styles.
packages/theme/src/theme-tool.js Updated to include tinyAuroraTheme in exports and modified theme management logic accordingly.
packages/theme/src/tooltip/vars.less Updated tooltip padding variables to reference predefined spacing variables instead of fixed values.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • zzcr

🐇 In the meadow, bright and fair,
New themes spring up everywhere!
With colors bold and styles anew,
Custom dreams now come to view.
Hop along, let’s change the scene,
For every project, a theme so keen! 🌈


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

Copy link

github-actions bot commented Dec 4, 2024

[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: 1

🧹 Outside diff range and nitpick comments (3)
packages/theme/build/gulp-dist.js (1)

36-36: Rename concatOldTheme function to better reflect its purpose

The function now handles both old and aurora themes, so its name should be updated accordingly.

Consider renaming to concatThemes or similar:

- function concatOldTheme(cb) {
+ function concatThemes(cb) {

Remember to update the task reference in gulp.task('build', ...) as well.

examples/sites/src/tools/useTheme.js (1)

109-113: Consider improving theme loading implementation

While the implementation works, there are a few potential improvements:

  1. The shared loadedTheme flag could prevent switching between themes
  2. Error handling for theme loading failures is missing
  3. The implementation is repetitive with the old-theme block

Consider this refactoring to address these issues:

-let loadedTheme = false
+const loadedThemes = new Set()

-if (!loadedTheme && val === 'old-theme') {
-  const themeTool = new TinyThemeTool()
-  themeTool.changeTheme(tinyOldTheme)
-  loadedTheme = true
-}
-if (!loadedTheme && val === 'aurora-theme') {
-  const themeTool = new TinyThemeTool()
-  themeTool.changeTheme(tinyAuroraTheme)
-  loadedTheme = true
-}
+const themeMap = {
+  'old-theme': tinyOldTheme,
+  'aurora-theme': tinyAuroraTheme
+}
+
+if (!loadedThemes.has(val) && val in themeMap) {
+  try {
+    const themeTool = new TinyThemeTool()
+    themeTool.changeTheme(themeMap[val])
+    loadedThemes.add(val)
+  } catch (error) {
+    console.error(`Failed to load theme: ${val}`, error)
+  }
+}
examples/sites/demos/pc/webdoc/theme.md (1)

119-121: Consider enhancing Aurora theme documentation

While the warning block correctly mentions the Aurora theme availability, consider adding:

  1. A dedicated section for Aurora theme configuration
  2. Example usage with specific variables
  3. Migration guide from other themes

Add a new section after the warning block:

  <p> 如果需要切换 <code>Aurora</code> 主题,可以从上面导出 <code>tinyAuroraTheme</code> 的主题。 </p>
</div>

+### Aurora 主题配置
+
+Aurora 主题提供了现代化的设计风格,使用方式如下:
+
+```ts
+import TinyThemeTool, { tinyAuroraTheme } from '@opentiny/vue-theme/theme-tool'
+
+const themeTool = new TinyThemeTool()
+themeTool.changeTheme(tinyAuroraTheme)
+```
+
+#### 主要特性
+
+- 现代化的色彩系统
+- 优化的组件间距
+- 改进的交互反馈
+
+#### 从其他主题迁移
+
+如果您正在从其他主题迁移到 Aurora 主题,请注意以下变化:
+...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c53a740 and 6f8c43b.

📒 Files selected for processing (7)
  • examples/sites/demos/pc/webdoc/theme.md (2 hunks)
  • examples/sites/src/tools/useTheme.js (2 hunks)
  • packages/theme/build/gulp-dist.js (2 hunks)
  • packages/theme/build/release.js (1 hunks)
  • packages/theme/src/aurora-theme-index.js (1 hunks)
  • packages/theme/src/aurora-theme-index.less (1 hunks)
  • packages/theme/src/theme-tool.js (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/theme/src/aurora-theme-index.less
  • packages/theme/src/aurora-theme-index.js
🔇 Additional comments (3)
packages/theme/src/theme-tool.js (1)

2-2: LGTM: Clean addition of aurora theme support

The changes cleanly integrate the new aurora theme while maintaining the existing theme tool functionality.

Let's verify the aurora theme file exists and has the expected exports:

Also applies to: 4-4

✅ Verification successful

Verified: Aurora theme file exists with correct exports

The aurora theme file exists at packages/theme/src/aurora-theme-index.js and contains the expected theme exports with all required properties:

  • id: 'tiny-aurora-theme'
  • name: 'AuroraTheme'
  • cnName: '欧若拉主题'
  • css: Contains complete theme CSS variables
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify aurora theme file exists and exports
fd -t f "aurora-theme-index.js$" 

# Check the theme exports
ast-grep --pattern 'export default { id: $_, name: $_, cnName: $_, css: $_ }'

Length of output: 31491

packages/theme/build/gulp-dist.js (1)

45-46: LGTM: Clean addition of aurora theme compilation

The aurora theme compilation is correctly integrated into the build process.

examples/sites/src/tools/useTheme.js (1)

19-19: LGTM: Import statement correctly adds tinyAuroraTheme

The import statement properly includes the new aurora theme alongside existing themes.

Comment on lines +26 to +39
// 2.1、读取 aurora-theme-index.js , dist/aurora-theme-index.less, 合并后写入 dist/ aurora-theme-index.js
jsStr = `
export default {
id: 'tiny-aurora-theme',
name: 'AuroraTheme',
cnName: '欧若拉主题',
css: \`#CSS#\`
}
`
cssStr = fs.readFileSync(path.resolve(root, 'dist/aurora-theme-index.css'), 'utf8')

jsStr = jsStr.replace('#CSS#', cssStr)
fs.writeFileSync(path.resolve(root, 'src/aurora-theme-index.js'), jsStr) // 供开发时(pnpm site), 可以访问到最新的定制主题变量
fs.writeFileSync(path.resolve(root, 'dist/aurora-theme-index.js'), jsStr) // 打包发布用
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider refactoring theme processing to reduce duplication

The aurora theme processing block duplicates the logic from the old theme processing. Consider extracting this into a reusable function to improve maintainability.

Here's a suggested refactor:

- // 2、读取 old-theme-index.js , dist/old-theme-index.less, 合并后写入 dist/ old-theme-index.js
- let jsStr = `
- export default {
-   id: 'tiny-old-theme',
-   name: 'OldTheme',
-   cnName: '旧的主题',
-   css: \`#CSS#\`
- }
- `
- let cssStr = fs.readFileSync(path.resolve(root, 'dist/old-theme-index.css'), 'utf8')
- 
- jsStr = jsStr.replace('#CSS#', cssStr)
- fs.writeFileSync(path.resolve(root, 'src/old-theme-index.js'), jsStr)
- fs.writeFileSync(path.resolve(root, 'dist/old-theme-index.js'), jsStr)
- 
- // 2.1、读取 aurora-theme-index.js , dist/aurora-theme-index.less, 合并后写入 dist/ aurora-theme-index.js
- jsStr = `
- export default {
-   id: 'tiny-aurora-theme',
-   name: 'AuroraTheme',
-   cnName: '欧若拉主题',
-   css: \`#CSS#\`
- }
- `
- cssStr = fs.readFileSync(path.resolve(root, 'dist/aurora-theme-index.css'), 'utf8')
- 
- jsStr = jsStr.replace('#CSS#', cssStr)
- fs.writeFileSync(path.resolve(root, 'src/aurora-theme-index.js'), jsStr)
- fs.writeFileSync(path.resolve(root, 'dist/aurora-theme-index.js'), jsStr)

+ function processTheme(themeConfig) {
+   const { id, name, cnName, filename } = themeConfig;
+   const jsStr = `
+   export default {
+     id: '${id}',
+     name: '${name}',
+     cnName: '${cnName}',
+     css: \`#CSS#\`
+   }
+   `;
+   
+   const cssStr = fs.readFileSync(path.resolve(root, `dist/${filename}.css`), 'utf8');
+   const finalJsStr = jsStr.replace('#CSS#', cssStr);
+   
+   fs.writeFileSync(path.resolve(root, `src/${filename}.js`), finalJsStr);
+   fs.writeFileSync(path.resolve(root, `dist/${filename}.js`), finalJsStr);
+ }
+ 
+ // Process themes
+ processTheme({
+   id: 'tiny-old-theme',
+   name: 'OldTheme',
+   cnName: '旧的主题',
+   filename: 'old-theme-index'
+ });
+ 
+ processTheme({
+   id: 'tiny-aurora-theme',
+   name: 'AuroraTheme',
+   cnName: '欧若拉主题',
+   filename: 'aurora-theme-index'
+ });

Committable suggestion skipped: line range outside the PR's diff.

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

🧹 Outside diff range and nitpick comments (1)
packages/theme/src/tooltip/vars.less (1)

73-75: Consider documenting the spacing token values.

To help developers understand the actual spacing values, consider adding comments with the default pixel values of --tv-space-lg and --tv-space-xl.

Example:

  // 弹框垂直内边距 (default: 12px)
  --tv-Tooltip-padding-y: var(--tv-space-lg);
  // 弹框水平内边距 (default: 16px)
  --tv-Tooltip-padding-x: var(--tv-space-xl);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6f8c43b and 8344b5a.

📒 Files selected for processing (1)
  • packages/theme/src/tooltip/vars.less (1 hunks)
🔇 Additional comments (1)
packages/theme/src/tooltip/vars.less (1)

73-73: LGTM! Verify spacing token values.

Good improvement replacing hardcoded pixel values with design system spacing tokens. This enhances theme customization and maintainability.

Let's verify the spacing token definitions:

Also applies to: 75-75

✅ Verification successful

Let me check the value of --tv-space-base to complete the verification.


Spacing tokens verified and properly defined

The spacing tokens are well-defined across theme files:

  • --tv-space-lg = 12px (3 × 4px base)
  • --tv-space-xl = 16px (4 × 4px base)

These values match the previous hardcoded values, ensuring layout consistency while improving maintainability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the spacing tokens are defined and their values
# Expected: Find definitions of --tv-space-lg and --tv-space-xl variables

# Search for spacing token definitions
rg --type less "(--tv-space-lg|--tv-space-xl)\s*:" packages/theme/

Length of output: 592


Script:

#!/bin/bash
# Search for --tv-space-base definition
rg --type less "^[^/]*--tv-space-base\s*:" packages/theme/

Length of output: 247

@zzcr zzcr merged commit cab4bc9 into opentiny:dev Dec 4, 2024
4 checks passed
@shenjunjian shenjunjian deleted the dev-aurora-theme-switch branch January 9, 2025 02:48
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