ExportBtn.js 1.8 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';  
import cx from 'classnames';
import s from './Custom.scss'; 
import {downloadForm} from '../../../utils/fileUtil'


class ExportBtn extends React.Component {
    constructor(props) {
        super(props);     
        this.dowloadForm=this.dowloadForm.bind(this);
    }
    static propTypes = {    
        'formName':PropTypes.string,
        'serviceName':PropTypes.string
    } 
    static defaultProps={ 
        bsSize:'lg',//sm|xs
        block:true,
        active:false,
        href:'javescript:;',
        linkable:false,
        disabled:false,
        isLoading:false,
        customColor:'success',
        serviceName:'hr'
    }  
    dowloadForm(){
    	const {formName,serviceName,disabled,isLoading}=this.props;
        if(disabled||isLoading){
            return 
        }
    	downloadForm(serviceName,formName);
    }
    render(){    
    	const {linkable,href,customColor,bsSize,disabled,block,isLoading}=this.props;
        if(linkable){
            return <a className={cx(s[customColor+'_btn'],s[bsSize],
                    disabled?s.disabled:'', 
                    block?s.block:'')} href={href}>
                    {this.props.children}
                    {isLoading&&<i  style={{width:'20px'}} className={cx('kr_icon','kr_icon-spin')}>&#xe65a;</i>}
                </a>;
        }else{
            return <div className={cx(s[customColor+'_btn'],s[bsSize],
                    disabled||isLoading?s.disabled:'', 
                    block?s.block:'')} onClick={this.dowloadForm}>
                    {this.props.children}
                    {isLoading&&<i  style={{width:'20px'}} className={cx('kr_icon','kr_icon-spin')}>&#xe65a;</i>}
                </div>;
        } 
    }
}



export default ExportBtn;