@@ -23,15 +23,11 @@ export default React.createClass( {
23
23
value : PropTypes . number
24
24
} ,
25
25
26
- getDefaultProps ( ) {
27
- return {
28
- tabClick : ( ) => { }
29
- }
30
- } ,
31
-
32
26
clickHandler ( event ) {
33
- event . preventDefault ( ) ;
34
- this . props . tabClick ( this . props ) ;
27
+ if ( this . props . tabClick ) {
28
+ event . preventDefault ( ) ;
29
+ this . props . tabClick ( this . props ) ;
30
+ }
35
31
} ,
36
32
37
33
ensureValue ( value ) {
@@ -42,14 +38,8 @@ export default React.createClass( {
42
38
return String . fromCharCode ( 8211 ) ;
43
39
} ,
44
40
45
- handleLinkClick ( event ) {
46
- if ( ! this . props . href ) {
47
- event . preventDefault ( ) ;
48
- }
49
- } ,
50
-
51
41
render ( ) {
52
- const { className, children, gridicon, href, label, loading, selected, value } = this . props ;
42
+ const { className, children, gridicon, href, label, loading, selected, tabClick , value } = this . props ;
53
43
54
44
const tabClass = classNames (
55
45
'stats-tab' ,
@@ -60,16 +50,22 @@ export default React.createClass( {
60
50
'is-low' : ! value
61
51
} ) ;
62
52
63
- const linkClass = ! href ? 'no-link' : null ;
53
+ const tabIcon = gridicon ? < Gridicon icon = { gridicon } size = { 18 } /> : null ;
54
+ const tabLabel = < span className = "label" > { label } </ span > ;
55
+ const tabValue = < span className = "value" > { this . ensureValue ( value ) } </ span > ;
56
+ const hasClickAction = href || tabClick ;
64
57
65
58
return (
66
59
< li className = { tabClass } onClick = { this . clickHandler } >
67
- < a href = { href } className = { linkClass } onClick = { this . handleLinkClick } >
68
- { gridicon ? < Gridicon icon = { gridicon } size = { 18 } /> : null }
69
- < span className = "label" > { label } </ span >
70
- < span className = "value" > { this . ensureValue ( value ) } </ span >
71
- { children }
72
- </ a >
60
+ {
61
+ hasClickAction
62
+ ? < a href = { href } >
63
+ { tabIcon } { tabLabel } { tabValue } { children }
64
+ </ a >
65
+ : < span className = "no-link" >
66
+ { tabIcon } { tabLabel } { tabValue } { children }
67
+ </ span >
68
+ }
73
69
</ li >
74
70
) ;
75
71
}
0 commit comments