-
Notifications
You must be signed in to change notification settings - Fork 1
/
mirror.js
55 lines (39 loc) · 1.08 KB
/
mirror.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
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
const displayName = 'Mirror'
const propTypes = {}
class Mirror extends Component {
constructor (props) {
super(props)
this._surface = null
this.state = {}
}
shouldComponentUpdate () {
return false
}
get node () {
return this.refs ? this.refs.node : null
}
set node (value) {}
reflect (surface=null) {
if (surface !== this._surface) {
this._surface && this._surface.remove(this.node)
const node = ReactDOM.findDOMNode(this.node)
while (node.firstChild) node.removeChild(node.firstChild)
this._surface = surface
surface && this._surface.add(this.node)
this.forceUpdate(() => this._surface && this._surface.update())
}
}
render () {
const { children=null, ...props } = this.props
return (
<div onMouseEnter={ () => (this._surface && (this._surface.active = this.node)) }>
<div ref='node' { ...props } />
</div>
)
}
}
Mirror.displayName = displayName
Mirror.propTypes = propTypes
export default Mirror