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

Refractored css-in-js for enhanced button #430

Merged
merged 1 commit into from
Mar 13, 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
41 changes: 32 additions & 9 deletions src/js/enhanced-button.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var React = require('react');
var KeyCode = require('./utils/key-code');
var Classable = require('./mixins/classable');
var StylePropable = require('./mixins/style-propable');
var WindowListenable = require('./mixins/window-listenable');
var FocusRipple = require('./ripples/focus-ripple');
var TouchRipple = require('./ripples/touch-ripple');

var EnhancedButton = React.createClass({

mixins: [Classable, WindowListenable],
mixins: [StylePropable, WindowListenable],

propTypes: {
centerRipple: React.PropTypes.bool,
Expand Down Expand Up @@ -36,6 +36,25 @@ var EnhancedButton = React.createClass({
};
},

/** Styles */
_main: function() {
var style = {
border: 0,
background: 'none',
};

if (this.props.linkButton) {
style = this.mergeAndPrefix({
display: 'inline-block',
cursor: (this.props.disabled) ? 'default' : 'pointer',
textDecoration: 'none',
}, style);
}

return this.mergeAndPrefix(style);
},


render: function() {
var {
centerRipple,
Expand All @@ -46,13 +65,10 @@ var EnhancedButton = React.createClass({
touchRippleColor,
onBlur,
onFocus,
onMouseOver,
onTouchTap,
...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
});

var touchRipple = (
<TouchRipple
ref="touchRipple"
Expand All @@ -71,10 +87,11 @@ var EnhancedButton = React.createClass({
show={this.state.isKeyboardFocused} />
);
var buttonProps = {
className: classes,
style: this._main(),
disabled: disabled,
onBlur: this._handleBlur,
onFocus: this._handleFocus,
onMouseOver: this._handleMouseOver,
onTouchTap: this._handleTouchTap
};
var buttonChildren = [
Expand All @@ -85,7 +102,7 @@ var EnhancedButton = React.createClass({
if (disabled && linkButton) {
return (
<span {...other}
className={classes}
className={this.props.className}
disabled={disabled}>
{this.props.children}
</span>
Expand Down Expand Up @@ -130,6 +147,7 @@ var EnhancedButton = React.createClass({
},

_handleFocus: function(e) {
this.getDOMNode().style.outline = 'none';
//setTimeout is needed becuase the focus event fires first
//Wait so that we can capture if this was a keyboard focus
//or touch focus
Expand All @@ -145,6 +163,11 @@ var EnhancedButton = React.createClass({
if (this.props.onFocus) this.props.onFocus(e);
},

_handleMouseOver: function(e) {
this.getDOMNode().style.textDecoration = 'none';
if (this.props.onMouseOver) this.props.onMouseOver(e);
},

_handleTouchTap: function(e) {
this._tabPressed = false;
this.setState({
Expand Down
1 change: 0 additions & 1 deletion src/less/components/components.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import "app-bar.less";
@import "card.less";
@import "date-picker/date-picker.less";
@import "enhanced-button.less";
@import "left-nav.less";
@import "paper.less";
@import "subheader.less";
Expand Down
24 changes: 0 additions & 24 deletions src/less/components/enhanced-button.less

This file was deleted.