4.0.3 • Published 5 years ago

the-form v4.0.3

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

the-form

Build Status npm Version JS Standard

Form of the-components

Installation

$ npm install the-form --save

Usage

'use strict'

import React from 'react'
import { TheForm, TheFormBinder, TheFormStyle } from 'the-form'
import { TheInput, TheInputStyle } from 'the-input'
import { TheButton, TheButtonStyle } from 'the-button'

class ExampleComponent extends React.PureComponent {
  constructor (props) {
    super(props)
    this.state = {
      values: {}
    }
    this.onUpdate = this.onUpdate.bind(this)
  }

  onUpdate (values) {
    this.setState({
      values: Object.assign({}, this.state.values, values)
    })
  }

  render () {
    const { Field, Label, Value, FieldSet, Legend } = TheForm

    const { values } = this.state
    return (
      <div>
        <TheFormStyle/>
        <TheInputStyle/>
        <TheButtonStyle/>

        <div>
          <TheFormBinder values={this.state.values}
                         onUpdate={this.onUpdate}
          >{
            ({
               formPropsOf,
               inputPropsOf,
               labelPropsOf,
               submitPropsOf,
             }) => (
              <TheForm>
                <Field>
                  <Label {...labelPropsOf('value01')}>Foo</Label>
                  <Value><TheInput.Text {...inputPropsOf('value01')}
                                        candidate={['foo', 'bar']}
                  /></Value>
                </Field>
                <Field>
                  <Label {...labelPropsOf('value02')}>Bar</Label>
                  <Value><TheInput.Radio {...inputPropsOf('value02')}
                                         options={{ '01': 'ORange', '02': 'Banana' }}
                  /></Value>
                </Field>

                <FieldSet>
                  <Legend>This is legend</Legend>
                  <Field>
                    <Label {...labelPropsOf('value01')}>Foo</Label>
                    <Value><TheInput.Text {...inputPropsOf('value01')}
                                          candidate={['foo', 'bar']}
                    /></Value>
                  </Field>
                </FieldSet>
              </TheForm>
            )
          }
          </TheFormBinder>
          <hr/>

          <TheForm spinning>
            <Field>
              <Label>Foo</Label>
              <Value><TheInput.Text name='value01' value={values.value01} onUpdate={this.onUpdate}/></Value>
            </Field>
            <Field>
              <Label>Bar</Label>
              <Value><TheInput.Radio name='value02' value={values.value02} onUpdate={this.onUpdate}
                                     options={{ '01': 'ORange', '02': 'Banana' }}
              /></Value>
            </Field>
          </TheForm>


          <hr/>
          <TheForm errors={{ value01: 'no,no,no' }}
                   errorLead={'You have an input error'}
          >
            <Field>
              <Label>Foo</Label>
              <Value><TheInput.Text name='value01' value={values.value01} onUpdate={this.onUpdate}/></Value>
            </Field>
          </TheForm>
        </div>
        <hr/>

        <div>
          <TheForm inline>
            <TheInput.Text name='value01' value={values.value01} onUpdate={this.onUpdate}/>
            <TheButton primary>Do it!</TheButton>
          </TheForm>

          <TheForm inline>
            <TheInput.Text name='value01' value={values.value01}
                           error='This is error'
                           onUpdate={this.onUpdate}/>
            <TheButton primary>Do it!</TheButton>
          </TheForm>
        </div>
      </div>
    )
  }
}

export default ExampleComponent

Components

TheForm

Form of the-components

Props

NameTypeDescriptionDefault
errorLeadnodeLead text when errornull
inlineboolAs inline stylesfalse
spinningboolShows spinnerfalse
role'form'

TheFormBinder

Props

NameTypeDescriptionDefault
errorsobjectInput errors{}
idstringDOM Id
onErrorfuncHandler for error update
onSubmitfuncHandler for form submit
onUpdatefuncHandler for input update
readOnlyarrayOf stringRead only fields[]
requiredarrayOf stringRequired input names[]
tabIndexnumberTab index
valuesobjectInput values{}

TheFormStyle

Style for TheForm

Props

NameTypeDescriptionDefault
optionsobjectStyle options{}

License

This software is released under the MIT License.

Links

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.30

5 years ago

2.0.29

6 years ago

2.0.28

6 years ago

2.0.27

6 years ago

2.0.26

6 years ago

2.0.25

6 years ago

2.0.24

6 years ago

2.0.23

6 years ago

2.0.22

6 years ago

2.0.21

6 years ago

2.0.20

6 years ago

2.0.18

6 years ago

2.0.17

6 years ago

2.0.16

6 years ago

2.0.15

6 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago