-
Notifications
You must be signed in to change notification settings - Fork 273
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): [toggle-menu] refactor toggle-menu theme vars #2248
Conversation
WalkthroughThe pull request introduces a comprehensive update to the CSS variable naming conventions for the toggle menu component. It transitions variable prefixes from Changes
Possibly related PRs
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: 0
🧹 Outside diff range and nitpick comments (3)
packages/theme/src/toggle-menu/vars.less (3)
15-21
: Improved variable naming and value consistency.The changes to the variable names and values enhance consistency and maintainability:
- The prefix change from
--ti-
to--tv-
aligns with the new naming convention.- Capitalizing the component name in variables (e.g.,
ToggleMenu
) improves readability.- Using references to other CSS variables (e.g.,
var(--tv-font-size-md)
) promotes theme-wide consistency.Consider using relative units (e.g.,
rem
orem
) for--tv-ToggleMenu-width
and--tv-ToggleMenu-tree-node-height
to improve flexibility and responsiveness across different screen sizes and user preferences.
23-27
: Consistent updates to search-related variables.The changes to the search-related variables improve consistency and maintainability:
- The naming convention aligns with the new standard.
- Using
var(--tv-icon-size)
for the search icon size promotes theme-wide consistency.Consider using a relative unit or referencing another theme variable for
--tv-ToggleMenu-filter-search-size
to improve flexibility and consistency with other form elements in the theme.
13-37
: Overall improvement in theme consistency and maintainability.The refactoring of the ToggleMenu variables has significantly enhanced the theme's consistency and maintainability:
- The new naming convention (
--tv-ToggleMenu-*
) is more consistent and easier to understand.- Extensive use of referenced variables (e.g.,
var(--tv-color-icon)
) promotes theme-wide consistency and easier updates.- The use of semantic color variables improves code readability and maintainability.
These changes will make it easier to manage and update the theme in the future, as well as ensure a consistent look and feel across the application.
For further improvement, consider:
- Using relative units (e.g.,
rem
orem
) for fixed pixel values to enhance responsiveness and flexibility.- Ensuring all component-specific variables are derived from global theme variables where appropriate, to maintain consistency across different components.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- packages/theme/src/toggle-menu/index.less (8 hunks)
- packages/theme/src/toggle-menu/vars.less (1 hunks)
🧰 Additional context used
🔇 Additional comments (12)
packages/theme/src/toggle-menu/vars.less (2)
13-13
: Improved method naming convention.The change from
.component-css-vars-toggle-menu()
to.inject-ToggleMenu-vars()
enhances clarity and consistency. It accurately reflects the method's purpose of injecting variables for the ToggleMenu component.
29-37
: Improved consistency and semantics in toggle-related variables.The updates to the toggle-related variables enhance the overall theme consistency and maintainability:
- The naming convention aligns with the new standard.
- Referencing other CSS variables (e.g.,
var(--tv-color-icon)
,var(--tv-color-bg-hover)
) promotes theme-wide consistency.- The use of semantic color variables improves maintainability and makes it easier to understand the purpose of each color.
These changes will make it easier to manage and update the theme in the future.
packages/theme/src/toggle-menu/index.less (10)
56-58
: LGTM! Consistent naming for filter search properties.The changes to the CSS variable names for filter search properties (e.g.,
--ti-toggle-menu-filter-search-size
to--tv-ToggleMenu-filter-search-size
) are consistent with the new naming convention. Using the same variable for width, height, and line-height ensures square proportions.
66-67
: LGTM! Consistent naming for icon properties.The changes to the CSS variable names for icon properties (color and size) are consistent with the new naming convention while maintaining their specific purposes.
126-126
: LGTM! Consistent naming for toggle font weight.The change to the CSS variable name for toggle font weight is consistent with the new naming convention while maintaining its specific purpose.
137-138
: LGTM! Consistent naming for hover state properties.The changes to the CSS variable names for hover state properties (background color and font weight) are consistent with the new naming convention while maintaining their specific purposes.
179-179
: LGTM! Consistent naming for font size.The change to the CSS variable name for font size is consistent with the new naming convention and matches the earlier change on line 42, ensuring consistency throughout the file.
188-190
: LGTM! Consistent naming for tree node properties.The changes to the CSS variable names for tree node properties (height, line-height, and font size) are consistent with the new naming convention while maintaining their specific purposes. The font size variable remains consistent with its usage elsewhere in the file.
25-25
: LGTM! Verify new CSS variable definitions.The changes to CSS variable names (e.g.,
--ti-toggle-menu-width
to--tv-ToggleMenu-width
) are consistent with the new naming convention. This refactoring improves overall consistency.Please ensure that these new CSS variables are properly defined in the theme. Run the following script to verify:
#!/bin/bash # Search for the definitions of the new CSS variables rg --type less "(--tv-ToggleMenu-width|--tv-ToggleMenu-name-text-color|--tv-ToggleMenu-font-size)" packages/theme/srcAlso applies to: 41-42
Line range hint
1-193
: Overall LGTM! Comprehensive refactoring of CSS variable names.The changes in this file consistently update CSS variable names from the
ti-
prefix to thetv-
prefix, improving overall consistency and following a clear naming convention. No functional changes were made to the styles themselves, which reduces the risk of introducing bugs.However, to ensure the refactoring doesn't cause any styling issues:
- Verify that all new CSS variables are correctly defined in the theme files.
- Conduct a thorough visual test of the ToggleMenu component in various states (default, hover, active) to confirm that the styling remains intact.
- Check for any potential impact on responsive designs or different viewport sizes.
Please run the following script to ensure all new CSS variables are defined:
#!/bin/bash # Search for all new CSS variable definitions rg --type less "^\s*--tv-ToggleMenu-" packages/theme/src
77-79
: LGTM! Consistent naming for toggle properties.The changes to the CSS variable names for toggle properties (height, line-height, background color, icon color, and hover icon color) are consistent with the new naming convention while maintaining their specific purposes.
Please ensure that these new CSS variables for toggle properties are properly defined in the theme. Run the following script to verify:
#!/bin/bash # Search for the definitions of the new CSS variables for toggle properties rg --type less "(--tv-ToggleMenu-filter-search-size|--tv-ToggleMenu-toggle-bg-color|--tv-ToggleMenu-toggle-icon-color|--tv-ToggleMenu-toggle-icon-color-hover)" packages/theme/srcAlso applies to: 84-84, 88-88
23-23
: LGTM! Verify the new mixin definition.The change from
.component-css-vars-toggle-menu()
to.inject-ToggleMenu-vars()
improves clarity and consistency in naming. This appears to be part of a larger refactoring effort.Please ensure that the
.inject-ToggleMenu-vars()
mixin is properly defined elsewhere in the codebase. Run the following script to verify:✅ Verification successful
Mixin
.inject-ToggleMenu-vars()
Definition VerifiedThe
.inject-ToggleMenu-vars()
mixin is properly defined inpackages/theme/src/toggle-menu/vars.less
and correctly used inindex.less
.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for the definition of the new mixin rg --type less "\.inject-ToggleMenu-vars\s*\(\)" packages/theme/srcLength of output: 1521
Script:
#!/bin/bash # Search for the definition of the new mixin without parentheses rg --type less "\.inject-ToggleMenu-vars" packages/theme/srcLength of output: 202
…le-menu-theme-vars-1012
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: 0
🧹 Outside diff range and nitpick comments (3)
examples/sites/demos/pc/app/toggle-menu/automatic-filtering.spec.ts (2)
10-10
: Good improvement in test logic!Changing from a click action to a visibility check is more appropriate for testing the filtering behavior. It correctly verifies that the item becomes visible again after clearing the filter.
For improved clarity, consider adding a comment explaining that this check is performed after clearing the filter. For example:
// Verify that the item is visible again after clearing the filter await expect(page.getByRole('treeitem', { name: '引入组件' })).toBeVisible()
Line range hint
1-11
: Consider enhancing test structure and readabilityThe changes have significantly improved the test coverage for the filtering functionality. To further enhance the test's structure and readability, consider the following suggestions:
- Add descriptive comments for each step of the test to improve readability.
- Consider breaking down the test into smaller, more focused test cases (e.g., one for applying the filter and one for clearing it).
- Use test hooks (like
test.beforeEach()
) to set up common test conditions.Here's an example of how you might restructure the test:
import { test, expect } from '@playwright/test' test.describe('Toggle Menu Automatic Filtering', () => { test.beforeEach(async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) await page.goto('toggle-menu#automatic-filtering') }) test('hides non-matching items when filter is applied', async ({ page }) => { // Apply filter await page.getByRole('textbox', { name: '请输入过滤值' }).fill('组件') // Verify item is hidden await expect(page.getByRole('treeitem', { name: '引入组件' })).not.toBeVisible() }) test('shows all items when filter is cleared', async ({ page }) => { // Apply and then clear filter await page.getByRole('textbox', { name: '请输入过滤值' }).fill('组件') await page.locator('.tiny-toggle-menu__filter-search > .tiny-svg').click() // Verify item is visible again await expect(page.getByRole('treeitem', { name: '引入组件' })).toBeVisible() }) })This structure improves readability and makes it easier to add more specific test cases in the future.
examples/sites/demos/pc/app/toggle-menu/draggable.spec.ts (1)
17-17
: Improved assertion with consistent element selection!The simplification of the assertion is a great improvement:
- It maintains consistency with the earlier
getByRole
usage.- The code is more readable and direct.
Consider if the exact match using a regular expression is necessary. If a precise match isn't required, you could simplify further:
await expect(page.getByRole('treeitem', { name: '其他组件', exact: true })).toHaveText('其他组件')This would be slightly more lenient (allowing for potential whitespace differences) while still ensuring the correct text is present.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- examples/sites/demos/pc/app/toggle-menu/automatic-filtering.spec.ts (1 hunks)
- examples/sites/demos/pc/app/toggle-menu/drag-events.spec.ts (1 hunks)
- examples/sites/demos/pc/app/toggle-menu/draggable.spec.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
examples/sites/demos/pc/app/toggle-menu/automatic-filtering.spec.ts (1)
8-8
: Excellent addition to improve test coverage!This new assertion verifies that the tree item '引入组件' is not visible after applying the filter. It's a crucial check to ensure the filtering functionality is working correctly by hiding non-matching items.
examples/sites/demos/pc/app/toggle-menu/drag-events.spec.ts (1)
7-7
: Approve simplification of drag node selection, but verify test behavior.The change simplifies the selection of the drag node by directly using the bounding box of the treeitem instead of a specific child element. This approach is more robust and less prone to breaking if the internal structure of the treeitem changes.
However, please ensure that this modification doesn't alter the intended behavior of the drag operation in the test. The starting point of the drag might be slightly different now, which could potentially affect the test results.
To verify that this change doesn't negatively impact the test, please run the following script:
examples/sites/demos/pc/app/toggle-menu/draggable.spec.ts (1)
6-8
: Excellent refactoring of element selection!The changes to lines 7-8 significantly improve the code:
- Enhanced readability and conciseness.
- Improved maintainability by using
getByRole
instead of text-based filtering.- Promotes accessibility by leveraging ARIA roles.
- Potentially better performance compared to the previous
locator
andfilter
combination.This refactoring aligns well with best practices for writing robust and accessible tests.
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