<commit_before>import { PureComponent, PropTypes, createElement } from 'react';
import { SPACE, ENTER } from '../constants/keyCodes';

/**
 * The `AccessibleFakeButton` is a generic component that can be used to render
 * a `div` or any other non `button` components as a button. This should not be
 * used often.
 *
 * The `AccessibleFakeButton` allows the user to tab focus the element, use the
 * space or enter key to trigger the `onClick` event, and toggles the `aria-pressed`
 * attribute.
 */
export default class AccessibleFakeButton extends PureComponent {
  static propTypes = {
    /**
     * Any children to display in the Accessible Fake Button.
     */
    children: PropTypes.node,

    /**
     * An optional onClick function to call whent he user clicks the
     * button or presses space || enter.
     */
    onClick: PropTypes.func,

    /**
     * An optional onKeyUp function to call.
     */
    onKeyUp: PropTypes.func,

    /**
     * The component to render the Fake button as.
     */
    component: PropTypes.oneOfType([
      PropTypes.func,
      PropTypes.string,
    ]).isRequired,

    /**
     * The tab index to use for the Fake button so it is keyboard focusable.
     */
    tabIndex: PropTypes.number.isRequired,
  };

  static defaultProps = {
    component: 'div',
    tabIndex: 0,
  };

  constructor(props) {
    super(props);

    this.state = { pressed: false };
    this._handleClick = this._handleClick.bind(this);
    this._handleKeyUp = this._handleKeyUp.bind(this);
  }

  _handleClick(e) {
    if (this.props.onClick) {
      this.props.onClick(e);
    }

    this.setState({ pressed: !this.state.pressed });
  }

  _handleKeyUp(e) {
    if (this.props.onKeyUp) {
      this.props.onKeyUp(e);
    }

    if ([SPACE, ENTER].indexOf(e.which || e.keyCode) !== -1) {
      this._handleClick(e);
    }
  }

  render() {
    const { component, children, ...props } = this.props;
    delete props.onClick;
    delete props.onKeyUp;

    return createElement(component, {
      ...props,
      role: 'button',
      onClick: this._handleClick,<commit_msg>Updated the AccessibleFakeButton for disabled.<commit_after>import { PureComponent, PropTypes, createElement } from 'react';
import { SPACE, ENTER } from '../constants/keyCodes';

/**
 * The `AccessibleFakeButton` is a generic component that can be used to render
 * a `div` or any other non `button` components as a button. This should not be
 * used often.
 *
 * The `AccessibleFakeButton` allows the user to tab focus the element, use the
 * space or enter key to trigger the `onClick` event, and toggles the `aria-pressed`
 * attribute.
 */
export default class AccessibleFakeButton extends PureComponent {
  static propTypes = {
    /**
     * Any children to display in the Accessible Fake Button.
     */
    children: PropTypes.node,

    /**
     * An optional onClick function to call whent he user clicks the
     * button or presses space || enter.
     */
    onClick: PropTypes.func,

    /**
     * An optional onKeyUp function to call.
     */
    onKeyUp: PropTypes.func,

    /**
     * The component to render the Fake button as.
     */
    component: PropTypes.oneOfType([
      PropTypes.func,
      PropTypes.string,
    ]).isRequired,

    /**
     * The tab index to use for the Fake button so it is keyboard focusable.
     */
    tabIndex: PropTypes.number.isRequired,

    /**
     * Boolean if the Button is disabled. This will prevent tab focus.
     */
    disabled: PropTypes.bool,
  };

  static defaultProps = {
    component: 'div',
    tabIndex: 0,
  };

  constructor(props) {
    super(props);

    this.state = { pressed: false };
    this._handleClick = this._handleClick.bind(this);
    this._handleKeyUp = this._handleKeyUp.bind(this);
  }

  _handleClick(e) {
    if (this.props.disabled) {
      return;
    }

    if (this.props.onClick) {
      this.props.onClick(e);
    }

    this.setState({ pressed: !this.state.pressed });
  }

  _handleKeyUp(e) {
    if (this.props.disabled) {
      return;
    }

    if (this.props.onKeyUp) {
      this.props.onKeyUp(e);
    }

    if ([SPACE, ENTER].indexOf(e.which || e.keyCode) !== -1) {
      this._handleClick(e);
    }
  }

  render() {
    const { component, children, disabled, tabIndex, ...props } = this.props;
    delete props.onClick;
    delete props.onKeyUp;

    return createElement(component, {
      ...props,
      disabled,
      tabIndex: disabled ? null : tabIndex,
      role: 'button',
      onClick: this._handleClick,
{'fraction_non_alphanumeric': 0.11680282623095606, 'fraction_numerical': 0.0008831971737690439, 'mean_word_length': 2.5866983372921615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3297661', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1377, 'n_words': 407}