Advertisement
Guest User

Untitled

a guest
May 29th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. import { Grid, Row, Form, Col, FormGroup, HelpBlock, ControlLabel, FormControl, InputGroup, Button, Panel, Glyphicon } from 'react-bootstrap'
  2.  
  3. const AddonHorizontal = ({addon, addonText}) => {
  4. let res = null
  5. if (addon) {
  6. res = (<Addon>
  7. <Glyphicon glyph={addon} />
  8. </Addon> )
  9. } else if (addonText) {
  10. res = (<Addon>
  11. {addonText}
  12. </Addon>)
  13. }
  14. return res
  15. }
  16.  
  17. AddonHorizontal.propTypes = {
  18. addon: PropTypes.string,
  19. addonText: PropTypes.string
  20. }
  21.  
  22. const InputGroupHorizontal = ({ addon, addonText, field, type = 'text', label }) => {
  23. const validationState = () => {
  24. if (field.error && field.touched) {
  25. return 'error'
  26. } else if (field.touched && field.valid) {
  27. return 'success'
  28. }
  29. }
  30. return (<InputGroup>
  31. <AddonHorizontal addon={addon} addonText={addonText} />
  32. <FormControl
  33. type={type}
  34. placeholder={label}
  35. {...field}
  36. validationState={validationState()} />
  37. </InputGroup>)
  38. }
  39.  
  40. const FormGroupHorizontal = ({controlId, type = 'text', label, field, addon, addonText}) => (
  41. <FormGroup controlId={controlId}>
  42. <Col componentClass={ControlLabel} sm={4}>
  43. {label}
  44. </Col>
  45. <Col sm={8}>
  46. <InputGroupHorizontal
  47. type={type}
  48. label={label}
  49. addon={addon}
  50. addonText={addonText}
  51. field={field} />
  52. <Feedback />
  53. <HelpBlock>
  54. {field.touched && field.error ? field.error : null}
  55. </HelpBlock>
  56. </Col>
  57. </FormGroup>
  58. )
  59.  
  60. FormGroupHorizontal.propTypes = {
  61. controlId: PropTypes.string.isRequired,
  62. type: PropTypes.string,
  63. label: PropTypes.string.isRequired,
  64. field: PropTypes.object.isRequired,
  65. addon: PropTypes.string,
  66. addonText: PropTypes.string
  67. }
  68.  
  69. FormGroupHorizontal.defaultProps = {
  70. type: 'text'
  71. }
  72.  
  73. const SubmitButton = ({handleSubmit, submitting, pristine}) => {
  74. const indicator = (<Loading
  75. type='spokes'
  76. color='#e3e3e3'
  77. height={32}
  78. width={32} />)
  79.  
  80. return (<Button
  81. onClick={handleSubmit}
  82. type='submit'
  83. disabled={submitting || pristine}
  84. bsStyle='primary'>
  85. {submitting ? 'Submitting' : 'Submit'}
  86. {submitting ? indicator : null}
  87. </Button>)
  88. }
  89.  
  90. const DeliveryComponent = ({ fields: { firstName, lastName, email, contactNumber, altContactNumber }, submitting, pristine, handleSubmit }) => (
  91. <Row>
  92. <Col sm={6} smOffset={2}>
  93. <Grid fluid>
  94. <Panel header={title} bsStyle='primary'>
  95. <Form horizontal controlId='test-delivery-form'>
  96. <FormGroupHorizontal controlId='first-name-group' label='First name' field={firstName} />
  97. <FormGroupHorizontal controlId='last-name-group' label='Last name' field={lastName} />
  98. <FormGroupHorizontal
  99. controlId='email-group'
  100. label='Email'
  101. field={email}
  102. addonText='@' />
  103. <FormGroupHorizontal
  104. controlId='phone-group'
  105. type='tel'
  106. label='Contact Number'
  107. addon='earphone'
  108. field={contactNumber} />
  109. <FormGroupHorizontal
  110. controlId='alt-phone-group'
  111. type='tel'
  112. label='Alternate Contact Number'
  113. addon='phone-alt'
  114. field={altContactNumber} />
  115. <FormGroup>
  116. <Col sm={8} smOffset={6}>
  117. <SubmitButton handleSubmit={handleSubmit} submitting={submitting} pristine={pristine} />
  118. </Col>
  119. </FormGroup>
  120. </Form>
  121. </Panel>
  122. </Grid>
  123. </Col>
  124. </Row>
  125. )
  126.  
  127. DeliveryComponent.propTypes = {
  128. handleSubmit: PropTypes.func,
  129. fields: PropTypes.object,
  130. submitting: PropTypes.bool,
  131. pristine: PropTypes.bool
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement