forked from JakeGinnivan/react-popout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.jsx
55 lines (49 loc) · 1.58 KB
/
demo.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
import React from 'react';
import Popout from '../lib/react-popout.jsx';
export default class Example extends React.Component {
constructor(props) {
super(props);
this.popout = this.popout.bind(this);
this.incrementTimer = this.incrementTimer.bind(this);
this.popoutClosed = this.popoutClosed.bind(this);
this.popoutContentClicked = this.popoutContentClicked.bind(this);
this.state = { isPoppedOut: false, timer: 0 };
}
incrementTimer() {
let newTimer = this.state.timer + 1;
this.setState({ timer: newTimer });
}
popout() {
this.setState({ isPoppedOut: true, timerId: setInterval(this.incrementTimer, 1000) });
}
popoutClosed() {
if (this.state.timerId) {
clearInterval(this.state.timerId);
this.setState({ isPoppedOut: false, timerId: null, timer: 0 });
}
}
popoutContentClicked() {
this.popoutClosed();
}
render() {
if (this.state.isPoppedOut) {
return (
// Remove url parameter to see about:blank support
<Popout title='Test' onClosing={this.popoutClosed}>
<div>
<div>Popped out content! Timer: {this.state.timer}</div>
<div onClick={this.popoutContentClicked}>Close</div>
</div>
</Popout>
);
} else {
return (
<div>
<strong>Example: Only render popout <a style={{ textDecoration: 'underline', color: 'blue', cursor: 'pointer' }}
onClick={this.popout}>(pop window out)</a></strong>
<div>Demo 1 - Inline content</div>
</div>
);
}
}
}