/ui-schema

React Form + UI generator for any design system, based on JSON-Schema

Primary LanguageJavaScriptMIT LicenseMIT

UI-Schema Logo

UI-Schema for React

JSON-Schema form + ui generator for any design system, first-class support for Material UI React.

Travis (.org) branch react compatibility MIT license

  • @ui-schema/ui-schema npm (scoped)

  • @ui-schema/ds-material npm (scoped)

  • @ui-schema/ds-bootstrap npm (scoped)

  • Additional Material-UI Widgets:

    • Date-Time Picker: @ui-schema/material-picker npm (scoped) Component Documentation
    • Codemirror as Material Input: @ui-schema/material-code npm (scoped) Component Documentation
    • DraftJS as Material TextField: @ui-schema/material-richtext npm (scoped) Component Documentation
    • Color Pickers: @ui-schema/material-color npm (scoped) Component Documentation

Documentation

Quick-Start

Schema Examples + Live Editor

Chat on Spectrum

🚀 Demo: UI-Schema + Material Design + CRA

Fullscreen Demo

Run on CodeSandbox

Run on Repl.it Clone on Repl.it

Demo Source


⚠️Work in progress!

UI-Schema is an extract and rewrite of the form-generator logic used internally by our admin panel.

The fundamentals are working, but a lot of JSON-schema stuff, code testing and widgets needs to be done.

Schema

JSON-Schema included keywords are used to describe the data and create the UI based on the data-schema and special UI keywords. A data-schema with integrated ui-schema enforces the consistency of the UX across different apps and devices.

Schema Documentation

Features

  • add any design-system and custom widget
  • translation of widgets
    • with any library
    • (optional) integrated translation library
    • include translation in schema
    • single or multi-language
  • modular core
    • add own validator plugins
    • add own schema-driven plugins
    • use what you need
  • performance optimized, only updates HTML which must re-render, perfect for big schemas
  • supports code-splitting (with custom widget mappings, lazy-loading widgets)
  • includes helper functions for store handling
  • conditional and combining schemas
  • easy nesting of editor for object/array widgets
  • supports JSON-Schema 2019-09 / draft-8

Design-System and Widgets Overview

Basic Example

This example shows the available props.

First time? Take the quick-start or take a look into the create-react-app UI-Schema example.

import React from "react";

// Import Schema-Editor
import {
    SchemaEditor,
    isInvalid,
    createOrderedMap, createStore, 
    createMap, createEmptyStore,
    updateValue
} from "@ui-schema/ui-schema";

// Get the widgets binding for your design-system
import {widgets} from "@ui-schema/ds-material";

// could be fetched from some API or bundled with the app
const schemaBase = {
    type: "object",
    properties: {
        country: {
            type: "string",
            widget: "Select",
            enum: [
                "usa",
                "canada",
                "eu"
            ],
            default: "eu"
        },
        name: {
            type: "string",
            maxLength: 20,
        }
    },
    required: [
        "country",
        "name",
    ],
};

const data = {};

const Editor = () => {
    // optional state for display errors/validity
    const [showValidity, setShowValidity] = React.useState(false);
    
    // needed variables and setters for the SchemaEditor, create wherever you like
    const [store, setStore] = React.useState(() => createStore(createOrderedMap(data)));
    const [schema/*, setSchema*/] = React.useState(() => createOrderedMap(schemaBase));
    
    return <React.Fragment>
        <SchemaEditor
            schema={schema}
            store={store}
            onChange={setStore}

            showValidity={showValidity}
            widgets={widgets}
        
            t={(text, context, schema) => {/* add translations */}}

            {/* 
              * or custom onChange, e.g. save-on-update:
              * - handler gets the previous store 
              * - returns updated store
            */}
            onChange={handler => setStore(data => handler(data))}
        >
            {/* (optional) add components which use the context of the Editor here */}
        </SchemaEditor>

        <button
            {/* show the validity only at submit (or pass `true` to `showValidity`) */} 
            onClick={() => 
                isInvalid(store.getValidity()) ?
                    setShowValidity(true) :
                    doingSomeAction()
            }
        >send!</button>
    </React.Fragment>
};

export {Editor}

Contributing

  1. Fork/Clone Repository
  2. Install root dev-dependencies (like lerna, webpack): npm i
  3. Start dev-server: npm start (will clean-dist + symlink-es-modules + init & hoist packages + starting demo app)
  4. Open browser on localhost:4200
  5. Explore packages
  6. Code -> Commit -> Pull Request -> Being Awesome!

Changes from any package are reflected inside the demo/docs package.

Commands:

  • Build: npm run build
  • Clean node_modules and build dirs: npm run clean
  • Clean build dirs: npm run clean-dist
  • Add new node_module to one package: lerna add <npm-package-name> --scope=@ui-schema/demo [--dev] [--peer], without --scope in all packages
  • Do not change package.json of packages manually, and if Bootstrap lerna: npm run bootstrap
  • Add new package lerna create <name> and follow on screen, e.g.: lerna create material-pickers add package name @ui-schema/material-picker, creates folder ./packages/material-pickers

Publish, for main-repo only:

  1. Currently manually lerna version <semver> --no-git-tag-version is needed
    • like lerna version 0.0.2 --no-git-tag-version, see docs
  2. Then tag the commit with the same version
  3. Push, CI will publish to npm using npm run release -- --yes
    • this leads to: lerna publish from-package --no-git-reset --yes
  4. todo: automate version bump by git-tags w/ publish, and switch to independent lerna versioning

Templates for monorepo packages:

License

This project is free software distributed under the MIT License.

See: LICENSE.

© 2020 bemit UG (haftungsbeschränkt)

License Icons

The icons in the badges of the readme's are either from simpleicons or are licensed otherwise:

Contributors

By committing your code/creating a pull request to this repository you agree to release the code under the MIT License attached to the repository.


Created by Michael Becker