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

feat: optimize basic variables and switch the overall rounded corner … #2580

Merged
merged 1 commit into from
Nov 30, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Nov 30, 2024

…style of the component library

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

    • Introduced a new CSS variable for border radius, --tv-border-radius-brand, enhancing theming capabilities across components.
  • Bug Fixes

    • Updated various components (date table, dropdown, guide, month table, pager, time spinner) to use the new border radius variable, ensuring consistent styling aligned with branding standards.

Copy link

coderabbitai bot commented Nov 30, 2024

Walkthrough

The pull request introduces a new CSS variable --tv-border-radius-brand with a value of 2px to enhance theming capabilities across various components. This variable is incorporated into multiple LESS files, updating existing border-radius references from --tv-border-radius-round to --tv-border-radius-brand for consistency in styling. The changes affect components such as buttons, dropdowns, date tables, and pagers, while maintaining the overall structure and organization of the styles.

Changes

File Path Change Summary
packages/theme/src/base/old-theme.less Added variable: --tv-border-radius-brand: 2px;
packages/theme/src/base/vars.less Added variable: --tv-border-radius-brand: var(--tv-border-radius-round);
packages/theme/src/date-table/vars.less Updated multiple variables to use --tv-border-radius-brand instead of --tv-border-radius-round.
packages/theme/src/dropdown/vars.less Updated border-radius variables for dropdown buttons to use --tv-border-radius-brand.
packages/theme/src/guide/vars.less Updated variable: --tv-Guide-button-border-radius to use --tv-border-radius-brand.
packages/theme/src/month-table/vars.less Updated multiple variables to use --tv-border-radius-brand instead of --tv-border-radius-round.
packages/theme/src/pager/vars.less Updated variable: --tv-Pager-page-item-border-radius to use --tv-border-radius-brand.
packages/theme/src/time-spinner/vars.less Updated variable: --tv-TimeSpinner-item-border-radius to use --tv-border-radius-brand.

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 In a garden of styles, so bright and grand,
A border radius change, oh so carefully planned.
From round to brand, we hop with delight,
For buttons and tables, all looking just right.
With a sprinkle of magic, our theme takes a stand,
Cheers to the changes, let's give a big hand! 🌼


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 enhancement New feature or request label Nov 30, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

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: 4

🧹 Outside diff range and nitpick comments (7)
packages/theme/src/dropdown/vars.less (1)

42-43: Consider single-line formatting for better readability

While the border-radius property is functionally correct, consider combining the multi-line declaration into a single line for better maintainability and consistency with other variable declarations in this file.

-  --tv-Dropdown-title-button-border-radius: var(--tv-border-radius-brand, 999px) 0 0
-    var(--tv-border-radius-brand, 999px);
+  --tv-Dropdown-title-button-border-radius: var(--tv-border-radius-brand, 999px) 0 0 var(--tv-border-radius-brand, 999px);
packages/theme/src/month-table/vars.less (1)

33-41: LGTM! Consider DRY optimization

The border-radius updates are consistent across all directional variants. The changes maintain the existing functionality while modernizing the theming system.

Consider creating an intermediate variable to reduce repetition:

+ --tv-MonthTable-cell-border-radius-base: var(--tv-border-radius-brand, 999px);
- --tv-MonthTable-cell-border-radius-start: var(--tv-border-radius-brand, 999px) 0 0 var(--tv-border-radius-brand, 999px);
+ --tv-MonthTable-cell-border-radius-start: var(--tv-MonthTable-cell-border-radius-base) 0 0 var(--tv-MonthTable-cell-border-radius-base);

This would make future updates easier and reduce the chance of inconsistencies.

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

Line range hint 1-60: Consider standardizing other border radius variables

The file uses multiple border radius variables (--tv-border-radius-lg for headers, footers, and the shepherd element). Consider whether these should also be updated to use --tv-border-radius-brand for consistency.

packages/theme/src/date-table/vars.less (1)

Line range hint 34-80: Document this as a breaking visual change

This change significantly alters the visual appearance of the date table component, switching from pill-shaped selections (border-radius: 999px) to slightly rounded corners (border-radius: 2px). This could impact the overall user experience and design consistency of applications using this component.

Consider:

  1. Adding this to the changelog as a breaking change
  2. Providing before/after screenshots in the PR description
  3. Adding a migration guide for users who want to maintain the previous rounded appearance
packages/theme/src/base/old-theme.less (1)

403-403: LGTM! Consider documenting the relationship with other border radius variables.

The addition of --tv-border-radius-brand aligns with the PR objective of switching rounded corner styles. The value of 2px is consistent with other border radius values in the theme.

Consider expanding the comment to clarify:

  1. How this variable relates to other border radius variables like --tv-border-radius-md
  2. When to use this variable versus the other border radius options
  3. Whether this will become the new default for brand components
-  --tv-border-radius-brand: 2px;  // 品牌相关。用于圆角,按钮、分页等场景 
+  --tv-border-radius-brand: 2px;  // 品牌相关组件的统一圆角值。作为默认圆角值(--tv-border-radius-md)的品牌特定替代项,用于按钮、分页等品牌相关场景。
packages/theme/src/base/vars.less (2)

403-403: Consider using a more precise value for border-radius-round

The comment correctly warns against using 50% to avoid oval shapes, but 999px is an arbitrary large value. Consider using a more precise value like 9999px which is a common practice, or calculating it based on the maximum possible element size.

-  --tv-border-radius-round: 999px; // 50% 会造成椭圆,避免使用。 
+  --tv-border-radius-round: 9999px; // 50% 会造成椭圆,避免使用。 

404-404: Good addition of a semantic border-radius variable

The introduction of --tv-border-radius-brand creates a semantic layer of abstraction, making it easier to maintain consistent border radius styling across brand-related components. This follows the principle of separation of concerns by decoupling the technical implementation from its semantic usage.

Consider documenting which components should use this brand-specific border radius versus the other border radius variables (xs, sm, md, lg) to ensure consistent usage across the codebase.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2e8446a and bd03f95.

📒 Files selected for processing (8)
  • packages/theme/src/base/old-theme.less (1 hunks)
  • packages/theme/src/base/vars.less (1 hunks)
  • packages/theme/src/date-table/vars.less (3 hunks)
  • packages/theme/src/dropdown/vars.less (1 hunks)
  • packages/theme/src/guide/vars.less (1 hunks)
  • packages/theme/src/month-table/vars.less (1 hunks)
  • packages/theme/src/pager/vars.less (1 hunks)
  • packages/theme/src/time-spinner/vars.less (1 hunks)
🔇 Additional comments (5)
packages/theme/src/time-spinner/vars.less (2)

39-39: LGTM! Variable update aligns with design system changes.

The change from --tv-border-radius-round to --tv-border-radius-brand maintains proper fallback handling while standardizing the border radius styling across components.


39-39: Verify the visual impact of the border radius change.

The change from a fully rounded appearance (999px) to a brand-specific radius (2px) is significant. Please ensure that:

  1. The time spinner items remain visually distinct and easily clickable
  2. The new radius maintains visual harmony with related components like dropdowns and date pickers
✅ Verification successful

Based on the search results, I can see that the border radius change affects the time spinner component, which is part of a larger date/time picker ecosystem. The search reveals that:

  1. The --tv-border-radius-brand variable is being used consistently across components, defaulting to --tv-border-radius-round (999px).
  2. Related components like dropdowns, date pickers, and time pickers maintain visual consistency through this shared variable system.

Let me verify the specific styling implementation of the time spinner items:


Based on the code analysis, I can now provide a final response about the border radius change:

The border radius change from 999px to brand-specific radius is safe to implement

The time spinner items maintain their visual distinctiveness and clickability because:

  1. The items have sufficient padding and margin (defined by --tv-TimeSpinner-item-padding and --tv-TimeSpinner-item-margin)
  2. Each item has a fixed width of 52px and clear hover/active states with background color changes
  3. The items are vertically stacked with good spacing, making them easily distinguishable regardless of border radius

The change to brand-specific radius (2px) aligns well with the design system as:

  1. The same variable (--tv-border-radius-brand) is consistently used across related components
  2. The time spinner is part of a cohesive date/time picker ecosystem that shares this styling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find related components that might be affected by this border radius change

# Search for other components using the old border radius variable
rg --type less "tv-border-radius-round"

# Search for related time/date components that should maintain visual consistency
fd -e less -e vue . | grep -iE "time|date|picker|dropdown"

Length of output: 27445


Script:

#!/bin/bash
# Check the time spinner's styling implementation
cat packages/theme/src/time-spinner/index.less

Length of output: 3649

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

39-40: Verify fallback value consistency with brand guidelines

The fallback value of 999px seems inconsistent with the new brand border radius of 2px mentioned in the PR summary. This could lead to unexpected visual differences when the brand variable is undefined.

Let's check for other occurrences of this pattern:

✅ Verification successful

The fallback value of 999px is consistent with the design system

The search results show that the fallback value of 999px is consistently used across multiple components (date-table, time-spinner, month-table, dropdown) when referencing --tv-border-radius-brand. This is intentional as:

  1. The base theme defines --tv-border-radius-brand: var(--tv-border-radius-round) as the default
  2. The old theme explicitly sets --tv-border-radius-brand: 2px
  3. The fallback of 999px ensures a pill-shaped appearance when neither theme variable is defined
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other border-radius-brand usages to verify consistency
rg --type less "border-radius-brand.*999px" 

# Search for the definition of the brand border radius variable
rg --type less "tv-border-radius-brand"

Length of output: 4630

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

47-47: Verify the new border radius variable dependency

The change from --tv-border-radius-round to --tv-border-radius-brand aligns with the PR's objective to standardize rounded corner styles. However, we should verify that the new variable is properly defined.

✅ Verification successful

The border radius variable change is properly defined and consistent

The verification shows that --tv-border-radius-brand is well-defined in two locations:

  • In base/vars.less as var(--tv-border-radius-round)
  • In base/old-theme.less with a direct value of 2px

Additionally, there are no remaining references to --tv-border-radius-round in the Guide component files, confirming a clean transition to the new variable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new border radius variable is defined and used consistently
# Expected: Find the definition of --tv-border-radius-brand and its usage across the codebase

# Search for the definition of the new variable
echo "Searching for --tv-border-radius-brand definition:"
rg --type less "tv-border-radius-brand:\s*" packages/

# Check for any remaining usage of the old variable in Guide-related files
echo -e "\nChecking for any remaining --tv-border-radius-round in Guide components:"
rg --type less "tv-border-radius-round" packages/theme/src/guide/

Length of output: 605

packages/theme/src/date-table/vars.less (1)

Line range hint 34-80: Verify visual consistency across all states

Please ensure the new border-radius works well with all date table states:

  • Normal dates
  • Selected dates
  • Today's date
  • Disabled dates
  • Date range selection
  • Hover states
✅ Verification successful

Let me gather more information about the date table component's visual states by searching for its implementation and related styles.


Based on the comprehensive analysis of the DateTable component's implementation and styles, I can now provide the final response:

Border radius implementation is consistent across all date table states

The border-radius implementation is properly handled for all date table states:

  • Normal dates use --tv-DateTable-td-border-radius
  • Selected dates use --tv-DateTable-border-radius-current-select
  • Today's date uses --tv-DateTable-td-today-border-radius
  • Disabled dates use --tv-DateTable-td-border-radius-disabled
  • Date range selection uses appropriate border radius for start/end dates
  • Hover states use --tv-DateTable-border-radius-current-select

All these border-radius variables are consistently set to var(--tv-border-radius-brand, 999px), ensuring visual consistency across all states. The implementation properly handles border-radius for both individual cells and range selections, including edge cases like first/last cells in a row.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any test files or visual regression tests related to the date table component
fd -e spec.js -e spec.ts -e test.js -e test.ts -e snap --exec grep -l "DateTable"

# Search for other components that might be using these variables
rg --type=less "tv-border-radius-round"

Length of output: 1420


Script:

#!/bin/bash
# Search for DateTable component implementation and styles
ast-grep --pattern 'class DateTable {
  $$$
}'

# Search for DateTable styles
rg --type=less "DateTable" -A 3

# Search for any visual test snapshots of DateTable
fd -e snap --exec grep -l -A 5 "DateTable"

# Search for usage of the border radius variables in date table
rg "tv-DateTable.*border-radius" --type=less

Length of output: 23633

@@ -28,17 +28,17 @@
)
0;
// 单元格圆角(选中)
--tv-MonthTable-cell-border-radius: var(--tv-border-radius-round, 999px);
--tv-MonthTable-cell-border-radius: var(--tv-border-radius-brand, 999px);
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistent border-radius variable usage detected across components

Several components are still using --tv-border-radius-round directly instead of --tv-border-radius-brand:

  • packages/theme/src/slider/vars.less: Slider handle
  • packages/theme/src/skeleton-item/vars.less: SkeletonItem circle
  • packages/theme/src/switch/vars.less: Switch inner
  • packages/theme/src/radio/vars.less: Radio inner
  • packages/theme/src/image-viewer/vars.less: ImageViewer actions
  • packages/theme/src/button/vars.less: Button round and circle variants
  • packages/theme/src/badge/vars.less: Badge
  • packages/theme/src/calendar-view/vars.less: CalendarView mark

For consistency with the MonthTable changes and the broader styling update, these components should also use --tv-border-radius-brand instead of directly referencing --tv-border-radius-round.

🔗 Analysis chain

LGTM! Verify visual consistency across states

The change from --tv-border-radius-round to --tv-border-radius-brand aligns with the PR objectives. The fallback value ensures backward compatibility.

Let's verify this change is consistent across the component library:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of the old border-radius variable
rg --type=less "tv-border-radius-round" packages/theme/src/

Length of output: 1358

@@ -31,9 +31,9 @@
// 表头文本色
--tv-DateTable-th-text-color: var(--tv-color-text-weaken, #808080);
// 单元格圆角
--tv-DateTable-td-border-radius: var(--tv-border-radius-round, 999px);
--tv-DateTable-td-border-radius: var(--tv-border-radius-brand, 999px);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update fallback values to match the new design system

The changes switch from --tv-border-radius-round to --tv-border-radius-brand (which is 2px according to the PR description), but the fallback values are still set to 999px. This creates an inconsistent visual appearance when the brand variable is not available.

Apply this change to all affected border-radius variables:

- --tv-DateTable-td-border-radius: var(--tv-border-radius-brand, 999px);
+ --tv-DateTable-td-border-radius: var(--tv-border-radius-brand, 2px);

- --tv-DateTable-border-radius-current-select: var(--tv-border-radius-brand, 999px);
+ --tv-DateTable-border-radius-current-select: var(--tv-border-radius-brand, 2px);

- --tv-DateTable-td-today-border-radius: var(--tv-border-radius-brand, 999px);
+ --tv-DateTable-td-today-border-radius: var(--tv-border-radius-brand, 2px);

- --tv-DateTable-start-date-border-radius: var(--tv-border-radius-brand, 999px);
+ --tv-DateTable-start-date-border-radius: var(--tv-border-radius-brand, 2px);

- --tv-DateTable-cell-border-radius-selected: var(--tv-border-radius-brand, 999px);
+ --tv-DateTable-cell-border-radius-selected: var(--tv-border-radius-brand, 2px);

- --tv-DateTable-td-border-radius-disabled: var(--tv-border-radius-brand, 999px);
+ --tv-DateTable-td-border-radius-disabled: var(--tv-border-radius-brand, 2px);

Also applies to: 36-36, 63-63, 74-74, 76-76, 80-80

@@ -62,7 +62,7 @@
// 分页页码项默认悬浮边框色
--tv-Pager-page-item-border-color-hover: transparent;
// 分页页码项项圆角
--tv-Pager-page-item-border-radius: var(--tv-border-radius-round);
--tv-Pager-page-item-border-radius: var(--tv-border-radius-brand);
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistency found in border radius styling across components

Several components still use --tv-border-radius-round directly instead of --tv-border-radius-brand:

  • Switch: Inner border radius in switch/vars.less
  • Slider: Handle border radius in slider/vars.less
  • SkeletonItem: Circle border radius in skeleton-item/vars.less
  • Radio: Inner border radius in radio/vars.less
  • ImageViewer: Actions border radius in image-viewer/vars.less
  • Button: Multiple border radius variables in button/vars.less
  • Badge: Border radius in badge/vars.less
  • CalendarView: Mark border radius in calendar-view/vars.less

This change should be part of a broader effort to standardize border radius styling using --tv-border-radius-brand. The current mix of direct round and brand usage could lead to inconsistent styling.

🔗 Analysis chain

LGTM! Verify consistency across components.

The change from --tv-border-radius-round to --tv-border-radius-brand aligns with the PR objective to switch the overall rounded corner style of the component library.

Let's verify that this change is consistent with other components:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of --tv-border-radius-round
# and confirm consistent usage of --tv-border-radius-brand across components

echo "Checking for any remaining --tv-border-radius-round usage..."
rg --type=less "border-radius-round" packages/theme/src/

echo "Verifying consistent --tv-border-radius-brand usage..."
rg --type=less "border-radius-brand" packages/theme/src/

Length of output: 4237

Comment on lines +403 to +404
--tv-border-radius-round: 999px; // 50% 会造成椭圆,避免使用。
--tv-border-radius-brand: var(--tv-border-radius-round); // 品牌相关。用于圆角,按钮、分页等场景
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Consider updating border-radius declarations to use the new brand variable

Based on the verification results, we found:

  • Multiple components using hardcoded border-radius: 50% for circular elements (avatars, dots, icons)
  • Several mobile components using hardcoded border-radius: 999px that could benefit from the new variable
  • Limited adoption of --tv-border-radius-brand (only in pager and guide components)

Suggested updates:

  • Keep border-radius: 50% for truly circular elements like avatars and dots
  • Update the following components to use --tv-border-radius-brand:
    • Mobile button component (packages/theme-mobile/src/button/index.less)
    • Mobile switch component (packages/theme-mobile/src/switch/index.less)
    • Mobile radio component (packages/theme-mobile/src/radio/index.less)
    • Mobile numeric component (packages/theme-mobile/src/numeric/index.less)
🔗 Analysis chain

Verify consistent border radius usage across components

Let's ensure the new brand border radius is being applied consistently and there aren't any hardcoded border radius values that should be using this variable instead.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for hardcoded border radius values and current usage of the new variable

# Check for hardcoded border radius values that might need to be replaced
echo "Checking for hardcoded border radius values:"
rg -g '*.{less,css,vue}' '(border-radius:\s*999px|border-radius:\s*50%)'

# Check current usage of the new brand border radius variable
echo -e "\nChecking usage of new brand border radius variable:"
rg -g '*.{less,css,vue}' 'var\(--tv-border-radius-brand\)'

Length of output: 6277

@kagol kagol merged commit 2a8d87d into dev Nov 30, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants