Skip to content
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

Enabled icon position on Flat button #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 33 additions & 10 deletions src/uiElements/buttons/components/flatButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ var FlatButton = React.createClass({

//Similar to the button className function, this takes in an icon prop. Make sure that the icon you pass in is
//part of the linear icon pack.
getIcon: function() {
return (
<i className={' icon icon-' + this.props.icon} style={this.getStyle()}></i>
)
getLeftIcon: function() {
var iconPosition = this.props.iconPosition;

if (this.props.icon) {
if (iconPosition === "left" || !iconPosition) {
return (
<i className={' icon icon-' + this.props.icon} style={this.getStyle(iconPosition)}></i>
)
}
}
},

getRightIcon: function() {
var iconPosition = this.props.iconPosition;

if (this.props.icon && iconPosition === "right") {
return (
<i className={' icon icon-' + this.props.icon} style={this.getStyle(iconPosition)}></i>
);
}
},

getText: function() {
Expand All @@ -37,11 +53,17 @@ var FlatButton = React.createClass({
}
},

getStyle: function() {
getStyle: function(iconPosition) {
if (this.props.text && this.props.icon) {
return ({
marginRight: 5
})
if (iconPosition === "right") {
return ({
marginLeft: 5
})
} else {
return ({
marginRight: 5
});
}
}
},

Expand All @@ -60,8 +82,9 @@ var FlatButton = React.createClass({
render: function() {
return this.renderButton(
<button disabled={this.props.disabled} className={this.getButtonClassName()} onClick={this.props.onClick}>
{this.getIcon()}
{this.getText()}
{this.getLeftIcon()}
{this.getText()}
{this.getRightIcon()}
</button>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/uiElements/buttons/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,20 @@ var ButtonExamples = React.createClass({
text="Secondary flat"
icon="star"
type="secondary"
iconPosition="right"
onClick={this.onClick}
/>,
<FlatButton
text="Primary flat"
icon="star"
type="primary"
iconPosition="left"
onClick={this.onClick}
/>,
<FlatButton
text="Plain flat"
icon="star"
iconPosition="right"
onClick={this.onClick}
/>,
]
Expand Down