Skip to content

refactor(tree): [tree] refactor tree theme #2319

New issue

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

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

Already on GitHub? # to your account

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Oct 19, 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

  • New Features

    • Updated theming conventions for tree components with new CSS variable naming (--tv-).
    • Enhanced styling consistency across tree components, including background colors, padding, and hover states.
  • Bug Fixes

    • Resolved inconsistencies in variable references and improved overall styling structure for tree components and popovers.
    • Clarified button selection in filter view tests for more accurate interactions.

Copy link

coderabbitai bot commented Oct 19, 2024

Walkthrough

The changes in this pull request involve a comprehensive update to the theming conventions for tree components in the CSS files index.less and vars.less. Key modifications include the renaming of CSS variables from the prefix --ti- to --tv-, reflecting a new naming scheme. Additionally, method signatures for injecting CSS variables have been updated. The changes affect various styling properties such as background colors, padding, and hover states, ensuring consistency across the tree component and its associated popover.

Changes

File Path Change Summary
packages/theme/src/tree/index.less Renamed CSS variables from --ti- to --tv-, updated method calls from .component-css-vars-tree() to .inject-Tree-vars() and similar for popover. Adjusted various properties including colors, padding, and hover states.
packages/theme/src/tree/vars.less Updated variable names from --ti- to --tv-, changed method signatures, and reorganized variable definitions for clarity and consistency.
examples/sites/demos/pc/app/tree/filter-view.spec.ts Modified test script to specifically target the first instance of the '高亮' radio button in the filter view.

Possibly related PRs

Suggested reviewers

  • zzcr

🐇 In the garden, colors bloom,
Variables shift, making room.
From --ti- to --tv-, a new dawn,
Tree components styled, the old ways gone.
With each hover, a fresh delight,
Theming anew, everything feels right! 🌼


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.

@github-actions github-actions bot added the refactoring Refactoring (重构) label Oct 19, 2024
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 (7)
packages/theme/src/tree/vars.less (4)

13-33: Approve function renaming and variable prefix changes.

The changes in this section improve consistency and follow a new naming convention:

  1. Function renamed to .inject-Tree-vars(), which is more descriptive.
  2. CSS variable prefix changed from --ti- to --tv- consistently.
  3. Updated references to use standardized spacing variables (e.g., --tv-space-xl).

These changes enhance code readability and maintain a consistent naming scheme.

Consider updating the documentation to reflect these naming changes, especially if there are any public-facing docs or API references.


35-63: Approve node-related variable changes with a suggestion.

The changes in this section improve the styling capabilities of the Tree component:

  1. Consistent renaming with the --tv-Tree- prefix enhances clarity.
  2. New variables for node content styling (e.g., hover and current states) provide more granular control.

These changes will make it easier to customize the Tree component's appearance.

For the simplified variable on line 33 (--tv-Tree-empty-min-height: 60px;), consider if this should remain a hard-coded value or if it should reference a design token for better maintainability and consistency across the design system.


66-68: Approve new node styling variables with a suggestion for improvement.

The addition of new variables for node padding and highlight background color enhances the styling capabilities of the Tree component.

The comment on line 68 indicates that there's no common variable for the highlight background color (#f2f2f2). Consider creating a common design token for this color to maintain consistency across the design system. This would allow for easier updates and ensure visual coherence with other components.


70-79: Approve new node content and menu styling variables with a suggestion for improvement.

The addition of new variables for node content height, border radius, and menu styling enhances the customization options for the Tree component.

The comment on line 79 indicates that there's no common variable for the menu box shadow. Consider creating a reusable design token for box shadows to maintain consistency across the design system. This would allow for easier updates and ensure visual coherence with other components that use similar shadows.

packages/theme/src/tree/index.less (3)

280-281: Redundant fill and color properties

Both fill and color properties are set to var(--tv-Tree-node-collapse-icon-color). Verify if both are necessary. If only one affects the icon, consider removing the redundant property for cleaner code.


336-337: Redundant fill and color properties in hover state

In the hover state, both fill and color properties are assigned var(--tv-Tree-node-checked-icon-color). Ensure that both are required for the desired styling. Removing unnecessary properties can simplify the code.


158-159: Redundant color and fill properties

Both color and fill are set to var(--tv-Tree-text-color). Confirm if both are needed for the elements being styled. If not, consider omitting one to streamline the CSS.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 50489a1 and f1448cc.

📒 Files selected for processing (2)
  • packages/theme/src/tree/index.less (14 hunks)
  • packages/theme/src/tree/vars.less (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
packages/theme/src/tree/vars.less (1)

120-131: Approve Tree popover variable changes.

The changes in this section improve consistency and clarity:

  1. Function renamed to .inject-Tree-in-Popover-vars(), aligning with the new naming convention.
  2. Consistent renaming of variables with the --tv-Tree-popover- prefix.

These changes enhance code readability and maintain a consistent naming scheme across the Tree component and its associated popover.

packages/theme/src/tree/index.less (4)

23-23: Update method call to .inject-Tree-vars();

The change from .component-css-vars-tree(); to .inject-Tree-vars(); aligns with the new theming convention and is appropriate.


27-31: CSS variables updated to new naming convention

The properties for background, color, line-height, padding-top, and padding-bottom now use the new --tv- prefixed variables, which is consistent with the updated theming structure.


38-38: Variable name consistency check

Ensure that --tv-Tree-node-checked-icon-color is the intended variable for the border color. The naming is consistent with the new convention.


397-397: Consistency in margin calculation

The margin-right property uses calc(var(--tv-Tree-node-label-margin-left) / 2). Ensure that this calculation aligns with the intended design and that the variable name reflects its usage on the right margin.

margin-right: var(--ti-tree-node-operate-icon-margin-left);
fill: var(--tv-Tree-node-operate-icon-color);
font-size: var(--tv-Tree-node-operate-icon-font-size);
margin-right: var(--tv-Tree-node-operate-icon-margin-left);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Possible incorrect variable in margin-right

The margin-right property is using var(--tv-Tree-node-operate-icon-margin-left);, which might be unintended. Consider using var(--tv-Tree-node-operate-icon-margin-right); or verify that the variable name is correct.

Apply this diff to correct the variable:

-          margin-right: var(--tv-Tree-node-operate-icon-margin-left);
+          margin-right: var(--tv-Tree-node-operate-icon-margin-right);
📝 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
margin-right: var(--tv-Tree-node-operate-icon-margin-left);
margin-right: var(--tv-Tree-node-operate-icon-margin-right);

zzcr
zzcr previously approved these changes Oct 21, 2024
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)
examples/sites/demos/pc/app/tree/filter-view.spec.ts (1)

10-10: LGTM! Consider adding a comment explaining the .nth(0) usage.

The addition of .nth(0) to the selector makes it more specific and potentially more robust, especially if there are or could be multiple radio buttons with the name '高亮' (highlight) in the future. This change helps prevent potential test flakiness.

Consider adding a brief comment explaining why .nth(0) is necessary here. For example:

// Ensure we select the first 'highlight' radio button in case multiple exist
const btnHighlight = preview.getByRole('radio', { name: '高亮' }).nth(0)

This will help other developers understand the reasoning behind this specific selector.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f1448cc and de88ccd.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/tree/filter-view.spec.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
examples/sites/demos/pc/app/tree/filter-view.spec.ts (1)

Line range hint 1-30: Overall, the changes in this file improve test reliability.

While this change is not directly related to the tree theme refactoring mentioned in the PR objectives, it contributes to the overall quality of the test suite. The modification makes the selector for the highlight radio button more specific, which can prevent potential issues if the UI structure changes in the future.

@zzcr zzcr merged commit 92ba61d into opentiny:dev Oct 21, 2024
4 of 6 checks passed
@shenjunjian shenjunjian deleted the refactor-tree-theme branch October 25, 2024 06:19
@shenjunjian shenjunjian restored the refactor-tree-theme branch October 25, 2024 06:20
@shenjunjian shenjunjian deleted the refactor-tree-theme branch November 7, 2024 02:18
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
refactoring Refactoring (重构)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants