Repository navigation
Expand file tree
/
Copy pathTextFieldLabel.js
More file actions
97 lines (88 loc) · 2.11 KB
/
Copy pathTextFieldLabel.js
File metadata and controls
97 lines (88 loc) · 2.11 KB
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
import React, {PropTypes} from 'react';
import transitions from '../styles/transitions';
function getStyles(props) {
const defaultStyles = {
position: 'absolute',
lineHeight: '22px',
top: 38,
transition: transitions.easeOut(),
zIndex: 1, // Needed to display label above Chrome's autocomplete field background
cursor: props.disabled ? 'not-allowed' : 'text',
transform: 'scale(1) translate(0, 0)',
transformOrigin: 'left top',
pointerEvents: 'auto',
userSelect: 'none',
};
const shrinkStyles = props.shrink ? Object.assign({
transform: 'scale(0.75) translate(0, -28px)',
pointerEvents: 'none',
}, props.shrinkStyle) : null;
return {
root: Object.assign(defaultStyles, props.style, shrinkStyles),
};
}
const TextFieldLabel = (props) => {
const {
muiTheme,
className,
children,
htmlFor,
onTouchTap,
} = props;
const {prepareStyles} = muiTheme;
const styles = getStyles(props);
return (
<label
className={className}
style={prepareStyles(styles.root)}
htmlFor={htmlFor}
onTouchTap={onTouchTap}
>
{children}
</label>
);
};
TextFieldLabel.propTypes = {
/**
* The label contents.
*/
children: PropTypes.node,
/**
* The css class name of the root element.
*/
className: PropTypes.string,
/**
* Disables the label if set to true.
*/
disabled: PropTypes.bool,
/**
* The id of the target element that this label should refer to.
*/
htmlFor: PropTypes.string,
/**
* @ignore
* The material-ui theme applied to this component.
*/
muiTheme: PropTypes.object.isRequired,
/**
* Callback function for when the label is selected via a touch tap.
*/
onTouchTap: PropTypes.func,
/**
* True if the floating label should shrink.
*/
shrink: PropTypes.bool,
/**
* Override the inline-styles of the root element when focused.
*/
shrinkStyle: PropTypes.object,
/**
* Override the inline-styles of the root element.
*/
style: PropTypes.object,
};
TextFieldLabel.defaultProps = {
disabled: false,
shrink: false,
};
export default TextFieldLabel;