1
1
import React , { PropTypes } from 'react' ;
2
- import ClassNames from 'classnames/bind' ;
3
- import style from './button.css' ;
4
2
5
3
/**
6
4
* Creates a reusable, customizable button.
7
5
*/
8
- const Button = ( { className, outline, href, loading, primary, secondary, success, warning, danger, link, large, small, block, disabled, children, ...others } ) => {
9
-
10
- const element = href ? 'a' : 'button' ;
11
- const cx = ClassNames . bind ( style ) ;
12
- let classNames = cx ( {
13
- large,
14
- small,
15
- block,
16
- disabled,
17
- className
18
- } ) ;
19
-
20
- if ( outline ) {
21
- classNames += ' ' + cx ( {
22
- primary_outline : ! secondary && ! success && ! warning && ! danger && ! link ,
23
- secondary,
24
- success_outline : success ,
25
- warning_outline : warning ,
26
- danger_outline : danger ,
27
- link_outline : link
28
- } ) ;
29
- } else {
30
- classNames += ' ' + cx ( {
31
- primary : ! secondary && ! success && ! warning && ! danger && ! link ,
32
- secondary,
33
- success,
34
- warning,
35
- danger,
36
- link
37
- } ) ;
38
- }
39
-
40
-
41
- let role ;
42
- if ( element === 'a' ) {
43
- role = 'button' ;
44
- }
45
- const props = {
46
- ...others ,
47
- href,
48
- className : classNames ,
49
- disabled : disabled || loading ,
50
- role
51
- } ;
52
-
53
- return React . createElement ( element , props ,
54
- children
55
- ) ;
6
+ const Button = ( { loading, disabled, children, theme, className, ...props } ) => {
56
7
8
+ var disabledStyle = disabled || loading ? theme . disabled : '' ;
9
+ return < button { ...props } className = { `${ theme . base } ${ disabledStyle } ${ className } ` } > { children } </ button >
57
10
} ;
58
11
59
12
Button . displayName = 'Button' ;
@@ -64,44 +17,10 @@ Button.styleguide = {
64
17
example : `
65
18
<section>
66
19
<p>Regular Buttons</p>
67
- <Button>Button</Button>
68
- <Button>Secondary</Button>
69
- <Button>Success</Button>
70
- <Button>Warning</Button>
71
- <Button>Danger</Button>
72
-
73
- <p>Disabled Regular Buttons</p>
74
- <Button disabled >Button</Button>
75
- <Button disabled>Secondary</Button>
76
- <Button disabled >Success</Button>
77
- <Button disabled >Warning</Button>
78
- <Button disabled >Danger</Button>
79
-
80
- <p>Outline Buttons</p>
81
- <Button>Button</Button>
82
- <Button>Secondary</Button>
83
- <Button>Success</Button>
84
- <Button>Warning</Button>
85
- <Button>Danger</Button>
86
-
87
- <p>Disabled Outline Buttons</p>
88
- <Button disabled>Button</Button>
89
- <Button disabled>Secondary</Button>
90
- <Button disabled>Success</Button>
91
- <Button disabled>Warning</Button>
92
- <Button disabled>Danger</Button>
93
-
94
- <p>Large Buttons</p>
95
- <Button>Button</Button>
96
- <Button>Secondary</Button>
97
-
98
- <p>Small Buttons</p>
99
- <Button>Button</Button>
100
- <Button>Secondary</Button>
101
-
102
- <p>Block Level Buttons</p>
103
- <Button>Button</Button>
104
- <Button>Secondary</Button>
20
+ <PrimaryButton>PrimaryButton</PrimaryButton>
21
+ <SecondaryButton>Secondary</SecondaryButton>
22
+ <div style={{clear: 'both'}}> </div>
23
+ <Button>Core 'unstyled' Button with primary theme as default</Button>
105
24
</section>
106
25
`
107
26
} ;
@@ -126,34 +45,7 @@ Button.propTypes = {
126
45
* Use outline styled button
127
46
* @examples <Button outline>
128
47
*/
129
- outline : PropTypes . bool ,
130
- /**
131
- * Define button href if anchor
132
- * @examples '#', 'http://some-website.com/'
133
- */
134
- href : PropTypes . string ,
135
- /**
136
- * Set loading animation on button
137
- * @examples <Button loading>
138
- */
139
- loading : PropTypes . bool ,
140
- /**
141
- * Use primary style button (button is set to this by default)
142
- * @examples <Button primary>
143
- */
144
- primary : PropTypes . bool ,
145
- type : PropTypes . string ,
146
- /**
147
- * Use secondary style button
148
- * @examples <Button secondary>
149
- */
150
- secondary : PropTypes . bool ,
151
- success : PropTypes . bool ,
152
- warning : PropTypes . bool ,
153
- danger : PropTypes . bool ,
154
- link : PropTypes . bool ,
155
- large : PropTypes . bool ,
156
- small : PropTypes . bool
48
+ theme : PropTypes . object
157
49
} ;
158
50
159
51
Button . defaultProps = {
@@ -170,8 +62,11 @@ Button.defaultProps = {
170
62
danger : false ,
171
63
link : false ,
172
64
large : false ,
173
- small : false
174
-
65
+ small : false ,
66
+ theme : {
67
+ base : "" ,
68
+ disabled : ""
69
+ }
175
70
} ;
176
71
177
72
export default Button ;
0 commit comments