1.5.3 • Published 2 days ago

@forml/core v1.5.3

Weekly downloads
112
License
MIT
Repository
github
Last release
2 days ago

Table of Contents

  1. forml
    1. Documentation
    2. Examples
    3. Installation
    4. Usage
    5. Customization
    6. Localization

forml

Build Status Libraries.io dependency status for latest release Coverage Status npm npm

forml - react json schema form

A lightweight, efficient, and powerful form rendering library for use with your JSON schemas. Automatically generate and customize working forms for use in your application. Great for rapid prototyping or production!

Documentation

View the documentation at forml.dev!

Examples

You can view the running demo.

Alternatively, you can run them yourself.

cd examples
npm install
npm start

Installation

# Substitute @forml/decorator-mui with your preferred decorator
npm i @forml/core @forml/decorator-mui

Usage

Basic usage is as follows:

import { SchemaForm } from '@forml/core';
import * as decorator from '@forml/decorator-mui';
import { useState } from 'react';

export function MyForm(props) {
    const [model, setModel] = useState('');
    const schema = { type: 'string', title: 'Sample Form' };
    const form = ['*'];

    return (
        <SchemaForm
            model={model}
            schema={schema}
            decorator={decorator}
            form={form}
            onChange={onChange}
        />
    );

    function onChange(event, model) {
        setModel(model);
    }
}

The example directorys index.js uses SchemaForm both for the example selector and the example itself.

Customization

Custom mapped components can be provided. Look at mapper/index.js to see a list of supported object types. New types may be added and used by explicitly setting the form type.

Appearance/final rendering is handled by the decorator components. Currently a barebones (pure HTML) and MaterialUI decorators are provided.

Localization

forml supports localization via injection. To inject a localizer:

import { SchemaForm } from '@forml/core';
import * as decorator from '@forml/decorator-mui';
import { useTranslate } from 'react-i18next';
import { useState } from 'react';

export function MyTranslatedForm(props) {
    const [model, setModel] = useState({});
    const { t } = useTranslate();
    const schema = {
        type: 'object',
        properties: {
            key: {
                type: 'string',
                title: 'Titles are passed through getLocalizedString',
                description: 'Descriptions too',
            },
        },
    };

    const localizer = { getLocalizedString: t };

    return (
        <SchemaForm
            model={model}
            schema={schema}
            localizer={localizer}
            decorator={decorator}
            onChange={onChange}
        />
    );

    function onChange(event, model) {
        setModel(model);
    }
}

Contributing

forml prides itself on being easily extensible. More UI packages are being added and contributions are welcome.

2.0.0-next.6

2 days ago

2.0.0-next.4

2 days ago

2.0.0-next.5

2 days ago

1.8.0-develop.1

5 months ago

2.0.0-next.1

5 months ago

1.5.3

1 year ago

1.7.4

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.6.4

2 years ago

1.7.0

2 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.20

3 years ago

1.5.19

3 years ago

1.5.18

3 years ago

1.5.17

3 years ago

1.5.16

3 years ago

1.5.15

3 years ago

1.5.14

3 years ago

1.5.13

3 years ago

1.5.12

3 years ago

1.5.11

3 years ago

1.5.10

3 years ago

1.5.9

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago