import React from "react";
class ClickOutside extends React.Component {
  constructor() {
    super(...arguments);
    this.clickCaptured = false;
    this.innerClick = () => {
      this.clickCaptured = true;
    };
    this.documentClick = (event) => {
      if (!this.clickCaptured && this.props.onClickOutside) {
        this.props.onClickOutside(event);
      }
      this.clickCaptured = false;
    };
  }
  render() {
    return this.renderComponent();
  }
  renderComponent() {
    if (typeof this.props.children === "function") {
      return this.props.children(this.getProps());
    }
    return React.createElement(this.props.wrapper || "span", this.getProps(), this.props.children);
  }
  getProps() {
    return {
      onMouseDown: this.innerClick,
      onTouchStart: this.innerClick
    };
  }
  componentDidMount() {
    document.addEventListener("mousedown", this.documentClick);
    document.addEventListener("touchstart", this.documentClick);
  }
  componentWillUnmount() {
    document.removeEventListener("mousedown", this.documentClick);
    document.removeEventListener("touchstart", this.documentClick);
  }
}
export {
  ClickOutside
};
//# sourceMappingURL=click-outside.js.map
