Button.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './Custom.scss';
class Button extends React.Component {
constructor(props) {
super(props);
this.btnOnClick=this.btnOnClick.bind(this);
}
static propTypes = {
onClick:PropTypes.func
}
static defaultProps={
bsSize:'nl',//sm|xs
block:false,
active:false,
href:'javescript:;',
linkable:false,
disabled:false,
isLoading:false,
customColor:'success'
}
btnOnClick(){
const {disabled,isLoading,onClick}=this.props;
if(disabled||isLoading){
return
}
onClick();
}
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')}></i>}
</a>;
}else{
return <div className={cx(s[customColor+'_btn'],s[bsSize],
disabled||isLoading?s.disabled:'',
block?s.block:'')} onClick={this.btnOnClick}>
{this.props.children}
{isLoading&&<i style={{width:'20px'}} className={cx('kr_icon','kr_icon-spin')}></i>}
</div>;
}
}
}
export default Button;