Skip to content

Commit 2d373ac

Browse files
committed
Merge branch 'master' into tooltip
2 parents 22ada67 + cf33fae commit 2d373ac

File tree

1,822 files changed

+27349
-7165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,822 files changed

+27349
-7165
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
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.
7+
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.
8+
9+
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.
10+
*/
11+
12+
import React from "react";
13+
import {ButtonIcon} from '../../SLDSIcons';
14+
const classNames = require("classnames");
15+
16+
const displayName = "SLDSButtonStateful";
17+
const propTypes = {
18+
assistiveText: React.PropTypes.string,
19+
disabled: React.PropTypes.bool,
20+
iconName: React.PropTypes.string,
21+
iconSize: React.PropTypes.string,
22+
type: React.PropTypes.string,
23+
variant: React.PropTypes.oneOf(["base", "neutral", "brand", "destructive", "icon", "inverse", "icon-inverse"]),
24+
};
25+
const defaultProps = {};
26+
27+
class SLDSButtonStateful extends React.Component {
28+
29+
constructor(props) {
30+
super(props);
31+
this.state = {active: false};
32+
}
33+
34+
handleClick() {
35+
this.setState({ active: !this.state.active });
36+
}
37+
38+
getClassName() {
39+
return classNames(this.props.className, "slds-button", {
40+
["slds-button--neutral"]: this.props.type !== "icon",
41+
["slds-button--inverse"]: this.props.variant === "inverse",
42+
["slds-not-selected"]: !this.state.active,
43+
["slds-is-selected"]: this.state.active,
44+
["slds-button--icon-border"]: this.props.type === "icon",
45+
});
46+
}
47+
48+
render() {
49+
if(this.props.type === "follow") {
50+
return (
51+
<button className={this.getClassName()} aria-live="assertive" onClick={this.handleClick.bind(this)}>
52+
<span className="slds-text-not-selected">
53+
<ButtonIcon disabled={this.props.disabled} name="add" size="small" position="left" className="slds-button__icon--stateful" />
54+
Follow
55+
</span>
56+
<span className="slds-text-selected">
57+
<ButtonIcon disabled={this.props.disabled} name="check" size="small" position="left" className="slds-button__icon--stateful" />
58+
Following
59+
</span>
60+
<span className="slds-text-selected-focus">
61+
<ButtonIcon disabled={this.props.disabled} name="close" size="small" position="left" className="slds-button__icon--stateful" />
62+
Unfollow
63+
</span>
64+
</button>
65+
)
66+
}
67+
else if(this.props.type === "join") {
68+
return (
69+
<button className={this.getClassName()} aria-live="assertive" onClick={this.handleClick.bind(this)}>
70+
<span className="slds-text-not-selected">
71+
<ButtonIcon disabled={this.props.disabled} name="add" size="small" position="left" className="slds-button__icon--stateful" />
72+
Join
73+
</span>
74+
<span className="slds-text-selected">
75+
<ButtonIcon disabled={this.props.disabled} name="check" size="small" position="left" className="slds-button__icon--stateful" />
76+
Member
77+
</span>
78+
<span className="slds-text-selected-focus">
79+
<ButtonIcon disabled={this.props.disabled} name="close" size="small" position="left" className="slds-button__icon--stateful" />
80+
Leave
81+
</span>
82+
</button>
83+
)
84+
}
85+
else if(this.props.type === "icon") {
86+
return (
87+
<button className={this.getClassName()} onClick={this.handleClick.bind(this)}>
88+
<ButtonIcon disabled={this.props.disabled} name={this.props.iconName} size={this.props.iconSize} assistiveText={this.props.assistiveText} className="slds-button__icon--stateful" />
89+
</button>
90+
)
91+
}
92+
else {
93+
return (
94+
<div className="">SLDS Stateful Button needs proper type prop: follow, join, or icon.</div>
95+
)
96+
}
97+
98+
}
99+
}
100+
101+
SLDSButtonStateful.displayName = displayName;
102+
SLDSButtonStateful.propTypes = propTypes;
103+
SLDSButtonStateful.defaultProps = defaultProps;
104+
105+
module.exports = SLDSButtonStateful;
106+

components/SLDSButton/index.js renamed to components/SLDSButton/index.jsx

Lines changed: 49 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,57 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1212
import React from "react";
1313
const classNames = require("classnames");
1414
import createChainedFunction from "../utils/create-chained-function";
15-
import {ButtonIcon} from "../SLDSIcons.js";
15+
import {ButtonIcon} from "../SLDSIcons";
1616
import omit from "lodash.omit";
1717

18-
class Button extends React.Component {
18+
const displayName = 'SLDSButton';
19+
const propTypes = {
20+
assistiveText: React.PropTypes.string,
21+
buttonSize: React.PropTypes.oneOf(["small"]),
22+
disabled: React.PropTypes.bool,
23+
hint: React.PropTypes.bool,
24+
iconName: React.PropTypes.string,
25+
iconPosition: React.PropTypes.oneOf(["left", "right"]),
26+
iconSize: React.PropTypes.oneOf(["x-small", "small", "medium", "large"]),
27+
iconVariant: React.PropTypes.oneOf(["bare", "container", "border", "border-filled", "small", "more"]),
28+
label: React.PropTypes.string,
29+
onClick: React.PropTypes.func,
30+
responsive: React.PropTypes.bool,
31+
tabindex: React.PropTypes.string,
32+
variant: React.PropTypes.oneOf(["base", "neutral", "brand", "destructive", "icon", "inverse", "icon-inverse"]),
33+
};
34+
const defaultProps = {};
35+
36+
37+
class SLDSButton extends React.Component {
1938

2039
constructor(props) {
2140
super(props);
22-
this.displayName = "SLDSButton";
2341
this.state = { active: false };
2442
}
2543

26-
componentWillMount(){
27-
/*===============================
28-
TODO: refactor so that React doesn"t throw warnings in console
29-
for (var key in this.props) {
30-
if(this.props.hasOwnProperty(key) && typeof(this.props[key]) === "string" && key !== "label"){
31-
this.props[key] = this.props[key].toLowerCase();
32-
}
33-
}
34-
===============================*/
35-
}
36-
3744
onClick() {
3845
this.setState({ active: !this.state.active });
3946
}
4047

4148
getClassName() {
42-
let isSelected = this.props.stateful && this.state.active ? true : false;
43-
let notSelected = this.props.stateful && !this.state.active ? true : false;
49+
const iconOnly = this.props.variant === 'icon' ? true : false;
4450
return classNames(this.props.className, "slds-button", {
45-
[`slds-button--${this.props.variant}`]: this.props.variant,
51+
[`slds-button--${this.props.variant}`]: !iconOnly,
4652
[`slds-button--icon-${this.props.iconVariant}`]: this.props.iconVariant,
4753
["slds-max-small-button--stretch"]: this.props.responsive,
48-
["slds-not-selected"]: notSelected,
49-
["slds-is-selected"]: isSelected,
50-
["slds-button--icon-inverse"]: this.props.inverse,
54+
["slds-button--small"]: this.props.buttonSize,
5155
});
5256
}
5357

5458
renderIcon(name){
55-
if(this.props.iconName || this.props.notSelectedIcon || this.props.selectedIcon || this.props.selectedFocusIcon){
59+
if(this.props.iconName){
5660
return (
5761
<ButtonIcon
58-
variant={this.props.variant}
59-
disabled={this.props.disabled}
60-
inverse={this.props.inverse}
61-
stateful={this.props.stateful}
6262
hint={this.props.hint}
6363
name={name}
64-
size={this.props.iconSize}
6564
position={this.props.iconPosition}
65+
size={this.props.iconSize}
6666
/>
6767
);
6868
}
@@ -72,68 +72,43 @@ class Button extends React.Component {
7272
if(this.props.iconVariant === "more"){
7373
return(
7474
<ButtonIcon
75-
variant={this.props.variant}
76-
disabled={this.props.disabled}
77-
inverse={this.props.inverse}
7875
name="down"
7976
size="x-small"
8077
/>
8178
);
8279
}
8380
}
8481

82+
renderLabel() {
83+
const iconOnly = this.props.variant === "icon" || this.props.variant === "icon-inverse";
84+
return iconOnly && this.props.assistiveText ? <span className="slds-assistive-text">{this.props.assistiveText}</span> : <span>{this.props.label}</span>;
85+
}
86+
8587

8688
render() {
8789
const props = omit(this.props, "className");
8890
const click = createChainedFunction(this.props.onClick, this.onClick.bind(this));
89-
const labelClasses = this.props.variant === "icon" ? "slds-assistive-text": "";
90-
if (this.props.disabled) { props["disabled"] = "disabled" };
9191

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

123-
Button.propTypes = {
124-
label: React.PropTypes.string.isRequired,
125-
variant: React.PropTypes.oneOf(["base", "neutral", "brand", "destructive", "icon"]),
126-
tabindex: React.PropTypes.string,
127-
disabled: React.PropTypes.bool,
128-
inverse: React.PropTypes.bool,
129-
hint: React.PropTypes.bool,
130-
stateful: React.PropTypes.bool,
131-
responsive: React.PropTypes.bool,
132-
iconName: React.PropTypes.string,
133-
iconVariant: React.PropTypes.oneOf(["bare", "container", "border", "border-filled", "small", "more"]),
134-
iconSize: React.PropTypes.oneOf(["x-small", "small", "medium", "large"]),
135-
iconPosition: React.PropTypes.oneOf(["left", "right"]),
136-
onClick: React.PropTypes.func,
137-
}
110+
SLDSButton.displayName = displayName;
111+
SLDSButton.propTypes = propTypes;
112+
SLDSButton.defaultProps = defaultProps;
138113

139-
module.exports = Button;
114+
module.exports = SLDSButton;

components/SLDSButtonGroup/index.js renamed to components/SLDSButtonGroup/index.jsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1111

1212
import React from "react";
1313

14-
class ButtonGroup extends React.Component {
14+
const displayName = "SLDSButtonGroup";
15+
const propTypes = {
16+
children: React.PropTypes.node.isRequired
17+
};
18+
const defaultProps = {};
19+
20+
class SLDSButtonGroup extends React.Component {
1521
constructor(props) {
1622
super(props);
1723
this.state = {};
1824
}
25+
1926
render() {
2027
return (
2128
<div className="slds-button-group" role="group">
2229
{this.props.children}
2330
</div>
24-
);
31+
)
2532
}
2633
}
2734

28-
module.exports = ButtonGroup;
35+
SLDSButtonGroup.displayName = displayName;
36+
SLDSButtonGroup.propTypes = propTypes;
37+
SLDSButtonGroup.defaultProps = defaultProps;
38+
39+
module.exports = SLDSButtonGroup;
2940

0 commit comments

Comments
 (0)