0.2.1 • Published 1 year ago

@ascentcore/react-schema-form v0.2.1

Weekly downloads
11
License
MIT
Repository
github
Last release
1 year ago

@ascentcore/react-schema-form

React Forms based on JSON Schemas

NPM JavaScript Style Guide

Install

npm install --save @ascentcore/react-schema-form

Usage

Having a schema defined (basic-schema.json):

{
    "$id": "https://example.com/person.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "title": "Person",
    "description": "Person Information",
    "required": ["firstName", "lastName", "type", "phoneNumbers"],
    "properties": {
        "firstName": {
            "type": "string",
            "title": "First Name",
            "description": "The person's first name."
        },
        "lastName": {
            "type": "string",
            "title": "Last Name",
            "description": "The person's last name."
        },
        "age": {
            "title": "Age",
            "description": "Age in years which must be equal to or greater than zero.",
            "type": "integer",
            "minimum": 10
        },
        "type": {
            "title": "Type",
            "type": "string",
            "enum": ["NW", "NE", "SW", "SE"]
        },
        "agree": {
            "title": "Agree with TOC",
            "type": "boolean",
            "default": false
        },
        "phoneNumbers": {
            "title": "Phone numbers",
            "type": "array",
            "items": {
                "title": "Phone number",
                "type": "string",
                "pattern": "^[0-9]+$"
            }
        }
    }
}

Example of form generation usage based on schema:

import React from 'react'
import schema from './basic-schema.json'
import { SchemaForm } from '@ascentcore/react-schema-form'

export default function BasicSchemaExample() {

    function onSubmit(data) {
        console.log(data)
    }

    const data = {
        firstName: 'Defined Value'
    }

    return (<SchemaForm schema={schema} onSubmit={onSubmit} data={data} />)

}

Development

Library dev building:

npm install
npm run start

Examples dev building:

cd example
npm install
npm run start

License

MIT

0.2.1

1 year ago

0.2.0

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.1.0

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago