0.9.22 • Published 5 years ago

@reform/api v0.9.22

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@reform/api

Simple and powerful React forms API. Write forms faster, more simple and clear.

Install

npm install @reform/api

*This package requires react@16.6+.

Usage

Main usage

TextInput.tsx

import * as React from "react";
import {Component} from "@reform/api";

export class TextInput extends Component {
    protected onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
        this.update(e.target.value);
    }

    protected get className() {
        if (!this.valid) {
            return "is-not-valid";
        }

        if (this.changed) {
            return "is-changed";
        }

        return "";
    }

    public render() {
        return <input {...this.getDefaultProps()}/>;
    }

    protected getDefaultProps() {
        return {
            className: this.className,
            onChange: this.onChange,
            value: this.value,
            name: this.name,
            type: "text",
        }
    }
}

Form.tsx

import * as React from "react";
import {Component, Store} from "@reform/api";
import {TextInput} from "./TextInput.tsx";

interface ISource {
  name: string;
}

export default () => {
    const defaultSource: ISource = {
        name: "Hello",
    };
    
    // will trigger 
    const onChange = (store: Store<ISource>) => {
        console.log("changed", store);
    }
        
    // will trigger on enter
    const onSubmit = (data: ISource, store: Store<ISource>) => {
        console.log("submit", data);
        return true;
    }
    
    return (
        <Form defaultSource={defaultSource}
              onSubmit={console.log}
              onChange={console.log}>
            <p><TextInput name={"name"}/></p>
            <p><button>Submit</button></p>
        </Form>
    );
};

Examples

Setup npm run bootstrap and play npm run doc:play.

0.9.22

5 years ago

0.9.20

5 years ago

0.9.19

5 years ago

0.9.18

6 years ago

0.9.17

6 years ago

0.9.16

6 years ago

0.9.15

6 years ago

0.9.14

6 years ago

0.9.13

6 years ago

0.9.12

6 years ago

0.9.11

6 years ago

0.9.10

6 years ago

0.9.9

6 years ago

0.9.8

6 years ago

0.9.7

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.6

6 years ago

0.8.5

6 years ago

0.8.4

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.11

6 years ago

0.7.10

6 years ago

0.7.9

6 years ago

0.7.8

6 years ago

0.7.7

6 years ago

0.7.6

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago