forked from Sharlaan/material-ui-superselectfield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatingLabel.js
More file actions
57 lines (48 loc) · 1.59 KB
/
Copy pathFloatingLabel.js
File metadata and controls
57 lines (48 loc) · 1.59 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
import React, { Component } from 'react';
import { floatingLabelTypes } from './types';
import { floatingLabelDefaultProps } from './defaultProps';
export default class FloatingLabel extends Component {
state = { flabelHeight: 0 };
static propTypes = floatingLabelTypes;
static defaultProps = floatingLabelDefaultProps;
componentDidMount () {
this.setState({ flabelHeight: this.flabel.offsetHeight });
}
render () {
const {
children,
defaultColors: { floatingLabelColor, focusColor },
disabled,
floatingLabelFocusStyle,
floatingLabelStyle,
isFocused,
shrink,
} = this.props;
const defaultStyles = {
color: floatingLabelColor,
cursor: 'pointer',
lineHeight: '22px',
pointerEvents: 'none',
position: 'static',
top: 0,
transform: 'scale(1) translateY(0)',
transformOrigin: 'left top',
transition: '450ms cubic-bezier(0.23, 1, 0.32, 1)', // transitions.easeOut(),
userSelect: 'none',
zIndex: 1, // Needed to display label above Chrome's autocomplete field background
...floatingLabelStyle,
};
const focusStyles = isFocused && !disabled && shrink && { color: focusColor, ...floatingLabelFocusStyle };
const shrinkStyles = shrink && {
cursor: 'default',
pointerEvents: 'none',
position: 'absolute',
transform: `scale(0.75) translateY(-${this.state.flabelHeight}px)`,
};
return (
<label ref={(ref) => (this.flabel = ref)} style={{ ...defaultStyles, ...shrinkStyles, ...focusStyles }}>
{children}
</label>
);
}
}