Skip to content

Commit 1e6e571

Browse files
committed
Merge pull request #44 from salesforce-ux/button
Button
2 parents 5801558 + 2b987c8 commit 1e6e571

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

components/SLDSButton/index.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ class Button extends React.Component {
5050
});
5151
}
5252

53-
renderIcon(){
54-
if(this.props.iconName){
53+
renderIcon(name){
54+
if(this.props.iconName || this.props.notSelectedIcon || this.props.selectedIcon || this.props.selectedFocusIcon){
5555
return (
5656
<ButtonIcon
5757
variant={this.props.variant}
5858
disabled={this.props.disabled}
5959
inverse={this.props.inverse}
6060
stateful={this.props.stateful}
6161
hint={this.props.hint}
62-
name={this.props.iconName}
62+
name={name}
6363
size={this.props.iconSize}
6464
position={this.props.iconPosition}
6565
/>
@@ -88,15 +88,34 @@ class Button extends React.Component {
8888
const labelClasses = this.props.variant === 'icon' ? 'slds-assistive-text': '';
8989
if (this.props.disabled) { props['disabled'] = 'disabled' };
9090

91-
return (
92-
<button tabIndex={this.props.tabindex} className={this.getClassName()} {...props} onClick={click}>
93-
{this.props.iconPosition === 'right' ? <span className={labelClasses}>{this.props.label}</span>: null}
94-
{this.renderIcon()}
95-
{this.renderIconMore()}
96-
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? <span className={labelClasses}>{this.props.label}</span>: null}
97-
{this.props.children}
98-
</button>
99-
);
91+
if(this.props.stateful){
92+
return (
93+
<button tabIndex={this.props.tabindex} className={this.getClassName()} {...props} onClick={click}>
94+
<span className="slds-text-not-selected">
95+
{this.renderIcon(this.props.notSelectedIcon)}
96+
{this.props.notSelectedLabel}
97+
</span>
98+
<span className="slds-text-selected">
99+
{this.renderIcon(this.props.selectedIcon)}
100+
{this.props.selectedLabel}
101+
</span>
102+
<span className="slds-text-selected-focus">
103+
{this.renderIcon(this.props.selectedFocusIcon)}
104+
{this.props.selectedFocusLabel}
105+
</span>
106+
</button>
107+
)
108+
}else{
109+
return (
110+
<button tabIndex={this.props.tabindex} className={this.getClassName()} {...props} onClick={click}>
111+
{this.props.iconPosition === 'right' ? <span className={labelClasses}>{this.props.label}</span>: null}
112+
{this.renderIcon(this.props.iconName)}
113+
{this.renderIconMore()}
114+
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? <span className={labelClasses}>{this.props.label}</span>: null}
115+
{this.props.children}
116+
</button>
117+
);
118+
}
100119
}
101120
}
102121

@@ -113,6 +132,7 @@ Button.propTypes = {
113132
iconVariant: React.PropTypes.oneOf(['bare', 'container', 'border', 'border-filled', 'small', 'more']),
114133
iconSize: React.PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
115134
iconPosition: React.PropTypes.oneOf(['left', 'right']),
135+
onClick: React.PropTypes.func,
116136
}
117137

118138
module.exports = Button;

demo/pages/HomePage/ButtonSection.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ module.exports = React.createClass( {
4444
alert('Icon Button Clicked');
4545
},
4646

47+
handleStatefulClick(e){
48+
console.log('the click event is ', e);
49+
},
50+
51+
4752
render() {
4853
let hintBtnParent = {backgroundColor: '#7fdbff', padding: '10px'};
4954
let inverseBtnParent = {backgroundColor: '#0074d9', padding: '10px'};
@@ -121,6 +126,20 @@ module.exports = React.createClass( {
121126
onClick={this.handleIconClick} />
122127
</div>
123128

129+
<div className='slds-p-vertical--small'>
130+
8. <SLDSButton
131+
label='Follow'
132+
variant='neutral'
133+
stateful={true}
134+
notSelectedIcon='add'
135+
notSelectedLabel='Follow'
136+
selectedIcon='check'
137+
selectedLabel='Following'
138+
selectedFocusIcon='close'
139+
selectedFocusLabel='Unfollow'
140+
onClick={this.handleStatefulClick} />
141+
</div>
142+
124143
</div>
125144
</div>
126145

0 commit comments

Comments
 (0)