forked from jstejada/react-typist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCursor.jsx
52 lines (43 loc) · 1.09 KB
/
Cursor.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
import React, {Component, PropTypes} from 'react';
import './Cursor.scss';
export default class Cursor extends Component {
static propTypes = {
blink: PropTypes.bool,
show: PropTypes.bool,
element: PropTypes.node,
hideWhenDone: PropTypes.bool,
hideWhenDoneDelay: PropTypes.number,
isDone: PropTypes.bool,
}
static defaultProps = {
blink: true,
show: true,
element: '|',
hideWhenDone: false,
hideWhenDoneDelay: 1000,
isDone: false,
}
constructor(props) {
super(props);
}
state = {
shouldRender: this.props.show,
}
componentWillReceiveProps(nextProps) {
const shouldHide = !this.props.isDone && nextProps.isDone && this.props.hideWhenDone;
if (shouldHide) {
setTimeout(()=> this.setState({shouldRender: false}), this.props.hideWhenDoneDelay);
}
}
render() {
if (this.state.shouldRender) {
const className = this.props.blink ? ' Cursor--blinking' : '';
return (
<span className={`Cursor${className}`}>
{this.props.element}
</span>
);
}
return null;
}
}