1.0.33 • Published 6 years ago

asireact-formcomponents v1.0.33

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Asitis React Formcomponent

Installation

Execute one of the following commands in powershell

  # Yarn users
  yarn global add asireact-formcomponents

  # NPM users
  npm install --save asireact-formcomponents

Usage

To import specific or multiple components from this library use the following:

  import { AutoComplete, FileUpload } from 'asireact-formcomponents'

Components

Props / parameters

PropTypeRequiredDescriptionDefault value
onChangefunctionNOCallback from input & selection
onSelectfunctionNOCallback from selection
keywordsarray : stringYESKeywords from which the autocomplete will match the input to
namestringNOName / identifier of input field
labelstringNOOptionable label for input
errorstringNOOptionable error message for label (requires label for effect)
debugboolNOAdds pre-tag with debug infofalse
multiboolNOAllows multiple word completionfalse
valuestringNOControl value from parent component
styleobjectNOStyle object to customize component
classNamestringNOAdds class to component.. hio hio

Example

import React, { Component } from 'react'
import { AutoComplete } from 'asireact-formcomponents'

class Example extends Component {

  handleAutoComplete(value, name){
    console.log(`AutoComplete ${name} returned text: ${value}`)
  }

  render() {
    const { multi, debug } = this.state
    return (
        <AutoComplete style={{marginTop: 50}} name='example' onChange={this.handleAutoComplete} />
    )
  }
}

export default Example

Props / parameters

PropTypeRequiredDescriptionDefault value
returnfunctionYESFunction to handle dropped files
acceptstringNOAccepted filetypes e.x. '.pdf, .xps'
dragTextstringNOLarge header text'DRAG FILES HERE'
selectTextstringNOInformative text that user can choose to open file browser'select from your computer'
dragTextstringNOText inbetween header and informative text'or'
styleobjectNOStyle object to customize component
classNamestringNOAdds class to component.. hio hio

Example

import React, { Component } from 'react'
import { FileUpload } from 'asireact-formcomponents'

class Example extends Component {

  constructor(props) {
    super(props)
    this.handleSubmit = this.handleSubmit.bind(this)
    this.handleFiles = this.handleFiles.bind(this)
  }

  handleSubmit(e) {
    if (this.state.files.length > 0) {

      // Create formdata and append files
      var fd = new FormData()
      this.state.files.forEach(function (file) {
        fd.append('files[]', file, file.name)
      })

      // Upload files to server
      axios.post('/upload', fd)
        .then(res => this.props.createAlert('success', res.data))
        .catch(err => this.props.createAlert('error', err.message))

      // Reset state  
      this.setState({ files: [] })
    }
  }

  // Function passed to component to receive dropped files
  handleFiles(files){
    this.setState({files})
  }

  render() {
    return (
      <div>
        <FileUpload return={this.handleFiles}/>
        <input type='submit' value='submit' onClick={this.handleSubmit} />
      </div>
    )
  }
}

export default Example 
1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

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