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

refactor(theme): [tooltip] refactor tooltip theme vars #2257

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Oct 14, 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

    • Introduced a new mixin for tooltip styles, improving consistency and maintainability.
    • Updated CSS variables for tooltip styling to a new naming convention, enhancing clarity and organization.
  • Bug Fixes

    • Resolved issues with tooltip appearance by standardizing variable references for colors, borders, and padding.
  • Refactor

    • Comprehensive restructuring of tooltip CSS variables and mixins for improved design alignment.

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request introduces significant updates to the tooltip component's styling by replacing the existing CSS variable naming convention from --ti- to --tv-. It includes the introduction of a new mixin, .inject-Tooltip-vars(), which replaces the previous mixin. The tooltip's CSS variables for various properties such as font, colors, and dimensions have been restructured to ensure consistency and maintainability.

Changes

File Path Change Summary
packages/theme/src/tooltip/index.less Updated mixin from .component-css-vars-tooltip() to .inject-Tooltip-vars(). Changed CSS variable prefixes from --ti- to --tv-. Adjusted popper arrow dimensions to fixed values. Updated state classes to use new variables.
packages/theme/src/tooltip/vars.less Replaced .component-css-vars-tooltip() with .inject-Tooltip-vars(). Renamed multiple CSS variables from --ti- to --tv- for consistency in tooltip styling. Removed and replaced certain border-related variables.

Possibly related PRs

Poem

🐇 In the garden of styles, we play,
With colors and variables, bright as the day.
From --ti- to --tv-, a leap we take,
For tooltips that shimmer, and no more mistake.
With mixins anew, our designs will delight,
Hopping through code, 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 14, 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: 2

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

89-89: Remove unnecessary blank line for cleaner code

Line 89 contains an extra blank line that isn't necessary. Removing it can improve code readability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b1240c9 and d675d9a.

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

13-79: LGTM!

The refactoring of tooltip theme variables from --ti- to --tv- is consistent and aligns with the project's naming conventions. The use of the .inject-Tooltip-vars() mixin enhances maintainability and promotes a standardized approach to theming.

packages/theme/src/tooltip/index.less (8)

20-20: Ensure the new mixin .inject-Tooltip-vars() is properly defined and imported

At line 20, the mixin .inject-Tooltip-vars(); replaces the previous .component-css-vars-tooltip();. Verify that this new mixin is correctly defined in your tooltip.less or related mixin files and that it's properly imported to ensure all necessary variables are injected.


30-30: Verify the definition of --tv-Tooltip-content-max-height

Line 30 sets the max-height using var(--tv-Tooltip-content-max-height);. Confirm that this CSS variable is defined in your vars.less file with the intended value to avoid potential rendering issues.


37-40: Check consistency and definitions of updated CSS variables

Lines 37-40 update several style properties to use new CSS variables:

  • border-radius: var(--tv-Tooltip-popper-border-radius);
  • padding: var(--tv-Tooltip-padding-y) var(--tv-Tooltip-padding-x);
  • font-size: var(--tv-Tooltip-popper-font-size);
  • line-height: var(--tv-Tooltip-popper-font-line-height);

Ensure that these variables are consistently named according to your naming conventions and that they are properly defined with appropriate values in your theme variables.


45-45: Confirm the --tv-Tooltip-box-shadow variable is defined and applied correctly

Line 45 sets the box-shadow using var(--tv-Tooltip-box-shadow);. Verify that this variable is defined in your theme variables and that it produces the desired shadow effect for the tooltip.


92-94: Ensure all state-related CSS variables are properly defined

For the tooltip states .is-normal, .is-info, .is-error, .is-warning, .is-success, and .is-light, new CSS variables are used:

  • Text color variables (e.g., var(--tv-Tooltip-popper-normal-text-color))
  • Background color variables (e.g., var(--tv-Tooltip-popper-normal-bg-color))
  • Border color variables (e.g., var(--tv-Tooltip-popper-normal-border-color))

Verify that all these variables are defined in vars.less with appropriate values to ensure the tooltip displays correctly in all states.

Also applies to: 100-102, 108-110, 121-123, 129-131, 142-144


114-114: Verify the definition of --tv-Tooltip-validate-icon-color

Line 114 sets the fill property using var(--tv-Tooltip-validate-icon-color);. Ensure this variable is defined to display the validation icons correctly in error tooltips.


136-137: Check dark mode variables for consistency

In the .is-dark class, the background and text colors use:

  • background: var(--tv-Tooltip-popper-dark-bg-color);
  • color: var(--tv-Tooltip-popper-dark-text-color);

Confirm that these variables align with your dark theme specifications and are defined properly to maintain visual consistency.


142-144: Ensure light theme variables are defined and styled correctly

For the .is-light class, new CSS variables are introduced:

  • var(--tv-Tooltip-popper-light-text-color)
  • var(--tv-Tooltip-popper-light-bg-color)
  • var(--tv-Tooltip-popper-light-border-color)

Verify that these variables are defined in your theme files and that they provide sufficient contrast for readability in light-themed tooltips.

// 文字提示错误图标色
--ti-tooltip-validate-icon-color: var(--ti-common-color-error, #f23030);
--tv-Tooltip-validate-icon-color: var(--tv-color-error-tex);
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 variable name --tv-color-error-tex

There appears to be a typo in the variable name --tv-color-error-tex; it should likely be --tv-color-error-text to match the naming convention of other color variables.

Apply this diff to correct the typo:

-  --tv-Tooltip-validate-icon-color: var(--tv-color-error-tex);
+  --tv-Tooltip-validate-icon-color: var(--tv-color-error-text);
📝 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
--tv-Tooltip-validate-icon-color: var(--tv-color-error-tex);
--tv-Tooltip-validate-icon-color: var(--tv-color-error-text);

Comment on lines +51 to +53
width: 12px;
height: 20px;
background-color: var(--tv-Tooltip-popper-border-color);
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 using CSS variables for arrow dimensions

The arrow dimensions are hardcoded:

  • width: 12px;
  • height: 20px;

To allow for more flexibility and theming options, consider defining these dimensions using CSS variables. This approach enhances customization and consistency across different themes.

Apply this change to define arrow dimensions using variables:

 .popper__arrow {
   position: absolute;
   display: block;
-  width: 12px;
-  height: 20px;
+  width: var(--tv-Tooltip-arrow-width, 12px);
+  height: var(--tv-Tooltip-arrow-height, 20px);
   background-color: var(--tv-Tooltip-popper-border-color);
   transform: rotateZ(45deg);
   border-radius: 2px;
 }
📝 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
width: 12px;
height: 20px;
background-color: var(--tv-Tooltip-popper-border-color);
width: var(--tv-Tooltip-arrow-width, 12px);
height: var(--tv-Tooltip-arrow-height, 20px);
background-color: var(--tv-Tooltip-popper-border-color);

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)

77-79: Improved consistency and added control for tooltip sizing.

These final changes enhance the tooltip styling system:

  1. The validate icon color now references a design system variable, improving consistency:

    --tv-Tooltip-validate-icon-color: var(--tv-color-error-icon);
  2. A new variable for content max height has been added:

    --tv-Tooltip-content-max-height: 50vh;

The content max height variable is a good addition for controlling tooltip sizing. Consider adding a brief comment explaining its purpose and usage to help other developers understand when and how to adjust this value.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d675d9a and fc2e399.

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

13-21: Improved method naming and variable consistency.

The changes in this segment enhance the overall structure and consistency of the tooltip styling:

  1. The method name change from .component-css-vars-tooltip() to .inject-Tooltip-vars() better reflects its purpose of injecting variables.
  2. The updated variables now reference a broader design system (e.g., --tv-color-border-active, --tv-line-height-number), which improves consistency across the entire UI.

These changes will make the code more maintainable and easier to understand.


23-28: Clarify the purpose of "(hide)" comments.

The updates to the normal tooltip style variables improve consistency with the new naming convention and design system. However, some variables are marked with "(hide)" comments:

// 文字提示正常文本色(hide)
--tv-Tooltip-popper-normal-text-color: var(--tv-color-text);
// 弹框正常边框色 (hide)
--tv-Tooltip-popper-normal-border-color: var(--tv-Tooltip-popper-normal-bg-color);

Could you clarify the purpose of these "(hide)" comments? Are these variables deprecated or not directly used? If they are no longer needed, consider removing them to keep the codebase clean.


30-56: Improved consistency and maintainability for status-specific tooltip styles.

The updates to the info, error, warning, and success tooltip style variables significantly enhance the overall design system integration:

  1. Consistent naming convention: All variables now follow the --tv-Tooltip-popper-[status]-[property] pattern.
  2. Design system integration: Variables now reference color variables from the broader design system (e.g., var(--tv-color-info-bg), var(--tv-color-error-text-white)).

These changes will make it easier to maintain a consistent look and feel across different tooltip types and simplify future updates to the design system.


58-68: Clarify the decision for light theme border color.

The updates to the dark and light theme tooltip style variables improve consistency with the new naming convention and design system. However, there's an interesting decision for the light theme border color:

--tv-Tooltip-popper-light-border-color: var(--tv-Tooltip-popper-light-bg-color);

This effectively removes the border for light theme tooltips by setting it to the same color as the background. Is this intentional? If so, consider adding a comment explaining the design decision to make it clear for future developers.


71-71: Improved consistency for box shadow.

The update to the box shadow variable enhances consistency with the overall design system:

--tv-Tooltip-box-shadow: var(--tv-shadow-2-down);

This change will ensure that tooltips use a standardized shadow effect, improving visual consistency across the UI.


73-75: Improved naming convention for padding variables.

The updates to the padding variables enhance readability and align with common CSS naming conventions:

--tv-Tooltip-padding-y: 12px;
--tv-Tooltip-padding-x: 16px;

These changes from padding-vertical and padding-horizontal to padding-y and padding-x make the code more concise and familiar to developers used to popular CSS frameworks.


13-79: Overall excellent refactoring of tooltip theme variables.

This refactoring significantly improves the tooltip styling system:

  1. Consistent naming convention with the --tv- prefix and logical variable names.
  2. Improved integration with the broader design system, enhancing visual consistency.
  3. Better organization of variables for different tooltip types and themes.
  4. Addition of a content max height variable for improved control over tooltip sizing.

These changes will make the codebase more maintainable and easier to understand. A few minor suggestions were made:

  • Clarify the purpose of "(hide)" comments on some variables.
  • Explain the design decision for setting the light theme border color to the background color.
  • Add a brief comment explaining the purpose and usage of the new content max height variable.

Overall, this is a well-executed refactoring that aligns with best practices for CSS variable management in a design system.

@kagol kagol merged commit 1e1d4ba into dev Oct 14, 2024
6 checks passed
@kagol kagol deleted the refactor-tooltip-theme-vars-1014 branch November 4, 2024 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring (重构)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants