Skip to content

ButtonGroup #69

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 2 commits into from
Nov 19, 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
2 changes: 1 addition & 1 deletion components/SLDSButton/SLDSButtonStateful/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SLDSButtonStateful extends React.Component {
else if(this.props.type === "icon") {
return (
<button className={this.getClassName()} onClick={this.handleClick.bind(this)}>
<ButtonIcon disabled={this.props.disabled} name="like" size="large" className="slds-button__icon--stateful" />
<ButtonIcon disabled={this.props.disabled} name={this.props.iconName} size={this.props.iconSize} assistiveText={this.props.assistiveText} className="slds-button__icon--stateful" />
</button>
)
}
Expand Down
10 changes: 5 additions & 5 deletions components/SLDSButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const propTypes = {
const defaultProps = {};


class Button extends React.Component {
class SLDSButton extends React.Component {

constructor(props) {
super(props);
Expand Down Expand Up @@ -128,8 +128,8 @@ class Button extends React.Component {
}
}

Button.displayName = displayName;
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;
SLDSButton.displayName = displayName;
SLDSButton.propTypes = propTypes;
SLDSButton.defaultProps = defaultProps;

module.exports = Button;
module.exports = SLDSButton;
15 changes: 13 additions & 2 deletions components/SLDSButtonGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,30 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND

import React from "react";

class ButtonGroup extends React.Component {
const displayName = "SLDSButtonGroup";
const propTypes = {
children: React.PropTypes.element.isRequired
};
const defaultProps = {};

class SLDSButtonGroup extends React.Component {
constructor(props) {
super(props);
this.state = {};
}

render() {
return (
<div className="slds-button-group" role="group">
{this.props.children}
</div>
);
)
}
}

SLDSButtonGroup.displayName = displayName;
SLDSButtonGroup.propTypes = propTypes;
SLDSButtonGroup.defaultProps = defaultProps;

module.exports = ButtonGroup;

18 changes: 10 additions & 8 deletions components/SLDSIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import SLDSUtilityIcon from './SLDSUtilityIcon';
export const ButtonIcon = React.createClass({

getDefaultProps() {

return {
category: 'utility', // Utility Icon Reference: https://www.lightningdesignsystem.com/resources/icons#utility
};
},

render() {

let className = 'slds-button__icon';
let label = null;

if (this.props.position) {
//If no position prop given, default to left
className += ' slds-button__icon--' + this.props.position;
Expand All @@ -36,13 +36,15 @@ export const ButtonIcon = React.createClass({
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} />;
if (this.props.assistiveText) {
label = <span className="slds-assistive-text">{this.props.assistiveText}</span>;
}
return <svg aria-hidden='true' className={className} dangerouslySetInnerHTML={{__html: useTag }} />;
*/
return <SLDSUtilityIcon name={this.props.name} category={this.props.category} aria-hidden='true' className={className} />;
return (
<span>
{label}
<SLDSUtilityIcon name={this.props.name} category={this.props.category} aria-hidden='true' className={className} />
</span>
)


}
Expand Down
5 changes: 3 additions & 2 deletions demo/pages/HomePage/ButtonGroupSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React from 'react';
import SLDSButtonGroup from '../../../components/SLDSButtonGroup';
import SLDSDropdownBase from '../../../components/SLDSDropdownBase';
import SLDSButton from '../../../components/SLDSButton';
import SLDSButtonStateful from '../../../components/SLDSButton/SLDSButtonStateful';
import {ButtonIcon, Icon} from "./../../../components/SLDSIcons";
import {default as PrismCode} from "react-prism/lib/PrismCode";

Expand Down Expand Up @@ -80,8 +81,8 @@ module.exports = React.createClass( {

<div className='slds-p-vertical--small'>
<SLDSButtonGroup>
<SLDSButton label='Chart' variant='icon' iconName='chart' iconVariant='border'/>
<SLDSButton label='Filter' variant='icon' iconName='filter' iconVariant='border'/>
<SLDSButtonStateful type="icon" assistiveText="View Reports" label='Chart' variant='icon' iconName='chart' />
<SLDSButtonStateful type="icon" assistiveText="Filter Data" label='Filter' variant='icon' iconName='filter' />
<SLDSButton label='Sort' variant='icon' iconName='sort' iconVariant='more'/>
</SLDSButtonGroup>
</div>
Expand Down
40 changes: 15 additions & 25 deletions dist/design-system-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ return /******/ (function(modules) { // webpackBootstrap

var _SLDSNotification2 = _interopRequireDefault(_SLDSNotification);

var _SLDSUtilityIcon = __webpack_require__(36);

var _SLDSUtilityIcon2 = _interopRequireDefault(_SLDSUtilityIcon);

module.exports = {
SLDSPicklistBase: _SLDSPicklistBase2['default'],
SLDSDropdownBase: _SLDSDropdownBase2['default'],
Expand All @@ -131,7 +135,8 @@ return /******/ (function(modules) { // webpackBootstrap
SLDSModalTrigger: _SLDSModalTrigger2['default'],
SLDSIcons: _SLDSIcons2['default'],
SLDSNotification: _SLDSNotification2['default'],
SLDSTooltip: _SLDSTooltip2['default']
SLDSTooltip: _SLDSTooltip2['default'],
SLDSUtilityIcon: _SLDSUtilityIcon2['default']
};

/***/ },
Expand Down Expand Up @@ -3462,41 +3467,29 @@ return /******/ (function(modules) { // webpackBootstrap
displayName: 'ButtonIcon',

getDefaultProps: function getDefaultProps() {

return {
category: 'utility' };
},

// Utility Icon Reference: https://www.lightningdesignsystem.com/resources/icons#utility
render: function render() {

var className = 'slds-button__icon';
if (this.props.variant !== 'icon') {
var label = null;

if (this.props.position) {
//If no position prop given, default to left
this.props.position ? className += ' slds-button__icon--' + this.props.position : className += ' slds-button__icon--left';
className += ' slds-button__icon--' + this.props.position;
}
if (this.props.size) {
className += ' slds-button__icon--' + this.props.size;
}
if (this.props.inverse) {
className += ' slds-button__icon--inverse';
}
if (this.props.stateful) {
className += ' slds-button__icon--stateful';
}
if (this.props.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} />;
}
return <svg aria-hidden='true' className={className} dangerouslySetInnerHTML={{__html: useTag }} />;
*/
return _react2['default'].createElement(_SLDSUtilityIcon2['default'], { name: this.props.name, category: this.props.category, 'aria-hidden': 'true', className: className });
if (this.props.assistiveText) {
label = _react2['default'].createElement('span', { className: 'slds-assistive-text' }, this.props.assistiveText);
}
return _react2['default'].createElement('span', null, label, _react2['default'].createElement(_SLDSUtilityIcon2['default'], { name: this.props.name, category: this.props.category, 'aria-hidden': 'true', className: className }));
}

});
Expand All @@ -3520,9 +3513,6 @@ return /******/ (function(modules) { // webpackBootstrap
var label = null;

var className = 'slds-icon';
if (this.props.stateful) {
className += '--stateful';
}
if (this.props.className) {
className += ' ' + this.props.className;
}
Expand Down Expand Up @@ -11288,7 +11278,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
return _react2["default"].createElement(_SLDSButton2["default"], {
label: "Dismiss Notification",
variant: "icon",
variant: "icon-inverse",
iconName: "close",
iconSize: size,
inverse: true,
Expand Down
2 changes: 1 addition & 1 deletion dist/design-system-react.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/design-system-react.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/design-system-react.min.js.map

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions lib/SLDSButton/SLDSButtonStateful/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
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";

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _SLDSIcons = require('../../SLDSIcons');

var classNames = require("classnames");

var displayName = "SLDSButtonStateful";
var propTypes = {};
var defaultProps = {};

var SLDSButtonStateful = (function (_React$Component) {
_inherits(SLDSButtonStateful, _React$Component);

function SLDSButtonStateful(props) {
_classCallCheck(this, SLDSButtonStateful);

_get(Object.getPrototypeOf(SLDSButtonStateful.prototype), "constructor", this).call(this, props);
this.state = { active: false };
}

_createClass(SLDSButtonStateful, [{
key: "handleClick",
value: function handleClick() {
this.setState({ active: !this.state.active });
}
}, {
key: "getClassName",
value: function getClassName() {
var _classNames;

return classNames(this.props.className, "slds-button", (_classNames = {}, _defineProperty(_classNames, "slds-button--neutral", this.props.type !== "icon"), _defineProperty(_classNames, "slds-button--inverse", this.props.variant === "inverse"), _defineProperty(_classNames, "slds-not-selected", !this.state.active), _defineProperty(_classNames, "slds-is-selected", this.state.active), _defineProperty(_classNames, "slds-button--icon-border", this.props.type === "icon"), _classNames));
}
}, {
key: "render",
value: function render() {
if (this.props.type === "follow") {
return _react2["default"].createElement(
"button",
{ className: this.getClassName(), "aria-live": "assertive", onClick: this.handleClick.bind(this) },
_react2["default"].createElement(
"span",
{ className: "slds-text-not-selected" },
_react2["default"].createElement(_SLDSIcons.ButtonIcon, { disabled: this.props.disabled, name: "add", size: "small", position: "left", className: "slds-button__icon--stateful" }),
"Follow"
),
_react2["default"].createElement(
"span",
{ className: "slds-text-selected" },
_react2["default"].createElement(_SLDSIcons.ButtonIcon, { disabled: this.props.disabled, name: "check", size: "small", position: "left", className: "slds-button__icon--stateful" }),
"Following"
),
_react2["default"].createElement(
"span",
{ className: "slds-text-selected-focus" },
_react2["default"].createElement(_SLDSIcons.ButtonIcon, { disabled: this.props.disabled, name: "close", size: "small", position: "left", className: "slds-button__icon--stateful" }),
"Unfollow"
)
);
} else if (this.props.type === "join") {
return _react2["default"].createElement(
"button",
{ className: this.getClassName(), "aria-live": "assertive", onClick: this.handleClick.bind(this) },
_react2["default"].createElement(
"span",
{ className: "slds-text-not-selected" },
_react2["default"].createElement(_SLDSIcons.ButtonIcon, { disabled: this.props.disabled, name: "add", size: "small", position: "left", className: "slds-button__icon--stateful" }),
"Join"
),
_react2["default"].createElement(
"span",
{ className: "slds-text-selected" },
_react2["default"].createElement(_SLDSIcons.ButtonIcon, { disabled: this.props.disabled, name: "check", size: "small", position: "left", className: "slds-button__icon--stateful" }),
"Member"
),
_react2["default"].createElement(
"span",
{ className: "slds-text-selected-focus" },
_react2["default"].createElement(_SLDSIcons.ButtonIcon, { disabled: this.props.disabled, name: "close", size: "small", position: "left", className: "slds-button__icon--stateful" }),
"Leave"
)
);
} else if (this.props.type === "icon") {
return _react2["default"].createElement(
"button",
{ className: this.getClassName(), onClick: this.handleClick.bind(this) },
_react2["default"].createElement(_SLDSIcons.ButtonIcon, { disabled: this.props.disabled, name: this.props.iconName, size: this.props.iconSize, assistiveText: this.props.assistiveText, className: "slds-button__icon--stateful" })
);
} else {
return _react2["default"].createElement(
"div",
{ className: "" },
"SLDS Stateful Button needs proper type prop: follow, join, or icon."
);
}
}
}]);

return SLDSButtonStateful;
})(_react2["default"].Component);

SLDSButtonStateful.displayName = displayName;
SLDSButtonStateful.propTypes = propTypes;
SLDSButtonStateful.defaultProps = defaultProps;

module.exports = SLDSButtonStateful;
Loading