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: replace input component in IconPicker #5047

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 6, 2024

Description

将IconPicker中的Input替换为当前组件库的Input。 fix: #5041

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced IconPicker component functionality across multiple applications, allowing for more customizable props such as iconSlot and inputComponent.
    • Introduced dynamic component rendering for improved flexibility in input types within the icon-picker.vue.
    • Simplified integration of the IconPicker with the Input component, streamlining the user interaction process.
  • Bug Fixes

    • Improved error handling in the currentList property for better management of icon loading errors.
  • Documentation

    • Updated properties in the Props interface for the icon-picker.vue to reflect new options and defaults.

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners December 6, 2024 01:14
Copy link

changeset-bot bot commented Dec 6, 2024

⚠️ No Changeset found

Latest commit: 19f43e2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

playground/src/views/demos/features/icons/index.vue

Oops! Something went wrong! :(

ESLint: 9.16.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

Walkthrough

The pull request modifies the IconPicker component across multiple files, transitioning it from a direct import to a functional component that allows for additional props. These props include iconSlot, inputComponent, and modelValueProp, enhancing the component's configurability and integration within various adapters. The changes are consistent across web-antd, web-ele, web-naive, and playground applications, while the icon-picker.vue file sees updates to its properties and methods, improving flexibility and error handling.

Changes

File Change Summary
apps/web-antd/src/adapter/component/index.ts Updated IconPicker to a functional component with props iconSlot: 'addonAfter', inputComponent: Input.
apps/web-ele/src/adapter/component/index.ts Updated IconPicker to a functional component with props iconSlot: 'append', modelValueProp: 'model-value', inputComponent: ElInput.
apps/web-naive/src/adapter/component/index.ts Updated IconPicker to a functional component with props iconSlot: 'suffix', inputComponent: NInput.
playground/src/adapter/component/index.ts Updated IconPicker to a functional component with props iconSlot: 'addonAfter', inputComponent: Input.
packages/effects/common-ui/src/components/icon-picker/icon-picker.vue Added new properties to Props interface, introduced onKeywordChange method, and replaced static Input with dynamic component.

Assessment against linked issues

Objective Addressed Explanation
Fix styling issues with IconPicker in forms (#5041)

Possibly related PRs

  • feat: form component IconPicker #5005: The changes in this PR involve the addition of the IconPicker component to the initComponentAdapter function, which is directly related to the modifications made to the IconPicker component in the main PR.
  • feat: add icon-picker component #4832: This PR introduces the icon-picker component, which is the same component being modified in the main PR, indicating a direct relationship in terms of functionality and purpose.
  • fix(@vben/common-ui): pagination current page error #4893: This PR addresses pagination functionality within the icon-picker component, which is relevant to the changes made in the main PR regarding the IconPicker component's implementation.
  • fix: resolve onChange issue in form component #4890: While this PR focuses on resolving an onChange issue in a form component, it is related to the overall context of form handling, which includes the IconPicker as a form component in the main PR.
  • fix: select Long option style problem #5030: This PR focuses on styling issues in select components, which may indirectly relate to the overall form handling and UI consistency that the IconPicker aims to achieve in the main PR.

Suggested labels

bug

Suggested reviewers

  • vince292007
  • anncwb

🐰 In the garden where icons bloom,
A picker now sheds its old costume.
With props anew, it dances bright,
Enhancing forms, a joyful sight!
Click and choose, let creativity flow,
With every icon, let your ideas grow!
🌼✨


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.

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (3)
playground/src/adapter/component/index.ts (1)

Line range hint 91-103: Excellent architectural approach to framework adaptation.

The consistent pattern of adapting IconPicker for each UI framework while respecting their specific conventions (suffix/append/addonAfter slots) is a robust solution to the styling issues. This approach ensures proper integration with each framework's form components and design system.

Also applies to: 91-103, 106-112

packages/effects/common-ui/src/components/icon-picker/icon-picker.vue (2)

45-48: Consider more specific default values

The default value for inputComponent is a simple div, which might not provide the expected input behavior.

Consider providing a more functional default:

-  inputComponent: () => h('div'),
+  inputComponent: () => h('input', { type: 'text' }),

157-157: Consider adding error boundary

The search input implementation might benefit from error handling for edge cases.

Consider wrapping the dynamic component with error handling:

-      <component :is="inputComponent" v-bind="searchInputProps" />
+      <component :is="inputComponent" v-bind="searchInputProps" @error="handleError" />

And add the error handler:

function handleError(e: Error) {
  console.error('Search input error:', e);
  // Handle gracefully
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 21d37a1 and 63f04b9.

📒 Files selected for processing (5)
  • apps/web-antd/src/adapter/component/index.ts (1 hunks)
  • apps/web-ele/src/adapter/component/index.ts (1 hunks)
  • apps/web-naive/src/adapter/component/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/icon-picker/icon-picker.vue (4 hunks)
  • playground/src/adapter/component/index.ts (1 hunks)
🔇 Additional comments (7)
apps/web-naive/src/adapter/component/index.ts (1)

92-98: LGTM! Implementation aligns with Naive UI patterns.

The IconPicker implementation correctly uses Naive UI's suffix slot pattern and properly integrates with NInput. Props spreading order ensures framework-specific props take precedence.

Let's verify the IconPicker integration with Naive UI forms:

✅ Verification successful

IconPicker integration is properly implemented and used correctly

Based on the verification results:

  1. The IconPicker is correctly used within forms as shown in playground/src/views/examples/form/basic.vue
  2. The component itself (icon-picker.vue) is framework-agnostic and uses a flexible slot system that works with any UI framework's input component
  3. The Naive UI adapter correctly sets iconSlot: 'suffix' which aligns with Naive UI's design patterns for input components with icons
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for IconPicker usage within form components
rg -l "IconPicker.*NForm" --type vue

Length of output: 66


Script:

#!/bin/bash
# Search for IconPicker usage in all files, including .tsx and .ts extensions
rg "IconPicker.*Form" -A 3 -B 3

Length of output: 33


Script:

#!/bin/bash
# Find all files that might contain IconPicker usage
fd -e ts -e tsx -e vue | xargs rg "IconPicker"

Length of output: 2249


Script:

#!/bin/bash
# Look for form-related components that might use IconPicker
ast-grep --pattern 'import { IconPicker } from $$$'

Length of output: 53


Script:

#!/bin/bash
# Let's check the basic form example that uses IconPicker
cat playground/src/views/examples/form/basic.vue

Length of output: 8547


Script:

#!/bin/bash
# Check the implementation of the IconPicker component itself
cat packages/effects/common-ui/src/components/icon-picker/icon-picker.vue

Length of output: 5675

apps/web-ele/src/adapter/component/index.ts (1)

91-103: LGTM! Properly adapted for Element Plus conventions.

The implementation correctly:

  • Uses Element Plus's append slot for icons
  • Sets model-value prop for proper v-model binding
  • Integrates with ElInput component

Let's verify the IconPicker integration with Element Plus forms:

✅ Verification successful

IconPicker integration with Element Plus forms verified successfully

The implementation is correctly adapted and working as expected:

  • Used within form components as demonstrated in playground/src/views/examples/form/basic.vue
  • Properly integrates with Element Plus Input as shown in the demos
  • Supports both standalone and form-embedded usage patterns
  • Correctly handles icon selection through the append slot
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for IconPicker usage within Element Plus forms
rg -l "IconPicker.*ElForm" --type vue

Length of output: 67


Script:

#!/bin/bash
# Search for IconPicker usage in all files, including .vue files
rg -l "IconPicker.*Form"

# Also search for general IconPicker usage to understand integration patterns
rg -l "IconPicker"

Length of output: 425


Script:

#!/bin/bash
# Check IconPicker usage in form examples and demos
rg -A 5 -B 5 "IconPicker" playground/src/views/examples/form/basic.vue

# Check IconPicker implementation in Element Plus form demo
rg -A 5 -B 5 "IconPicker" playground/src/views/demos/features/icons/index.vue

Length of output: 1949

playground/src/adapter/component/index.ts (1)

106-112: LGTM! Follows Ant Design Vue conventions.

The implementation correctly uses Ant Design Vue's addonAfter slot pattern and integrates with the Input component.

Let's verify the IconPicker integration with Ant Design forms:

✅ Verification successful

IconPicker integration verified and working as expected

The component is correctly integrated in the form system and follows Ant Design Vue patterns:

  • Found in basic form example (playground/src/views/examples/form/basic.vue) as a form field component
  • Implementation with addonAfter slot aligns with Ant Design Vue's input addon pattern
  • Props spreading ensures proper framework integration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for IconPicker usage within Ant Design forms
rg -l "IconPicker.*Form" --type vue

# Verify the icon rendering in addonAfter slot
ast-grep --pattern 'IconPicker iconSlot="addonAfter"'

Length of output: 121


Script:

#!/bin/bash
# Search for IconPicker usage in all files
rg -l "IconPicker"

# Search for specific IconPicker usage patterns
rg "IconPicker.*Form" -A 2

# Look for form-related files that might use IconPicker
fd -e ts -e tsx -e vue -e js ".*form.*" -i

Length of output: 1792


Script:

#!/bin/bash
# Check IconPicker usage in form examples
rg -A 5 "IconPicker" playground/src/views/examples/form/basic.vue

# Check IconPicker implementation in other UI framework adapters
rg -A 5 "IconPicker.*Input" apps/web-antd/src/adapter/component/index.ts
rg -A 5 "IconPicker.*Input" apps/web-ele/src/adapter/component/index.ts
rg -A 5 "IconPicker.*Input" apps/web-naive/src/adapter/component/index.ts

Length of output: 405

apps/web-antd/src/adapter/component/index.ts (1)

105-111: LGTM! Verify component integration

The changes correctly integrate the ant-design-vue Input component with IconPicker, using the appropriate 'addonAfter' slot for icon placement. This aligns with the PR objective of fixing styling issues.

Let's verify the IconPicker integration across the codebase:

✅ Verification successful

IconPicker integration verified successfully

The codebase analysis shows that the IconPicker component is properly integrated across different UI framework adaptations:

  • Element Plus uses append slot with ElInput
  • Naive UI uses suffix slot with NInput
  • Ant Design uses addonAfter slot with Input

The component is used in various scenarios:

  • Form fields (playground/src/views/examples/form/basic.vue)
  • Icon demonstration pages with different configurations
  • Properly imported from @vben/common-ui across all framework adaptations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify IconPicker usage and potential styling issues
# Look for IconPicker usage in form components
rg -g '*.{vue,tsx}' -A 5 'IconPicker.*Form'

Length of output: 45


Script:

#!/bin/bash
# Let's try a broader search for IconPicker usage
rg -g '*.{vue,tsx,ts}' -A 5 'IconPicker'

# Also search for potential icon-related form fields
rg -g '*.{vue,tsx,ts}' -B 2 -A 5 'icon.*Form|Form.*icon'

# Check if there are any specific icon-picker components
fd -e vue -e tsx -e ts IconPicker

Length of output: 9253

packages/effects/common-ui/src/components/icon-picker/icon-picker.vue (3)

31-38: LGTM! Well-defined props interface

The new props enhance component flexibility and allow proper integration with different UI libraries. The props are well-documented with clear TypeScript types.


124-135: LGTM! Clean implementation of input handling

The keyword change handler and computed props are well-implemented:

  • Proper event handling with modelValueProp
  • Consistent class naming
  • Clear placeholder text

146-154: Verify dynamic component integration

The template changes look good, using the dynamic component correctly. However, let's verify the integration with different UI libraries.

Let's check the usage across different UI libraries:

✅ Verification successful

Dynamic component integration verified successfully

The IconPicker component is correctly integrated with different UI libraries:

  • Element Plus: Uses ElInput with append slot and model-value prop
  • Naive UI: Uses NInput with suffix slot
  • Ant Design: Uses Input with addonAfter slot

The component properly handles different input components and slot names through props, making it adaptable across UI frameworks. The implementation in icon-picker.vue correctly uses these dynamic props with proper defaults.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify IconPicker integration across UI libraries
# Look for IconPicker usage in different UI library adapters
rg -g '**/adapter/**/*.{ts,tsx}' 'IconPicker.*inputComponent'

Length of output: 63


Script:

#!/bin/bash
# Let's try a broader search to understand the IconPicker component structure and its usage
# First, let's find all files related to IconPicker
fd "icon-picker" --type f

# Then let's look for any props or setup related to inputComponent
rg "inputComponent" -A 5 -B 5

# Also search for IconPicker usage patterns
rg "IconPicker" -A 3 -B 3

Length of output: 19551

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (1)
playground/src/views/demos/features/icons/index.vue (1)

88-89: Consider adding aria-label for accessibility.

The integration of Input component with IconPicker looks good. Consider adding an aria-label to improve accessibility when icons are used as interactive elements.

-        <IconPicker :input-component="inputComponent" icon-slot="addonAfter" />
+        <IconPicker 
+          :input-component="inputComponent" 
+          icon-slot="addonAfter"
+          aria-label="Select icon" 
+        />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 63f04b9 and 19f43e2.

📒 Files selected for processing (1)
  • playground/src/views/demos/features/icons/index.vue (4 hunks)
🔇 Additional comments (2)
playground/src/views/demos/features/icons/index.vue (2)

2-2: LGTM! Verify component creation approach.

The addition of h function and creation of inputComponent looks good. This approach allows for proper integration of the Ant Design Vue Input component with IconPicker.

Let's verify if this is the recommended approach for component creation in the codebase:

Also applies to: 24-25

✅ Verification successful

Based on the context gathered, I can now provide the final response:

Using h function is appropriate in this case

The use of Vue's h function to create the input component is the correct approach here as:

  1. It's being used to create a component instance that needs to be passed as a prop to IconPicker
  2. The component is simple and doesn't require complex configuration
  3. This pattern is consistent with the file's purpose as a demo component showcasing different icon picker configurations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances of component creation using h function
# to ensure consistency with the codebase patterns
rg "const \w+ = h\(" -A 2

Length of output: 227


Script:

#!/bin/bash
# Let's search for alternative patterns of component creation in Vue files
# to understand the common patterns used in the codebase
rg "defineComponent|createVNode|render\(" -A 2 "\.vue$"

Length of output: 104


Script:

#!/bin/bash
# Let's also check if there are any style guide or component documentation files
# that might specify the preferred approach
fd "README|CONTRIBUTING|GUIDE" -e md -X cat {}

Length of output: 20508


Script:

#!/bin/bash
# Check for other Vue files in the same directory to understand local patterns
fd -e vue -p "playground/src/views/demos/features/icons" -x cat {}

Length of output: 3163


100-100: Verify IconPicker props documentation.

The usage of v-model binding looks correct. Let's ensure the new props are properly documented.

@vince292007 vince292007 merged commit d1862fb into vbenjs:main Dec 6, 2024
14 checks passed
@vince292007 vince292007 added the bug Something isn't working label Dec 6, 2024
@mynetfan mynetfan deleted the fix/icon-picker branch December 8, 2024 13:18
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.

Bug: 表单引入示例图标选择器会导致样式异常
2 participants