Implement TalkProvider

This commit is contained in:
Chi Vinh Le
2017-08-21 21:23:59 +07:00
parent 7c7a8d6b64
commit 84e4091ea6
6 changed files with 70 additions and 38 deletions
@@ -1,13 +1,16 @@
import {Component, cloneElement, Children} from 'react';
import PropTypes from 'prop-types';
import {findDOMNode} from 'react-dom';
import pym from 'coral-framework/services/pym';
export default class ClickOutside extends Component {
static propTypes = {
onClickOutside: PropTypes.func.isRequired
};
static contextTypes = {
pym: PropTypes.object,
};
domNode = null;
handleClick = (e) => {
@@ -18,14 +21,20 @@ export default class ClickOutside extends Component {
};
componentDidMount() {
const {pym} = this.context;
this.domNode = findDOMNode(this);
document.addEventListener('click', this.handleClick, true);
pym.onMessage('click', this.handleClick);
if (pym) {
pym.onMessage('click', this.handleClick);
}
}
componentWillUnmount() {
const {pym} = this.context;
document.removeEventListener('click', this.handleClick, true);
pym.messageHandlers.click = pym.messageHandlers.click.filter((h) => h !== this.handleClick);
if (pym) {
pym.messageHandlers.click = pym.messageHandlers.click.filter((h) => h !== this.handleClick);
}
}
render() {