-
Notifications
You must be signed in to change notification settings - Fork 281
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(collapse): [collapse] refactor collapse theme vars #2201
Conversation
WalkthroughThe changes across multiple LESS files involve a comprehensive refactoring of CSS variable declarations and styling approaches. Key modifications include renaming functions and variables to align with a new theming structure, the introduction of new CSS variables, and the simplification of styles for various components, including collapsible items and collapsible sections. These updates aim to improve consistency and maintainability in the theme's styling. Changes
Possibly related PRs
Suggested labels
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (3)
packages/theme/src/base/vars.less (2)
307-307
: LGTM! Consider adding an English translation.The addition of "折叠面板头部背景色" (collapsible panel header background color) to the comment for
--tv-color-bg-secondary
aligns well with the PR objective of refactoring collapse theme variables.Consider adding an English translation of the new comment part for consistency with other multilingual comments in the file and to improve accessibility for non-Chinese speaking developers.
Line range hint
1-478
: Summary: Changes align with PR objectives and maintain consistency.The modifications to the comments for
--tv-color-bg-secondary
and--tv-color-bg-gray-1
are focused and align well with the PR objective of refactoring collapse theme variables. These changes improve clarity without introducing breaking changes or altering the actual variable values.Consider creating a separate section for collapse-specific variables in the future if more collapse-related theme variables are added. This would improve organization and make it easier for developers to find and manage collapse-specific styles.
packages/theme/src/collapse-item/vars.less (1)
15-39
: Consider adding English translations for commentsThe comments are currently written in Chinese. To enhance maintainability and readability for all contributors, especially in a global development team, please consider adding English translations or replacing them with English comments.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
- packages/theme/src/base/vars.less (1 hunks)
- packages/theme/src/collapse-item/index.less (2 hunks)
- packages/theme/src/collapse-item/vars.less (1 hunks)
- packages/theme/src/collapse/index.less (1 hunks)
- packages/theme/src/collapse/vars.less (1 hunks)
🔇 Additional comments (10)
packages/theme/src/collapse/vars.less (3)
14-14
: New CSS variable: Good practice for themingThe introduction of
--tv-Collapse-divider-line-color
is a good addition for improving theming capabilities of the Collapse component. Usingvar(--tv-color-border-divider)
as the value demonstrates a centralized approach to color management, which helps maintain consistency across the UI.This change aligns well with best practices for CSS theming and variable management.
13-14
: Summary: Refactoring aligns with PR objectivesThe changes in this file align well with the PR objectives of refactoring the collapse theme variables:
- The function name change to
.inject-Collapse-vars()
improves clarity and consistency.- The introduction of
--tv-Collapse-divider-line-color
enhances theming capabilities.These modifications refactor the theme variables without introducing functional changes or API modifications, as stated in the PR objectives. The changes are focused and maintain the existing behavior while improving the internal structure.
Overall, these changes are a positive step towards better code organization and theming flexibility for the Collapse component.
13-13
: Function name change: Verify impact on existing codeThe function name has been changed from
.component-css-vars-collapse()
to.inject-Collapse-vars()
. This new name follows a more specific naming convention, which is good for clarity. However, we need to ensure this change doesn't break existing code.To verify the impact of this change, please run the following script:
This script will help us identify if there are any remaining references to the old function name that need to be updated, and confirm that the new function name is being used correctly.
✅ Verification successful
Function name change verified: No references to
.component-css-vars-collapse()
found. The new function.inject-Collapse-vars()
is correctly referenced in the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining references to the old function name # Search for any remaining references to the old function name echo "Searching for references to .component-css-vars-collapse():" rg --type less ".component-css-vars-collapse\(\)" . # Search for references to the new function name echo "Searching for references to .inject-Collapse-vars():" rg --type less ".inject-Collapse-vars\(\)" .Length of output: 478
packages/theme/src/collapse/index.less (3)
Line range hint
1-19
: Overall changes align with refactoring objectivesThe changes in this file align well with the PR objectives of refactoring the collapse component's theme variables. The introduction of CSS variables and the new
.inject-Collapse-vars()
method improve theming flexibility without altering the component's functionality.However, the AI summary mentions the removal of fixed border styles for the top and bottom of the collapse component, which are not visible in the provided code snippet.
To ensure these removals don't negatively impact the component's appearance, please run the following script:
#!/bin/bash # Description: Check for removed border styles and their potential replacements # Search for any remaining hardcoded border styles echo "Searching for any remaining hardcoded border styles in collapse component:" rg --type less "border-(top|bottom):\s*1px solid #d9d9d9" packages/theme/src/collapse/ # Check for new CSS variables that might replace the removed styles echo "Checking for new CSS variables related to border styles:" rg --type less "--tv-Collapse-(top|bottom)-border-color" packages/theme/src/collapse/Please review the results of this script to ensure that the removed border styles have been appropriately replaced or are no longer necessary.
19-19
: Good use of CSS variable for border colorThe use of
var(--tv-Collapse-divider-line-color)
for the border color is a good practice. It allows for easy theming and consistency across the component.To ensure this variable is properly defined and used consistently, please run the following script:
#!/bin/bash # Description: Check the definition and usage of --tv-Collapse-divider-line-color # Search for the definition of the CSS variable echo "Searching for the definition of --tv-Collapse-divider-line-color:" rg --type less "--tv-Collapse-divider-line-color\s*:" # Check for other usages of this variable echo "Checking for other usages of --tv-Collapse-divider-line-color:" rg --type less "var\(--tv-Collapse-divider-line-color\)"
18-18
: Verify the implementation of.inject-Collapse-vars()
The change from
.component-css-vars-collapse()
to.inject-Collapse-vars()
appears to be part of the refactoring effort. This new method likely sets up CSS variables for the component, allowing for more flexible theming.To ensure this change is consistent across the codebase, please run the following script:
✅ Verification successful
Requesting further verification with corrected shell scripts
Please run the following scripts to verify the implementation:
Implementation of
.inject-Collapse-vars()
VerifiedThe
.inject-Collapse-vars()
method has been correctly implemented, and there are no remaining instances of.component-css-vars-collapse()
. The CSS variable--tv-Collapse-divider-line-color
is properly defined and utilized within theindex.less
file.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining instances of .component-css-vars-collapse() and verify the implementation of .inject-Collapse-vars() # Search for any remaining instances of the old method echo "Searching for remaining instances of .component-css-vars-collapse():" rg --type less "\.component-css-vars-collapse\(\)" # Check the implementation of the new method echo "Checking the implementation of .inject-Collapse-vars():" rg --type less "\.inject-Collapse-vars\s*\(\)" -A 10Length of output: 1161
Script:
# Searching for the definition of --tv-Collapse-divider-line-color: rg --type less '--tv-Collapse-divider-line-color\s*:' # Checking for other usages of --tv-Collapse-divider-line-color: rg --type less 'var\(--tv-Collapse-divider-line-color\)' # Searching for remaining instances of .component-css-vars-collapse(): rg --type less '\.component-css-vars-collapse\(\)' # Checking the implementation of .inject-Collapse-vars(): rg --type less '\.inject-Collapse-vars\(\)' -A 10Length of output: 1188
packages/theme/src/base/vars.less (1)
310-310
: LGTM! Consider updating related components.The removal of "折叠面板" (collapsible panel) from the comment for
--tv-color-bg-gray-1
aligns with the PR objective of refactoring collapse theme variables. The remaining comment parts accurately describe the variable's purpose.To ensure consistency across the codebase, please verify if any components or documentation referencing
--tv-color-bg-gray-1
for collapsible panels need to be updated. Run the following script to check for such references:✅ Verification successful
LGTM! The removal of "折叠面板" from the
--tv-color-bg-gray-1
comment aligns with the PR's refactoring objectives, and no related references were found in the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for references to --tv-color-bg-gray-1 in relation to collapsible panels # Test: Search for --tv-color-bg-gray-1 usage in component files rg --type=vue --type=less --type=css --type=js --type=ts $'--tv-color-bg-gray-1.*collaps' ./src # Test: Search for --tv-color-bg-gray-1 usage in documentation rg --type=md $'--tv-color-bg-gray-1.*collaps' ./docsLength of output: 1014
Script:
#!/bin/bash # Description: Search for references to --tv-color-bg-gray-1 in relation to collapsible panels # Test: Search for --tv-color-bg-gray-1 usage in component files rg --type=vue --type=less --type=css --type=js --type=ts -- '--tv-color-bg-gray-1.*collaps' ./src # Test: Search for --tv-color-bg-gray-1 usage in documentation rg --type=md -- '--tv-color-bg-gray-1.*collaps' ./docsLength of output: 231
Script:
#!/bin/bash # Description: Search for references to --tv-color-bg-gray-1 in relation to collapsible panels # Test: Search for --tv-color-bg-gray-1 usage in component files rg -e '--tv-color-bg-gray-1.*collaps' --include '*.vue' --include '*.less' --include '*.css' --include '*.js' --include '*.ts' ./srcLength of output: 576
Script:
#!/bin/bash # Description: Search for references to --tv-color-bg-gray-1 in relation to collapsible panels # Test: Search for --tv-color-bg-gray-1 usage in component files with specified extensions rg -e '--tv-color-bg-gray-1.*collaps' -g '*.vue' -g '*.less' -g '*.css' -g '*.js' -g '*.ts' ./srcLength of output: 145
Script:
#!/bin/bash # Description: Search for references to --tv-color-bg-gray-1 in relation to collapsible panels within packages/theme/src # Test: Search for --tv-color-bg-gray-1 usage in component files with specified extensions rg -e '--tv-color-bg-gray-1.*collaps' -g '*.vue' -g '*.less' -g '*.css' -g '*.js' -g '*.ts' ./packages/theme/srcLength of output: 114
packages/theme/src/collapse-item/index.less (3)
19-22
: Approved: Use of CSS variables enhances theming flexibilityThe introduction of CSS variables and the
.inject-CollapseItem-vars();
mixin improves maintainability and allows for easier theming of the collapse item component.
99-101
: Approved: Consistent padding and typography for contentThe adjustments to padding and the use of CSS variables for font size enhance the consistency and readability of the content within the collapse item.
84-87
: Verify hover styles for the arrow iconThe styles applied to the arrow icon on hover when the component is not disabled need verification to ensure they work as intended.
Run the following script to check if the hover styles are correctly applied:
@@ -10,93 +10,31 @@ | |||
* | |||
*/ | |||
|
|||
.component-css-vars-collapse-item() { | |||
.inject-CollapseItem-vars() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
🛠️ Refactor suggestion
Inconsistent Function Naming Detected
The function .inject-radio-vars()
in packages/theme/src/radio/vars.less
uses lowercase "radio," whereas other functions use PascalCase (e.g., .inject-RadioGroup-vars()
). Please standardize the naming to ensure consistency across all components.
🔗 Analysis chain
Ensure consistency in function naming conventions
The function name has been changed to .inject-CollapseItem-vars()
. Please verify that this naming convention is consistent with other components and aligns with the project's standards.
Run the following script to check for consistency:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all LESS functions that inject component variables to ensure naming consistency.
# Test: Search for function definitions following the `.inject-<ComponentName>-vars()` pattern.
rg --type less '^\.inject-[A-Za-z0-9_-]+-vars\(\)'
Length of output: 899
&.is-disabled &__word-overflow { | ||
cursor: not-allowed; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust selector for word overflow in disabled state
The styles for &__word-overflow
within the disabled state might not be applied correctly due to improper nesting.
Refactor the selector to ensure correct scope:
-&.is-disabled &__word-overflow {
+&.is-disabled {
+ &__word-overflow {
cursor: not-allowed;
-}
+ }
+}
📝 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.
&.is-disabled &__word-overflow { | |
cursor: not-allowed; | |
} | |
&.is-disabled { | |
&__word-overflow { | |
cursor: not-allowed; | |
} | |
} |
&.is-disabled &__arrow svg { | ||
fill: var(--tv-CollapseItem-disabled-text-color); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct selector for arrow icon in disabled state
The selector &.is-disabled &__arrow svg
may not correctly apply styles to the arrow icon when disabled.
Modify the selector nesting to properly target the arrow icon:
-&.is-disabled &__arrow svg {
+&.is-disabled {
+ &__arrow svg {
fill: var(--tv-CollapseItem-disabled-text-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.
&.is-disabled &__arrow svg { | |
fill: var(--tv-CollapseItem-disabled-text-color); | |
} | |
&.is-disabled { | |
&__arrow svg { | |
fill: var(--tv-CollapseItem-disabled-text-color); | |
} | |
} |
&.is-disabled &__header { | ||
color: var(--tv-CollapseItem-disabled-text-color); | ||
background-color: var(--tv-CollapseItem-disabled-header-bg-color); | ||
cursor: not-allowed; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix selector nesting for the disabled state
The current selector &.is-disabled &__header
may not target the .collapse-item__header
element correctly when the component is disabled. This could lead to styles not being applied as intended.
Please adjust the nesting to ensure proper compilation:
-&.is-disabled &__header {
+&.is-disabled {
+ &__header {
color: var(--tv-CollapseItem-disabled-text-color);
background-color: var(--tv-CollapseItem-disabled-header-bg-color);
cursor: not-allowed;
-}
+ }
+}
📝 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.
&.is-disabled &__header { | |
color: var(--tv-CollapseItem-disabled-text-color); | |
background-color: var(--tv-CollapseItem-disabled-header-bg-color); | |
cursor: not-allowed; | |
} | |
&.is-disabled { | |
&__header { | |
color: var(--tv-CollapseItem-disabled-text-color); | |
background-color: var(--tv-CollapseItem-disabled-header-bg-color); | |
cursor: not-allowed; | |
} | |
} |
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Bug Fixes
Refactor