4.1.3 • Published 7 years ago

react-input v4.1.3

Weekly downloads
86
License
MIT
Repository
-
Last release
7 years ago

React Input

npm version Build Status Coverage Status npm downloads

Overview

React input is a lightweight, dependency free component for building forms in React without having to think about what happens under the hood. It uses one component and an array of objects that describe the inputs in the form.

Usage

Install the component via npm: npm install react-input.

<Form
  fields={[
    {
      name: 'Email',
      key: 'email',
      type: 'email',
      error: false,
      required: false,
      placeholder: 'Enter an email',
      onChange: value => {
        // handle a changed value on the input
      },
      renderAfter: () => (
        <div>Include an element after the input, which is useful for instructional text or strength meters for passwords</div>
      ),
      renderBefore: () => (
        <div>Include an element before the input</div>
      )
    },
    // additional inputs to include in the form
  ]}
  onChange={state => /* handle form change */ }
  onSubmit={state => /* handle form submit */ }
/>

For a detailed example, see the example project.

Form Props

NameTypeDescriptionRequiredDefault
fieldsarrayArray of inputs to includetrue
labelsbooleanIf false, labels are disabledtrue
isPendingbooleanIf true, an .is-pending class is added to the formnull
isRejectedbooleanIf true, an .is-rejected class is added to the formnull
isFulfilledbooleanIf true, an .is-fulfilled class is added to the formnull

The isPending, isRejected and isFulfilled props are useful to add different styles to the form for different states.

Form Events

EventDescription
onChangeRuns when any input in the form changes. The first parameter is the state of the form after the change.
onSubmitRuns when the submit button is clicked. The first parameter is the current state of the form.

Input Properties and Events

Only text based inputs can be used, e.g., email, text, tel and password.

Properties

NameTypeDescriptionRequiredDefault
keystringUnique key for the fieldtrue
typestringThe type of input'text'
namestringThe name of input
labelbooleanLabel for the input fieldtrue
requiredbooleanMake field requiredtrue
errorbooleanIs the input in an error state?false
renderAfterfunctionElement to render after the input
renderBeforefunctionElement to render before the input

Events

EventDescription
onChangeRuns when the value of the input changes. The first parameter is the value.

In addition to the props listed above, all standard HTML input attributes are supported and can be used as props on the inputs.


Copyright 2015 Patrick Burtchaell. Licensed MIT.

4.1.3

7 years ago

4.1.2

7 years ago

4.1.1

8 years ago

4.1.0

8 years ago

4.0.4

8 years ago

4.0.3

8 years ago

4.0.2

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.0.9

8 years ago

3.0.8

8 years ago

3.0.7

8 years ago

3.0.6

8 years ago

3.0.5

8 years ago

3.0.4

8 years ago

3.0.3

9 years ago

3.0.2

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

3.0.1-beta

9 years ago

3.0.0-beta

9 years ago

2.0.2

9 years ago

2.0.1-alpha.4

9 years ago

2.0.1-alpha.3

9 years ago

2.0.1-alpha.2

9 years ago

2.0.1-alpha.1

9 years ago

1.1.0

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago