<commit_before>import React, { Component, PropTypes } from 'react';
import classNames from 'classnames';

require('./ButtonWithPanel.css');

class ButtonWithPanel extends Component {
  constructor(props) {
    super(props);
    this.state = { open: false };
    this._onPanelOpen = () => {
      this.setState({ open: true });
      if (this.props.panel.onOpen) {
        this.props.panel.onOpen();
      }
    }
    this._onPanelClose = () => {
      this.setState({ open: false });
      if (this.props.panel.onClose) {
        this.props.panel.onClose();
      }
    }
    this._onButtonClick = this._onButtonClick.bind(this);
    this._panelCreated = panel => { this._panel = panel; };
  }

  openPanel() {
    if (this._panel) {
      this._panel.open();
    }
  }

  _onButtonClick() {
    this.openPanel();
  }

  render() {
    const { className, label, panel } = this.props;
    const { open } = this.state;
    return (
      <div className={classNames('buttonWithPanel', className, { open })}>
        <div className='buttonWithPanelButtonWrapper'>
          <input type='button'
                 className={classNames('buttonWithPanelButton', `${className}Button`)}
                 value={label}
                 onClick={this._onButtonClick}/>
        </div>
        {React.cloneElement(panel, {
          ref: this._panelCreated,
          onOpen: this._onPanelOpen,
          onClose: this._onPanelClose
        })}
      </div>
    );
  }
}

ButtonWithPanel.propTypes = {
  className: PropTypes.string,
  label: PropTypes.string.isRequired,
  panel: PropTypes.object.isRequired,
};

export default ButtonWithPanel;<commit_msg>Fix panel button open/close callback invocation.<commit_after>import React, { Component, PropTypes } from 'react';
import classNames from 'classnames';

require('./ButtonWithPanel.css');

class ButtonWithPanel extends Component {
  constructor(props) {
    super(props);
    this.state = { open: false };
    this._onPanelOpen = () => {
      this.setState({ open: true });
      if (this.props.panel.props.onOpen) {
        this.props.panel.props.onOpen();
      }
    };
    this._onPanelClose = () => {
      this.setState({ open: false });
      if (this.props.panel.props.onClose) {
        this.props.panel.props.onClose();
      }
    };
    this._onButtonClick = this._onButtonClick.bind(this);
    this._panelCreated = panel => { this._panel = panel; };
  }

  openPanel() {
    if (this._panel) {
      this._panel.open();
    }
  }

  _onButtonClick() {
    this.openPanel();
  }

  render() {
    const { className, label, panel } = this.props;
    const { open } = this.state;
    return (
      <div className={classNames('buttonWithPanel', className, { open })}>
        <div className='buttonWithPanelButtonWrapper'>
          <input type='button'
                 className={classNames('buttonWithPanelButton', `${className}Button`)}
                 value={label}
                 onClick={this._onButtonClick}/>
        </div>
        {React.cloneElement(panel, {
          ref: this._panelCreated,
          onOpen: this._onPanelOpen,
          onClose: this._onPanelClose,
        })}
      </div>
    );
  }
}

ButtonWithPanel.propTypes = {
  className: PropTypes.string,
  label: PropTypes.string.isRequired,
  panel: PropTypes.object.isRequired,
};

export default ButtonWithPanel;
{'fraction_non_alphanumeric': 0.14187574671445638, 'fraction_numerical': 0.0, 'mean_word_length': 2.540169133192389, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '7299868', 'n_tokens_mistral': 992, 'n_tokens_neox': 999, 'n_words': 178}