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

Merged
merged 6 commits into from
Oct 14, 2024

Conversation

zzcr
Copy link
Member

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

    • Updated the carousel component styling with a new CSS variable naming convention for improved consistency.
    • Enhanced the visual appearance of carousel items, arrows, and indicators with updated styles.
  • Bug Fixes

    • Simplified and standardized CSS variable usage, improving maintainability and reducing potential styling issues.
  • Refactor

    • Replaced old method calls for CSS variable injection with a new standardized method across carousel components.

Copy link

coderabbitai bot commented Oct 12, 2024

Walkthrough

The changes in this pull request involve a systematic update of CSS variable naming conventions across carousel-related files. Specifically, the prefix for CSS variables has been changed from --ti- to --tv-, reflecting a new theming approach. Method calls for injecting CSS variables have also been updated accordingly. These modifications apply to various properties, including dimensions, colors, and styles for carousel items, arrows, and indicators, while maintaining the overall structure and functionality of the components.

Changes

File Path Change Summary
packages/theme/src/carousel-item/index.less Updated CSS variable prefix from --ti- to --tv-, modified method call from .component-css-vars-carousel-item() to .inject-CarouselItem-vars(), adjusted properties for .item-title and &__mask.
packages/theme/src/carousel-item/vars.less Replaced method .component-css-vars-carousel-item() with .inject-Carousel-vars(), updated CSS variable names from --ti- to --tv-, modified variable values for consistency.
packages/theme/src/carousel/index.less Changed CSS variable prefix from --ti- to --tv-, updated method call from .component-css-vars-carousel() to .inject-Carousel-vars(), simplified styles for arrows and indicators.
packages/theme/src/carousel/vars.less Updated method name from .component-css-vars-carousel() to .inject-Carousel-vars(), changed variable prefixes from --ti- to --tv-, adjusted dimensions and hover states.
examples/sites/demos/pc/app/carousel/card-show.spec.ts Added a wait of 200 milliseconds after clicking the right button in the carousel and changed expected CSS fill color for the button from 'rgb(194, 194, 194)' to 'rgb(144, 144, 144)'.

Possibly related PRs

🐇✨ In the land of CSS, a change was made,
From --ti- to --tv-, a new path laid.
With colors and sizes, all fresh and bright,
The carousel spins with a joyful delight!
A hop and a skip, the styles now align,
In the garden of code, everything's fine! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c97a135 and 5be4d5f.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/carousel/card-show.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/sites/demos/pc/app/carousel/card-show.spec.ts

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 12, 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: 3

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

13-18: Approve changes with suggestions for documentation

The refactoring of the carousel item theme variables looks good. The new naming convention (--tv-CarouselItem-*) is more specific and consistent, which should improve maintainability and reduce the risk of naming conflicts.

However, given the significant changes in variable names and the injection method, please consider the following suggestions:

  1. Update any relevant documentation to reflect these new variable names and the .inject-CarouselItem-vars() function.
  2. If there are any migration guides or upgrade instructions for the project, make sure to include information about these theme variable changes.
  3. Consider adding a comment in the file explaining the --tv- prefix and referencing where the referenced variables (e.g., --tv-size-height-lg) are defined.

Would you like me to draft a documentation update or migration guide snippet for these changes?

packages/theme/src/carousel/vars.less (3)

15-17: Consider using relative units for arrow dimensions.

The variable naming update from --ti- to --tv- is consistent with the new convention. However, using fixed pixel values for dimensions might limit responsiveness.

Consider using relative units (e.g., em, rem) for better scalability across different screen sizes:

- --tv-Carousel-arrow-height: 32px;
- --tv-Carousel-arrow-width: 32px;
+ --tv-Carousel-arrow-height: 2rem;
+ --tv-Carousel-arrow-width: 2rem;

27-41: Consider using relative units for indicator dimensions.

The variable naming updates and the use of referenced variables for colors are good practices. However, using fixed pixel values for dimensions might limit responsiveness.

Consider using relative units (e.g., em, rem) for better scalability across different screen sizes:

- --tv-Carousel-indicators-border-radius: 13px;
- --tv-Carousel-indicators-height: 8px;
- --tv-Carousel-indicator-active-width: 12px;
- --tv-Carousel-indicator-active-button-width: 12px;
+ --tv-Carousel-indicators-border-radius: 0.8125rem;
+ --tv-Carousel-indicators-height: 0.5rem;
+ --tv-Carousel-indicator-active-width: 0.75rem;
+ --tv-Carousel-indicator-active-button-width: 0.75rem;

45-47: Consider using a theme variable for default indicator background color.

The variable naming updates and the use of a referenced variable for the active background color are good practices. However, using a hard-coded color value for the default background might limit theme flexibility.

Consider using a theme variable for the default indicator background color:

- --tv-Carousel-outside-button-bg-color: #000;
+ --tv-Carousel-outside-button-bg-color: var(--tv-color-text-primary);

This change assumes that --tv-color-text-primary is defined elsewhere in your theme and represents a dark color suitable for this purpose. Adjust the variable name as needed to fit your theme structure.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 98246dd and 35ff94c.

📒 Files selected for processing (4)
  • packages/theme/src/carousel-item/index.less (3 hunks)
  • packages/theme/src/carousel-item/vars.less (1 hunks)
  • packages/theme/src/carousel/index.less (6 hunks)
  • packages/theme/src/carousel/vars.less (1 hunks)
🧰 Additional context used
🔇 Additional comments (18)
packages/theme/src/carousel-item/index.less (6)

38-38: LGTM! Consistent with new naming convention.

The updated CSS variable --tv-CarouselItem-title-height follows the new naming convention and improves specificity. This change enhances code consistency and readability.


40-41: LGTM! Consistent naming and smart use of variables.

The updated CSS variables follow the new naming convention, improving consistency and readability. Nice touch using the same variable for both height and line-height, which ensures vertical centering of the text.


43-43: LGTM! Consistent with new naming convention.

The updated CSS variable --tv-CarouselItem-title-bg-color follows the new naming convention, improving specificity and consistency with other changes.


48-48: LGTM! Consistent with new naming convention.

The updated CSS variable --tv-CarouselItem-title-span-font-size follows the new naming convention, improving specificity and consistency with other changes.


89-89: LGTM! Consistent with new naming convention. Verify all updates.

The updated CSS variable --tv-CarouselItem-mask-bg-color follows the new naming convention, improving specificity and consistency with other changes.

As this is the last variable change in this file, please run the following script to ensure all variables have been updated consistently:

#!/bin/bash
# Description: Verify all CSS variables have been updated to the new naming convention

# Test: Check for any remaining --ti- prefixed variables and list all --tv- prefixed variables
echo "Checking for any remaining --ti- prefixed variables:"
rg --type less "\-\-ti\-" packages/theme/src/carousel-item/

echo "Listing all --tv- prefixed variables:"
rg --type less "\-\-tv\-" packages/theme/src/carousel-item/

19-19: LGTM! Verify usage across the codebase.

The updated method name .inject-CarouselItem-vars() is more descriptive and follows a clear naming pattern. This change improves code readability and maintainability.

To ensure this change doesn't break anything, please verify its usage across the codebase:

packages/theme/src/carousel/vars.less (9)

19-19: Approve arrow font size variable update.

The variable naming update and the use of a referenced variable for font size are good practices. This change promotes consistency and easier maintenance of the theme.


21-21: Approve arrow hover background color variable update.

The variable naming update and the use of a referenced variable for the hover background color are good practices. This change enhances theme consistency and maintainability.


23-25: Approve arrow background and SVG color variable updates.

The variable naming updates and the use of referenced variables for colors are good practices. These changes promote theme consistency and easier maintenance.


49-49: Approve label button font size variable addition.

The addition of the --tv-Carousel-labels-button-font-size variable, referencing --tv-font-size-md, is a good practice. This promotes consistency in font sizes across the theme and improves maintainability.


51-51: Approve arrow hover text color variable addition.

The addition of the --tv-Carousel-arrow-hover-text-color variable, referencing --tv-color-icon-hover, is a good practice. This enhances theme consistency and improves maintainability of hover states.


53-55: Approve left and right arrow background color variable additions.

The addition of separate variables for left and right arrow background colors, both referencing --tv-color-bg, is a good practice. This allows for potential future customization while maintaining current consistency.


57-59: Approve arrow disabled state variable additions.

The addition of separate variables for arrow disabled background color and icon color, referencing --tv-color-bg-disabled and --tv-color-icon-disabled respectively, is a good practice. This allows for consistent and customizable styling of disabled states across the theme.


13-60: Overall assessment: Improved theme consistency and maintainability.

The changes in this file significantly improve the consistency and maintainability of the carousel component's theming. The new naming convention with the --tv- prefix is consistently applied, and the use of referenced theme variables for colors and some dimensions is a good practice.

Some suggestions for further improvement include:

  1. Consider using relative units (e.g., rem) for dimensions to improve responsiveness.
  2. Review the use of hard-coded color values and consider replacing them with theme variables where appropriate.

These changes align well with the PR objective of refactoring carousel theme variables. Great work on improving the overall structure and consistency of the theme!


13-13: Approve function name change and verify usage.

The new function name .inject-Carousel-vars() is more descriptive and aligns better with its purpose. This is a good improvement in code readability.

Please ensure that all calls to this function have been updated across the codebase. Run the following script to verify:

✅ Verification successful

Function name change verified successfully.

The old function name .component-css-vars-carousel() is no longer present in the codebase. All usages have been updated to .inject-Carousel-vars() as shown in:

  • packages/theme/src/carousel/vars.less
  • packages/theme/src/carousel/index.less
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining occurrences of the old function name and verify the new function name usage.

echo "Checking for old function name usage:"
rg --type less "\.component-css-vars-carousel\(\)"

echo "Verifying new function name usage:"
rg --type less "\.inject-Carousel-vars\(\)"

Length of output: 392

packages/theme/src/carousel/index.less (3)

21-21: Updated CSS variable injection method is correctly implemented

The change from .component-css-vars-carousel() to .inject-Carousel-vars(); is correctly applied.


41-42: CSS variable updates are correctly applied

The changes correctly update the CSS variables to the new --tv- prefix for arrow dimensions, background colors, and SVG fill colors. The use of variables enhances theme consistency and maintainability.

Also applies to: 46-46, 69-70, 71-73, 78-79, 80-82, 86-88, 99-99, 102-102


126-128: Indicator styles updated with new CSS variables

The indicator styles are updated to use the new --tv- prefixed CSS variables, which enhances theme consistency and makes customization easier.

Also applies to: 133-134, 142-142, 146-149, 153-153, 155-157, 162-164, 184-184, 193-193, 206-206


.@{svg-prefix-cls} {
fill: var(--ti-carousel-indicator-active-text-color);
fill: var(--tv-Carousel-indicator-active-text-color);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent use of CSS variables for SVG fill color

The fill property of .@{svg-prefix-cls} is set to var(--tv-Carousel-indicator-active-text-color), an indicator variable. In other places (lines 72~, 81~), the fill color uses var(--tv-Carousel-arrow-svg-color). For consistency, consider using the arrow-specific variable here as well.

Consider updating the fill color:

- fill: var(--tv-Carousel-indicator-active-text-color);
+ fill: var(--tv-Carousel-arrow-svg-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
fill: var(--tv-Carousel-indicator-active-text-color);
fill: var(--tv-Carousel-arrow-svg-color);

display: flex;
align-items: center;
justify-content: center;
opacity: var(--ti-carousel-opacity);
opacity: 0.5;
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 a CSS variable for arrow opacity

The opacity property is set to a fixed value 0.5. To maintain consistency and allow for theme customization, consider using a CSS variable.

Suggestion:

- opacity: 0.5;
+ opacity: var(--tv-Carousel-arrow-opacity);

Define --tv-Carousel-arrow-opacity in your vars.less file to allow for theme customization.

📝 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
opacity: 0.5;
opacity: var(--tv-Carousel-arrow-opacity);

background-color: var(--ti-carousel-arrow-bg-color);
color: var(--ti-carousel-indicator-active-text-color);
background-color: var(--tv-Carousel-arrow-bg-color);
color: var(--tv-Carousel-indicator-active-text-color);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential inconsistency in CSS variable usage for arrow text color

The color property for .@{carousel-prefix-cls}__arrow is set to var(--tv-Carousel-indicator-active-text-color), which is an indicator variable. It might be more appropriate to use an arrow-specific variable for consistency.

Consider updating the variable:

- color: var(--tv-Carousel-indicator-active-text-color);
+ color: var(--tv-Carousel-arrow-text-color);

Ensure that --tv-Carousel-arrow-text-color is defined in your vars.less file.

Committable suggestion was skipped due to low confidence.

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 35ff94c and c97a135.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/carousel/card-show.spec.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
examples/sites/demos/pc/app/carousel/card-show.spec.ts (1)

14-14: LGTM: CSS color change approved.

The change in the expected CSS fill color from 'rgb(194, 194, 194)' to 'rgb(144, 144, 144)' aligns with the theme refactoring mentioned in the PR objectives.

To ensure consistency across the project, please verify that this color change is applied correctly in different themes (if applicable). You can use the following script to check for any remaining instances of the old color:

✅ Verification successful

CSS color change verified across the project.

All instances of 'rgb(194, 194, 194)' have been successfully updated to the new color, ensuring consistency with the theme refactoring.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of the old color value
rg --type css --type vue 'rgb\(194,\s*194,\s*194\)' || echo "No instances of the old color found."

Length of output: 164


Script:

#!/bin/bash
# Search for any remaining instances of the old color value in CSS and Vue files
rg --type css -g "*.vue" 'rgb\(194,\s*194,\s*194\)' || echo "No instances of the old color found."

Length of output: 136

@@ -6,9 +6,10 @@ test('轮播卡片', async ({ page }) => {
const preview = page.locator('#card-show')
const btnRight = preview.getByRole('button').nth(1)
await btnRight.click()
await page.waitForTimeout(200)
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 a more robust waiting mechanism.

While adding a wait time can help with timing issues, using fixed timeouts (waitForTimeout) in tests can lead to flaky tests if the timing is not consistent across different environments or load conditions.

Consider using a more robust waiting mechanism, such as waiting for a specific element to appear or for a particular state to be reached. For example:

await page.waitForSelector('selector-for-next-slide', { state: 'visible' });

This approach will make the test more reliable and less dependent on specific timing.

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