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(autocomplete): [autocomplete] modify variable names and add … #2263

Merged
merged 3 commits into from
Oct 15, 2024

Conversation

MomoPoppy
Copy link
Collaborator

@MomoPoppy MomoPoppy commented Oct 14, 2024

…refactor styles

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

    • Enhanced styling for the autocomplete component with new CSS variables for improved visual design.
    • Updated suggestion rendering logic for better user interaction and feedback.
    • New props added to the autocomplete component for greater customization and control.
  • Bug Fixes

    • Refined loading state representation for the suggestion list.

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes in this pull request involve substantial updates to the styling and structure of the autocomplete component across multiple LESS and Vue files. Key modifications include the removal of outdated CSS variable prefixes, the introduction of new variables for improved styling control, and enhancements to the suggestion rendering logic in the Vue component. The overall structure remains consistent, but the updates streamline the styling process and improve the clarity of the component's functionality.

Changes

File Path Change Summary
packages/theme/src/autocomplete/index.less Removed prefix class variables, introduced new CSS variables, updated styling for suggestion box, and refined nested structure for suggestion list.
packages/theme/src/autocomplete/vars.less Replaced old CSS variable declarations with new ones, changing the naming convention from --ti- to --tv- for better organization.
packages/vue/src/autocomplete/src/pc.vue Updated template structure, refined loading state representation, and enhanced list item rendering logic with conditional classes for better visual feedback.

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

In a world of styles so bright,
Autocomplete shines with new light.
Variables fresh, a mixin's grace,
A suggestion box finds its place.
With each change, clarity grows,
In the garden of code, creativity flows! 🐇✨


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: 0

🧹 Outside diff range and nitpick comments (5)
packages/theme/src/autocomplete/vars.less (2)

14-23: Approve general styling variables with a suggestion.

The new variables for line height, font size, text color, and icon size are well-structured and promote consistency by referencing global theme variables. The addition of a selected text color variable improves styling flexibility.

Consider adding a comment to explain the purpose of --tv-Autocomplete-text-color-selected, such as:

// Text color for selected items in the autocomplete list
--tv-Autocomplete-text-color-selected: var(--tv-color-text-active, #1476ff);

This would enhance code readability and maintainability.


34-37: Approve list item styling variables with suggestions for improvement.

The new variables for list item styling (padding and hover background color) are good additions that provide specific control over the autocomplete list items.

Consider the following improvements:

  1. Replace the hardcoded padding value with a theme variable:
--tv-Autocomplete-li-padding: var(--tv-space-sm, 5.5px) var(--tv-space-xl, 16px);
  1. Add a variable for the active/selected item background color:
// Background color for active/selected list item
--tv-Autocomplete-li-bg-color-active: var(--tv-color-bg-active, #e6f2ff);

These changes would further enhance consistency and provide more styling flexibility.

packages/vue/src/autocomplete/src/pc.vue (3)

54-56: LGTM! Consider adding a comment for clarity.

The changes to the class attribute improve flexibility and visual feedback. The removal of the redundant tiny-autocomplete class is a good optimization.

Consider adding a brief comment explaining the purpose of the popperClass prop for better maintainability:

:class="[
  popperClass ? popperClass : '', // Custom classes for the popper
  { 'is-loading': !hideLoading && state.loading }
]"

83-86: LGTM! Consider handling object comparisons.

The addition of the selected class improves visual feedback for the selected item. This is a good enhancement to the user experience.

If modelValue could be an object, consider using a more robust comparison:

:class="{
  highlighted: state.highlightedIndex === index,
  selected: typeof modelValue === 'object'
    ? modelValue[valueKey] === item[valueKey]
    : modelValue === item[valueKey]
}"

This change would handle cases where modelValue is an object while maintaining the current behavior for primitive values.


Line range hint 114-151: LGTM! Consider enhancing prop documentation.

The addition of new props and emits enhances the component's functionality and aligns well with the template changes.

To improve maintainability and ease of use, consider adding JSDoc comments for the new props. For example:

/**
 * The key of the value field in the suggestion objects.
 * @default 'value'
 */
valueKey: {
  type: String,
  default: 'value'
},

/**
 * Custom class name for the autocomplete dropdown.
 */
popperClass: String,

// ... (continue for other new props)

This documentation will help other developers understand the purpose and expected values for each prop.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 50c0b05 and b371b72.

📒 Files selected for processing (4)
  • packages/theme/src/autocomplete/index.less (2 hunks)
  • packages/theme/src/autocomplete/vars.less (1 hunks)
  • packages/theme/src/base/vars.less (1 hunks)
  • packages/vue/src/autocomplete/src/pc.vue (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/theme/src/base/vars.less
🧰 Additional context used
🔇 Additional comments (9)
packages/theme/src/autocomplete/vars.less (3)

25-32: Approve panel styling variables.

The new variables for panel styling (margin, border radius, background color, and box shadow) are well-defined and reference appropriate global theme variables. This approach ensures consistency with the overall theme while providing specific control over the autocomplete panel's appearance.

The use of a sophisticated box shadow variable (--tv-shadow-3-down) is particularly noteworthy, as it allows for easy adjustment of the panel's depth perception.


14-37: Address overall changes and their potential impact.

The refactoring of autocomplete variables introduces several significant changes:

  1. The naming convention has changed from --ti- to --tv-.
  2. The new set of variables is more concise but relies more on global theme variables.
  3. Some specific styling options (e.g., divider color) have been removed.

These changes improve overall consistency and simplify the theming system. However, they may require updates in other files and could impact existing customizations. Please ensure that:

  1. All files using the old --ti-autocomplete-* variables are updated to use the new --tv-Autocomplete-* variables.
  2. The documentation is updated to reflect these changes.
  3. A migration guide is provided for users who may have customized the removed variables.

Run the following script to check for usage of the old variable prefix in the codebase:

#!/bin/bash
# Description: Check for usage of old autocomplete variable prefix

# Test: Search for usage of old variable prefix
rg --type less --type vue '\-\-ti\-autocomplete\-'

If any results are found, update those occurrences to use the new variable names or add appropriate fallback values.


14-37: ⚠️ Potential issue

Address potential impact of removed variables.

Several variables have been removed without direct replacements, including:

  • --ti-autocomplete-suggestion-border-color
  • --ti-autocomplete-li-divider-border-color
  • --ti-autocomplete-loading-text-color
  • --ti-autocomplete-dropdown-gap

These removals might impact existing customizations. Please verify if these styles are still necessary and consider either:

  1. Adding back essential variables that are still needed.
  2. Documenting the changes in the migration guide if these styles are intentionally removed.

Run the following script to check for usage of the removed variables in the codebase:

If any results are found, consider addressing those usages or adding back the necessary variables.

packages/vue/src/autocomplete/src/pc.vue (1)

76-76: LGTM! Good use of self-closing tag.

The change to a self-closing tag for the icon-loading-shadow component is a good practice for components without content. It improves code readability and follows Vue 3 conventions.

packages/theme/src/autocomplete/index.less (5)

28-36: Verify redundancy between mixin and explicit variable definitions

The addition of .component-css-vars-autocomplete(); mixin and the subsequent explicit definitions of CSS variables within &-suggestion may introduce redundancy. Please ensure that the mixin does not already include these variables to avoid conflicting or duplicate styles.


41-44: Confirm scrollbar view styling adjustments

Applying margin: 0; and padding: 8px 0; to .tiny-scrollbar__view alters the spacing within the scrollbar. Verify that these changes align with the design requirements and do not negatively impact the user experience or overlap with existing scrollbar styles.


58-58: Consistent hover state styling for list items

Setting the background-color to var(--tv-Autocomplete-li-bg-color-hover) for the hover and highlighted states ensures consistent theming across the component. This enhances the visual feedback for users interacting with the suggestion list.


62-62: Apply theme variable for selected text color

Using color: var(--tv-Autocomplete-text-color-selected); for the .selected class promotes consistency with the overall theme and allows for easier customization.


68-69: Use CSS variable for icon sizing

Setting the icon size with font-size: var(--tv-Autocomplete-icon-size); in .tiny-svg ensures that icon dimensions are controlled by theme variables, allowing for consistent scaling across different components.

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 (2)
packages/theme/src/autocomplete/index.less (2)

43-43: Consider using CSS variables for padding.

The padding for .tiny-scrollbar__view is set to 8px 0;. Using a CSS variable for padding would enhance consistency and make future adjustments easier.

Apply this diff to use a CSS variable:

- padding: 8px 0;
+ padding: var(--tv-Autocomplete-scrollbar-padding);

Ensure that --tv-Autocomplete-scrollbar-padding is defined accordingly.


73-73: Adjust icon size using a CSS variable for consistency.

The font size for .tiny-svg is set using var(--tv-Autocomplete-icon-size);. Confirm that this variable is defined and consider using it consistently across similar icons for uniformity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b371b72 and 212fff6.

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

28-29: Verify the inclusion of the mixin .component-css-vars-autocomplete().

Ensure that the mixin .component-css-vars-autocomplete() is defined and properly imported so that all CSS variable definitions are correctly applied to the &-suggestion class.


62-62: Ensure hover state background color variable is defined.

The background color for the highlighted state uses var(--tv-Autocomplete-li-bg-color-hover);. Verify that this variable is properly defined to avoid any unexpected styling issues on hover.


66-66: Confirm selected text color variable is defined.

The selected list item's text color is set to var(--tv-Autocomplete-text-color-selected);. Please ensure this variable is defined to maintain the intended styling for selected items.


30-36: ⚠️ Potential issue

Confirm all new CSS variables are defined.

The code introduces new CSS variables such as --tv-Autocomplete-panel-border-radius, --tv-Autocomplete-panel-bg-color, and others. Please verify that these variables are defined in vars.less or the appropriate variables file to prevent potential styling issues.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 212fff6 and 9b6272a.

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

13-14: Function name change and new variable naming convention

The function name has been updated from .component-css-vars-autocomplete() to .inject-Autocomplete-vars(), which better reflects its purpose. The new naming convention for variables (using --tv- prefix) is more consistent and aligns with modern CSS practices.


15-21: Text-related variables improvements

The new variables for line height, font size, and text color provide more granular control over the text appearance. The addition of a separate variable for selected text color (--tv-Autocomplete-text-color-selected) is a good improvement for accessibility and user experience.


22-23: Icon size variable addition

The introduction of --tv-Autocomplete-icon-size is a good addition, allowing for consistent icon sizing across the component.


25-32: Panel-related variables enhancements

The new panel-related variables provide more detailed control over the appearance of the Autocomplete panel. The addition of --tv-Autocomplete-panel-box-shadow is particularly useful for creating depth and improving visual hierarchy.


13-37: Overall improvement in variable structure and naming

The refactoring of CSS variables for the Autocomplete component represents a significant improvement in organization, naming conventions, and granularity of control. These changes align with modern CSS best practices and will likely improve the maintainability of the codebase.

However, it's important to note that these changes may have a significant impact on existing implementations that rely on the old variable names.

To ensure a smooth transition, please consider the following:

  1. Update the component's documentation to reflect the new variable names and their purposes.
  2. Provide a migration guide for users updating from the previous version.
  3. Consider adding deprecation warnings for the old variable names if backward compatibility is a concern.

To verify the impact of these changes, you can run the following script to check for any remaining usage of the old variable names:

This will help ensure that all occurrences of the old variable names have been updated throughout the codebase.

Comment on lines +34 to +37
// 列表项内间距
--tv-Autocomplete-li-padding: 5.5px var(--tv-space-xl, 16px);
// 列表项悬浮背景色
--tv-Autocomplete-li-bg-color-hover: var(--tv-color-bg-hover, #f5f5f5);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

List item-related variables refinement

The new variables for list item padding and hover background color offer more precise control over the appearance of individual items in the Autocomplete list.

However, there's an opportunity for improvement:

Consider adding a variable for the selected item's background color to provide more flexibility in styling. For example:

  // 列表项悬浮背景色
  --tv-Autocomplete-li-bg-color-hover: var(--tv-color-bg-hover, #f5f5f5);
+ // 列表项选中背景色
+ --tv-Autocomplete-li-bg-color-selected: var(--tv-color-bg-active, #e6f2ff);

This addition would allow for distinct styling of hovered and selected items, enhancing user experience.

📝 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-Autocomplete-li-padding: 5.5px var(--tv-space-xl, 16px);
// 列表项悬浮背景色
--tv-Autocomplete-li-bg-color-hover: var(--tv-color-bg-hover, #f5f5f5);
// 列表项内间距
--tv-Autocomplete-li-padding: 5.5px var(--tv-space-xl, 16px);
// 列表项悬浮背景色
--tv-Autocomplete-li-bg-color-hover: var(--tv-color-bg-hover, #f5f5f5);
// 列表项选中背景色
--tv-Autocomplete-li-bg-color-selected: var(--tv-color-bg-active, #e6f2ff);

@zzcr zzcr merged commit 47fac6d into opentiny:dev Oct 15, 2024
3 checks passed
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