@react-jsonschema-form-custom/material-ui-fy2ybeyiz

Material UI implementation of react-jsonschema-form

Usage no npm install needed!

<script type="module">
  import reactJsonschemaFormCustomMaterialUiFy2ybeyiz from 'https://cdn.skypack.dev/@react-jsonschema-form-custom/material-ui-fy2ybeyiz';
</script>

README

React Json Schema Form Custom (material-ui-fy2ybeyiz)

Material UI port of jsonschema-form.

live playground and Detailed Docs

Install instructions via npm

npm install --save @react-jsonschema-form-custom/material-ui-fy2ybeyiz

Example Usage

More detailed example can be seen here

// Library
import React from 'react';
import MaterialJsonSchemaForm from '@react-jsonschema-form-custom/material-ui-fy2ybeyiz';

// Internals
const schema = require('./path-to your-schema.json');
const uiSchema = require('./path-to your-ui-schema.json');
const formData = require('./path-to your-ui-formData.json');

const Example () => {
    const onSubmit = (value, callback) => {
        console.log('onSubmit: %s', JSON.stringify(value)); // eslint-disable-line no-console
        setTimeout(() => callback && callback(), 2000); // just an example in real world can be your XHR call
    }
    
    const onCancel = () => {
        console.log('on reset being called');
    }
    
    const onFormChanged = ({ formData }) => {
        console.log('onFormChanged: ',formData); // eslint-disable-line no-console
    }
    
    const onUpload = (value) => {
        console.log('onUpload: ', value); // eslint-disable-line no-console
    }
    
    return (
      <MaterialJsonSchemaForm
        schema={givenSchema}
        uiSchema={givenUISchema}
        formData={givenFormData}
        onCancel={onCancel}
        onSubmit={onSubmit}
        onUpload={onUpload}
        onChange={onFormChanged}
        onError={onError}
        /* Optional Param for custom functions to be executed for transforming data */
        interceptors={{
            translateRatings: (givenData, uiData) => ({ givenData, uiData }),
        }}
        /* Optional Param for custom components */
        components={{
        customComponent: ({ onChange, ...rest }) => (
          <CustomComponent onChange={onChange} formData={givenFormData} uiData={givenUIData} {...rest} />
        ),
        customRating: ({ onChange, ...rest }) => (
          <CustomRating onChange={onChange} formData={givenFormData} uiData={givenUIData} {...rest} />
        ),
        }}
        /* Optional Param for custom validation */
        validations={{
            confirmPassword: ({ schema, validations, formData, value }) => value !== formData.pass1 && ({
            message: validations.confirmPassword.message,
            inline: true,
            }),
        }}
        /* Optional Param to auto submit form on press of enter */
        submitOnEnter
      />
    );
}

export default Example;