aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/text-field/text-field.component.js
blob: 110d169a01c6c9df6f69c6c7c276f3aca29191d3 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import { default as MaterialTextField } from '@material-ui/core/TextField'

const inputLabelBase = {
  transform: 'none',
  transition: 'none',
  position: 'initial',
  color: '#000',
  fontFamily: 'Overpass',
}

const styles = {
  typography: {
    fontFamily: 'Overpass',
  },
  materialLabel: {
    '&$materialFocused': {
      color: '#000',
    },
    '&$materialError': {
      color: '#000',
    },
    fontWeight: '400',
    fontFamily: 'Overpass',
    color: '#000',
  },
  materialFocused: {},
  materialUnderline: {
    '&:before': {
      borderBottom: '2px solid #000',
    },
    '&:hover:before': {
      borderBottom: '2px solid #000000cc!important',
    },
    '&:after': {
      borderBottom: '2px solid #000',
    },
  },
  materialError: {},
  materialInput: {
    color: 'white',
  },
  // Non-material styles
  formLabel: {
    '&$formLabelFocused': {
      color: '#000',
    },
    '&$materialError': {
      color: '#000',
    },
    fontFamily: 'Overpass',
  },
  formLabelFocused: {},
  inputFocused: {},
  inputRoot: {
    'label + &': {
      marginTop: '8px',
    },
    border: 'none',
    height: '48px',
    fontFamily: 'Overpass',
    background: '#f0f0f0',
    borderRadius: '4px',
    padding: '0 16px',
    display: 'flex',
    alignItems: 'center',
    '&$inputFocused': {
      border: 'none',
    },
  },
  input: {
    color: 'black',
    fontFamily: 'Overpass',
  },
  largeInputLabel: {
    ...inputLabelBase,
    fontSize: '1rem',
  },
  inputLabel: {
    ...inputLabelBase,
    fontSize: '.75rem',
  },
}

const TextField = props => {
  const { error, classes, material, startAdornment, largeLabel, ...textFieldProps } = props

  return (
    <MaterialTextField
      error={Boolean(error)}
      helperText={error}
      InputLabelProps={{
        shrink: material ? undefined : true,
        className: material ? '' : (largeLabel ? classes.largeInputLabel : 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.materialInput : classes.input,
          underline: material ? classes.materialUnderline : '',
          focused: material ? '' : classes.inputFocused,
        },
      }}
      {...textFieldProps}
    />
  )
}

TextField.defaultProps = {
  error: null,
}

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

export default withStyles(styles)(TextField)