1.7.0 • Published 8 months ago

@forml/hooks v1.7.0

Weekly downloads
24
License
MIT
Repository
github
Last release
8 months 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.9

8 months ago

2.0.0-next.6

8 months ago

2.0.0-next.4

8 months ago

2.0.0-next.5

8 months ago

1.8.0-develop.1

1 year ago

2.0.0-next.1

1 year ago

1.5.3

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago