项目作者: luisfuertes

项目描述 :
Cloud Widgets
高级语言: JavaScript
项目地址: git://github.com/luisfuertes/cloud-widgets.git
创建时间: 2018-06-13T09:52:11Z
项目社区:https://github.com/luisfuertes/cloud-widgets

开源协议:

下载


Storybook

Storybook documentation

Inputs

TextInput

Prop name Type Description Default
id String Input id null
label String Input label “”
value String Input value “”
type String Input type “text”
placeholder String Input placeholder “”
validation Function Function to validate input () => {}
onChange Function onChange callback () => {}
onBlur Function onBlur callback () => {}
onFocus Function onFocus callback () => {}
autoFocus Bool Input autofocus false
className String Input classname “”

TextAreaInput

SelectInput

MultiSelectInput

Checkbox

Button

TagInput

RadioInput

RadioGroup

GeosuggestInput

Installation

For install:
npm install cloud-widgets --save

Usage

  1. import _ from 'lodash'
  2. import { FormUtils, TextInput, TextAreaInput, SelectInput, MultiSelectInput, TagInput, Button } from 'cloud-widgets'
  3. ...
  4. constructor(props) {
  5. super(props)
  6. this.formInputs = {}
  7. }
  8. _onSubmit(e) {
  9. // Function in FormUtils to validate inputs
  10. if (FormUtils.validateForm(this.formInputs)) {
  11. const data = {
  12. firstName: _.get(this.state, 'firstName', ''),
  13. lastName: _.get(this.state, 'lastName', ''),
  14. }
  15. this.props.onSubmit(data)
  16. }
  17. }
  18. _mandatoryValidate(value) {
  19. // Validation function example
  20. if (value != null && value != '') {
  21. return { isValid: true, error: '' }
  22. } else {
  23. return { isValid: false, error: 'Mandatory field' }
  24. }
  25. }
  26. ...
  27. render() {
  28. return (
  29. <TextInput
  30. ref={i => {
  31. this.formInputs.firstName = i
  32. }}
  33. id={'firstName'}
  34. label={'FirstName:'}
  35. value={this.state.firstName}
  36. placeholder={' '}
  37. onChange={firstName => this.setState({ firstName })}
  38. validation={v => this._mandatoryValidate(v)}
  39. />
  40. )
  41. }