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(numeric): [numeric]refactor numeric theme vars #2200

Merged
merged 1 commit into from
Sep 29, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Sep 28, 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 additional <tiny-numeric> components with varying properties in multiple demo files, enhancing the numeric input experience.
  • Bug Fixes

    • Adjusted test cases to accurately reflect changes in the structure of the numeric components.
  • Chores

    • Updated CSS variable naming conventions and styles for numeric input components to improve consistency and maintainability across the application.

Copy link

coderabbitai bot commented Sep 28, 2024

Walkthrough

The pull request introduces multiple modifications to the <tiny-numeric> component across several Vue files, adding new instances with varying properties and adjusting existing ones. It also updates the CSS variable naming conventions in the LESS files, reflecting a shift in styling practices. The changes include updates to test cases to align with the modified component structure, ensuring consistency in the component's behavior and appearance.

Changes

File Path Change Summary
examples/sites/demos/pc/app/numeric/dynamic-disabled-composition-api.vue
examples/sites/demos/pc/app/numeric/dynamic-disabled.vue
Added four new <tiny-numeric> components with various properties; scoped styles updated.
examples/sites/demos/pc/app/numeric/numeric-size-composition-api.vue
examples/sites/demos/pc/app/numeric/numeric-size.vue
Adjusted instances of <tiny-numeric> components, adding and removing specific instances.
packages/theme/src/numeric/index.less
packages/theme/src/numeric/vars.less
Updated CSS variable names from ti- to tv-, altered method calls, and modified property values for consistency.
examples/sites/demos/pc/app/numeric/numeric-size.spec.ts Adjusted test case indices for the "small" and "mini" sizes of the numeric component.

Possibly related PRs

Suggested labels

refactoring

Suggested reviewers

  • kagol

Poem

🐰 In the garden where numbers play,
Tiny inputs dance and sway.
With styles anew and components bright,
They hop along, a joyful sight!
A world of metrics, neat and fine,
In every change, our dreams align! 🌼


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 Sep 28, 2024
@zzcr zzcr changed the title refactor(numeric): refactor numeric theme vars refactor(numeric): [numeric]refactor numeric theme vars Sep 28, 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: 6

🧹 Outside diff range and nitpick comments (6)
examples/sites/demos/pc/app/numeric/dynamic-disabled-composition-api.vue (1)

5-7: LGTM! Consider adding comments for clarity.

The additional <tiny-numeric> components effectively demonstrate various configurations, enhancing the example. This aligns well with the PR's refactoring objective.

Consider adding comments above each new <tiny-numeric> component to describe its specific configuration. This would improve readability and make the purpose of each instance clearer. For example:

<!-- Numeric input with 'kg' unit -->
<tiny-numeric v-model="value1" :disabled="disabled" unit="kg" class="mr20"></tiny-numeric>

<!-- Numeric input without controls and left-side display -->
<tiny-numeric v-model="value1" :disabled="disabled" :controls="false" show-left class="mr20"></tiny-numeric>

<!-- Numeric input with controls on the right -->
<tiny-numeric v-model="value1" :disabled="disabled" controls-position="right" class="mr20"></tiny-numeric>
examples/sites/demos/pc/app/numeric/numeric-size.spec.ts (1)

Line range hint 22-27: LGTM, but consider using more robust selectors.

The change from .nth(2) to .nth(3) for the mini numeric component is consistent with the previous change for the small numeric component.

To make the tests more robust and less dependent on the exact order of elements, consider using more specific selectors. For example:

const miniNumeric = page.locator('.tiny-numeric.tiny-numeric--mini')

This approach would be more resilient to changes in the DOM structure and make the tests easier to maintain.

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

63-63: Translate Comments to English for Consistency

The comment is written in Chinese: // 保证文本居中. To maintain consistency and readability for all developers, please translate comments to English.

Update the comment as follows:

 line-height: 1.5;
-// 保证文本居中
+// Ensure the text is vertically centered

84-84: Avoid Duplicate Border Property

The border property is redefined multiple times without overriding other styles. This may be redundant.

Consider reviewing and consolidating the border property to ensure it's only defined when necessary.


89-89: Translate Comments to English for Consistency

The comment is written in Chinese: // 保证文本居中. Please translate it to English.

Update the comment as follows:

 &:focus {
   outline: 0;
-  .placeholder(@color: var(--tv-Numeric-input-placeholder-text-color));
-  // 保证文本居中
+  .placeholder(@color: var(--tv-Numeric-input-placeholder-text-color));
+  // Ensure the text is vertically centered
 }

323-323: Translate Comments to English for Consistency

The comment // 消除父子元素间多出来的空白 is in Chinese. Please translate the comment for consistency and readability.

Update the comment as follows:

 font-size: 0;
-// 消除父子元素间多出来的空白
+// Eliminate extra whitespace between parent and child elements
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 41f9ca8 and 0175947.

📒 Files selected for processing (7)
  • examples/sites/demos/pc/app/numeric/dynamic-disabled-composition-api.vue (2 hunks)
  • examples/sites/demos/pc/app/numeric/dynamic-disabled.vue (2 hunks)
  • examples/sites/demos/pc/app/numeric/numeric-size-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/numeric/numeric-size.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/numeric/numeric-size.vue (1 hunks)
  • packages/theme/src/numeric/index.less (8 hunks)
  • packages/theme/src/numeric/vars.less (1 hunks)
🔇 Additional comments (9)
examples/sites/demos/pc/app/numeric/numeric-size-composition-api.vue (2)

Line range hint 1-20: Clarification needed on PR objectives and changes

The changes enhance the demo by showcasing all available sizes of the <tiny-numeric> component, including the default size. However, there are a few points that need clarification:

  1. The AI summary mentioned the removal of a <tiny-numeric> component after the mini-sized one, but this removal is not visible in the provided diff. Could you confirm if this removal was intended and if it's missing from the diff?

  2. The PR objective states "refactor numeric theme vars", but the changes in this file don't directly reflect this. Could you elaborate on how these changes relate to the refactoring effort?

  3. Consider updating the PR description to accurately reflect the changes made in this file, specifically mentioning the addition of the default-sized component to the demo.

To check for any related changes that might not be visible in this file:

#!/bin/bash
# Description: Check for related changes in the PR

# List all changed files in the PR
echo "Changed files in this PR:"
git diff --name-only HEAD~1

# Check for any changes related to numeric theme variables
echo "Changes related to numeric theme variables:"
git diff HEAD~1 | grep -i 'numeric.*theme\|theme.*numeric'

This will help us understand the full scope of changes related to the numeric component and theme variables.


5-6: LGTM, but clarification needed on PR objectives

The addition of a default-sized <tiny-numeric> component enhances the demo by showcasing all available sizes. However, this change doesn't seem to directly relate to the stated PR objective of "refactor numeric theme vars". Could you clarify how this change aligns with the refactoring effort?

To improve code readability, consider adding a comment explaining the purpose of this default-sized component:

+    <!-- Default size -->
     <tiny-numeric v-model="value"></tiny-numeric>
     <br /><br />

To verify the impact of this change, let's check for any related changes in the theme variables:

✅ Verification successful

Verified: Numeric theme variables refactored as per PR objectives

The recent changes successfully refactor the numeric theme variables from --ti- to --tv-, aligning with the PR's goal. Additionally, the addition of the <tiny-numeric> component enhances the demo by showcasing the updated theme variations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for changes in numeric theme variables

# Search for files that might contain numeric theme variables
echo "Files potentially containing numeric theme variables:"
fd -e scss -e css -e less | grep -i 'theme\|var\|numeric'

# Search for any recent changes related to numeric variables
echo "Recent changes related to numeric variables:"
git log -p -S "numeric" --since="1 week ago" -- '*.scss' '*.css' '*.less'

Length of output: 1081


Script:

#!/bin/bash
# Description: Check for changes in numeric theme variables

# Search for files that might contain numeric theme variables
echo "Files potentially containing numeric theme variables:"
fd --extensions scss,css,less | grep -iE 'theme|var|numeric'

# Search for any recent changes related to numeric variables
echo "Recent changes related to numeric theme variables in the last week:"
git log -p -S "numeric" --since="1 week ago" -- '*.scss' '*.css' '*.less'

Length of output: 36514

examples/sites/demos/pc/app/numeric/numeric-size.vue (1)

5-6: LGTM! Consider documentation updates.

The addition of a <tiny-numeric> instance without a size attribute is a good way to demonstrate the default size. This change aligns well with the PR objective of refactoring numeric theme variables.

As this is a demo file, please verify if any corresponding documentation needs to be updated to reflect these changes in the size demonstrations.

Also, could you clarify if an instance of <tiny-numeric> without a size attribute was removed as mentioned in the AI summary? It's not visible in the provided diff, and this information might be relevant for a complete understanding of the changes.

examples/sites/demos/pc/app/numeric/dynamic-disabled-composition-api.vue (2)

23-28: LGTM! Scoped style addition is appropriate.

The addition of the scoped style for .mr20 is a good practice. It provides consistent spacing between the numeric input components and ensures that the styling is limited to this component.


Line range hint 1-28: Overall, the changes effectively demonstrate the <tiny-numeric> component's capabilities.

The additions to this file align well with the PR's objective of refactoring numeric theme variables. The new examples showcase various configurations, providing a more comprehensive demonstration of the component's features. The consistent use of styling and bindings maintains code quality and readability.

examples/sites/demos/pc/app/numeric/dynamic-disabled.vue (1)

32-36: Good addition of scoped style for consistent spacing.

The introduction of a scoped style block with the .mr20 class is a good practice. It ensures consistent spacing between components and improves the overall layout of the demo.

The use of scoped styles in Vue components is recommended for better encapsulation and maintainability.

examples/sites/demos/pc/app/numeric/numeric-size.spec.ts (1)

15-20: LGTM, but please verify the DOM structure.

The change from .nth(1) to .nth(2) for the small numeric component suggests that the order of elements has changed. This is consistent with the large numeric still being the first element.

To ensure this change is correct, please verify the new DOM structure. You can run the following script to check the structure of .tiny-numeric elements:

This will show the first three .tiny-numeric elements. Verify that the second one (index 1) has the tiny-numeric--small class.

packages/theme/src/numeric/index.less (1)

76-76: Variable Name Typo: Correct to Maintain Consistency

The variable --tv-Numeric-input-placeholder-text-color should be consistently named throughout the codebase. Verify that the variable name is correct and matches its definition.

Please ensure that --tv-Numeric-input-placeholder-text-color is defined in vars.less and used consistently.

packages/theme/src/numeric/vars.less (1)

13-100: Well-organized refactoring of numeric theme variables

The refactoring systematically updates variable names to the new naming convention, enhancing consistency and maintainability across the codebase.

Comment on lines +5 to +7
<tiny-numeric v-model="value1" :disabled="disabled" unit="kg" class="mr20"></tiny-numeric>
<tiny-numeric v-model="value1" :disabled="disabled" :controls="false" show-left class="mr20"></tiny-numeric>
<tiny-numeric v-model="value1" :disabled="disabled" controls-position="right" class="mr20"></tiny-numeric>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider using separate v-model bindings for each component.

The additions effectively demonstrate various configurations of the <tiny-numeric> component, which is great for showcasing its versatility. However, using the same v-model="value1" for all components might lead to unexpected behavior, as changing one component will update all others.

Consider using separate v-model bindings for each component to ensure independent behavior. For example:

<tiny-numeric v-model="value1" :disabled="disabled" unit="kg" class="mr20"></tiny-numeric>
<tiny-numeric v-model="value2" :disabled="disabled" :controls="false" show-left class="mr20"></tiny-numeric>
<tiny-numeric v-model="value3" :disabled="disabled" controls-position="right" class="mr20"></tiny-numeric>

Then update the data() section accordingly:

data() {
  return {
    value1: 1,
    value2: 1,
    value3: 1,
    // ... other properties
  }
}

The consistent use of the "mr20" class and the variety of component configurations are good practices for maintaining uniform spacing and demonstrating component flexibility.

@@ -19,11 +19,11 @@
@input-prefix-cls: ~'@{css-prefix}input';

.@{numeric-prefix-cls} {
.component-css-vars-numeric();
.inject-Numeric-vars();
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure Consistent Naming Convention for Mixins

The mixin name .inject-Numeric-vars(); uses PascalCase. For consistency with other mixin calls in the codebase, consider using all lowercase letters.

Consider renaming the mixin to:

.inject-numeric-vars();

text-align: center;
cursor: pointer;
user-select: none;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Property user-select: none; May Affect Accessibility

Setting user-select: none; prevents users from selecting text, which may affect accessibility.

Consider whether preventing text selection is necessary. If not, you might want to remove this property to improve user experience.

Comment on lines +388 to +389
border-bottom: 1px solid var(--tv-Numeric-input-normal-border-color);
border-left: 1px solid var(--tv-Numeric-input-normal-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

Border Properties May Need Consistent Variables

The border properties use hardcoded colors. To maintain consistency and theming capabilities, consider using CSS variables.

Update the border properties to use the appropriate CSS variables, such as --tv-Numeric-input-border-color.

 &__increase {
   border-radius: 0 4px 0 0;
-  border-bottom: 1px solid var(--tv-Numeric-input-normal-border-color);
-  border-left: 1px solid var(--tv-Numeric-input-normal-border-color);
+  border-bottom: 1px solid var(--tv-Numeric-input-border-color);
+  border-left: 1px solid var(--tv-Numeric-input-border-color);

Ensure that --tv-Numeric-input-border-color is defined and represents the intended color.

📝 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
border-bottom: 1px solid var(--tv-Numeric-input-normal-border-color);
border-left: 1px solid var(--tv-Numeric-input-normal-border-color);
border-bottom: 1px solid var(--tv-Numeric-input-border-color);
border-left: 1px solid var(--tv-Numeric-input-border-color);

Comment on lines +23 to +25
--tv-Numeric-input-dividing-border-color: var(--tv-color-border-divider);
// 分割线高度
--ti-numeric-input-dividing-border-height: var(--ti-common-space-5x, 20px);
// 禁用时分割线display(hide)
--ti-numeric-input-dividing-border-display: none;
--tv-Numeric-input-dividing-border-height: 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

Inconsistent naming of 'dividing-border' and 'divider' variables

There is inconsistency in the variable naming between 'dividing-border' and 'divider'. For example:

  • Line 23~: --tv-Numeric-input-dividing-border-color
  • Line 25~: --tv-Numeric-input-dividing-border-height
  • Line 67~: --tv-Numeric-input-divider-height-medium
  • Line 78~: --tv-Numeric-input-divider-height-small
  • Line 89~: --tv-Numeric-input-divider-height-mini

Consider standardizing the variable names to use either 'divider' or 'dividing-border' consistently for better maintainability and readability.

Apply this diff to rename the variables to use 'divider':

- --tv-Numeric-input-dividing-border-color: var(--tv-color-border-divider);
+ --tv-Numeric-input-divider-color: var(--tv-color-border-divider);

- --tv-Numeric-input-dividing-border-height: 20px;
+ --tv-Numeric-input-divider-height: 20px;

Update all relevant references accordingly.

Also applies to: 67-67, 78-78, 89-89

// medium尺寸图标大小
--ti-numeric-input-icon-size-medium: var(--ti-common-font-size-2, 16px);
--tv-Numeric-input-icon-size-medium: var(--tv-icon-size);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Standardize icon size variables across different sizes

In the default and medium sizes, the icon size is set using a variable (var(--tv-icon-size)), while in small and mini sizes, the icon sizes are hardcoded to 14px. For consistency, consider defining variables for the small and mini icon sizes.

Define new variables for small and mini icon sizes:

+ --tv-icon-size-sm: 14px;
+ --tv-icon-size-xs: 12px; /* Adjust if necessary */

- --tv-Numeric-input-icon-size-small: 14px;
+ --tv-Numeric-input-icon-size-small: var(--tv-icon-size-sm);

- --tv-Numeric-input-icon-size-mini: 14px;
+ --tv-Numeric-input-icon-size-mini: var(--tv-icon-size-xs);

This approach enhances scalability and maintains consistency across different size variants.

Also applies to: 76-76, 87-87

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.

1 participant