2.0.0-alpha.5 • Published 2 years ago

carry-on-react-forms v2.0.0-alpha.5

Weekly downloads
3
License
MIT
Repository
github
Last release
2 years ago

carry-on-forms

Read the documentation at: https://dfadev.github.io/carry-on

carry-on plugin to add React form components

Usage

import { register, State } from "carry-on-react";
import { form, Form, FormButtons, Field } from "carry-on-react-forms";

register({
  state: {
    siteConfig: {
      name: "Hello World",
      byline: "the timeless greeting"
    }
  }
});

register({
  state: ({ set }) => ({
    counter: {
      value: 0,
      inc: () => set(state => void state.counter.value++, "Inc"),
      dec: () => set(state => void state.counter.value--, "Dec")
    }
  })
});

register(
  form({
    init: {
      field: "value",
      checkbox: false,
      slowfield: "zzz"
    },
    onSubmit: ({ get, set }) => values => true,
    onReset: ({ get, set }) => values => {},
    onValidate: ({ get, set }) => vals =>
      new Promise((resolve, reject) => {
        resolve({
          isValid: true,
          errors: {
            field: "invalid"
          }
        });
      })
  })
);

const App = () => (
  <div>
    <State constant>
      {({ siteConfig: { name, byline } }) => (
        <>
          <h1>{name}</h1>
          <h6>{byline}</h6>
        </>
      )}
    </State>
    <hr />
    <h4>Magical Counter</h4>
    <State debounce={500}>
      {({ counter: { value, inc, dec } }) => (
        <>
          <div>{value}</div>
          <button onClick={inc}>inc</button>
          <button onClick={dec}>dec</button>
        </>
      )}
    </State>
    <hr />
    <Form>
      <Field path="field">
        {({ element, touched, error }) => (
          <div>
            <input {...element} />
            {touched && error && <div>{error}</div>}
          </div>
        )}
      </Field>
      <hr />
      <Field path="checkbox" type="checkbox">
        {({ element, touched, error }) => (
          <div>
            <input type="checkbox" {...element} />
            {touched && error && <div>{error}</div>}
          </div>
        )}
      </Field>
      <hr />
      <Field path="slowfield" throttle={1000}>
        {({ element, touched, error }) => (
          <div>
            <input {...element} />
            {touched && error && <div>{error}</div>}
          </div>
        )}
      </Field>
      <hr />
      <FormButtons>
        {({ submit, reset }) => (
          <div>
            <button {...submit}>submit</button>
            <button {...reset}>reset</button>
          </div>
        )}
      </FormButtons>
      <hr />
    </Form>
  </div>
);
2.0.0-alpha.3

2 years ago

2.0.0-alpha.4

2 years ago

2.0.0-alpha.5

2 years ago

2.0.0-alpha.2

2 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

0.0.51

4 years ago

0.0.50

5 years ago

0.0.49

5 years ago

0.0.48

5 years ago

0.0.47

5 years ago

0.0.46

5 years ago

0.0.45

5 years ago

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.36

5 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago