Skip to content

Commit

Permalink
Add linkButton functionality to buttons. Fixes #130
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Nguyen committed Dec 14, 2014
1 parent c4964a4 commit 5740ab6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
18 changes: 18 additions & 0 deletions docs/src/app/components/pages/components/buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ var ButtonPage = React.createClass({
desc: 'This is the text to display inside the button. This only applies to flat and ' +
'raised buttons.'
},
{
name: 'linkButton',
type: 'bool',
header: 'default: false',
desc: 'If true, an anchor element will be generated instead of a button element.'
},
{
name: 'primary',
type: 'bool',
Expand All @@ -128,6 +134,12 @@ var ButtonPage = React.createClass({
desc: 'This is the text to display inside the button. This only applies to flat and ' +
'raised buttons.'
},
{
name: 'linkButton',
type: 'bool',
header: 'default: false',
desc: 'If true, an anchor element will be generated instead of a button element.'
},
{
name: 'primary',
type: 'bool',
Expand All @@ -148,6 +160,12 @@ var ButtonPage = React.createClass({
desc: 'This is the name of the icon to display inside the button. This only applies to ' +
'floating action buttons.'
},
{
name: 'linkButton',
type: 'bool',
header: 'default: false',
desc: 'If true, an anchor element will be generated instead of a button element.'
},
{
name: 'mini',
type: 'bool',
Expand Down
40 changes: 30 additions & 10 deletions src/js/enhanced-button.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var React = require('react'),
KeyCode = require('./utils/key-code.js'),
Classable = require('./mixins/classable.js'),
WindowListenable = require('./mixins/window-listenable');
var React = require('react');
var KeyCode = require('./utils/key-code.js');
var Classable = require('./mixins/classable.js');
var WindowListenable = require('./mixins/window-listenable');

var EnhancedButton = React.createClass({

Expand All @@ -10,6 +10,7 @@ var EnhancedButton = React.createClass({
propTypes: {
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
linkButton: React.PropTypes.bool,
onBlur: React.PropTypes.func,
onFocus: React.PropTypes.func,
onTouchTap: React.PropTypes.func
Expand All @@ -30,14 +31,33 @@ var EnhancedButton = React.createClass({
className,
disabled,
icon,
linkButton,
onTouchTap,
...other } = this.props,
classes = this.getClasses('mui-enhanced-button', {
'mui-is-disabled': disabled,
'mui-is-keyboard-focused': this.state.isKeyboardFocused
});
...other } = this.props;
var classes = this.getClasses('mui-enhanced-button', {
'mui-is-disabled': disabled,
'mui-is-keyboard-focused': this.state.isKeyboardFocused,
'mui-is-link-button': linkButton
});

return (
return this.props.linkButton ? (
this.props.disabled ? (
<span {...other}
className={classes}
disabled={disabled}>
{this.props.children}
</span>
) : (
<a {...other}
className={classes}
disabled={disabled}
onBlur={this._onBlur}
onFocus={this._onFocus}
onTouchTap={this._onTouchTap}>
{this.props.children}
</a>
)
) : (
<button {...other}
className={classes}
disabled={disabled}
Expand Down
13 changes: 13 additions & 0 deletions src/less/components/enhanced-button.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@
outline: none;
}

&.mui-is-link-button {
display: inline-block;
cursor: pointer;

&:hover {
text-decoration: none;
}

&.mui-is-disabled {
cursor: default;
}
}

}
1 change: 0 additions & 1 deletion src/less/components/flat-button.less
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@
}
}
}

}
1 change: 1 addition & 0 deletions src/less/components/raised-button.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

display: inline-block;
min-width: @button-min-width;
height: @button-height;

* { .ease-out(); }

Expand Down

0 comments on commit 5740ab6

Please sign in to comment.