Skip to content

Add disabled state to neutral button. #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions components/SLDSButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Button extends React.Component {
render() {
const props = omit('className', this.props);
const click = createChainedFunction(this.props.onClick, this.onClick.bind(this));
if (this.props.disabled) { props['disabled'] = 'disabled' };

//If the button is only an icon render this:
if(this.props.variant === 'icon'){
Expand All @@ -69,7 +70,7 @@ class Button extends React.Component {
name={this.props.iconName}
category='utility'
size={this.props.iconSize}
className={'slds-icon'} />
/>
<span className="slds-assistive-text">{this.props.label}</span>
</button>
);
Expand All @@ -78,13 +79,9 @@ class Button extends React.Component {
else{
return (
<button className={this.getClassName()} {...props} onClick={click}>

{this.props.iconPosition === 'right' ? this.props.label : null}

{this.renderIcon()}

{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}

{this.props.iconPosition === 'right' ? this.props.label : null}
{this.renderIcon()}
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}
</button>
);
}
Expand All @@ -94,6 +91,7 @@ class Button extends React.Component {
Button.propTypes = {
label: React.PropTypes.string.isRequired,
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'icon']),
disabled: React.PropTypes.bool,
iconName: React.PropTypes.string,
iconSize: React.PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
iconPosition: React.PropTypes.oneOf(['left', 'right']),
Expand Down
15 changes: 10 additions & 5 deletions demo/code-snippets/SLDSButton.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@

<SLDSButton
label='Test Button'
label='Neutral'
variant='neutral'
disabled={false}
iconName='download'
iconSize='small'
iconPosition='left'
iconPosition='right'
onClick={this.handleButtonClick} />

* Only label is required
* variant must be neutral, brand, or icon
* iconSize must be small, medium, or large
* iconPosition must be left or right

Below are component prop defaults and available options:
* variant='base' ('neutral', 'brand', 'icon')
* disabled='false'
* iconSize='medium' ('x-small', 'medium', 'small', 'large')
* iconPosition='left'('left', 'right', 'large')

18 changes: 14 additions & 4 deletions demo/pages/HomePage/ButtonSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ module.exports = React.createClass( {
return {};
},

handleNeutralClick () {
alert('Neutral Button Clicked');
},


handleButtonClick () {
alert('Test Button Clicked');
handleDisabledClick () {
alert('Disabled Button Clicked');
},

render() {
Expand All @@ -47,12 +49,20 @@ module.exports = React.createClass( {
</PrismCode>
<div className='slds-p-vertical--large'>
<SLDSButton
label='Test'
label='Neutral'
variant='neutral'
disabled={false}
iconName='download'
iconSize='small'
iconPosition='right'
onClick={this.handleNeutralClick} />

<SLDSButton
label='Disabled'
variant='neutral'
disabled={true}
onClick={this.handleButtonClick} />

</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions tests/SLDSButton/button.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('SLDSButton: ', function(){
let brand = TestUtils.findRenderedDOMComponentWithClass(button, 'slds-button--brand');
expect(brand).to.not.equal(undefined);
});

})


Expand Down