简体   繁体   English

如何使用react-jsonschema-form和material-ui?

[英]How to use react-jsonschema-form with material-ui?

I am doing a form using react-jsonschema-form , but i really want to customize my application (including the form) with the Material-UI . 我正在使用react-jsonschema-form做一个表单,但我真的想用Material-UI自定义我的应用程序(包括表单)。 I am having trouble to use both together because react-jsonchema-form uses a uiSchema for styling and the Material-UI is set on a prop like this : 我很难同时使用它们,因为react-jsonchema-form使用uiSchema进行样式设置,而Material-UI设置在这样的prop

SimpleModal.propTypes = {
  classes: PropTypes.object.isRequired,
}; 

<FormControl className={classes.formControl}>

How can i use the Material-UI inside the schema forms ? 如何在schema forms使用Material-UI

If you want use component in material UI i did like this... import material UI 如果你想在材质UI中使用组件,我确实喜欢这个...导入材质UI

        import TextField from '@material-ui/core/TextField'

declare constant and costum widgets 声明常量和costum小部件

          const MyCustomWidget = props => {
          return (
            <TextField
              type="text"
              label="Name1"
              value={props.value}
              onChange={event => props.onChange(event.target.value)}
              margin="normal"
            />
          )
        }

        const widgets = {
          TextWidget: MyCustomWidget,
        }

and in the return of my component 并在我的组件的返回

        return (
          <div>
            {' '}
            <Form schema={schema1} widgets={widgets} >
              {/* this is for disable the button Submit of Form */}{' '}
            </Form>
          </div>

It works for me 这个对我有用

Now you can start use it with standard react-jsonschema-form library! 现在您可以开始使用标准的react-jsonschema-form库! I searched for a long time and found that now it can already be done. 我搜索了很长时间,发现现在已经可以完成了。

This PR explain using HOC: https://github.com/mozilla-services/react-jsonschema-form/issues/1222 这个PR解释使用HOC: https//github.com/mozilla-services/react-jsonschema-form/issues/1222

GitHub: https://github.com/cybertec-postgresql/rjsf-material-ui GitHub: https//github.com/cybertec-postgresql/rjsf-material-ui

Playground with material-ui components: https://cybertec-postgresql.github.io/rjsf-material-ui/ 带有material-ui组件的游乐场: https//cybertec-postgresql.github.io/rjsf-material-ui/

import { withTheme } from 'react-jsonschema-form';
import { Theme as MuiTheme } from 'rjsf-material-ui';

const Form = withTheme(MuiTheme);

Weird to see there's no answer. 很奇怪看到没有答案。

Quick answer: you cant! 快速回答: 你不能!

Check out project's FAQ about that, it says: 查看项目的常见问题解答 ,它说:

Q: Will react-jsonschema-form support Material, Ant-Design, Foundation, or [some other specific widget library or frontend style]? 问:react-jsonschema-form是否支持Material,Ant-Design,Foundation或[其他一些特定的小部件库或前端样式]?

A: Probably not. 答:可能不是。 We use Bootstrap v3 and it works fine for our needs. 我们使用Bootstrap v3,它可以满足我们的需求。 We would like for react-jsonschema-form to support other frameworks, we just don't want to support them ourselves. 我们希望react-jsonschema-form支持其他框架,我们只是不想自己支持它们。 Ideally, these frontend styles could be added to react-jsonschema-form with a third-party library. 理想情况下,这些前端样式可以添加到react-jsonschema-form与第三方库。

But ! 但是 ... :) don't go so fast! ...... :)不要这么快!

The closest I have come to achieve a Material "look and feel" was to use a Bootstrap Theme, Paper by Bootswatch which is quite nice! 我最接近实现材料“外观和感觉”的是使用Bootstrap主题, Bootswatch的纸张非常好!

Hope this helps anyone 希望这有助于任何人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM