-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputUI.js
72 lines (70 loc) · 1.7 KB
/
InputUI.js
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
ass UIPractice extends React.Component {
static propTypes = {
title: React.PropTypes.string,
placeholder: React.PropTypes.string,
defaultValue: React.PropTypes.string,
showError: React.PropTypes.bool,
ErrorMsg: React.PropTypes.string,
tips: React.PropTypes.string,
};
static defaultProps = {
title: 'Title',
placeholder: 'placeholder',
defaultValue: '',
showError: false,
ErrorMsg: 'errror message',
tips: 'tips message here.',
};
constructor(props) {
super(props)
this.state = {
isFocusing: false,
value: props.defaultValue || '',
}
}
handleFocus() {
this.setState({isFocusing: true})
}
handleBlur() {
this.setState({isFocusing: false})
}
handleChange(e) {
this.setState({value: e.target.value})
}
render() {
const { tips , title, placeholder} = this.props
const { isFocusing, value } = this.state
let focus = isFocusing ? 'focus' : ''
let phClass = 'ph'
if (value != null && value.length > 0) {
if (!isFocusing)
focus = 'focus'
} else if (isFocusing) {
phClass = 'ph show'
}
return (
<div className='input-field'>
<div className={`text-area ${focus}`}>
<div className={`title ${focus}`}>
{title}
</div>
<input
className='input-area'
onFocus={this.handleFocus.bind(this)}
onBlur={this.handleBlur.bind(this)}
onChange={this.handleChange.bind(this)}
value={this.state.value}
/>
<div className={phClass}>
{placeholder}
</div>
<div className={`under-line ${isFocusing ? 'focus' : ''}`} />
<div className={`tips ${isFocusing ? 'focus' : ''}`}>
{tips}
</div>
</div>
</div>
)
}
}
ReactDOM.render(<UIPractice/>, document.getElementById('app'));