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/custom template per field #4352

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

lucasmcht
Copy link

Fixes #3695 (Rework of PR #3881)

Reasons for making this change

Currently, to per-field customize the template, it is necessary to send the function/class of the component in the uiSchema, breaking the JSON nature of the uiSchema. It's not possible to provide just the registration key.

This pull request includes updates to the @rjsf/utils package to allow for per-field customization using string keys from the Registry, as well as updates to the documentation to reflect these changes. Additionally, it simplifies the types in the codebase by introducing a new RJSFBaseProps type.

Feature Enhancements

  • packages/utils/src/getTemplate.ts: Updated getTemplate() to allow per-field customization using string keys from the Registry.

Documentation Updates

  • packages/docs/docs/advanced-customization/custom-templates.md: Updated to include examples of specifying templates using both components and string values from the Registry.

Type Simplification

  • packages/utils/src/types.ts: Introduced RJSFBaseProps to simplify and consolidate the properties passed to various template components. This change affects multiple type definitions, including ErrorListProps, FieldErrorProps, FieldHelpProps, FieldTemplateProps, and others.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

packages/utils/src/types.ts Outdated Show resolved Hide resolved
packages/utils/src/types.ts Outdated Show resolved Hide resolved
/** The `registry` object */
registry: Registry<T, S, F>;
};

/** The set of RJSF templates that can be overridden by themes or users */
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding documentation around the change you made below, here as well

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what kind of documentation I should add, could you specify please ?

Copy link
Member

Choose a reason for hiding this comment

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

I suggest mentioning the ability to add per-field customizations and maybe add an example of a custom template since it is now supported?

Choose a reason for hiding this comment

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

Wow, I'm super glad this feature is finally getting into the master branch. It's almost having an one year birthday 🎂. We use this feature extensively to customize the layout of the form. I think its a very nice use case to describe in the docs, since I'm aware it's a very long desired flexibility. I could also contribute by providing the Layout template.

@heath-freenome
Copy link
Member

@lucasmcht Also, can you fix the type errors in the themes?

@heath-freenome
Copy link
Member

@lucasmcht Some of your tests are failing

@heath-freenome
Copy link
Member

@lucasmcht Please fix the tests so that we can merge this. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

current per-field customization break JSON rules
3 participants