<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Box from '../box';
import Icon from '../icon';
import cx from 'classnames';
import buttonTheme from '../button/theme.css';
import theme from './theme.css';

class IconButton extends Component {
  handleMouseUp = (event) => {
    this.blur();
    if (this.props.onMouseUp) {
      this.props.onMouseUp(event);
    }
  };

  handleMouseLeave = (event) => {
    this.blur();
    if (this.props.onMouseLeave) {
      this.props.onMouseLeave(event);
    }
  };

  blur() {
    if (this.buttonNode.blur) {
      this.buttonNode.blur();
    }
  }

  render() {
    const { children, className, disabled, element, icon, size, color, tint, selected, type, ...others } = this.props;

    const classNames = cx(
      buttonTheme['button-base'],
      theme['icon-button'],
      theme[`is-${size}`],
      {
        [theme['is-disabled']]: disabled,
        [theme['is-selected']]: selected,
      },
      className,
    );

    const props = {
      ...others,
      ref: (node) => {
        this.buttonNode = node;
      },
      className: classNames,
      disabled: element === 'button' ? disabled : null,
      element: element,
      onMouseUp: this.handleMouseUp,
      onMouseLeave: this.handleMouseLeave,
      type: element === 'button' ? type : null,
      'data-teamleader-ui': 'icon-button',
    };

    return (
      <Box {...props}>
        <Icon color={color === 'white' ? 'neutral' : color} tint={color === 'white' ? 'lightest' : tint}>
          {icon}
        </Icon>
        {children}
      </Box>
    );
  }
}

IconButton.propTypes = {
  /** The content to display inside the button. */
  children: PropTypes.node,
  /** A class name for the button to give custom styles. */
  className: PropTypes.string,
  /** If true, component will be disabled. */
  disabled: PropTypes.bool,
  /** A custom element to be rendered */
  element: PropTypes.oneOfType([PropTypes.element, PropTypes.string]),
  /** The icon displayed inside the button. */
  icon: PropTypes.element,
  /** Callback function that is fired when mouse leaves the component. */
  onMouseLeave: PropTypes.func,<commit_msg>:recycle: convert IconButton to a function component<commit_after>import React, { useRef } from 'react';
import PropTypes from 'prop-types';
import Box from '../box';
import Icon from '../icon';
import cx from 'classnames';
import buttonTheme from '../button/theme.css';
import theme from './theme.css';

const IconButton = ({
  children,
  className,
  disabled,
  element,
  icon,
  size,
  color,
  tint,
  selected,
  type,
  onMouseUp,
  onMouseLeave,
  ...others
}) => {
  const buttonRef = useRef();

  const handleMouseUp = (event) => {
    blur();
    if (onMouseUp) {
      onMouseUp(event);
    }
  };

  const handleMouseLeave = (event) => {
    blur();
    if (onMouseLeave) {
      onMouseLeave(event);
    }
  };

  const blur = () => {
    const currentButtonRef = buttonRef.current;
    if (currentButtonRef.blur) {
      currentButtonRef.blur();
    }
  };

  const classNames = cx(
    buttonTheme['button-base'],
    theme['icon-button'],
    theme[`is-${size}`],
    {
      [theme['is-disabled']]: disabled,
      [theme['is-selected']]: selected,
    },
    className,
  );

  const props = {
    ...others,
    ref: buttonRef,
    className: classNames,
    disabled: element === 'button' ? disabled : null,
    element: element,
    onMouseUp: handleMouseUp,
    onMouseLeave: handleMouseLeave,
    type: element === 'button' ? type : null,
    'data-teamleader-ui': 'icon-button',
  };

  return (
    <Box {...props}>
      <Icon color={color === 'white' ? 'neutral' : color} tint={color === 'white' ? 'lightest' : tint}>
        {icon}
      </Icon>
      {children}
    </Box>
  );
};

IconButton.propTypes = {
  /** The content to display inside the button. */
  children: PropTypes.node,
  /** A class name for the button to give custom styles. */
  className: PropTypes.string,
  /** If true, component will be disabled. */
  disabled: PropTypes.bool,
  /** A custom element to be rendered */
  element: PropTypes.oneOfType([PropTypes.element, PropTypes.string]),
  /** The icon displayed inside the button. */
  icon: PropTypes.element,
  /** Callback function that is fired when mouse leaves the component. */
  onMouseLeave: PropTypes.func,
{'fraction_non_alphanumeric': 0.15344157329064714, 'fraction_numerical': 0.0, 'mean_word_length': 2.751286449399657, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, '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': '1354199', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1339, 'n_words': 361}