-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.jsx
65 lines (57 loc) · 1.22 KB
/
text.jsx
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
"use strict"
import React from 'react';
import { IControl } from '../base';
/**
* @class UITextInput
*/
class UITextInput extends IControl {
static propTypes = {
/**
* @property {Boolean} password - if true, this is a password input
*/
password: React.PropTypes.bool,
/**
* @property {Boolean} multiline - if true, this is a textarea
*/
multiline: React.PropTypes.bool,
};
static defaultProps = {
password: false,
multiline: false,
};
static styles = {
multiline: {
minHeight: '150px',
width: 'calc(100% - 5px)',
},
};
/**
* Manually focus to the input
*
* @method focus
*/
focus() {
this.refs.input.focus();
}
/**
* Manually blur from the current input
*
* @method blur
*/
blur() {
this.refs.input.blur();
}
render() {
if (this.props.multiline) {
const newProps = this.createProps({
style: UITextInput.styles.multiline,
});
return <textarea ref="input" {...newProps} />;
} else {
const type = this.props.password ? 'password' : 'text';
const newProps = this.createProps({type});
return <input ref="input" {...newProps} />;
}
}
}
module.exports = UITextInput;