-
Notifications
You must be signed in to change notification settings - Fork 278
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(floatbar): [floatbar] refactor theme vars #2302
Conversation
WalkthroughThe changes in this pull request involve updates to the Changes
Possibly related PRs
Suggested reviewers
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: 3
🧹 Outside diff range and nitpick comments (14)
examples/sites/demos/pc/app/floatbar/custom-style-composition-api.vue (1)
4-7
: LGTM! Consider using i18n for better localization management.The change from English to Chinese labels is consistent and aligns with the refactoring objectives. However, for better maintainability and easier localization in the future, consider using an i18n library to manage these text strings.
Example of using i18n (assuming you're using vue-i18n):
<template> <tiny-floatbar class="custom"> <ul> <li><a>{{ $t('floatbar.localImport') }}</a></li> <li><a>{{ $t('floatbar.onDemandImport') }}</a></li> <li><a>{{ $t('floatbar.searchImport') }}</a></li> <li><a>{{ $t('floatbar.fullImport') }}</a></li> </ul> </tiny-floatbar> </template>This approach would allow for easier management of multiple languages in the future.
examples/sites/demos/pc/app/floatbar/custom-style.vue (2)
4-7
: LGTM! Consider adding internationalization support.The change from English to Chinese labels is good for localization. However, to make the component more versatile, consider implementing internationalization (i18n) support. This would allow users to easily switch between different languages or use the component in various locales.
Here's a suggestion for implementing i18n:
- Use a translation function or library (e.g., vue-i18n).
- Replace hardcoded strings with translation keys.
Example:
<template> <tiny-floatbar class="custom"> <ul> <li><a>{{ $t('floatbar.local_import') }}</a></li> <li><a>{{ $t('floatbar.on_demand_import') }}</a></li> <li><a>{{ $t('floatbar.search_import') }}</a></li> <li><a>{{ $t('floatbar.full_import') }}</a></li> </ul> </tiny-floatbar> </template>This approach would make it easier to support multiple languages in the future.
25-26
: LGTM! Consider using CSS variables for better theme customization.The style changes look good and align with modern UI practices. The neutral background color and the new hover effect should improve the component's versatility and visual feedback.
To further improve the component's customizability and align with the PR's refactoring goals, consider using CSS variables for key style properties. This would allow easier theming and customization. Here's an example:
:root { --floatbar-width: 120px; --floatbar-bg-color: #dbdbdb; --floatbar-hover-bg-color: #fff; } .custom { position: static; width: var(--floatbar-width); background-color: var(--floatbar-bg-color); } .custom li:hover { background: var(--floatbar-hover-bg-color); }This approach would make it easier for users to customize the floatbar's appearance without modifying the component's source code.
Also applies to: 28-29
examples/sites/demos/pc/app/floatbar/custom-style.spec.ts (5)
8-8
: Locator updated to reflect localized content.The change from 'Default-A' to '本地引入' (Locally Imported) aligns with the localization efforts. This update ensures that the test accurately targets the correct element in the updated UI.
Consider adding a comment explaining the meaning of '本地引入' for non-Chinese speakers, to improve code readability:
// Locator for the "Locally Imported" list item const item = page.getByRole('listitem').filter({ hasText: '本地引入' })
10-10
: Updated background color assertion for floatbar.The change in expected background color from 'rgb(222, 184, 135)' to 'rgb(219, 219, 219)' reflects the updated styling of the floatbar component. This aligns with the PR's objective of refactoring theme variables.
For improved maintainability, consider using a constant for the color value:
const FLOATBAR_BG_COLOR = 'rgb(219, 219, 219)' await expect(floatbar).toHaveCSS('background-color', FLOATBAR_BG_COLOR)This approach makes it easier to update the expected color in the future and ensures consistency across multiple tests if needed.
12-12
: Updated background color assertion for list item.The change in expected background color from 'rgba(24, 144, 255, 0.06)' to 'rgb(255, 255, 255)' reflects the updated styling of the list items. This aligns with the PR's objective of refactoring theme variables.
For consistency with the previous suggestion and improved maintainability, consider using a constant for the color value:
const LIST_ITEM_BG_COLOR = 'rgb(255, 255, 255)' await expect(item).toHaveCSS('background-color', LIST_ITEM_BG_COLOR)This approach makes it easier to update the expected color in the future and ensures consistency across multiple tests if needed.
13-13
: Updated color assertion for anchor element.The change in expected color from 'rgb(255, 255, 255)' to 'rgb(25, 25, 25)' for the anchor element reflects the updated styling. This change likely improves readability against the new white background of the list item.
For consistency with previous suggestions and improved maintainability, consider using a constant for the color value:
const ANCHOR_COLOR = 'rgb(25, 25, 25)' await expect(item.locator('a')).toHaveCSS('color', ANCHOR_COLOR)Additionally, to improve the test's resilience to minor CSS changes, you might want to use
toHaveCSS
with aRegExp
for color matching:await expect(item.locator('a')).toHaveCSS('color', /rgb\(25,?\s*25,?\s*25\)/)This allows for slight variations in whitespace or commas in the RGB value, which can occur in different browsers or CSS processing tools.
Line range hint
1-14
: Overall assessment of changes in custom-style.spec.tsThe modifications in this file accurately reflect the PR's objectives of refactoring the floatbar component's theme variables. The test case has been updated to account for:
- Localization of content (English to Chinese)
- Changes in component styling (background colors and text colors)
These updates ensure that the test suite remains in sync with the component's new design and localization efforts. The changes are consistent and well-implemented.
To further improve the test suite:
- Consider extracting color constants to a separate file for reuse across multiple test files.
- If these style changes are part of a broader theme update, consider creating a helper function to verify theme-related styles, which could be reused across different component tests.
packages/theme/src/floatbar/vars.less (5)
13-13
: Approve method name change with a minor suggestion.The new method name
.inject-Floatbar-vars()
is more descriptive of its purpose. However, to maintain consistency with CSS naming conventions, consider using lowercase for "floatbar":-.inject-Floatbar-vars() { +.inject-floatbar-vars() {This change would improve consistency while retaining the clarity of the new name.
16-16
: Approve variable change with a minor suggestion.The variable name change and the use of a referenced value (
var(--tv-border-radius-lg)
) are improvements. However, to maintain consistency with CSS naming conventions, consider using lowercase for "float-bar":- --tv-Float-bar-border-radius: var(--tv-border-radius-lg); + --tv-float-bar-border-radius: var(--tv-border-radius-lg);This change would improve consistency while retaining the benefits of the new naming scheme and value reference.
18-18
: Approve font size variable change with a minor suggestion.The variable name change and the use of a referenced value (
var(--tv-font-size-md)
) are improvements. However, to maintain consistency with CSS naming conventions, consider using lowercase for "float-bar":- --tv-Float-bar-font-size: var(--tv-font-size-md); + --tv-float-bar-font-size: var(--tv-font-size-md);This change would improve consistency while retaining the benefits of the new naming scheme and value reference.
20-22
: Approve background color and margin variable changes with minor suggestions.The variable name changes and the use of referenced values are improvements. However, to maintain consistency with CSS naming conventions, consider using lowercase for "float-bar":
- --tv-Float-bar-list-bg-color: var(--tv-color-bg-secondary); + --tv-float-bar-list-bg-color: var(--tv-color-bg-secondary); - --tv-Float-bar-li-margin-vertical: var(--tv-space-md); + --tv-float-bar-li-margin-vertical: var(--tv-space-md);These changes would improve consistency while retaining the benefits of the new naming scheme and value references.
13-27
: Overall assessment: Improved structure with minor inconsistenciesThe refactoring of the floatbar CSS variables has generally improved the code structure and maintainability:
- The new method name
.inject-Floatbar-vars()
is more descriptive.- The prefix change from
--ti-
to--tv-
is consistent throughout.- The use of referenced variables for values improves maintainability and consistency.
However, there are some areas for improvement:
- Consistency in naming: Consider using lowercase for "float-bar" in all variable names to align with CSS naming conventions.
- Hover state: Verify if using the same color for both normal and hover text states is intentional.
Addressing these points will further enhance the quality and consistency of the code.
To improve the overall architecture and maintainability of the theme system, consider the following suggestions:
Create a separate file for common variables (like
--tv-border-radius-lg
,--tv-font-size-md
, etc.) if not already present. This would centralize these shared values and make it easier to maintain consistency across components.Document the purpose and usage of each variable with comments. This will help other developers understand the intent behind each variable and how they should be used.
Consider implementing a naming convention guide for CSS variables to ensure consistency across the entire project. This could include rules for prefixes, capitalization, and component-specific naming patterns.
If not already in place, consider implementing a CSS linting tool that can automatically check for naming convention adherence and other best practices in your Less files.
packages/theme/src/floatbar/index.less (1)
Line range hint
1-62
: Overall assessment: Improved theming with some recommendationsThe changes in this file generally enhance the theming capabilities of the float bar component by introducing more CSS variables. This is a positive direction for maintaining consistency and flexibility across different themes.
However, there are a few areas where further improvements could be made:
- Consider using CSS variables for all color and shadow values to maintain full theming flexibility.
- Ensure consistency in the use of CSS variables vs. hard-coded values throughout the file.
- Double-check the implementation of the new
.inject-Floatbar-vars()
mixin to ensure it contains all necessary variables.- Fix the typo in the
min-width
property of theli
element.These changes will further improve the maintainability and flexibility of the component's styling.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
- examples/sites/demos/pc/app/floatbar/custom-style-composition-api.vue (2 hunks)
- examples/sites/demos/pc/app/floatbar/custom-style.spec.ts (1 hunks)
- examples/sites/demos/pc/app/floatbar/custom-style.vue (2 hunks)
- packages/theme/src/floatbar/index.less (1 hunks)
- packages/theme/src/floatbar/vars.less (1 hunks)
🧰 Additional context used
🔇 Additional comments (6)
examples/sites/demos/pc/app/floatbar/custom-style-composition-api.vue (1)
19-20
: LGTM! Verify the width reduction doesn't cause layout issues.The style changes look good and align with the refactoring objectives. The new hover effect is a nice UX improvement. However, please ensure that the width reduction from 200px to 120px doesn't cause any content overflow or layout issues.
To verify the layout, please check the following:
- All text within the floatbar fits without truncation or overflow.
- The floatbar aligns correctly with other elements on the page.
- The new width works well across different screen sizes.
Consider adding responsive design rules if needed:
@media (max-width: 768px) { .custom { width: 100%; /* Full width on smaller screens */ } }Also applies to: 22-23
packages/theme/src/floatbar/vars.less (1)
25-27
: Approve text color variable changes with suggestions and a question.The variable name changes and the use of referenced values are improvements. However, there are a couple of points to consider:
- To maintain consistency with CSS naming conventions, consider using lowercase for "float-bar":
- --tv-Float-bar-list-text-color: var(--tv-color-text); + --tv-float-bar-list-text-color: var(--tv-color-text); - --tv-Float-bar-list-hover-text-color: var(--tv-color-text); + --tv-float-bar-list-hover-text-color: var(--tv-color-text);
- Both the normal and hover text colors are set to the same value (
var(--tv-color-text)
). Is this intentional? Typically, hover states have a different color to provide visual feedback to the user.Could you confirm if using the same color for both normal and hover states is intentional? If not, consider using a different color variable for the hover state.
packages/theme/src/floatbar/index.less (4)
27-27
: Approved: Improved theming for border-radiusThe use of a dedicated CSS variable
--tv-Float-bar-border-radius
for the border-radius improves theming capabilities and follows the new naming convention.
29-29
: Approved: Enhanced theming for background colorThe use of the CSS variable
--tv-Float-bar-list-bg-color
for the background color improves theming flexibility and follows the new naming convention.
50-56
: Approved: Improved theming for anchor tag colorsThe use of CSS variables
--tv-Float-bar-list-text-color
and--tv-Float-bar-list-hover-text-color
for the anchor tag colors in normal and hover/focus states improves theming flexibility and follows the new naming convention.
20-20
: Verify the new mixin implementationThe mixin call has been changed from
.component-css-vars-floatbar()
to.inject-Floatbar-vars()
. This change appears to be part of a larger refactoring effort to standardize naming conventions.Please ensure that the new mixin
.inject-Floatbar-vars()
is properly defined and includes all necessary variables. Run the following script to verify the mixin definition:✅ Verification successful
Mixin
.inject-Floatbar-vars()
is properly definedThe new mixin
.inject-Floatbar-vars()
is found inpackages/theme/src/floatbar/vars.less
and includes all necessary variables. The refactoring appears to be correctly implemented.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence and implementation of the new mixin # Test: Search for the mixin definition rg --type less -A 10 $'\.inject-Floatbar-vars\(\)'Length of output: 1474
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: 2
🧹 Outside diff range and nitpick comments (1)
packages/theme/src/floatbar/vars.less (1)
14-14
: Standardize code comments to English for consistencyThe code comments are currently written in Chinese. For an international open-source project, using English for code comments can enhance collaboration and maintainability. Consider translating the comments to English.
Also applies to: 16-16, 18-18, 20-20, 22-22, 24-24, 26-26
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- packages/theme/src/floatbar/index.less (1 hunks)
- packages/theme/src/floatbar/vars.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/theme/src/floatbar/index.less
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
<tiny-floatbar>
component to display list item labels in Chinese.Bug Fixes
Refactor
Tests