Skip to content

Conversation

@Elm1992
Copy link
Contributor

@Elm1992 Elm1992 commented Jul 12, 2025

Description

image 函数式的写法更灵活一些,遇到这种动态变class的时候,不用把逻辑单拎出一块写。

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Summary by CodeRabbit

  • New Features

    • The form item class property now supports both static strings and dynamic functions, allowing for more flexible styling of form items.
  • Documentation

    • Updated documentation to reflect the enhanced support for dynamic form item class definitions.

@Elm1992 Elm1992 requested review from a team, anncwb, jinmao88, mynetfan and vince292007 as code owners July 12, 2025 06:42
@changeset-bot
Copy link

changeset-bot bot commented Jul 12, 2025

⚠️ No Changeset found

Latest commit: 9c6cf1b

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 12, 2025

Walkthrough

The changes introduce support for the formItemClass property in form configuration to accept either a static string or a function returning a string. This is achieved by updating type definitions, documentation, and runtime handling to resolve the class dynamically if a function is provided.

Changes

File(s) Change Summary
docs/src/components/common-ui/vben-form.md Updated documentation to reflect that formItemClass can now be a string or a function returning a string.
packages/@core/ui-kit/form-ui/src/types.ts Updated FormCommonConfig.formItemClass type to `(() => string)
packages/@core/ui-kit/form-ui/src/form-render/form.vue Added runtime check to invoke formItemClass if it is a function with error handling; updated imports.

Suggested reviewers

  • jinmao88

Poem

A string or a function, now both are allowed,
For styling your forms, developers are wowed!
With types extended and docs made clear,
Dynamic classes bring new cheer.
Rabbits hop and forms now flex—
Code that adapts, what’s next?
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a24274a and 9c6cf1b.

📒 Files selected for processing (1)
  • packages/@core/ui-kit/form-ui/src/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/@core/ui-kit/form-ui/src/types.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: post-update (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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: 1

🧹 Nitpick comments (1)
packages/@core/ui-kit/form-ui/src/types.ts (1)

180-183: Consider function parameters for enhanced flexibility.

The current function signature () => string provides basic dynamic class support. For more advanced use cases, consider if the function should receive parameters like form values or field context in future iterations.

Current implementation is appropriate for the stated requirements.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8bf482 and 1845e59.

📒 Files selected for processing (3)
  • docs/src/components/common-ui/vben-form.md (1 hunks)
  • packages/@core/ui-kit/form-ui/src/form-render/form.vue (3 hunks)
  • packages/@core/ui-kit/form-ui/src/types.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/@core/ui-kit/form-ui/src/form-render/form.vue (1)
Learnt from: mynetfan
PR: vbenjs/vue-vben-admin#5075
File: packages/effects/common-ui/src/components/api-select/api-select.vue:61-62
Timestamp: 2024-12-09T04:41:58.914Z
Learning: 在文件 `packages/effects/common-ui/src/components/api-select/api-select.vue` 的组件 `ApiSelect` 中,`childrenField` 的默认值设置为空字符串是有意的,因为并非所有组件都使用树形数据。
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (4)
docs/src/components/common-ui/vben-form.md (1)

398-398: Documentation correctly reflects the new function support.

The type annotation accurately represents the new union type that allows formItemClass to be either a string or a function returning a string.

packages/@core/ui-kit/form-ui/src/form-render/form.vue (2)

15-20: Import addition looks good.

The isFunction utility import is necessary for the new functionality and is correctly added.


147-147: Correct usage of resolved class value.

The resolved formItemClass value is properly used in the cn() function call, maintaining the correct class merging behavior.

packages/@core/ui-kit/form-ui/src/types.ts (1)

38-39: Well-designed type extension.

The FormItemClassTypeExtended type alias cleanly extends the existing functionality while maintaining backwards compatibility through the union type approach.

@jinmao88
Copy link
Collaborator

有类型警告的报错 看看能否解决

@Elm1992
Copy link
Contributor Author

Elm1992 commented Jul 16, 2025

有类型警告的报错 看看能否解决

改啦

@jinmao88 jinmao88 merged commit 07b64ad into vbenjs:main Jul 17, 2025
13 checks passed
xionglongjun pushed a commit to stack-haven/avmc-frontend-service that referenced this pull request Jul 23, 2025
* feat: add function support for formItemClass prop

* feat: add try-catch to formItemClass function

* fix: formItemClass function ts error

---------

Co-authored-by: sqchen <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants