<commit_before>/**
 * @file IconAnchor component
 * @author liangxiaojun(<EMAIL>)
 */

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import CircularLoading from '../CircularLoading/CircularLoading';
import TouchRipple from '../TouchRipple/TouchRipple';
import Theme from '../Theme';
import TipProvider from '../TipProvider';

import Util from '../_vendors/Util';

class IconAnchor extends Component {

    static Theme = Theme;

    constructor(props, ...restArgs) {
        super(props, ...restArgs);
    }

    clickHandler = e => {
        const {disabled, isLoading, onClick} = this.props;
        !disabled && !isLoading && onClick && onClick(e);
    };

    startRipple = e => {
        this.refs.touchRipple.addRipple(e);
    };

    endRipple = () => {
        this.refs.touchRipple.removeRipple();
    };

    render() {

        const {

                className, theme, iconCls, disabled, isLoading,
                tip, tipPosition,

                ...restProps

            } = this.props,

            iconAnchorClassName = classNames('icon-anchor', {
                [`theme-${theme}`]: theme,
                [className]: className
            });

        return (
            <TipProvider text={tip}
                         position={tipPosition}>

                <a {...restProps}
                   className={iconAnchorClassName}
                   disabled={disabled || isLoading}
                   onClick={this.clickHandler}>

                    {
                        isLoading ?
                            <CircularLoading size="small"/>
                            :
                            (
                                iconCls ?
                                    <i className={`icon-anchor-icon ${iconCls}`}
                                       aria-hidden="true"></i>
                                    :
                                    null
                            )
                    }

                    {
                        disabled || isLoading ?
                            null
                            :
                            <TouchRipple ref="touchRipple"
                                         className={disabled || isLoading ? 'hidden' : ''}
                                         displayCenter={true}/>
                    }

                </a>

            </TipProvider>
        );

    }
}

IconAnchor.propTypes = {

    /**
     * The CSS class name of the root element.
     */
    className: PropTypes.string,

    /**
     * Override the styles of the root element.
     */
    style: PropTypes.object,

    /**
     * The button theme.Can be primary,highlight,success,warning,error.
     */
    theme: PropTypes.oneOf(Util.enumerateValue(Theme)),

    /**
     * Disables the button if set to true.
     */
    disabled: PropTypes.bool,

    /**
     * If true,the button will be have loading effect.
     */
    isLoading: PropTypes.bool,

    /**
     * The icon within the IconAnchor is a Font Awesome component.This property is the className of the icon.
     */
    iconCls: PropTypes.string.isRequired,

    /**
     * The URL to link to when the button is clicked.
     */
    href: PropTypes.string,

    /**
     * How to open the linked document.The value can be _blank,_self,_parent or _top.
     */
    target: PropTypes.string,

    alt: PropTypes.string,

    tip: PropTypes.string,
    tipPosition: PropTypes.oneOf(Util.enumerateValue(TipProvider.Position)),

    /**
     * Callback function fired when the button is touch-tapped.
     */
    onClick: PropTypes.func

};

IconAnchor.defaultProps = {

    theme: Theme.DEFAULT,

    disabled: false,
    isLoading: false,
    href: 'javascript:void(0)',
    target: '_blank',<commit_msg>update IconAnchor<commit_after>/**
 * @file IconAnchor component
 * @author liangxiaojun(<EMAIL>)
 */

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import CircularLoading from '../CircularLoading/CircularLoading';
import TouchRipple from '../TouchRipple/TouchRipple';
import Theme from '../Theme';
import TipProvider from '../TipProvider';

import Util from '../_vendors/Util';

class IconAnchor extends Component {

    static Theme = Theme;

    constructor(props, ...restArgs) {
        super(props, ...restArgs);
    }

    /**
     * public
     */
    startRipple = (e, props) => {
        !this.props.disableTouchRipple && this.refs.touchRipple && this.refs.touchRipple.addRipple(e, props);
    };

    /**
     * public
     */
    endRipple = () => {
        !this.props.disableTouchRipple && this.refs.touchRipple && this.refs.touchRipple.removeRipple();
    };

    /**
     * public
     */
    triggerRipple = (e, props) => {
        this.startRipple(e, props);
        setTimeout(() => {
            this.endRipple();
        }, 250);
    };

    clickHandler = e => {
        const {disabled, isLoading, onClick} = this.props;
        !disabled && !isLoading && onClick && onClick(e);
    };

    render() {

        const {

                className, theme, iconCls, disabled, isLoading,
                tip, tipPosition, disableTouchRipple,

                ...restProps

            } = this.props,

            iconAnchorClassName = classNames('icon-anchor', {
                [`theme-${theme}`]: theme,
                [className]: className
            });

        return (
            <TipProvider text={tip}
                         position={tipPosition}>

                <a {...restProps}
                   className={iconAnchorClassName}
                   disabled={disabled || isLoading}
                   onClick={this.clickHandler}>

                    {
                        isLoading ?
                            <CircularLoading size="small"/>
                            :
                            (
                                iconCls ?
                                    <i className={`icon-anchor-icon ${iconCls}`}
                                       aria-hidden="true"></i>
                                    :
                                    null
                            )
                    }

                    {
                        disableTouchRipple ?
                            null
                            :
                            <TouchRipple ref="touchRipple"
                                         className={disabled || isLoading ? 'hidden' : ''}
                                         displayCenter={true}/>
                    }

                </a>

            </TipProvider>
        );

    }
}

IconAnchor.propTypes = {

    /**
     * The CSS class name of the root element.
     */
    className: PropTypes.string,

    /**
     * Override the styles of the root element.
     */
    style: PropTypes.object,

    /**
     * The button theme.Can be primary,highlight,success,warning,error.
     */
    theme: PropTypes.oneOf(Util.enumerateValue(Theme)),

    /**
     * Disables the button if set to true.
     */
    disabled: PropTypes.bool,

    /**
     * If true,the button will be have loading effect.
     */
    isLoading: PropTypes.bool,

    /**
     * The icon within the IconAnchor is a Font Awesome component.This property is the className of the icon.
     */
    iconCls: PropTypes.string.isRequired,

    /**
     * The URL to link to when the button is clicked.
     */
    href: PropTypes.string,

    /**
     * How to open the linked document.The value can be _blank,_self,_parent or _top.
     */
    target: PropTypes.string,

    alt: PropTypes.string,
    disableTouchRipple: PropTypes.bool,

    tip: PropTypes.string,
    tipPosition: PropTypes.oneOf(Util.enumerateValue(TipProvider.Position)),

    /**
     * Callback function fired when the button is touch-tapped.
     */
    onClick: PropTypes.func

};

IconAnchor.defaultProps = {

    theme: Theme.DEFAULT,

    disabled: false,
    isLoading: false,
    href: 'javascript:void(0)',
    target: '_blank',
    disableTouchRipple: false,
{'fraction_non_alphanumeric': 0.1110563900517114, 'fraction_numerical': 0.0006156119182467373, 'mean_word_length': 1.423329355608592, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5804316', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2036, 'n_words': 483}