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): [drawer] refactor drawer theme vars #2237

Merged
merged 2 commits into from
Oct 12, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Oct 11, 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 two new CSS variables for semi-transparent background colors, enhancing overlay effects.
  • Style Updates

    • Comprehensive updates to the drawer component's styling, including new variable naming conventions and standardized padding/margin.
    • Fixed dimensions for drawer header buttons and updated close icon styles.
  • Refactor

    • Transitioned from --ti- to --tv- prefixed CSS variables for consistency across the drawer component.

Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

The changes in this pull request introduce two new CSS variables for background colors in the vars.less file and update the styling of the drawer component across multiple files. The drawer component transitions from --ti- prefixed variables to --tv- prefixed variables, altering method calls and standardizing styles with fixed pixel values. This includes updates to background colors, border radii, padding, and margin properties, reflecting a shift towards a new naming convention and design system.

Changes

File Change Summary
packages/theme/src/base/vars.less Added new variables: --tv-color-mask-bg: rgba(0, 0, 0, 30%) and --tv-color-bg-mask: rgba(0, 0, 0, 30%).
packages/theme/src/drawer/index.less Updated class definitions and variable usages from --ti- to --tv-, changed method call to .inject-Drawer-vars(), standardized padding and margin values, and updated background colors and border radii.
packages/theme/src/drawer/vars.less Changed method signature from .component-css-vars-drawer() to .inject-Drawer-vars(), updated several variables to new --tv- prefixed names, and simplified some variable definitions.

Possibly related PRs

🐰 In the land of style and flair,
A mask for drawers, we now declare!
With colors new and pixels tight,
Our components shine, oh what a sight!
From ti- to tv-, we hop along,
In this vibrant theme, we all belong! 🌈


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 11, 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: 9

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

313-313: LGTM! Consider adding a comment for clarity.

The new variable --tv-color-mask-bg is well-named and appropriately placed in the background color section. The use of rgba() for a semi-transparent black is perfect for mask/overlay effects.

Consider adding a brief comment to explain the intended use of this variable, similar to other variables in this file. For example:

-  --tv-color-mask-bg: rgba(0, 0, 0, 30%); // 遮罩层带有透明度的背景色
+  --tv-color-mask-bg: rgba(0, 0, 0, 30%); // Semi-transparent background color for overlay/mask effects
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between feea189 and f5d3045.

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

15-41: Verify all variable references are updated to the new prefix

The variables have been updated from the --ti- prefix to the --tv- prefix to align with the new design system. Ensure that all references to the old variables (--ti-Drawer-) are updated throughout the codebase to prevent styling inconsistencies.

Run the following script to check for any remaining references to old variables:

#!/bin/bash
# Description: Check for any remaining references to old Drawer variables.

# Test: Search for variables with '--ti-Drawer-' prefix. Expect: No matches.
rg --type less '--ti-Drawer-'

13-13: Ensure consistent use of the updated function name

The function name has been changed from .component-css-vars-drawer() to .inject-Drawer-vars(). Please verify that all references to the old function name have been updated throughout the codebase to prevent any potential issues.

Run the following script to check for any remaining references to the old function name:

✅ Verification successful

All references to .component-css-vars-drawer() have been successfully updated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to `.component-css-vars-drawer()`

# Test: Search for the old function name. Expect: No matches.
rg --type less '\.component-css-vars-drawer\(\)'

Length of output: 538


Script:

#!/bin/bash
# Description: Check for any remaining references to `.component-css-vars-drawer()`

# Test: Search for the old function name. Expect: No matches.
rg --type less '\.component-css-vars-drawer\(\)'

Length of output: 50

packages/theme/src/drawer/index.less (6)

7-7: Update to New Mixin Method is Appropriate

The mixin method call has been updated to .inject-Drawer-vars();, aligning with the new theming system. This change is appropriate and ensures consistency with the updated variable naming convention.


19-19: Variable Name Update is Correct

The background color for the mask has been updated to use var(--tv-Drawer-mask-bg-color), which follows the new variable naming convention. This change is correct.


29-30: Background Color and Shadow Variables Updated Appropriately

The background-color and box-shadow properties now use var(--tv-Drawer-bg-color) and var(--tv-Drawer-shadow), respectively. These changes align with the new variable naming convention and enhance theming consistency.


60-60: Consistent Use of Border Radius Variables

The border-radius properties have been updated to use var(--tv-Drawer-border-radius-size). This ensures consistency and aligns with the new theming variables.

Also applies to: 67-67, 74-74


148-153: Well-Defined Close Icon Colors with Hover State

The close icon's fill color and hover state are set using var(--tv-Drawer-close-icon-color) and var(--tv-Drawer-close-icon-color-hover). This practice allows for easy theming and customization.


169-171: Consistent Use of Typography Variables

The font size, color, and weight for the title are set using variables var(--tv-Drawer-head-title-font-size), var(--tv-Drawer-head-title-text-color), and var(--tv-Drawer-head-title-font-weight). This promotes consistency and theming flexibility.

Comment on lines +15 to +17
--tv-Drawer-min-width: 500px;
// 最大宽度
--ti-drawer-max-width: calc(var(--ti-common-space-10, 10px) * 100);
--tv-Drawer-max-width: 1000px;
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 parameterizing width values for flexibility

The minimum and maximum width variables are now set to fixed pixel values (500px and 1000px). Consider using relative units (like em, rem, or percentages) or referencing global sizing variables to enhance responsiveness and maintainability.

Apply this diff if you decide to use global variables:

 - --tv-Drawer-min-width: 500px;
 - --tv-Drawer-max-width: 1000px;
+ --tv-Drawer-min-width: var(--tv-size-min-width);
+ --tv-Drawer-max-width: var(--tv-size-max-width);

Committable suggestion was skipped due to low confidence.

Comment on lines +123 to +124
margin-left: 32px;
margin-right: 32px;
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 Variables Instead of Fixed Margins

The margin-left and margin-right properties are set to 32px. To enhance flexibility and maintain consistency across the theme, consider using variables instead of fixed pixel values.

You could define a variable in vars.less, such as @drawer-horizontal-margin, and use it here:

margin-left: @drawer-horizontal-margin;
margin-right: @drawer-horizontal-margin;

Comment on lines +137 to +138
top: 20px;
right: 20px;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Variables for Close Button Positioning

The top and right properties of the close button are set to fixed values (20px). For better consistency and theming flexibility, consider defining these values as variables.

Define variables in vars.less:

@drawer-close-button-top: 20px;
@drawer-close-button-right: 20px;

Then apply them:

top: @drawer-close-button-top;
right: @drawer-close-button-right;

Comment on lines +140 to +141
height: 24px;
width: 24px;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Variables for Close Button Size

The height and width of the close button are hardcoded to 24px. To allow for easier adjustments and maintain consistency, consider using a variable.

Define a variable:

@drawer-close-button-size: 24px;

Then apply it:

height: @drawer-close-button-size;
width: @drawer-close-button-size;

padding: var(--ti-drawer-header-padding-top) var(--ti-drawer-header-padding-right)
var(--ti-drawer-header-padding-bottom) var(--ti-drawer-header-padding-left);
background: var(--ti-drawer-bg-color);
padding: 32px 0 24px;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace Fixed Padding with Variables in Header

The header's padding is set to 32px 0 24px. Using variables for padding values enhances maintainability and allows for easier theme adjustments.

Define variables:

@drawer-header-padding-top: 32px;
@drawer-header-padding-bottom: 24px;

Then apply them:

padding: @drawer-header-padding-top 0 @drawer-header-padding-bottom;

Comment on lines +181 to +184
width: var(--tv-Drawer-help-icon-width-height);
height: var(--tv-Drawer-help-icon-width-height);
margin-left: 8px;
fill: var(--tv-Drawer-help-icon-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

Use Variable for Help Icon Margin

While the width, height, and fill are set using variables, the margin-left is hardcoded to 8px. Consider using a variable for the margin to maintain consistency.

Define a variable:

@drawer-help-icon-margin-left: 8px;

Then apply it:

margin-left: @drawer-help-icon-margin-left;

@@ -202,30 +197,28 @@
.@{drawer-prefix-cls}__body {
flex: auto;
overflow: auto;
padding: var(--ti-drawer-padding-top) var(--ti-drawer-padding-right) var(--ti-drawer-padding-bottom) var(--ti-drawer-padding-left);
border-bottom: 1px solid var(--ti-drawer-divider-body-border-color);
padding: 0 32px;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Variables for Body Padding

The padding for the body is set to 0 32px. Consider using a variable for the horizontal padding to maintain consistency.

Define a variable:

@drawer-body-horizontal-padding: 32px;

Then apply it:

padding: 0 @drawer-body-horizontal-padding;

Comment on lines +208 to +209
justify-content: flex-end;
padding: 24px 0 32px;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Variables for Footer Padding

The footer's padding is set to 24px 0 32px. Replacing fixed values with variables enhances consistency and makes future adjustments easier.

Define variables:

@drawer-footer-padding-top: 24px;
@drawer-footer-padding-bottom: 32px;

Then apply them:

padding: @drawer-footer-padding-top 0 @drawer-footer-padding-bottom;


.@{drawer-prefix-cls}__confirm-btn {
order: 0;

&.reverse {
margin-left: var(--ti-drawer-divider-footer-button-margin-left);
margin-left: 8px;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Variables for Button Spacing

The margin-left for the confirm and cancel buttons is set to 8px. Using a variable for this spacing would improve consistency and ease adjustments.

Define a variable:

@drawer-button-spacing: 8px;

Then apply it:

margin-left: @drawer-button-spacing;

Also applies to: 221-221

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/drawer/vars.less (1)

Line range hint 1-12: Typographical error in the header comment

In the header comment, the year is incorrectly listed as "202" instead of "2020".

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f5d3045 and 57d8f12.

📒 Files selected for processing (2)
  • packages/theme/src/base/vars.less (1 hunks)
  • packages/theme/src/drawer/vars.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/theme/src/base/vars.less
🧰 Additional context used
🔇 Additional comments (1)
packages/theme/src/drawer/vars.less (1)

13-41: Variables updated to align with new design system

The refactoring correctly updates the variable names to the new --tv- prefix and references the appropriate design tokens.

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