Skip to content

Commit 170b79d

Browse files
committed
Merge pull request #17 from salesforce-ux/button
Add disabled state to neutral button.
2 parents abd5921 + 48856e1 commit 170b79d

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

components/SLDSButton/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Button extends React.Component {
6060
render() {
6161
const props = omit('className', this.props);
6262
const click = createChainedFunction(this.props.onClick, this.onClick.bind(this));
63+
if (this.props.disabled) { props['disabled'] = 'disabled' };
6364

6465
//If the button is only an icon render this:
6566
if(this.props.variant === 'icon'){
@@ -69,7 +70,7 @@ class Button extends React.Component {
6970
name={this.props.iconName}
7071
category='utility'
7172
size={this.props.iconSize}
72-
className={'slds-icon'} />
73+
/>
7374
<span className="slds-assistive-text">{this.props.label}</span>
7475
</button>
7576
);
@@ -78,13 +79,9 @@ class Button extends React.Component {
7879
else{
7980
return (
8081
<button className={this.getClassName()} {...props} onClick={click}>
81-
82-
{this.props.iconPosition === 'right' ? this.props.label : null}
83-
84-
{this.renderIcon()}
85-
86-
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}
87-
82+
{this.props.iconPosition === 'right' ? this.props.label : null}
83+
{this.renderIcon()}
84+
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}
8885
</button>
8986
);
9087
}
@@ -94,6 +91,7 @@ class Button extends React.Component {
9491
Button.propTypes = {
9592
label: React.PropTypes.string.isRequired,
9693
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'icon']),
94+
disabled: React.PropTypes.bool,
9795
iconName: React.PropTypes.string,
9896
iconSize: React.PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
9997
iconPosition: React.PropTypes.oneOf(['left', 'right']),

demo/code-snippets/SLDSButton.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11

22
<SLDSButton
3-
label='Test Button'
3+
label='Neutral'
44
variant='neutral'
5+
disabled={false}
56
iconName='download'
67
iconSize='small'
7-
iconPosition='left'
8+
iconPosition='right'
89
onClick={this.handleButtonClick} />
910

1011
* Only label is required
11-
* variant must be neutral, brand, or icon
12-
* iconSize must be small, medium, or large
13-
* iconPosition must be left or right
12+
13+
Below are component prop defaults and available options:
14+
* variant='base' ('neutral', 'brand', 'icon')
15+
* disabled='false'
16+
* iconSize='medium' ('x-small', 'medium', 'small', 'large')
17+
* iconPosition='left'('left', 'right', 'large')
18+

demo/pages/HomePage/ButtonSection.jsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ module.exports = React.createClass( {
2828
return {};
2929
},
3030

31+
handleNeutralClick () {
32+
alert('Neutral Button Clicked');
33+
},
3134

32-
33-
handleButtonClick () {
34-
alert('Test Button Clicked');
35+
handleDisabledClick () {
36+
alert('Disabled Button Clicked');
3537
},
3638

3739
render() {
@@ -47,12 +49,20 @@ module.exports = React.createClass( {
4749
</PrismCode>
4850
<div className='slds-p-vertical--large'>
4951
<SLDSButton
50-
label='Test'
52+
label='Neutral'
5153
variant='neutral'
54+
disabled={false}
5255
iconName='download'
5356
iconSize='small'
5457
iconPosition='right'
58+
onClick={this.handleNeutralClick} />
59+
60+
<SLDSButton
61+
label='Disabled'
62+
variant='neutral'
63+
disabled={true}
5564
onClick={this.handleButtonClick} />
65+
5666
</div>
5767
</div>
5868

tests/SLDSButton/button.test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('SLDSButton: ', function(){
3434
let brand = TestUtils.findRenderedDOMComponentWithClass(button, 'slds-button--brand');
3535
expect(brand).to.not.equal(undefined);
3636
});
37+
3738
})
3839

3940

0 commit comments

Comments
 (0)