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(base-select): [base-select] refactor vars for base-select #2399

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

MomoPoppy
Copy link
Collaborator

@MomoPoppy MomoPoppy commented Oct 25, 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 base select component with customizable styles and responsive design.
    • Enhanced functionality with new props for user interaction, including searchable, showEmptyImage, and more.
  • Bug Fixes

    • Improved browser compatibility for the base select component.
  • Documentation

    • Added new LESS stylesheet and variables for consistent theming across the base select component.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes introduce new LESS styles and variables for the base select component, enhancing its design and functionality. A new stylesheet index.less is created to define styles, while vars.less establishes CSS variables for consistent theming. Additionally, the pc.vue component is updated with multiple new props, improving configurability and user interaction. These modifications collectively enhance the component's layout, responsiveness, and usability across different scenarios.

Changes

File Path Change Summary
packages/theme/src/base-select/index.less New LESS stylesheet created for base select component, defining styles, layout, and responsive design.
packages/theme/src/base-select/vars.less New LESS file created with CSS custom properties for the base select component, including colors and spacing. New mixin added: .inject-BaseSelect-vars().
packages/vue/src/base-select/src/pc.vue Multiple new props added to tiny-base-select component: inputBoxType, searchable, showEmptyImage, tagType, clearNoMatchValue, showLimitText, showProportion, clickExpand, maxVisibleRows, allText. Import statement for base select theme added.

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

🐇 In the meadow where styles bloom,
A select component finds its room.
With colors bright and props anew,
It dances in the breeze, so true.
From tags to themes, it takes its flight,
A joyful hop in the coding night! 🌙


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 25, 2024
@MomoPoppy MomoPoppy force-pushed the MomoPoppy/refactor-base-select-1025 branch from 6051890 to 09447a2 Compare October 25, 2024 09:09
@zzcr zzcr merged commit 3920df1 into opentiny:dev Oct 25, 2024
3 of 4 checks passed
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: 7

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

13-19: Consider adding English comments for better international collaboration.

The variable definitions are well-structured with appropriate fallbacks, but the comments are in Chinese. Consider adding English translations or replacing with English comments to improve maintainability for international contributors.

Example:

- // 文本色
+ // Text color
- // 字号
+ // Font size
- // 行高
+ // Line height
packages/theme/src/base-select/index.less (3)

31-47: Consider adding browser support comments.

The browser-specific code blocks would benefit from additional documentation explaining the specific issues they address.

 &&__multiple:not(&__collapse-tags):not(&__filterable) &__tags > span {
-  // 兼容ie10-ie11
+  // Fix for IE10-IE11: Ensures proper tag wrapping in multiple select mode
   @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
     display: flex;
     flex-wrap: wrap;
     justify-content: flex-start;
     align-content: flex-start;
   }

-  // 兼容edge
+  // Fix for Edge: Ensures proper tag layout and width calculation
   @supports (-ms-ime-align: auto) {
     width: 100%;
     display: flex;

243-245: Consider using more semantic class names.

The class name 'hidden' is too generic. Consider using something more specific like 'select-tag-hidden'.

-      .hidden {
+      .select-tag-hidden {
         visibility: hidden;
       }

377-378: Address the TODO comment about suffix button vertical alignment.

The comment indicates that the suffix button's vertical alignment needs optimization.

Would you like me to help implement the vertical alignment fix or create a GitHub issue to track this task?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c363512 and 09447a2.

📒 Files selected for processing (3)
  • packages/theme/src/base-select/index.less (1 hunks)
  • packages/theme/src/base-select/vars.less (1 hunks)
  • packages/vue/src/base-select/src/pc.vue (3 hunks)
🔇 Additional comments (7)
packages/theme/src/base-select/vars.less (4)

1-11: LGTM: License header is properly formatted.

The copyright notices and MIT-style license disclaimer are correctly included.


21-28: LGTM: Icon properties are well-defined with appropriate state handling.

The icon-related properties follow best practices by:

  • Using semantic color variables
  • Handling all interactive states (normal, hover, disabled)
  • Maintaining consistent naming conventions

47-56: LGTM: Input and tags properties are well-structured.

The properties use consistent spacing variables and follow the established naming conventions.


57-63: LGTM: Collapse button properties are properly defined.

The collapse button properties use appropriate semantic color variables and consistent spacing.

packages/theme/src/base-select/index.less (2)

1-19: LGTM! File structure and imports are well organized.

The file header, imports, and prefix variable definitions follow best practices.


1-401: Overall well-structured and maintainable stylesheet.

The stylesheet demonstrates good practices with:

  • Proper use of CSS variables for theming
  • Well-organized component structure
  • Good browser compatibility handling

While there are some minor suggestions for improvement, the implementation is solid and follows best practices.

packages/vue/src/base-select/src/pc.vue (1)

255-255: Prop inputBoxType is correctly passed to tiny-input

The inputBoxType prop is properly introduced and passed to the tiny-input component, enhancing configurability and allowing for consistent input box styling.

Comment on lines +30 to +31
// 边框激活色
--tv-BaseSelect-input-border-color-active: var(--tv-color-border-active, #191919);
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 adding border colors for other input states.

While the active state is handled, consider adding border colors for other common input states:

  • Default state
  • Hover state
  • Focus state
  • Error state
+ // Default border color
+ --tv-BaseSelect-input-border-color: var(--tv-color-border, #c2c2c2);
+ // Hover border color
+ --tv-BaseSelect-input-border-color-hover: var(--tv-color-border-hover, #808080);
  // Active border color
  --tv-BaseSelect-input-border-color-active: var(--tv-color-border-active, #191919);
+ // Focus border color
+ --tv-BaseSelect-input-border-color-focus: var(--tv-color-border-focus, #1476ff);
+ // Error border color
+ --tv-BaseSelect-input-border-color-error: var(--tv-color-error, #ff4d4f);
📝 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-BaseSelect-input-border-color-active: var(--tv-color-border-active, #191919);
// Default border color
--tv-BaseSelect-input-border-color: var(--tv-color-border, #c2c2c2);
// Hover border color
--tv-BaseSelect-input-border-color-hover: var(--tv-color-border-hover, #808080);
// Active border color
--tv-BaseSelect-input-border-color-active: var(--tv-color-border-active, #191919);
// Focus border color
--tv-BaseSelect-input-border-color-focus: var(--tv-color-border-focus, #1476ff);
// Error border color
--tv-BaseSelect-input-border-color-error: var(--tv-color-error, #ff4d4f);

Comment on lines +33 to +46
// 尾部图标距离输入框的垂直距离(默认尺寸)
--tv-BaseSelect-suffix-top: var(--tv-space-xl, 16px);
// 尾部图标距离输入框的垂直距离(中型尺寸)
--tv-BaseSelect-suffix-top-medium: 20px;
// 尾部图标距离输入框的垂直距离(小型尺寸)
--tv-BaseSelect-suffix-top-small: var(--tv-space-xl, 16px);
// 尾部图标距离输入框的垂直距离(迷你尺寸)
--tv-BaseSelect-suffix-top-mini: var(--tv-space-lg, 12px);
// 尾部图标右侧外间距
--tv-BaseSelect-suffix-icon-margin-right: var(--tv-space-sm, 4px);
// 尾部文本外间距
--tv-BaseSelect-suffix-txt-margin: 0 var(--tv-space-sm, 4px);
// 尾部文本色
--tv-BaseSelect-suffix-text-color: var(--tv-color-text-weaken, #808080);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace hard-coded pixel value with a CSS variable.

The medium suffix top spacing uses a hard-coded value of 20px. Consider using a CSS variable for consistency with other spacing values.

- --tv-BaseSelect-suffix-top-medium: 20px;
+ --tv-BaseSelect-suffix-top-medium: var(--tv-space-2xl, 20px);
📝 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-BaseSelect-suffix-top: var(--tv-space-xl, 16px);
// 尾部图标距离输入框的垂直距离(中型尺寸)
--tv-BaseSelect-suffix-top-medium: 20px;
// 尾部图标距离输入框的垂直距离(小型尺寸)
--tv-BaseSelect-suffix-top-small: var(--tv-space-xl, 16px);
// 尾部图标距离输入框的垂直距离(迷你尺寸)
--tv-BaseSelect-suffix-top-mini: var(--tv-space-lg, 12px);
// 尾部图标右侧外间距
--tv-BaseSelect-suffix-icon-margin-right: var(--tv-space-sm, 4px);
// 尾部文本外间距
--tv-BaseSelect-suffix-txt-margin: 0 var(--tv-space-sm, 4px);
// 尾部文本色
--tv-BaseSelect-suffix-text-color: var(--tv-color-text-weaken, #808080);
// 尾部图标距离输入框的垂直距离(默认尺寸)
--tv-BaseSelect-suffix-top: var(--tv-space-xl, 16px);
// 尾部图标距离输入框的垂直距离(中型尺寸)
--tv-BaseSelect-suffix-top-medium: var(--tv-space-2xl, 20px);
// 尾部图标距离输入框的垂直距离(小型尺寸)
--tv-BaseSelect-suffix-top-small: var(--tv-space-xl, 16px);
// 尾部图标距离输入框的垂直距离(迷你尺寸)
--tv-BaseSelect-suffix-top-mini: var(--tv-space-lg, 12px);
// 尾部图标右侧外间距
--tv-BaseSelect-suffix-icon-margin-right: var(--tv-space-sm, 4px);
// 尾部文本外间距
--tv-BaseSelect-suffix-txt-margin: 0 var(--tv-space-sm, 4px);
// 尾部文本色
--tv-BaseSelect-suffix-text-color: var(--tv-color-text-weaken, #808080);

Comment on lines +219 to +220
z-index: 2;
}
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 variable for z-index value.

The hardcoded z-index value should be moved to a CSS variable for better maintainability.

-        z-index: 2;
+        z-index: var(--tv-BaseSelect-expanded-z-index, 2);
📝 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
z-index: 2;
}
z-index: var(--tv-BaseSelect-expanded-z-index, 2);
}

Comment on lines +161 to +162
max-width: 160px;
}
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 variable for max-width value.

The hardcoded max-width value of 160px should be moved to a CSS variable for better maintainability and consistency.

-      max-width: 160px;
+      max-width: var(--tv-BaseSelect-tag-max-width, 160px);
📝 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
max-width: 160px;
}
max-width: var(--tv-BaseSelect-tag-max-width, 160px);
}

Comment on lines +336 to +337
transition: transform 0.3s;
transform: rotateZ(180deg);
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 enhancing transition properties.

The transition could be more comprehensive to include other animated properties.

-      transition: transform 0.3s;
+      transition: transform 0.3s, fill 0.3s;
📝 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
transition: transform 0.3s;
transform: rotateZ(180deg);
transition: transform 0.3s, fill 0.3s;
transform: rotateZ(180deg);

@@ -26,8 +26,7 @@
clickExpand ? 'is-click-expand' : '',
state.showCollapseTag ? 'collapse-tag-clicked' : '',
state.selectDisabled ? 'is-disabled' : '',
$parent.$attrs.class,
inputBoxType === 'underline' ? 'tiny-base-select__underline' : ''
$parent.$attrs.class
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid directly accessing $parent in the template

Using $parent.$attrs.class in the template can lead to tight coupling between components and breaks the encapsulation of component design. It is recommended to pass necessary data through props or use provide/inject for better maintainability and reusability.

Apply this diff to refactor the code:

-          $parent.$attrs.class
+          parentClass

Then, in your component's props, add:

props: {
  // existing props
  parentClass: {
    type: String,
    default: ''
  }
}

And in the parent component, pass the class attribute:

<base-select :class="..." :parent-class="$attrs.class" ...></base-select>

@@ -548,6 +548,7 @@
import TinyCheckbox from '@opentiny/vue-checkbox'

import '@opentiny/vue-theme/select/index.less'
import '@opentiny/vue-theme/base-select/index.less'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Based on the search results, I can now generate the final response:

The base-select style import path is correct but needs to be updated

The current import path '@opentiny/vue-theme/base-select/index.less' should be changed to use the theme-saas package instead, as the styles are located in packages/theme-saas/src/base-select/index.less. The vue-theme package does not exist in the codebase.

  • Update the import statement to: import '@opentiny/theme-saas/src/base-select/index.less'
🔗 Analysis chain

Confirm the import path for base-select styles

The import statement for base-select styles ensures that the component has the necessary styles applied. Please verify that the path '@opentiny/vue-theme/base-select/index.less' is correct and that it does not duplicate style imports.

You can run the following script to check for duplicate imports of the base-select styles:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for multiple imports of base-select styles in the codebase.

# Test: Search for all import statements of base-select styles.
# Expect: Only one import statement per component or as intended.

rg -t vue -t js -F "import '@opentiny/vue-theme/base-select/index.less'"

Length of output: 108


Script:

#!/bin/bash
# Let's try a different approach to find the style imports
# 1. First check if the path exists
fd "base-select" --type f

# 2. Then search for any imports containing base-select without file type restrictions
rg "import.*base-select.*less"

# 3. Also check for the theme package structure
fd --type f --full-path ".*vue-theme.*base-select"

Length of output: 507


Script:

#!/bin/bash
# Let's verify the theme structure and base-select style files
# 1. Check for base-select style files in theme packages
fd "index.less" --type f --parent-directory "base-select"

# 2. Check the content of theme-saas base-select styles to understand the structure
rg -g "base-select/*.less" -l ""

# 3. Look for any other potential style imports for base-select
rg -g "*.{vue,js}" "base-select.*\.less"

Length of output: 661


Script:

#!/bin/bash
# Let's try one final check with simpler commands
# 1. Find all less files related to base-select
fd -e less -g "*base-select*"

# 2. Check the theme package structure
fd . "packages/theme-saas"

# 3. Check the theme package structure for vue-theme
fd . "packages/vue-theme"

Length of output: 45692

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