@@ -2,72 +2,19 @@ import React, { Component } from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import classnames from 'classnames' ;
4
4
import { themr } from 'react-css-themr' ;
5
+
5
6
import InjectFontIcon from '../font_icon/FontIcon' ;
6
7
import rippleFactory from '../ripple/Ripple' ;
7
8
8
9
const factory = ( ripple , FontIcon ) => {
9
10
class Button extends Component {
10
- static propTypes = {
11
- accent : PropTypes . bool ,
12
- children : PropTypes . node ,
13
- className : PropTypes . string ,
14
- disabled : PropTypes . bool ,
15
- flat : PropTypes . bool ,
16
- floating : PropTypes . bool ,
17
- href : PropTypes . string ,
18
- icon : PropTypes . oneOfType ( [
19
- PropTypes . string ,
20
- PropTypes . element ,
21
- ] ) ,
22
- inverse : PropTypes . bool ,
23
- label : PropTypes . string ,
24
- mini : PropTypes . bool ,
25
- neutral : PropTypes . bool ,
26
- onMouseLeave : PropTypes . func ,
27
- onMouseUp : PropTypes . func ,
28
- primary : PropTypes . bool ,
29
- raised : PropTypes . bool ,
30
- theme : PropTypes . shape ( {
31
- accent : PropTypes . string ,
32
- button : PropTypes . string ,
33
- flat : PropTypes . string ,
34
- floating : PropTypes . string ,
35
- icon : PropTypes . string ,
36
- inverse : PropTypes . string ,
37
- mini : PropTypes . string ,
38
- neutral : PropTypes . string ,
39
- primary : PropTypes . string ,
40
- raised : PropTypes . string ,
41
- rippleWrapper : PropTypes . string ,
42
- toggle : PropTypes . string ,
43
- } ) ,
44
- type : PropTypes . string ,
45
- } ;
46
-
47
11
static defaultProps = {
48
- accent : false ,
12
+ type : 'default' ,
13
+ size : 'medium' ,
49
14
className : '' ,
50
- flat : false ,
51
- floating : false ,
52
- mini : false ,
53
- neutral : true ,
54
- primary : false ,
55
- raised : false ,
56
- type : 'button' ,
15
+ href : '' ,
57
16
} ;
58
17
59
- getLevel = ( ) => {
60
- if ( this . props . primary ) return 'primary' ;
61
- if ( this . props . accent ) return 'accent' ;
62
- return 'neutral' ;
63
- }
64
-
65
- getShape = ( ) => {
66
- if ( this . props . raised ) return 'raised' ;
67
- if ( this . props . floating ) return 'floating' ;
68
- return 'flat' ;
69
- }
70
-
71
18
handleMouseUp = ( event ) => {
72
19
this . buttonNode . blur ( ) ;
73
20
if ( this . props . onMouseUp ) this . props . onMouseUp ( event ) ;
@@ -79,32 +26,12 @@ const factory = (ripple, FontIcon) => {
79
26
} ;
80
27
81
28
render ( ) {
82
- const {
83
- accent, // eslint-disable-line
84
- children,
85
- className,
86
- flat, // eslint-disable-line
87
- floating, // eslint-disable-line
88
- href,
89
- icon,
90
- inverse,
91
- label,
92
- mini,
93
- neutral,
94
- primary, // eslint-disable-line
95
- raised, // eslint-disable-line
96
- theme,
97
- type,
98
- ...others
99
- } = this . props ;
29
+ const { children, type, size, className, href, icon, theme, ...others } = this . props ;
100
30
const element = href ? 'a' : 'button' ;
101
- const level = this . getLevel ( ) ;
102
- const shape = this . getShape ( ) ;
103
31
104
- const classes = classnames ( theme . button , [ theme [ shape ] ] , {
105
- [ theme [ level ] ] : neutral ,
106
- [ theme . mini ] : mini ,
107
- [ theme . inverse ] : inverse ,
32
+ const classes = classnames ( theme . button , {
33
+ [ theme [ type ] ] : true ,
34
+ [ theme [ size ] ] : true ,
108
35
} , className ) ;
109
36
110
37
const props = {
@@ -115,13 +42,10 @@ const factory = (ripple, FontIcon) => {
115
42
disabled : this . props . disabled ,
116
43
onMouseUp : this . handleMouseUp ,
117
44
onMouseLeave : this . handleMouseLeave ,
118
- type : ! href ? type : null ,
119
- 'data-react-toolbox' : 'button' ,
120
45
} ;
121
46
122
47
return React . createElement ( element , props ,
123
48
icon ? < FontIcon className = { theme . icon } value = { icon } /> : null ,
124
- label ,
125
49
children ,
126
50
) ;
127
51
}
0 commit comments