1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 20:05:27 +02:00
metamask-extension/ui/app/components/text-field/text-field.component.js

110 lines
2.5 KiB
JavaScript
Raw Normal View History

import React from 'react'
2018-05-11 01:51:26 +02:00
import PropTypes from 'prop-types'
2018-05-20 08:04:19 +02:00
import { withStyles } from '@material-ui/core/styles'
import { default as MaterialTextField } from '@material-ui/core/TextField'
2018-05-11 01:51:26 +02:00
const inputLabelBase = {
transform: 'none',
transition: 'none',
position: 'initial',
color: '#5b5b5b',
}
2018-05-11 01:51:26 +02:00
const styles = {
2018-05-20 08:04:19 +02:00
materialLabel: {
'&$materialFocused': {
2018-05-11 01:51:26 +02:00
color: '#aeaeae',
},
2018-05-20 08:04:19 +02:00
'&$materialError': {
color: '#aeaeae',
},
2018-05-11 01:51:26 +02:00
fontWeight: '400',
color: '#aeaeae',
},
2018-05-20 08:04:19 +02:00
materialFocused: {},
materialUnderline: {
2018-05-11 01:51:26 +02:00
'&:after': {
2018-05-20 08:04:19 +02:00
borderBottom: '2px solid #f7861c',
2018-05-11 01:51:26 +02:00
},
},
2018-05-20 08:04:19 +02:00
materialError: {},
// Non-material styles
formLabel: {
'&$formLabelFocused': {
color: '#5b5b5b',
},
'&$materialError': {
color: '#5b5b5b',
},
},
formLabelFocused: {},
2018-05-22 00:00:13 +02:00
inputFocused: {},
2018-05-20 08:04:19 +02:00
inputRoot: {
'label + &': {
marginTop: '8px',
},
border: '1px solid #d2d8dd',
height: '48px',
borderRadius: '4px',
padding: '0 16px',
display: 'flex',
alignItems: 'center',
2018-05-22 00:00:13 +02:00
'&$inputFocused': {
2018-05-20 08:04:19 +02:00
border: '1px solid #2f9ae0',
},
},
largeInputLabel: {
...inputLabelBase,
fontSize: '1rem',
},
2018-05-20 08:04:19 +02:00
inputLabel: {
...inputLabelBase,
2018-05-20 08:04:19 +02:00
fontSize: '.75rem',
},
2018-05-11 01:51:26 +02:00
}
const TextField = props => {
const { error, classes, material, startAdornment, largeLabel, ...textFieldProps } = props
2018-05-11 01:51:26 +02:00
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.input,
underline: material ? classes.materialUnderline : '',
focused: material ? '' : classes.inputFocused,
},
}}
{...textFieldProps}
/>
)
}
2018-05-11 01:51:26 +02:00
TextField.defaultProps = {
error: null,
}
2018-05-11 01:51:26 +02:00
TextField.propTypes = {
error: PropTypes.string,
classes: PropTypes.object,
material: PropTypes.bool,
startAdornment: PropTypes.element,
largeLabel: PropTypes.bool,
2018-05-11 01:51:26 +02:00
}
export default withStyles(styles)(TextField)