1
1
import React from 'react' ;
2
- import PropTypes from 'prop-types' ;
3
2
import './style/index.less' ;
4
3
5
4
export interface ButtonProps {
@@ -15,53 +14,28 @@ export interface ButtonProps {
15
14
children ?: React . ReactNode ;
16
15
htmlType ?: React . ButtonHTMLAttributes < HTMLButtonElement > [ 'type' ] ;
17
16
}
18
- export default function Button ( props : ButtonProps = { } ) {
19
- const { prefixCls, type, size, active, disabled, block, basic, className, loading, children, htmlType, ...others } =
20
- props ;
21
17
22
- const cls = [
23
- className ,
24
- prefixCls ,
25
- size ? `${ prefixCls } -${ size } ` : false ,
26
- type ? `${ prefixCls } -${ type } ` : false ,
27
- basic ? `${ prefixCls } -basic` : false ,
28
- loading ? `${ prefixCls } -loading` : false ,
29
- disabled || loading ? 'disabled' : false ,
30
- active ? 'active' : false ,
31
- block ? 'block' : false ,
32
- ]
33
- . filter ( Boolean )
34
- . join ( ' ' ) ;
35
- return (
36
- < button { ...others } disabled = { disabled || loading } type = { htmlType } className = { cls } >
37
- { children &&
38
- React . Children . map ( children , ( child ) => {
39
- if ( React . isValidElement ( child ) ) return child ;
40
- return < span > { child } </ span > ;
41
- } ) }
42
- </ button >
43
- ) ;
18
+ export default class Button extends React . PureComponent < ButtonProps > {
19
+ public static defaultProps : ButtonProps = {
20
+ type : 'light' ,
21
+ prefixCls : 'w-btn' ,
22
+ size : 'default' ,
23
+ htmlType : 'button' ,
24
+ } ;
25
+ render ( ) {
26
+ const { prefixCls, className, children, type, htmlType, size } = this . props ;
27
+ const cls = [ className , prefixCls , size ? `${ prefixCls } -${ size } ` : false , type ? `${ prefixCls } -${ type } ` : false ]
28
+ . filter ( Boolean )
29
+ . join ( ' ' ) ;
30
+ return (
31
+ < button type = { htmlType } className = { cls } >
32
+ { children &&
33
+ React . Children . map ( children , ( child ) => {
34
+ if ( ! child ) return child ;
35
+ if ( React . isValidElement ( child ) ) return child ;
36
+ return < span > { child } </ span > ;
37
+ } ) }
38
+ </ button >
39
+ ) ;
40
+ }
44
41
}
45
-
46
- Button . defaultProps = {
47
- prefixCls : 'w-btn' ,
48
- disabled : false ,
49
- active : false ,
50
- loading : false ,
51
- block : false ,
52
- basic : false ,
53
- htmlType : 'button' ,
54
- type : 'light' ,
55
- size : 'default' ,
56
- } ;
57
- Button . propTypes = {
58
- prefixCls : PropTypes . string ,
59
- loading : PropTypes . bool ,
60
- disabled : PropTypes . bool ,
61
- block : PropTypes . bool ,
62
- active : PropTypes . bool ,
63
- basic : PropTypes . bool ,
64
- htmlType : PropTypes . string ,
65
- type : PropTypes . oneOf ( [ 'primary' , 'success' , 'warning' , 'danger' , 'light' , 'dark' , 'link' ] ) ,
66
- size : PropTypes . oneOf ( [ 'large' , 'default' , 'small' ] ) ,
67
- } ;
0 commit comments