-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Enable antd (ant-design) support #1561
Conversation
Hi. I've added a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This will be a great addition to the library.
I'm going to focus on getting the playground (#1539) done before merging additional themes, so it will be easier to test and preview what's going on.
packages/antd/package.json
Outdated
"less-loader": "^5.0.0", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react-jsonschema-form": "^2.0.0-alpha.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can move some of these (react
, react-dom
, react-jsonschema-form
) to devDependencies
.
packages/antd/package.json
Outdated
@@ -0,0 +1,79 @@ | |||
{ | |||
"name": "@react-jsonschema-form/antd", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"name": "@react-jsonschema-form/antd", | |
"name": "@rjsf/antd", |
This is the name under which the package will be published. Can you rename to the above? Once this PR is merged, I can publish it under the rjsf
npm organization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please replace other occurrences in the readme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to double-check, will the core package remain react-jsonschema-form
, or will that also migrate to the rjsf
npm organization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning more towards keeping it called react-jsonschema-form
. It would be easier to upgrade that way; and that way, if someone installs the @latest
version of it, they won't get the v2.0.0-alpha.1 alpha version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, just to let you know, I've updated this -- changed the name back to @rjsf/core
for the core package -- it seemed best to keep all rjsf packages under the @rjsf
organization to maintain a clear separation between org-owned packages and other community packages. We can still keep this called @rjsf/antd
though.
packages/antd/README.md
Outdated
|
||
### Prerequisites | ||
|
||
- `antd == 3` (not tested yet with version 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you envision having to make a separate theme to support antd 4, or can one theme support both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, antd 4 introduced breaking changes related to the Form component. I haven't looked into the details yet, but I think we need to fix a period of time where we support two themes, and then slowly deprecate antd 3.
packages/antd/README.md
Outdated
- `react-jsonschema-form >= 1.6.0` | ||
|
||
```sh | ||
npm install antd @react-jsonschema-form/core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm install antd @react-jsonschema-form/core | |
npm install antd react-jsonschema-form |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Hi. I'm using Ant Design and would like to use react-jsonschema-form. I need to settle on an approach very shortly, and I was just wondering if there is a rough ETA for this merge? |
@jeremypeters Just saw that the dependencies from OP are now merged. So I will have a look and finalise this pull request in the next week or so. I'm very busy at the moment, unfortunately, but will get to it. |
Thanks @delyanr . No worries at all - totally understand. I'll just use the Ant Design CSS for the time-being 👍 |
@epicfaace Almost at the finish line now with this pull request. Seems like the checks are failing because the Finally, I spent a decent amount of time getting the antd styles to work in the playground but failed miserably. Any help to get that one, so we can finally merge would be greatly appreciated. Any ideas why that might not be working correctly? Thanks! |
Hey! Any update on this? :) |
Base on previous work, I created a workable antd 4.0 with 2.0.0 rjsf, storybook here https://apis.wener.me/storybook/?path=/story/rjsf-demo--playground ,not pub to npm yet, consider to make a pr, but for now, anyone want to use antd, just copy and paste https://github.com/wenerme/apis/tree/master/packages/ui/stories/rjsf/antd. then, everything should just works! |
@erikhofer I'm going through an internal update to v4 this week, so will have a look at this during the weekend to try and finalise it (and maybe split into v3 and v4 versions). In the meantime, what @wenerme pointed to should work. Thanks |
Current antd rjsf is followed the bootstrap style, but should not follow every style, antd's component can be more expressive,like the title and description, reorder should also support dnd, can support more input widgets. |
@delyanr thanks for your help! Now that we have the infrastructure for tests / etc. for material-ui ready, we should be able to merge this in soon. Could you add some simple snapshot tests such as the ones in material-ui (https://github.com/rjsf-team/react-jsonschema-form/tree/master/packages/material-ui/test)? |
<Select.Option | ||
disabled={enumDisabled && enumDisabled.indexOf(value) !== -1} | ||
key={String(optionValue)} | ||
value={String(optionValue)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this just be value={optionValue}
? OptionValue can be a number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this a while ago now, but I remember I had some issues with boolean values. Playing around with the latest Antd version, I see that they work well, but are not part of the typescript props, so prefer to still pass through strings to be honest.
getPopupContainer={getPopupContainer} | ||
id={id} | ||
mode={typeof multiple !== 'undefined' ? 'multiple' : undefined} | ||
name={id} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think name is one of the Antd Select props -- any reason this is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There have been issues raised around the name
attribute for the Select component, e.g. ant-design/ant-design#12612. Generally agree that this should be part of the Select component. However, for the purposes of RJSF we don't need it, so happy to remove. Any reason we should not leave it though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good -- thanks for your work on this. Can you address the license issue -- and then we can merge?
Some things which we should fix (but need not block this merge):
- When I update the value of altdatewidget / alttimewidget, it doesn't call onChange properly -- the formData isn't updating on the playground.
- When I change the name of the key in additionalProperties and focus out, the key name changes, but then the textbox for the key becomes blank (when it should actually still have the same value as before).
- It would be nice to (later) convert this source to typescript and use tsdx instead of webpack for building, so we have some kind of unified build process for all themes (the hope is that we can do this with @rjsf/core eventually, too).
- If someone has already imported the antd css in their project, is there a way to still use @rjsf/antd without causing duplicate imports (as it stands, I believe we will end up having this css duplicated)?
I've fixed the first two points. Not sure I have the time to address the other two at this time, sorry. Once this is merged, others are free to contribute, etc. Thanks |
@@ -64,8 +64,6 @@ const SelectWidget = ({ | |||
|
|||
const { enumOptions, enumDisabled } = options; | |||
|
|||
const emptyValue = multiple ? [] : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this? I think this is required for multiple select support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too, but seems like Ant Design component handles it just fine. Having the emptyValue
however breaks the placeholder, so that's a bug there, and hence why I removed it. You can try it in the playground.
For some reason the deploy preview (https://deploy-preview-1561--rjsf.netlify.app/) is not working. Looking into it... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@delyanr can you explain what antd-dayjs-webpack-plugin
is for and why it's a peer dependency? If someone uses another non-webpack build system, they won't need it, right?
@delyanr is there an alternative way that lets us not include the Additionally, adding versus regular playground: |
Looks like we may need to do this for the above problem: https://ant.design/docs/react/customize-theme#How-to-avoid-modifying-global-styles -- or maybe we could try lazy-loading antd into the playground iframe somehow |
* Enable antd (ant-design) support * Change name of package in local package.json for consistency * Add local readme file * Tidy the package dependencies * Change README.md references to rjsf npm organisation * Update package.json an dimports to reflect the new rjsf organization * Deprecate antd custom withTheme as core now has forwardRef * Ensure Theme is not default export for consistency * Add scripts for building dist and lib in package.json * Fix test to use non-default import * Add babel-plugin-import to ensure styles are imported on demand * Add rjsf-antd theme to the playground * Migrate rjsf-antd code to antd v4 support * Implement EmailWidget and URLWidget for rjsf-antd * Reimplement rjsf-antd tests based on latest * Enable rjsf-antd support in the playground * Finalise rjsf-antd packages files * Remove useless build:lib script * Enable support for additionalProperties schemas * Update the test snapshots * Fix minor styling issues with descriptions * Ensure popups are rendered next to fields (even when used with iframes) * Implement AltDate/AltDateTimeWidgets for antd theme * update package-lock * Fix SelectWidget placeholder never being shown * Fix issue with the alternative date pickers * Fix issue with additionalProperties blanking out * Change license for consistency * Add semicolon * build cjs, es, and umd * antd - switch to new build process, fix global styles Co-authored-by: Ashwin Ramaswami <[email protected]>
- Ensure the root field is always wrapped in Form.Item The original ternary expression has existed since the antd theme was added in rjsf-team#1561. I am not familiar enough with antd to know what, if any, undesirable effects this change could cause.
Reasons for making this change
Implement antd (ant-design) theme, fields and widgets as separate sub-package. Usage is as simple as importing the
Form
component from the package.Pending to-dos:
README.md
file.withTheme
HOC. Deps: add forwardRef to withTheme #1498Regarding the last to-do, could you let me know what needs to be done to publish the package (I've never used lerna before)?
Checklist