Skip to content

Commit 2a54df7

Browse files
committed
Clean up and declare propTypes
1 parent 8a9d796 commit 2a54df7

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

components/SLDSButton/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class Button extends React.Component {
3939

4040
getClassName() {
4141
let isStateful = this.props.stateful && this.state.active ? true : false;
42-
4342
return classNames(this.props.className, 'slds-button', {
4443
[`slds-button--${this.props.variant}`]: this.props.variant,
4544
['slds-is-selected']: isStateful,
@@ -61,8 +60,8 @@ class Button extends React.Component {
6160
render() {
6261
const props = omit('className', this.props);
6362
const click = createChainedFunction(this.props.onClick, this.onClick.bind(this));
64-
const labelClasses = this.props.variant === 'icon' ? 'slds-assistive-text' : '';
6563

64+
//If the button is only an icon render this:
6665
if(this.props.variant === 'icon'){
6766
return (
6867
<button className={this.getClassName()} {...props} onClick={click}>
@@ -72,15 +71,19 @@ class Button extends React.Component {
7271
className={'slds-icon'} />
7372
<span className="slds-assistive-text">{this.props.label}</span>
7473
</button>
75-
)
76-
}else{
74+
);
75+
}
76+
//Else we assume the button has a visible label (with or without an icon):
77+
else{
7778
return (
7879
<button className={this.getClassName()} {...props} onClick={click}>
79-
{this.props.iconPosition === 'right' ? this.props.label : null}
80+
81+
<span aria-live="assertive">{this.props.iconPosition === 'right' ? this.props.label : null}</span>
8082

8183
{this.renderIcon()}
8284

83-
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}
85+
<span aria-live="assertive">{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}</span>
86+
8487
</button>
8588
);
8689
}
@@ -91,7 +94,7 @@ Button.propTypes = {
9194
label: React.PropTypes.string.isRequired,
9295
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'icon']),
9396
iconName: React.PropTypes.string,
94-
iconSize: React.PropTypes.string,
97+
iconSize: React.PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
9598
iconPosition: React.PropTypes.oneOf(['left', 'right']),
9699
}
97100

demo/code-snippets/SLDSButton.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11

22

3-
<SLDSButton
4-
label='Test Button'
5-
variant='neutral'
6-
iconName='download'
7-
iconSize='small'
8-
iconPosition='left'
9-
onClick={this.handleButtonClick} />
3+
<SLDSButton label='Test Button' variant='neutral' iconName='download' iconSize='small' iconPosition='left' onClick={this.handleButtonClick} />
104

115
* Only label is required
6+
* variant must be neutral, brand, or icon
7+
* iconSize must be small, medium, or large
8+
* iconPosition must be left or right
9+

demo/pages/HomePage/ButtonSection.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = React.createClass( {
5151
variant='neutral'
5252
iconName='download'
5353
iconSize='small'
54-
iconPosition='left'
54+
iconPosition='right'
5555
onClick={this.handleButtonClick} />
5656
</div>
5757
</div>

demo/pages/HomePage/ModalSection.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ Utilize our detailed guidelines to confidently design excellent apps that fit ri
9797
isOpen={this.state.modalIsOpen}
9898
title={<span>Lightning Design System: Style with Ease</span>}
9999
footer={[
100-
<button className='slds-button slds-button--neutral' onClick={this.closeModal}>Cancel</button>,
101-
<button className='slds-button slds-button--neutral slds-button--brand' onClick={this.handleSubmitModal}>Save</button>
100+
<SLDSButton label='Cancel' variant='neutral' onClick={this.closeModal} />,
101+
<SLDSButton label='Save' variant='brand' onClick={this.handleSubmitModal} />
102102
]}
103103
onRequestClose={this.closeModal}>
104104
{this.getModalContent()}

0 commit comments

Comments
 (0)