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(date-picker): [date-picker] Adapting to the old-theme #2575

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

Youyou-smiles
Copy link
Collaborator

@Youyou-smiles Youyou-smiles commented Nov 29, 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 color variables for improved theming consistency, enhancing the visual experience.
    • Added box-sizing: border-box; to month table cells for better layout handling.
  • Bug Fixes

    • Refined CSS selectors for date table styling to ensure accurate targeting of elements.

Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

The pull request introduces modifications to several LESS stylesheet files, focusing on theme variables and CSS selectors. Key changes include the update of a color variable for active background states in the old-theme.less file, as well as adjustments to CSS selectors in both the index.less files for the date table and month table. The date table's styles are refined to target specific table cells more accurately, while the month table gains a new box-sizing property to improve layout consistency.

Changes

File Change Summary
packages/theme/src/base/old-theme.less Updated --tv-color-bg-active-emphasize from var(--tv-base-color-brand) to var(--tv-base-color-brand-2). Comments adjusted for clarity.
packages/theme/src/date-table/index.less Modified selectors to target td elements directly instead of relying on the .in-range class, enhancing specificity in styling.
packages/theme/src/month-table/index.less Added box-sizing: border-box; to the .cell class within the &:not(.in-range) selector for improved layout.

Possibly related PRs

Suggested reviewers

  • zzcr

🐰 In the meadow, colors bright,
A theme refreshed, a lovely sight.
With styles that dance and cells that play,
Our UI shines in a brand-new way!
Hopping forward, we embrace the change,
A vibrant world, no longer strange! 🌈


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 29, 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 (1)
packages/theme/src/month-table/index.less (1)

144-147: Document the layout fix for future maintenance

The addition of box-sizing: border-box appears to be addressing a specific layout issue with the old theme. Consider adding a comment explaining why this property is necessary specifically for cells not in range.

    &:not(.in-range) {
      .cell {
+       // Fix cell sizing inconsistency in old theme by including padding and border in width calculation
        box-sizing: border-box;
        width: auto;
        border-radius: var(--tv-MonthTable-cell-border-radius);
      }
    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 487a38b and 9e7e8b0.

📒 Files selected for processing (3)
  • packages/theme/src/base/old-theme.less (1 hunks)
  • packages/theme/src/date-table/index.less (1 hunks)
  • packages/theme/src/month-table/index.less (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/theme/src/base/old-theme.less
🔇 Additional comments (1)
packages/theme/src/month-table/index.less (1)

144-144: Verify box-sizing consistency across all cell states

Adding box-sizing: border-box only to cells not in range could create inconsistent sizing behavior between different cell states. Consider applying this consistently across all cell states to maintain uniform sizing calculations.

Comment on lines +263 to 277
&__row td:first-of-type div {
border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
}
&__row .in-range:last-of-type div {
&__row td:last-of-type div {
border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
}
&__row td:nth-child(1 of .available.in-range) div {
&__row td.pre-month + td.available.in-range div {
border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
}
&__row td:nth-last-child(1 of .available.in-range) div {
&__row td.available.in-range:has(+ td.next-month) div {
border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

The border radius variable usage is incorrect

The code is using --tv-DateTable-td-border-radius-disabled for non-disabled states, which is inconsistent with the codebase patterns. The search results show that:

  1. The codebase uses --tv-DateTable-td-border-radius for normal states
  2. --tv-DateTable-td-border-radius-disabled is specifically used for disabled states

The code should be modified to use the correct variables:

  &__row td:first-of-type div {
-    border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-left-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
  }
  &__row td:last-of-type div {
-    border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-right-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
  }
  &__row td.pre-month + td.available.in-range div {
-    border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-left-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
  }
  &__row td.available.in-range:has(+ td.next-month) div {
-    border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-right-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
  }
🔗 Analysis chain

Review the border radius variable usage and browser compatibility

There are several concerns with the new selectors:

  1. The selectors are using --tv-DateTable-td-border-radius-disabled variable for non-disabled states, which seems incorrect. Consider using a more appropriate variable like --tv-DateTable-td-border-radius for normal states.

  2. The :has() selector (line 275) has limited browser support. Consider providing a fallback for better browser compatibility.

Consider applying this refactor for better maintainability and consistency:

-  &__row td:first-of-type div {
-    border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-  }
-
-  &__row td:last-of-type div {
-    border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-  }
-
-  &__row td.pre-month + td.available.in-range div {
-    border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-  }
-
-  &__row td.available.in-range:has(+ td.next-month) div {
-    border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-  }
+  // Border radius for normal states
+  &__row {
+    td:first-of-type div {
+      border-top-left-radius: var(--tv-DateTable-td-border-radius);
+      border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
+    }
+
+    td:last-of-type div {
+      border-top-right-radius: var(--tv-DateTable-td-border-radius);
+      border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
+    }
+
+    // Range selection borders
+    td.pre-month + td.available.in-range div {
+      border-top-left-radius: var(--tv-DateTable-td-border-radius);
+      border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
+    }
+
+    // Fallback for browsers that don't support :has
+    td.available.in-range.next-month-boundary div {
+      border-top-right-radius: var(--tv-DateTable-td-border-radius);
+      border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
+    }
+
+    // Modern browsers
+    @supports selector(:has(*)) {
+      td.available.in-range:has(+ td.next-month) div {
+        border-top-right-radius: var(--tv-DateTable-td-border-radius);
+        border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
+      }
+    }
+  }

This refactor:

  1. Uses appropriate border radius variables
  2. Provides better organization of selectors
  3. Adds browser compatibility support
  4. Maintains the same functionality while being more maintainable

Let's verify the browser support for the :has selector:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check browser support for :has selector
curl -s "https://caniuse.com/api/features?feature=css-has" | jq '.data."css-has".support'

Length of output: 91


Script:

#!/bin/bash
# Let's check if there are any existing CSS variables defined for border radius
rg "tv-DateTable-td-border-radius" -A 2 -B 2

# Also check for any other border radius variables that might be more appropriate
rg "border-radius.*var\(--" -A 2 -B 2

Length of output: 104115

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

🧹 Outside diff range and nitpick comments (2)
packages/theme/src/month-table/index.less (1)

Line range hint 1-158: Consider documenting theme-specific layout behaviors

Since this is part of adapting the date-picker to the old theme, consider:

  1. Documenting these layout changes in the theme documentation
  2. Creating theme-specific variables for layout properties to make future theme switches easier
  3. Ensuring consistent box-model behavior across all date-picker related components (date-table, month-table, year-table)

Consider extracting common layout properties into theme variables:

 &:not(.in-range) {
   .cell {
-    box-sizing: border-box;
-    width: auto;
+    box-sizing: var(--tv-MonthTable-cell-box-sizing, border-box);
+    width: var(--tv-MonthTable-cell-width, auto);
     border-radius: var(--tv-MonthTable-cell-border-radius);
   }
 }
packages/theme/src/date-table/index.less (1)

263-278: Consider extracting border radius logic into theme variables

To improve maintainability and theme consistency, consider extracting the border radius logic into dedicated theme variables. This would:

  1. Make it easier to maintain consistent styling across different states
  2. Allow for better theme customization
  3. Reduce code duplication

Consider adding these variables to vars.less:

  • --tv-DateTable-range-border-radius
  • --tv-DateTable-edge-border-radius

Then use them consistently across all border radius definitions in this file.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 487a38b and 9e7e8b0.

📒 Files selected for processing (3)
  • packages/theme/src/base/old-theme.less (1 hunks)
  • packages/theme/src/date-table/index.less (1 hunks)
  • packages/theme/src/month-table/index.less (1 hunks)
🔇 Additional comments (3)
packages/theme/src/month-table/index.less (1)

144-147: Verify layout consistency with the old theme

The addition of box-sizing: border-box is a good practice for predictable layouts. However, changing the width from 100% to auto might affect cell alignment and spacing.

Please ensure that:

  1. The cell alignment remains consistent across different states (in-range vs not-in-range)
  2. The layout matches the old theme's behavior exactly

Let's verify the old theme's implementation:

packages/theme/src/base/old-theme.less (2)

348-348: LGTM! Color variable change aligns with documented usage.

The change from var(--tv-base-color-brand) to var(--tv-base-color-brand-2) for --tv-color-bg-active-emphasize is appropriate, as --tv-base-color-brand-2 is specifically documented for date selection hover background color in the comments.


348-348: Verify the usage of the color variable in date-picker styles.

Let's confirm that this color variable is being used appropriately in the date-picker component's styles.

✅ Verification successful

Color variable is correctly used in date-picker related components

The variable --tv-color-bg-active-emphasize is properly used in date-picker related components:

  • In date-table component for range selection and week selection backgrounds
  • In time-spinner component for active item backgrounds
  • The color change from #5e7ce0 to var(--tv-base-color-brand-2) maintains theme consistency
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of the --tv-color-bg-active-emphasize variable in date-picker related files

# Search for the variable usage in LESS/CSS files
rg --type=less --type=css "tv-color-bg-active-emphasize" 

# Search specifically in date-picker related files
fd -e less -e css "date" | xargs rg "tv-color-bg-active-emphasize"

Length of output: 19860

Comment on lines +263 to 270
&__row td:first-of-type div {
border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
}
&__row .in-range:last-of-type div {
&__row td:last-of-type div {
border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Review border radius styling for first/last cells

The current implementation has several concerns:

  1. Using --tv-DateTable-td-border-radius-disabled for all cells might not be appropriate as it's meant for disabled states
  2. The broad selectors td:first-of-type and td:last-of-type will apply border radius to all cells, which might not be desired for middle cells in a range selection

Consider using a more specific approach:

-  &__row td:first-of-type div {
+  &__row td:first-of-type:not(.in-range) div {
     border-top-left-radius: var(--tv-DateTable-td-border-radius);
     border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
   }

-  &__row td:last-of-type div {
+  &__row td:last-of-type:not(.in-range) div {
     border-top-right-radius: var(--tv-DateTable-td-border-radius);
     border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
   }
📝 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.

Suggested change
&__row td:first-of-type div {
border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
}
&__row .in-range:last-of-type div {
&__row td:last-of-type div {
border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
}
&__row td:first-of-type:not(.in-range) div {
border-top-left-radius: var(--tv-DateTable-td-border-radius);
border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
}
&__row td:last-of-type:not(.in-range) div {
border-top-right-radius: var(--tv-DateTable-td-border-radius);
border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
}

Comment on lines +271 to 278
&__row td.pre-month + td.available.in-range div {
border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
}
&__row td:nth-last-child(1 of .available.in-range) div {
&__row td.available.in-range:has(+ td.next-month) div {
border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Revise range border styling implementation

The verification reveals that:

  1. The :has() selector is widely used across the codebase, and the project's browserslist configuration ("> 1%, last 2 versions") suggests modern browser support is acceptable
  2. The --tv-DateTable-td-border-radius-disabled variable is consistently used for disabled states, while --tv-DateTable-td-border-radius is used for normal states, confirming that using the disabled variant for range cells is incorrect
  3. The suggested alternative using :last-child might miss edge cases, as the current :has() implementation is more precise for handling next-month transitions

Recommended changes:

   &__row td.pre-month + td.available.in-range div {
-    border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-left-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
   }
   &__row td.available.in-range:has(+ td.next-month) div {
-    border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-right-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
   }
🔗 Analysis chain

Review range border styling implementation

The current implementation has several concerns:

  1. The :has() selector has limited browser support
  2. Using --tv-DateTable-td-border-radius-disabled for range cells seems incorrect
  3. The current approach might not handle all edge cases correctly

Consider the following improvements:

   &__row td.pre-month + td.available.in-range div {
-    border-top-left-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-left-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-left-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-left-radius: var(--tv-DateTable-td-border-radius);
   }

-  &__row td.available.in-range:has(+ td.next-month) div {
+  &__row td.available.in-range:last-child div,
+  &__row td.available.in-range + td.next-month div {
-    border-top-right-radius: var(--tv-DateTable-td-border-radius-disabled);
-    border-bottom-right-radius: var(--tv-DateTable-td-border-radius-disabled);
+    border-top-right-radius: var(--tv-DateTable-td-border-radius);
+    border-bottom-right-radius: var(--tv-DateTable-td-border-radius);
   }

Let's verify browser compatibility requirements:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any browser compatibility requirements in the project
rg -l "browserslist|@supports|\.browserlist" --type yaml --type json

Length of output: 116


Script:

#!/bin/bash
# Check the browser compatibility configuration in package.json files
cat package.json packages/theme-saas/package.json | jq -r '.browserslist // empty'

# Check if :has() selector is already used elsewhere in the codebase
rg -l ":has\(" --type css --type less

# Check for existing border radius variables in theme files
rg "tv-DateTable-td-border-radius" --type css --type less

Length of output: 3768

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