<commit_before>import { PureComponent } from 'react';
import ReactDOM from 'react-dom';

export interface Props {
  /**
   *  When clicking outside of current element
   */
  onClick: () => void;
  /**
   *  Runs the 'onClick' function when pressing a key outside of the current element. Defaults to true.
   */
  includeButtonPress: boolean;
}

interface State {
  hasEventListener: boolean;
}

export class ClickOutsideWrapper extends PureComponent<Props, State> {
  static defaultProps = {
    includeButtonPress: true,
  };
  state = {
    hasEventListener: false,
  };

  componentDidMount() {
    window.addEventListener('click', this.onOutsideClick, false);
    if (this.props.includeButtonPress) {
      // Use keyup since keydown already has an eventlistener on window
      window.addEventListener('keyup', this.onOutsideClick, false);
    }
  }

  componentWillUnmount() {
    window.removeEventListener('click', this.onOutsideClick, false);
    if (this.props.includeButtonPress) {
      window.removeEventListener('keyup', this.onOutsideClick, false);
    }
  }

  onOutsideClick = (event: any) => {
    const domNode = ReactDOM.findDOMNode(this) as Element;

    if (!domNode || !domNode.contains(event.target)) {
      this.props.onClick();
    }
  };

  render() {
    return this.props.children;
  }<commit_msg>Dashboard: Panel menu no longer lingers (#26974)<commit_after>import { PureComponent } from 'react';
import ReactDOM from 'react-dom';

export interface Props {
  /**
   *  When clicking outside of current element
   */
  onClick: () => void;
  /**
   *  Runs the 'onClick' function when pressing a key outside of the current element. Defaults to true.
   */
  includeButtonPress: boolean;
}

interface State {
  hasEventListener: boolean;
}

export class ClickOutsideWrapper extends PureComponent<Props, State> {
  static defaultProps = {
    includeButtonPress: true,
  };
  state = {
    hasEventListener: false,
  };

  componentDidMount() {
    document.addEventListener('click', this.onOutsideClick, false);
    if (this.props.includeButtonPress) {
      // Use keyup since keydown already has an eventlistener on window
      document.addEventListener('keyup', this.onOutsideClick, false);
    }
  }

  componentWillUnmount() {
    document.removeEventListener('click', this.onOutsideClick, false);
    if (this.props.includeButtonPress) {
      document.removeEventListener('keyup', this.onOutsideClick, false);
    }
  }

  onOutsideClick = (event: any) => {
    const domNode = ReactDOM.findDOMNode(this) as Element;

    if (!domNode || !domNode.contains(event.target)) {
      this.props.onClick();
    }
  };

  render() {
    return this.props.children;
  }
{'fraction_non_alphanumeric': 0.11559836976658021, 'fraction_numerical': 0.001852537977028529, 'mean_word_length': 3.568527918781726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2772660', 'n_tokens_mistral': 807, 'n_tokens_neox': 777, 'n_words': 200}