Skip to content

Commit

Permalink
Merge pull request #20 from salesforce-ux/button
Browse files Browse the repository at this point in the history
Button
  • Loading branch information
ivansfdc committed Oct 14, 2015
2 parents d90e322 + 4ede46c commit 487ef3f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 54 deletions.
49 changes: 22 additions & 27 deletions components/SLDSButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Button extends React.Component {

constructor(props) {
super(props);
this.displayName = 'SLDSButton';
this.state = { active: false };
};

Expand All @@ -38,20 +39,27 @@ class Button extends React.Component {
}

getClassName() {
let isStateful = this.props.stateful && this.state.active ? true : false;
let isSelected = this.props.stateful && this.state.active ? true : false;
let notSelected = this.props.stateful && !this.state.active ? true : false;
return classNames(this.props.className, 'slds-button', {
[`slds-button--${this.props.variant}`]: this.props.variant,
['slds-is-selected']: isStateful,
['slds-not-selected']: notSelected,
['slds-is-selected']: isSelected,
});
}

renderIcon(){
if(this.props.iconName){
return (
<ButtonIcon
variant={this.props.variant}
disabled={this.props.disabled}
inverse={this.props.inverse}
stateful={this.props.stateful}
name={this.props.iconName}
size={this.props.iconSize}
position={this.props.iconPosition || 'left'} />
position={this.props.iconPosition}
/>
);
}
}
Expand All @@ -60,38 +68,25 @@ class Button extends React.Component {
render() {
const props = omit('className', this.props);
const click = createChainedFunction(this.props.onClick, this.onClick.bind(this));
const labelClasses = this.props.variant === 'icon' ? 'slds-assistive-text': '';
if (this.props.disabled) { props['disabled'] = 'disabled' };

//If the button is only an icon render this:
if(this.props.variant === 'icon'){
return (
<button className={this.getClassName()} {...props} onClick={click}>
<Icon
name={this.props.iconName}
category='utility'
size={this.props.iconSize}
/>
<span className="slds-assistive-text">{this.props.label}</span>
</button>
);
}
//Else we assume the button has a visible label (with or without an icon):
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}
</button>
);
}
return (
<button className={this.getClassName()} {...props} onClick={click}>
{this.props.iconPosition === 'right' ? <span className={labelClasses}>{this.props.label}</span>: null}
{this.renderIcon()}
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? <span className={labelClasses}>{this.props.label}</span>: null}
</button>
);
}
}

Button.propTypes = {
label: React.PropTypes.string.isRequired,
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'icon']),
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'destructive', 'icon']),
disabled: React.PropTypes.bool,
inverse: React.PropTypes.bool,
stateful: React.PropTypes.bool,
iconName: React.PropTypes.string,
iconSize: React.PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
iconPosition: React.PropTypes.oneOf(['left', 'right']),
Expand Down
20 changes: 12 additions & 8 deletions components/SLDSIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ export const ButtonIcon = React.createClass({

const useTag = '<use xlink:href="'+SLDSSettings.getAssetsPath()+'/icons/' + this.props.category + '-sprite/svg/symbols.svg#' + this.props.name + '" />';
let className = 'slds-button__icon';
if (this.props.stateful) {
className += '--stateful';
}
if (this.props.position) {
className = className + ' slds-button__icon--' + this.props.position;
if (this.props.variant !== 'icon') {
//If no position prop given, default to left
this.props.position ? className += ' slds-button__icon--' + this.props.position : className += ' slds-button__icon--left';
}
if (this.props.size) {
className = className + ' slds-button__icon--' + this.props.size;
className += ' slds-button__icon--' + this.props.size;
}
if (this.props.inverse) {
className = className + ' slds-button__icon--inverse';
className += ' slds-button__icon--inverse';
}
if (this.props.stateful) {
className += ' slds-button__icon--stateful';
}
if (this.props.hint) {
className = className + ' slds-button__icon--hint';
className += ' slds-button__icon--hint';
}
if (this.props.destructive) {
className += ' slds-button__icon--destructive';
}
if(this.props.category === 'utility'){
return <SLDSUtilityIcon name={this.props.name} aria-hidden='true' className={className} />;
Expand Down
4 changes: 2 additions & 2 deletions components/SLDSModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ module.exports = React.createClass( {
headingClasses.push('slds-text-heading--small');
} else {
headingClasses.push('slds-text-heading--medium')

closeButton =(<SLDSButton
label='Close'
variant='icon'
iconName='close'
iconSize='small'
iconSize='large'
inverse={true}
className='slds-modal__close'
onClick={this.closeModal} />);
}
Expand Down
25 changes: 10 additions & 15 deletions demo/code-snippets/SLDSButton.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@

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

* Only label is required

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')
* label='' *required
* variant='base' ['neutral', 'brand', 'destructive', 'icon']
* disabled={false}
* inverse={false}
* stateful={false}
* iconName='' //see https://www.lightningdesignsystem.com/resources/icons#utility
* iconSize='medium' ['x-small', 'medium', 'small', 'large']
* iconPosition='left' ['left', 'right', 'large']

<SLDSButton label='Neutral' variant='neutral' onClick={this.handleNeutralClick} />

27 changes: 25 additions & 2 deletions demo/pages/HomePage/ButtonSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ module.exports = React.createClass( {
alert('Neutral Button Clicked');
},

handleBrandClick () {
alert('Brand Button Clicked');
},

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

handleIconClick(){
alert('Icon Button Clicked');
},

render() {
return (

Expand All @@ -51,7 +59,11 @@ module.exports = React.createClass( {
<SLDSButton
label='Neutral'
variant='neutral'
disabled={false}
onClick={this.handleNeutralClick} />

<SLDSButton
label='Neutral Icon'
variant='neutral'
iconName='download'
iconSize='small'
iconPosition='right'
Expand All @@ -61,8 +73,19 @@ module.exports = React.createClass( {
label='Disabled'
variant='neutral'
disabled={true}
onClick={this.handleButtonClick} />
onClick={this.handleDisabledClick} />

<SLDSButton
label='Brand'
variant='brand'
onClick={this.handleBrandClick} />

<SLDSButton
label='Settings'
variant='icon'
iconName='settings'
iconSize='large'
onClick={this.handleIconClick} />
</div>
</div>

Expand Down
30 changes: 30 additions & 0 deletions lib/SLDSToast/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

module.exports = _react2['default'].createClass({
displayName: 'exports',

render: function render() {
return _react2['default'].createElement(
'div',
null,
'TOAST!!!'
);
}
});

0 comments on commit 487ef3f

Please sign in to comment.