-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathTextArea.js
More file actions
49 lines (46 loc) · 1.57 KB
/
Copy pathTextArea.js
File metadata and controls
49 lines (46 loc) · 1.57 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
import React from 'react';
import ReactDOM from 'react-dom';
import RIEStatefulBase from 'riek/lib/RIEStatefulBase';
export default class TextArea extends RIEStatefulBase {
keyDown = (event) => {
if (event.keyCode === 27) { this.cancelEditing() } // Escape
};
renderEditingComponent = () => {
return <textarea
rows={this.props.rows}
cols={this.props.cols}
disabled={this.state.loading}
className={this.makeClassString()}
defaultValue={this.props.value}
onInput={this.textChanged}
onBlur={this.finishEditing}
ref="input"
onKeyDown={this.keyDown}
{...this.props.editProps} />;
};
renderNormalComponent = () => {
const value = this.state.newValue || this.props.value
const spans_and_brs = []
var anySpan = false
let i = 0
value.split("\n").map(line => {
if(line.length > 0){
anySpan = true
spans_and_brs.push(<span key={i}>{line}</span>)
}
spans_and_brs.push(<br key={i+1} />)
i += 2
});
spans_and_brs.pop() // remove last br tag
if(!anySpan){
spans_and_brs.length=0
spans_and_brs.unshift(<span key="placeholder">{''}</span>)
}
return <span
tabIndex="0"
className={this.makeClassString()}
onFocus={this.startEditing}
onClick={this.startEditing}
{...this.props.defaultProps}>{spans_and_brs}</span>;
};
}