aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send-content/send-row-wrapper/send-row-wrapper.component.js
blob: 92382da0188a7380a03d1337f57e96ee4e513396 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import SendRowErrorMessage from './send-row-error-message/send-row-error-message.container'

export default class SendRowWrapper extends Component {

  static propTypes = {
    label: PropTypes.string,
    showError: PropTypes.bool,
    children: PropTypes.node,
    errorType: PropTypes.string,
  };

  render () {
    const {
        label,
        errorType = '',
        showError = false,
        children,
    } = this.props

    let formField = children[0]
    let customLabelContent = null

    if (children.length === 2) {
      formField = children[1]
      customLabelContent = children[0]
    }

    return (
      <div className="send-v2__form-row">
        <div className="send-v2__form-label">
            {label}
            (showError && <SendRowErrorMessage errorType={errorType}/>)
            {customLabelContent}
        </div>
        <div className="send-v2__form-field">
            {formField}
        </div>
      </div>
    );
  }

}

SendRowWrapper.contextTypes = {
  t: PropTypes.func,
}