Skip to content

refactor(link): [link] refactor the link theme #2273

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

Merged
merged 2 commits into from
Oct 16, 2024
Merged

refactor(link): [link] refactor the link theme #2273

merged 2 commits into from
Oct 16, 2024

Conversation

Youyou-smiles
Copy link
Collaborator

@Youyou-smiles Youyou-smiles commented Oct 16, 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 link styles with new color values for various states, enhancing visual consistency.
  • Bug Fixes
    • Corrected CSS color values for links to ensure accurate rendering across different states.
  • Refactor
    • Renamed CSS variables for improved clarity and consistency in styling.
    • Updated method signatures to reflect changes in naming conventions.

Copy link

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request involve updates to expected CSS color values for various link elements across multiple test files. Additionally, there are modifications to CSS variable naming conventions and method signatures within the theme's LESS files. The updates aim to standardize color values for link states and enhance consistency in styling.

Changes

File Path Change Summary
examples/sites/demos/pc/app/link/basic-usage.spec.ts Updated expected CSS color of the first link element.
examples/sites/demos/pc/app/link/dynamic-disable.spec.ts Updated expected CSS color values for all disabled anchor elements to a uniform value.
examples/sites/demos/pc/app/link/link-style.spec.ts Updated expected CSS color values for various links and their hover states.
packages/theme/src/link/index.less Renamed CSS variable references, replaced method calls, and updated properties related to font sizes, weights, SVG dimensions, hover states, and disabled states.
packages/theme/src/link/vars.less Renamed function, updated CSS variable names, and adjusted variables for link states with new values.

Possibly related PRs

Suggested reviewers

  • zzcr

🐇 In the land where colors gleam,
Links now shine, a vibrant dream.
With hues anew, they dance and play,
A stylish hop, hip-hip-hooray!
From gray to blue, they take their flight,
In every state, they shine so bright! 🌈


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8f6d2e3 and 8c9b881.

📒 Files selected for processing (2)
  • packages/theme/src/link/index.less (2 hunks)
  • packages/theme/src/link/vars.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/theme/src/link/index.less
  • packages/theme/src/link/vars.less

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 16, 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: 1

🧹 Outside diff range and nitpick comments (5)
examples/sites/demos/pc/app/link/basic-usage.spec.ts (1)

12-12: Consider enhancing test coverage and improving maintainability

The update to the expected hover color aligns with the PR's objective of refactoring the link theme. However, there are a few points to consider:

  1. The test only checks the hover state color. Consider adding a test for the default (non-hover) state as well to ensure complete coverage of link behavior.

  2. The specific color value '20, 118, 255' is hardcoded. To improve maintainability and make future theme changes easier, consider using a constant or configuration value instead.

  3. There's no explanation for why this specific color was chosen. Adding a comment explaining the rationale behind the color change would improve code readability and maintainability.

Here's a suggested improvement:

import { LINK_HOVER_COLOR } from '../../../constants/colors';

// ... rest of the code ...

// Check default state
await expect(link.first()).toHaveCSS('color', LINK_DEFAULT_COLOR);

// Check hover state
await link.first().hover();
await expect(link.first()).toHaveCSS('color', LINK_HOVER_COLOR);

This approach would centralize color definitions and make it easier to update them across all tests in the future.

examples/sites/demos/pc/app/link/link-style.spec.ts (2)

20-23: LGTM! Consider adding a comment explaining the color choice.

The color change for the default link is consistent across all states (initial, hover, and after pseudo-element). The new color 'rgb(20, 118, 255)' appears to be a shade of blue, which is typical for default links.

Consider adding a comment explaining the rationale behind this specific color choice, especially if it's part of a broader design system or brand guidelines. This would help future maintainers understand the context of this change.


Line range hint 1-53: Consider a comprehensive review of the link color scheme.

The changes in this file consistently update the expected colors for various link types in the test suite. While most color choices align well with user expectations, there are a few points to consider:

  1. The primary link color (near-black) might have accessibility issues.
  2. The info link color is identical to the default link color, which could lead to user confusion.
  3. It's unclear if these color changes are part of a broader design system update.

To ensure a cohesive and accessible design:

  1. Conduct a comprehensive review of the entire link color scheme, ensuring each link type has a distinct and appropriate color.
  2. Verify that all colors meet WCAG 2.1 accessibility standards for color contrast.
  3. Consider creating a color palette or design tokens that can be reused across the project for consistency.
  4. Update the documentation to reflect the new color choices and their rationale.

This will help maintain a consistent user experience and make future updates easier to manage.

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

15-89: Consistent application of new CSS variable naming convention.

The update of all CSS variable names to use the --ti-Link- prefix is consistent and improves code organization. This change reduces the risk of naming conflicts and enhances code readability.

Consider updating any relevant documentation to reflect this new naming convention, if not already done.

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

92-92: Approve icon-specific underline styles, suggest documentation.

The introduction of icon-specific underline width variables (--ti-Link-has-icon-underline-width) provides more granular control over underline styles when icons are present. The use of calc() for dynamic positioning is a good approach.

Consider adding comments or documentation to explain the purpose and expected values of the new --ti-Link-has-icon-underline-width variable. This will help other developers understand and correctly use this styling option.

Also applies to: 96-96

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e2a5fba and 8f6d2e3.

📒 Files selected for processing (5)
  • examples/sites/demos/pc/app/link/basic-usage.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/link/dynamic-disable.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/link/link-style.spec.ts (1 hunks)
  • packages/theme/src/link/index.less (2 hunks)
  • packages/theme/src/link/vars.less (1 hunks)
🧰 Additional context used
🔇 Additional comments (26)
examples/sites/demos/pc/app/link/dynamic-disable.spec.ts (7)

10-10: LGTM: Consistent color update for disabled default link

The change to use 'rgb(194, 194, 194)' as the expected color for the disabled default link is consistent with the refactoring objective. It maintains the test's effectiveness while standardizing the color across all link types.


14-14: LGTM: Consistent color update for disabled primary link

The change to use 'rgb(194, 194, 194)' as the expected color for the disabled primary link maintains consistency with the refactoring pattern established for the default link.


18-18: LGTM: Consistent color update for disabled success link

The change to use 'rgb(194, 194, 194)' as the expected color for the disabled success link continues the consistent refactoring pattern across different link types.


22-22: LGTM: Consistent color update for disabled warning link

The change to use 'rgb(194, 194, 194)' as the expected color for the disabled warning link maintains the consistent refactoring pattern established for all link types.


26-26: LGTM: Consistent color update for disabled danger link

The change to use 'rgb(194, 194, 194)' as the expected color for the disabled danger link further reinforces the consistent refactoring pattern across all link types.


30-30: LGTM: Consistent color update for disabled info link and overall refactoring

The change to use 'rgb(194, 194, 194)' as the expected color for the disabled info link completes the consistent refactoring pattern across all link types. This modification, along with the previous ones, successfully standardizes the expected color for all disabled links in the test.

The refactoring achieves the following:

  1. Consistency: All link types now expect the same color when disabled.
  2. Simplification: The test now checks for a single, uniform color value across different link types.
  3. Maintainability: Future color changes can be made more easily by updating a single value.

These changes align well with the PR objective of refactoring the link theme while maintaining the test's effectiveness.


Line range hint 1-32: Overall assessment: Successful refactoring of link theme in test file

The changes in this file successfully refactor the link theme by standardizing the expected color for disabled links across all types (default, primary, success, warning, danger, and info). This refactoring aligns well with the PR objectives and offers several benefits:

  1. Consistency: A uniform color expectation ('rgb(194, 194, 194)') is now applied to all disabled link types.
  2. Simplification: The test logic is simplified by using a single color value for all checks.
  3. Maintainability: Future updates to the disabled link color can be made more easily by changing a single value.

The changes maintain the effectiveness of the test while improving its structure and readability. This refactoring contributes positively to the overall code quality and aligns with best practices for test maintenance.

examples/sites/demos/pc/app/link/link-style.spec.ts (4)

32-35: LGTM! Appropriate color choice for success link.

The color change for the success link to 'rgb(92, 179, 0)' is consistent across all states and appears to be an appropriate shade of green typically associated with success. This color choice aligns well with user expectations for success-related elements.


38-41: LGTM! Suitable color choice for warning link.

The color change for the warning link to 'rgb(255, 136, 0)' is consistent across all states. This shade of orange is typically associated with warnings, making it an appropriate choice for a warning link. The color aligns well with user expectations for warning-related elements.


44-47: LGTM! Appropriate color choice for danger link.

The color change for the danger link to 'rgb(242, 48, 48)' is consistent across all states. This shade of red is typically associated with danger or errors, making it an appropriate choice for a danger link. The color aligns well with user expectations for danger-related elements.


26-29: ⚠️ Potential issue

Verify accessibility standards for the primary link color.

The color change for the primary link to 'rgb(25, 25, 25)' (very close to black) is consistent across all states. However, this color choice raises some concerns:

  1. It's unusual for a primary link to be nearly black, as this might not visually indicate that it's clickable.
  2. The contrast between this color and typical background colors might not meet accessibility standards, particularly for users with visual impairments.

Please verify that this color choice meets WCAG 2.1 accessibility standards for color contrast. You can use tools like the WebAIM Contrast Checker to ensure compliance.

Additionally, consider running the following command to check if this color is used consistently across the project:

#!/bin/bash
# Search for the use of rgb(25, 25, 25) color in the project
rg -t css -t less -t scss -t js -t ts 'rgb\(25,\s*25,\s*25\)' || echo "Color not found in other files"

This will help ensure that the color choice is part of a consistent design system.

packages/theme/src/link/vars.less (4)

35-89: Comprehensive coverage of link states and properties.

The changes thoroughly cover all necessary link states (default, hover, primary, danger, success, warning, and info) and their respective properties (text color, border color, disabled state). The consistency in naming and structure across different states is commendable.


13-94: Excellent consistency and thorough commenting.

The changes demonstrate remarkable consistency in naming, structure, and commenting throughout the file. Each variable is accompanied by a clear comment explaining its purpose, which significantly enhances code readability and maintainability.


13-13: Function renaming looks good, but verify usage.

The renaming of .component-css-vars-link() to .inject-Link-vars() improves clarity and follows a more specific naming convention. This change enhances code readability and maintainability.

Please verify that all references to this function have been updated across the codebase. Run the following script to check for any remaining occurrences of the old function name:

#!/bin/bash
# Search for any remaining occurrences of the old function name
rg --type less "\.component-css-vars-link\(\)"

15-89: Good use of centralized theme variables, but verify their existence.

The use of centralized theme variables (e.g., --tv-font-size-md, --tv-color-border-hover) is a positive change. It promotes consistency across the UI and simplifies future theme updates.

Please ensure that all referenced --tv-* variables are properly defined elsewhere in the codebase. Run the following script to check for the definitions of these variables:

#!/bin/bash
# Search for definitions of the new theme variables
rg --type less "^\s*--tv-" | sort | uniq
packages/theme/src/link/index.less (11)

53-54: Approve hover and disabled state style updates.

The color and fill properties for hover and disabled states have been correctly updated to use the new camelCase variable names. This change maintains consistency with the earlier variable renaming while preserving the existing functionality.

Also applies to: 59-60


65-67: Approve SVG icon hover style updates with improved naming.

The font weight, color, and fill properties for SVG icon hover states have been correctly updated to use the new camelCase variable names. The new variable names (e.g., --ti-Link-has-svg-hover-text-color) are more specific, which improves clarity and maintainability.


72-74: Approve disabled SVG icon style updates, query font weight choice.

The color and fill properties for disabled SVG icon states have been correctly updated to use the new camelCase variable names. However, I noticed that the disabled state now uses the default font weight (--ti-Link-font-weight) instead of a specific disabled font weight.

Is this intentional? If a different font weight is desired for the disabled state, consider creating a specific variable like --ti-Link-disabled-font-weight. Please confirm if this change in font weight behavior is intended.


82-82: Approve underline style updates with full-width improvement.

The underline styles have been updated correctly:

  1. The width is now set to 100%, ensuring the underline spans the full width of the link. This improves the visual consistency of the underline effect.
  2. The border-bottom property now uses the new camelCase variable name, maintaining consistency with the earlier variable renaming.

These changes enhance both the appearance and the maintainability of the underline styles.

Also applies to: 88-88


106-109: Approve link type mixin updates.

The link type mixin has been correctly updated to use the new camelCase variable names for various states (default, hover, disabled). This change maintains consistency with the earlier variable renaming while preserving the existing functionality of the mixin.


115-118: Approve primary link type mixin updates.

The primary link type mixin has been correctly updated to use the new camelCase variable names for various states. This change is consistent with the earlier variable renaming and maintains the existing functionality of the mixin.


124-127: Approve danger link type mixin updates.

The danger link type mixin has been correctly updated to use the new camelCase variable names for various states. This change aligns with the earlier variable renaming and preserves the existing functionality of the mixin.


133-136: Approve success, warning, and info link type mixin updates.

The success, warning, and info link type mixins have all been correctly updated to use the new camelCase variable names for various states. These changes are consistent with the earlier variable renaming and maintain the existing functionality of each mixin. The uniform application of these updates across all link types demonstrates a thorough and consistent refactoring approach.

Also applies to: 142-145, 151-154


22-22: Approve method renaming, verify implementation.

The change from .component-css-vars-link() to .inject-Link-vars() improves clarity and follows a more specific naming convention. This is a good refactoring step.

Please ensure that the .inject-Link-vars() method is properly implemented and contains all the necessary CSS variables for the link component. Run the following script to verify the method's existence and content:

#!/bin/bash
# Description: Verify the implementation of .inject-Link-vars() method

# Test: Search for the .inject-Link-vars() method definition
rg --type less -A 10 '\.inject-Link-vars\s*\(\s*\)\s*{'

30-31: Approve CSS variable renaming, verify global consistency.

The update of CSS variable names from lowercase to camelCase format (e.g., --ti-link-* to --ti-Link-*) improves naming consistency. This is a positive change.

To ensure all instances have been updated, please run the following script to check for any remaining lowercase versions of these variables:

#!/bin/bash
# Description: Search for any remaining lowercase --ti-link-* variables

# Test: Look for lowercase --ti-link-* variables
rg --type less '--ti-link-[a-z-]+'

If any results are found, they should be updated to maintain consistency across the codebase.

Also applies to: 34-36, 38-38


Line range hint 1-154: Summary of link theme refactoring

The refactoring of the link theme has been successfully implemented with the following key points:

  1. CSS variables have been consistently renamed from lowercase to camelCase format (e.g., --ti-link-* to --ti-Link-*).
  2. The method for injecting link variables has been renamed to .inject-Link-vars().
  3. Underline behavior has been improved with full-width underlining and specific handling for links with icons.
  4. All link types (default, primary, danger, success, warning, info) have been updated consistently.

These changes improve code consistency and maintainability without altering the component's functionality.

To ensure a complete and correct refactoring, please run the following final verification steps:

  1. Confirm that all --ti-link-* variables have been renamed:
#!/bin/bash
# Search for any remaining lowercase --ti-link-* variables in all less files
rg --type less '--ti-link-[a-z-]+' packages/theme/src/
  1. Verify that the .inject-Link-vars() method is properly implemented:
#!/bin/bash
# Search for the .inject-Link-vars() method definition
rg --type less -A 10 '\.inject-Link-vars\s*\(\s*\)\s*{' packages/theme/src/
  1. Check for any potential regressions by running the component's test suite, if available.

Comment on lines +50 to +53
await expect(anchor).toHaveCSS('color', 'rgb(20, 118, 255)')
await anchor.hover()
await expect(await getAfter(6)).toBe('rgb(37, 43, 58)')
await expect(anchor).toHaveCSS('color', 'rgb(92, 97, 115)')
await expect(await getAfter(6)).toBe('rgb(20, 118, 255)')
await expect(anchor).toHaveCSS('color', 'rgb(20, 118, 255)')
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 differentiating info link color from default link color.

The color change for the info link to 'rgb(20, 118, 255)' is consistent across all states. However, this is the same color used for the default link, which might lead to the following issues:

  1. Users may not be able to distinguish between default and info links visually.
  2. It could create confusion about the purpose or importance of these links.

Consider using a distinct color for info links to improve user experience and maintain clear visual hierarchy. For example, you might use a different shade of blue or another color typically associated with information (like teal or cyan).

If this is an intentional design decision, please add a comment explaining the rationale to help future maintainers understand the context.

// 链接字重
--ti-link-font-weight: var(--ti-common-font-weight-4, normal);
--ti-Link-font-weight: var(--tv-font-weight-regular);
Copy link
Member

Choose a reason for hiding this comment

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

tv开头

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