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

fix(dropdown): [dropdown] rename getTip api in dropdown-item; replace reset.less cssvars by --tv- vars #2331

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Oct 21, 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

修改dropdown-item中的getTip函数
滚动条的cssvar替换
scrollbar的样式移到 scrollbar组件的最外层了

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new computed property for tooltip functionality, enhancing reactivity in dropdown items.
    • Added new properties to the dropdown item component: appendToBody, textField, tip, and tipPosition.
    • Implemented responsive scrollbar styles with new media query support.
  • Bug Fixes

    • Updated tooltip content binding to use the new computed property for improved consistency.
  • Style

    • Refactored CSS styles for scrollbars and removed outdated icon color definitions.
    • Changed scrollbar height from 80px to 8px for a more streamlined appearance.

Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes in this pull request primarily involve the refactoring of the tooltip handling in the dropdown item component. The getTip function has been renamed to computedTip, transitioning it into a computed property format to align with Vue's reactivity model. Additionally, several CSS styles related to icons and scrollbars have been updated or removed, reflecting a shift in variable usage and a simplification of styles. New properties have also been added to the dropdown item component to enhance its functionality.

Changes

File Path Change Summary
packages/renderless/src/dropdown-item/index.ts Renamed getTip to computedTip, modified its implementation to a computed property that checks if props.tip is a function.
packages/renderless/src/dropdown-item/vue.ts Updated API exports to reflect computedTip, added a computed property in initState, and modified initApi to use computedTip.
packages/theme/src/base/reset.less Removed several icon color class definitions, updated .tiny-hl-query-node color property, and changed scrollbar styles to use new variable names.
packages/theme/src/base/vars.less Updated scrollbar height variable from 80px to 8px.
packages/theme/src/scrollbar/index.less Added new media query styles for scrollbars for screens with a minimum width of 768px, defining styles for scrollbar appearance and behavior.
packages/vue/src/dropdown-item/src/pc.vue Modified v-auto-tip directive to use state.computedTip, and added new props: appendToBody, textField, tip, and tipPosition to enhance component functionality.

Possibly related PRs

Suggested labels

refactoring, bug

Suggested reviewers

  • zzcr

Poem

In the meadow where tips now gleam,
Computed properties reign supreme.
Icons fade, scrollbars slim,
A dropdown dance, a joyous whim!
With props anew, we hop and play,
In code we trust, come what may! 🐇✨


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 bug Something isn't working label Oct 21, 2024
@shenjunjian shenjunjian changed the title fix(dropdown): rename getTip api in dropdown-item; replace reset.less cssvars by --tv- vars fix(dropdown): [dropdown] rename getTip api in dropdown-item; replace reset.less cssvars by --tv- vars Oct 21, 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: 1

🧹 Outside diff range and nitpick comments (4)
packages/theme/src/scrollbar/index.less (1)

87-133: LGTM! Changes align well with PR objectives.

The new media query and its contents effectively implement the scrollbar styles using the --tv- prefixed CSS variables, which aligns with the PR objective of replacing reset.less cssvars. The comprehensive styling for both default and minimum scrollbar classes enhances the component's flexibility.

Consider using CSS variables for all border-radius values.

For consistency and easier maintenance, consider using CSS variables for all border-radius values, including the one on line 123.

Here's a suggested change:

-    border-radius: 2px;
+    border-radius: var(--tv-border-radius-scrollbar-thumb-min);

Don't forget to define this new variable in your variables file.

Add a comment explaining the media query's purpose.

To improve code readability and maintainability, consider adding a brief comment explaining the purpose of this media query.

Here's a suggested addition:

+// Apply custom scrollbar styles only on larger screens (tablets and above)
 @media (min-width: 768px) {
   // ... (existing code)
 }
packages/vue/src/dropdown-item/src/pc.vue (2)

16-18: LGTM! Consider destructuring state for cleaner template syntax.

The update to use state.computedTip aligns well with Vue's reactivity model and the refactoring mentioned in the summary. The addition of effect and tipPosition enhances the tooltip's customization options.

Consider destructuring state in the setup function to allow for a cleaner template syntax:

-v-auto-tip="
-  state.computedTip ? { always: true, content: state.computedTip, effect, placement: tipPosition } : false
-"
+v-auto-tip="
+  computedTip ? { always: true, content: computedTip, effect, placement: tipPosition } : false
+"

This change would require updating the setup function to return the destructured computedTip.


Line range hint 91-94: LGTM! Consider adding prop validation and documentation.

The addition of these new props enhances the component's flexibility and aligns with the changes seen in the template.

To improve maintainability and developer experience, consider:

  1. Adding prop validation for the new props. For example:
appendToBody: {
  type: Boolean,
  default: false
},
textField: {
  type: String,
  default: 'text'
},
tip: {
  type: [String, Function],
  default: ''
},
tipPosition: {
  type: String,
  default: 'top'
}
  1. Adding JSDoc comments to describe the purpose and expected values for each new prop.

  2. Updating the component's documentation to reflect these new props and their usage.

packages/renderless/src/dropdown-item/index.ts (1)

189-197: Approve changes with a minor suggestion for clarity.

The refactoring of getTip to computedTip is a good improvement. It aligns with Vue's reactivity model and provides more flexibility in computing the tip. The function correctly handles both function and non-function tip props, maintaining backwards compatibility.

Consider adding a type annotation for the return value of the inner function for improved clarity:

export const computedTip =
  ({ props, vm }: Pick<IDropdownItemRenderlessParams, 'props' | 'vm'>): () => string =>
  () => {
    if (props.tip && typeof props.tip === 'function') {
      return props.tip({ itemData: props.itemData, vm })
    }

    return props.tip || ''
  }

This change explicitly declares that the inner function returns a string, which matches the expected behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 65d3aeb and 24a9a5c.

📒 Files selected for processing (6)
  • packages/renderless/src/dropdown-item/index.ts (1 hunks)
  • packages/renderless/src/dropdown-item/vue.ts (4 hunks)
  • packages/theme/src/base/reset.less (2 hunks)
  • packages/theme/src/base/vars.less (1 hunks)
  • packages/theme/src/scrollbar/index.less (1 hunks)
  • packages/vue/src/dropdown-item/src/pc.vue (1 hunks)
🧰 Additional context used
🔇 Additional comments (8)
packages/vue/src/dropdown-item/src/pc.vue (1)

Line range hint 1-114: Overall, the changes look good and align with the PR objectives.

The modifications to the DropdownItem component improve its reactivity and add new customization options. The shift from getTip to computedTip enhances consistency with Vue's reactivity model, while the new props provide more flexibility in usage.

A few minor suggestions have been made to further improve code quality and developer experience:

  1. Consider destructuring state in the setup function for cleaner template syntax.
  2. Add prop validation for the new props.
  3. Enhance documentation with JSDoc comments and update the component's documentation to reflect the new props and their usage.

These changes contribute positively to the component's functionality and maintainability.

packages/renderless/src/dropdown-item/vue.ts (6)

40-40: LGTM: Import statement updated correctly.

The addition of computedTip to the import statement is consistent with the renaming of getTip to computedTip as mentioned in the PR objectives.


58-58: LGTM: API array updated correctly.

The replacement of 'getTip' with 'computedTip' in the api array is consistent with the renaming of the function and ensures that the new computedTip function is properly exposed in the API.


83-83: Clarify the purpose of adding children: [].

The addition of children: [] to the state object seems unrelated to the PR objectives. Could you please explain the purpose of this change? If it's not necessary, consider removing it to keep the changes focused on the stated objectives.


84-84: LGTM: computedTip added as a computed property.

The addition of computedTip as a computed property in the state object is consistent with the renaming of getTip to computedTip and aligns with the PR objectives.


111-111: LGTM: API initialization updated correctly.

The replacement of getTip: getTip({ props, vm }) with computedTip: computedTip({ props, vm }) in the initApi function is consistent with the renaming of the function and ensures that the new computedTip function is properly initialized in the API.


Line range hint 1-148: Overall, the changes align with the PR objectives, but one clarification is needed.

The renaming of getTip to computedTip has been consistently implemented throughout the file, including updates to imports, API array, state initialization, and API initialization. These changes align well with the PR objectives and the AI-generated summary.

However, the addition of children: [] to the state object (line 83) seems unrelated to the stated objectives. Please provide clarification on the purpose of this addition or consider removing it if it's not necessary for this PR.

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

441-441: Approved: Scrollbar height adjustment improves UI consistency

The change from 80px to 8px for the scrollbar height is a good improvement. This adjustment:

  1. Aligns the scrollbar height with the scrollbar width (8px).
  2. Provides a more standard and less obtrusive scrollbar size.
  3. Likely enhances the overall aesthetics and usability of scrollable elements in the UI.

This change should result in a more consistent and polished user interface across the application.

@@ -52,7 +31,7 @@

// 高亮节点
.tiny-hl-query-node {
color: var(--ti-common-color-text-highlight) !important;
color: var(----tv-color-text-active) !important;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the CSS variable name to ensure proper styling.

The CSS variable var(----tv-color-text-active) appears to have an extra pair of hyphens. CSS custom properties should begin with two hyphens --. Please correct it to var(--tv-color-text-active).

Apply this diff to fix the variable name:

-color: var(----tv-color-text-active) !important;
+color: var(--tv-color-text-active) !important;
📝 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
color: var(----tv-color-text-active) !important;
color: var(--tv-color-text-active) !important;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants