aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/text-field/text-field.component.js
blob: b695a449a5c887ad860c3f757274ec00e5936604 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import { default as MaterialTextField } from '@material-ui/core/TextField'

const styles = {
  materialLabel: {
    '&$materialFocused': {
      color: '#aeaeae',
    },
    '&$materialError': {
      color: '#aeaeae',
    },
    fontWeight: '400',
    color: '#aeaeae',
  },
  materialFocused: {},
  materialUnderline: {
    '&:after': {
      borderBottom: '2px solid #f7861c',
    },
  },
  materialError: {},
  // Non-material styles
  formLabel: {
    '&$formLabelFocused': {
      color: '#5b5b5b',
    },
    '&$materialError': {
      color: '#5b5b5b',
    },
  },
  formLabelFocused: {},
  inputFocused: {},
  inputRoot: {
    'label + &': {
      marginTop: '8px',
    },
    border: '1px solid #d2d8dd',
    height: '48px',
    borderRadius: '4px',
    padding: '0 16px',
    display: 'flex',
    alignItems: 'center',
    '&$inputFocused': {
      border: '1px solid #2f9ae0',
    },
  },
  inputLabel: {
    fontSize: '.75rem',
    transform: 'none',
    transition: 'none',
    position: 'initial',
    color: '#5b5b5b',
  },
}

class TextField extends Component {
  static defaultProps = {
    error: null,
  }

  static propTypes = {
    error: PropTypes.string,
    classes: PropTypes.object,
    material: PropTypes.bool,
    startAdornment: PropTypes.element,
  }

  render () {
    const { error, classes, material, startAdornment, ...textFieldProps } = this.props

    return (
      <MaterialTextField
        error={Boolean(error)}
        helperText={error}
        InputLabelProps={{
          shrink: material ? undefined : true,
          className: material ? '' : classes.inputLabel,
          FormLabelClasses: {
            root: material ? classes.materialLabel : classes.formLabel,
            focused: material ? classes.materialFocused : classes.formLabelFocused,
            error: classes.materialError,
          },
        }}
        InputProps={{
          startAdornment: startAdornment || undefined,
          disableUnderline: !material,
          classes: {
            root: material ? '' : classes.inputRoot,
            input: material ? '' : classes.input,
            underline: material ? classes.materialUnderline : '',
            focused: material ? '' : classes.inputFocused,
          },
        }}
        {...textFieldProps}
      />
    )
  }
}

export default withStyles(styles)(TextField)