Skip to content

Commit 544b390

Browse files
committed
Update Button component to accept disabled, destructive, and inverse variants/states
1 parent f9f718a commit 544b390

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

components/SLDSButton/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,26 @@ class Button extends React.Component {
3939
}
4040

4141
getClassName() {
42-
let isStateful = this.props.stateful && this.state.active ? true : false;
42+
let isSelected = this.props.stateful && this.state.active ? true : false;
43+
let notSelected = this.props.stateful && !this.state.active ? true : false;
4344
return classNames(this.props.className, 'slds-button', {
4445
[`slds-button--${this.props.variant}`]: this.props.variant,
45-
['slds-is-selected']: isStateful,
46+
['slds-not-selected']: notSelected,
47+
['slds-is-selected']: isSelected,
4648
});
4749
}
4850

4951
renderIcon(){
5052
if(this.props.iconName){
5153
return (
5254
<ButtonIcon
55+
variant={this.props.variant}
56+
disabled={this.props.disabled}
57+
inverse={this.props.inverse}
58+
stateful={this.props.stateful}
5359
name={this.props.iconName}
5460
size={this.props.iconSize}
55-
inverse={this.props.inverse}
5661
position={this.props.iconPosition}
57-
variant={this.props.variant}
5862
/>
5963
);
6064
}
@@ -79,8 +83,10 @@ class Button extends React.Component {
7983

8084
Button.propTypes = {
8185
label: React.PropTypes.string.isRequired,
82-
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'icon']),
86+
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'destructive', 'icon']),
8387
disabled: React.PropTypes.bool,
88+
inverse: React.PropTypes.bool,
89+
stateful: React.PropTypes.bool,
8490
iconName: React.PropTypes.string,
8591
iconSize: React.PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
8692
iconPosition: React.PropTypes.oneOf(['left', 'right']),

components/SLDSIcons.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ export const ButtonIcon = React.createClass({
3333
this.props.position ? className += ' slds-button__icon--' + this.props.position : className += ' slds-button__icon--left';
3434
}
3535
if (this.props.size) {
36-
className += ' slds-button__icon--' + this.props.size;
36+
className += ' slds-button__icon--' + this.props.size;
3737
}
3838
if (this.props.inverse) {
39-
className += ' slds-button__icon--inverse';
39+
className += ' slds-button__icon--inverse';
4040
}
4141
if (this.props.stateful) {
4242
className += ' slds-button__icon--stateful';
4343
}
4444
if (this.props.hint) {
45-
className += ' slds-button__icon--hint';
45+
className += ' slds-button__icon--hint';
46+
}
47+
if (this.props.destructive) {
48+
className += ' slds-button__icon--destructive';
4649
}
4750
if(this.props.category === 'utility'){
4851
return <SLDSUtilityIcon name={this.props.name} aria-hidden='true' className={className} />;

demo/code-snippets/SLDSButton.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
Below are component prop defaults and available options:
33
* label='' *required
4-
* variant='base' ['neutral', 'brand', 'icon']
4+
* variant='base' ['neutral', 'brand', 'destructive', 'icon']
55
* disabled={false}
66
* inverse={false}
7+
* stateful={false}
78
* iconName='' //see https://www.lightningdesignsystem.com/resources/icons#utility
89
* iconSize='medium' ['x-small', 'medium', 'small', 'large']
910
* iconPosition='left' ['left', 'right', 'large']

demo/pages/HomePage/ButtonSection.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ module.exports = React.createClass( {
6161
variant='neutral'
6262
onClick={this.handleNeutralClick} />
6363

64+
<SLDSButton
65+
label='Neutral Icon'
66+
variant='neutral'
67+
iconName='download'
68+
iconSize='small'
69+
iconPosition='right'
70+
onClick={this.handleNeutralClick} />
71+
6472
<SLDSButton
6573
label='Disabled'
6674
variant='neutral'
@@ -70,10 +78,6 @@ module.exports = React.createClass( {
7078
<SLDSButton
7179
label='Brand'
7280
variant='brand'
73-
iconName='download'
74-
iconSize='small'
75-
iconPosition='right'
76-
inverse={true}
7781
onClick={this.handleBrandClick} />
7882

7983
<SLDSButton

0 commit comments

Comments
 (0)