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 into js for raised-buttons #417

Merged
merged 5 commits into from
Mar 11, 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
62 changes: 42 additions & 20 deletions docs/src/app/components/pages/components/buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,44 @@ var ComponentDoc = require('../../component-doc.jsx');

var ButtonPage = React.createClass({


/** Styles */
_buttonLabel: function() {
return {
padding: '0px 16px 0px 8px',
}
},

render: function() {

var code =
'//Flat Buttons\n' +
'<FlatButton label="Default" />\n' +
'<FlatButton label="Primary" primary={true} />\n' +
'<FlatButton label="Secondary" secondary={true} />\n' +
'<FlatButton secondary={true}>\n' +
' <span className="example-image-button">Choose an Image</span>\n' +
' <input type="file" id="imageButton" className="example-image-input"></input>\n' +
'</FlatButton>\n' +
'<div className="button-example-container">\n' +
' <FlatButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true}>\n' +
' <FlatButton secondary={true} label="Choose an Image">\n' +
' <input type="file" id="imageButton" className="example-image-input"></input>\n' +
' </FlatButton>\n' +
'</div>\n' +
'<div className="button-example-container">\n' +
' <FlatButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="GitHub">\n' +
' <FontIcon className="muidocs-icon-custom-github example-flat-button-icon"/>\n' +
' <span>Github</span>\n' +
' </FlatButton>\n' +
'</div>\n' +
'<FlatButton label="Disabled" disabled={true} />\n\n' +
'//Raised Buttons\n' +
'<RaisedButton label="Default" />\n' +
'<RaisedButton label="Primary" primary={true} />\n' +
'<RaisedButton label="Secondary" secondary={true} />\n' +
'<RaisedButton secondary={true}>\n' +
' <span className="mui-raised-button-label example-image-button">Choose an Image</span>\n' +
' <input type="file" id="imageButton" className="example-image-input"></input>\n' +
'</RaisedButton>\n' +
'<div className="button-example-container">\n' +
' <RaisedButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true}>\n' +
' <RaisedButton secondary={true} label="Choose an Image">\n' +
' <input type="file" className="example-image-input"></input>\n' +
' </RaisedButton>\n' +
'</div>\n' +
'<div className="button-example-container">\n' +
' <RaisedButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="Github">\n' +
' <FontIcon className="muidocs-icon-custom-github example-button-icon"/>\n' +
' <span className="mui-raised-button-label example-icon-button-label">Github</span>\n' +
' </RaisedButton>\n' +
'</div>\n' +
'<RaisedButton label="Disabled" disabled={true} />\n\n' +
Expand Down Expand Up @@ -83,6 +91,12 @@ var ButtonPage = React.createClass({
type: 'bool',
header: 'default: false',
desc: 'If true, the button will use the secondary button colors.'
},
{
name: 'labelStyle',
type: 'object',
header: 'optional',
desc: 'Override the inline-styles of the button\'s label element.'
}
]
},
Expand Down Expand Up @@ -115,6 +129,12 @@ var ButtonPage = React.createClass({
type: 'bool',
header: 'default: false',
desc: 'If true, the button will use the secondary button colors.'
},
{
name: 'labelStyle',
type: 'object',
header: 'optional',
desc: 'Override the inline-styles of the button\'s label element.'
}
]
},
Expand Down Expand Up @@ -146,6 +166,12 @@ var ButtonPage = React.createClass({
type: 'bool',
header: 'default: false',
desc: 'If true, the button will use the secondary button colors.'
},
{
name: 'labelStyle',
type: 'object',
header: 'optional',
desc: 'Override the inline-styles of the button\'s label element.'
}
]
}
Expand All @@ -171,15 +197,13 @@ var ButtonPage = React.createClass({
<FlatButton label="Secondary" secondary={true} />
</div>
<div className="button-example-container">
<FlatButton secondary={true}>
<span className="example-image-button">Choose an Image</span>
<FlatButton secondary={true} label="Choose an Image">
<input type="file" id="imageButton" className="example-image-input"></input>
</FlatButton>
</div>
<div className="button-example-container">
<FlatButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true}>
<FlatButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="GitHub" labelStyle={this._buttonLabel()}>
<FontIcon className="muidocs-icon-custom-github example-flat-button-icon"/>
<span className="example-icon-button-label">Github</span>
</FlatButton>
</div>
<div className="button-example-container">
Expand All @@ -198,15 +222,13 @@ var ButtonPage = React.createClass({
<RaisedButton label="Secondary" secondary={true} />
</div>
<div className="button-example-container">
<RaisedButton secondary={true}>
<span className="mui-raised-button-label example-image-button">Choose an Image</span>
<RaisedButton secondary={true} label="Choose an Image">
<input type="file" className="example-image-input"></input>
</RaisedButton>
</div>
<div className="button-example-container">
<RaisedButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true}>
<RaisedButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="Github" labelStyle={this._buttonLabel()}>
<FontIcon className="muidocs-icon-custom-github example-button-icon"/>
<span className="mui-raised-button-label example-icon-button-label">Github</span>
</RaisedButton>
</div>
<div className="button-example-container">
Expand Down
21 changes: 19 additions & 2 deletions docs/src/app/components/pages/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@ var Router = require('react-router');
var mui = require('mui');
var RaisedButton = mui.RaisedButton;
var HomeFeature = require('./home-feature.jsx');
var Theme = mui.Styles.Theme;

var HomePage = React.createClass({

mixins: [Router.Navigation],

_raisedButton: function() {
return {
label: {
color: Theme.primary1Color,
},
githubStyle: {
margin: '16px 32px 0px 8px',
minWidth: 0,
},
demoStyle: {
margin: '16px 32px 0px 32px',
minWidth: 0,
}
}
},

render: function() {

return (
Expand All @@ -22,8 +39,8 @@ var HomePage = React.createClass({
Components <span className="no-wrap">that
Implement</span> <span className="no-wrap">Google&apos;s Material Design</span>
</h2>
<RaisedButton className="demo-button" label="Demo" onTouchTap={this._onDemoClick} linkButton={true} />
<RaisedButton className="github-button" label="GitHub" linkButton={true} href="https://github.com/callemall/material-ui" />
<RaisedButton className="demo-button" label="Demo" onTouchTap={this._onDemoClick} linkButton={true} style={this._raisedButton().demoStyle} labelStyle={this._raisedButton().label}/>
<RaisedButton className="github-button" label="GitHub" linkButton={true} href="https://github.com/callemall/material-ui" style={this._raisedButton().githubStyle} labelStyle={this._raisedButton().label}/>
</div>
</div>
</div>
Expand Down
15 changes: 6 additions & 9 deletions docs/src/less/pages/components/buttons.less
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
margin-top: 24px;
margin-right: auto;
margin-left: auto;
padding: 0px 8px;
padding: 0px 8px;
}

.example-image-input {
Expand All @@ -48,19 +48,16 @@
opacity: 0;
}

.example-flat-button-icon,
.example-button-icon {
.mui-text-full-white;
height: 100%;
display: inline-block;
vertical-align: middle;
float: left;
padding: 0px 8px;
padding-left: 12px;
line-height: 36px;
}

.example-flat-button-icon {
display: inline-block;
float: left;
line-height: 36px;
padding-left: 12px;
}
.example-button-icon {
.mui-text-full-white;
}
13 changes: 0 additions & 13 deletions docs/src/less/pages/home-page-hero.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@
.mui-font-weight-light;
}

.demo-button, .github-button {
margin-right: 32px;
margin-top: 16px;

.mui-raised-button-label {
color: @primary-1-color;
}
}

.github-button {
margin-right: 0;
}

@media @device-large {
margin-top: 32px;

Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ module.exports = {
NavigationChevronLeft: require('./js/svg-icons/navigation-chevron-left'),
NavigationChevronRight: require('./js/svg-icons/navigation-chevron-right')
},
Styles: {
Theme: require('./js/styles/theme').get(),
},
Snackbar: require('./js/snackbar'),
Tab: require('./js/tabs/tab'),
Tabs: require('./js/tabs/tabs'),
Toggle: require('./js/toggle'),
Snackbar: require('./js/snackbar'),
TextField: require('./js/text-field'),
Toolbar: require('./js/toolbar'),
ToolbarGroup: require('./js/toolbar-group'),
Expand Down
45 changes: 22 additions & 23 deletions src/js/flat-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var FlatButton = React.createClass({
}
},
primary: React.PropTypes.bool,
secondary: React.PropTypes.bool
secondary: React.PropTypes.bool,
labelStyle: React.PropTypes.object,
},

getInitialState: function() {
Expand All @@ -29,7 +30,7 @@ var FlatButton = React.createClass({

/** Styles */

_getBackgroundColor: function() {
_getHoveredBackgroundColor: function() {
return this.props.primary ? CustomVariables.flatButtonPrimaryHoverColor :
this.props.secondary ? CustomVariables.flatButtonSecondaryHoverColor :
CustomVariables.flatButtonHoverColor;
Expand All @@ -39,16 +40,12 @@ var FlatButton = React.createClass({

var style = {
transition: Transitions.easeOut(),

fontSize: Typography.fontStyleButtonFontSize,
letterSpacing: 0,
textTransform: 'uppercase',

fontWeight: Typography.fontWeightMedium,

borderRadius: 2,
userSelect: 'none',

position: 'relative',
overflow: 'hidden',
backgroundColor: CustomVariables.flatButtonColor,
Expand All @@ -69,17 +66,17 @@ var FlatButton = React.createClass({
};

if (this.state.hovered && !this.props.disabled) {
style.backgroundColor = this._getBackgroundColor();
style.backgroundColor = this._getHoveredBackgroundColor();
}

return style;
return this.mergeAndPrefix(style);
},

_label: function() {
return {
return this.mergeAndPrefix({
position: 'relative',
padding: '0 ' + CustomVariables.spacing.desktopGutterLess + 'px',
};
padding: '0px ' + CustomVariables.spacing.desktopGutterLess + 'px',
}, this.props.labelStyle);
},


Expand All @@ -94,44 +91,46 @@ var FlatButton = React.createClass({
...other
} = this.props;

var children = label ?
<span style={this._label()}>{label}</span> :
this.props.children;

var focusRippleColor = primary ? CustomVariables.flatButtonPrimaryFocusRippleColor :
secondary ? CustomVariables.flatButtonSecondaryFocusRippleColor :
CustomVariables.flatButtonFocusRippleColor;
var touchRippleColor = primary ? CustomVariables.flatButtonPrimaryRippleColor :
secondary ? CustomVariables.flatButtonSecondaryRippleColor :
CustomVariables.flatButtonRippleColor;

var labelElement;

if (label) labelElement = <span style={this._label()}>{label}</span>;

return (
<EnhancedButton {...other}
ref="enhancedButton"
style={this._main()}
onMouseOver={this._onMouseOver}
onMouseOut={this._onMouseOut}
onMouseOver={this._handleMouseOver}
onMouseOut={this._handleMouseOut}
focusRippleColor={focusRippleColor}
touchRippleColor={touchRippleColor}
onKeyboardFocus={this._handleKeyboardFocus}>
{children}
{labelElement}
{this.props.children}
</EnhancedButton>
);
},

_onMouseOver: function(e) {
this.setState({hovered: true});
_handleMouseOver: function(e) {
if (!this.refs.enhancedButton.isKeyboardFocused()) this.setState({hovered: true});
if (this.props.onMouseOver) this.props.onMouseOver(e);
},

_onMouseOut: function(e) {
this.setState({hovered: false});
_handleMouseOut: function(e) {
if (!this.refs.enhancedButton.isKeyboardFocused()) this.setState({hovered: false});
if (this.props.onMouseOut) this.props.onMouseOut(e);
},

_handleKeyboardFocus: function(keyboardFocused) {

if (keyboardFocused && !this.props.disabled) {
this.getDOMNode().style.backgroundColor = this._getBackgroundColor();
this.getDOMNode().style.backgroundColor = this._getHoveredBackgroundColor();
} else {
this.getDOMNode().style.backgroundColor = 'transparent';
}
Expand Down
4 changes: 3 additions & 1 deletion src/js/paper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Paper = React.createClass({
propTypes: {
circle: React.PropTypes.bool,
innerClassName: React.PropTypes.string,
innerStyle: React.PropTypes.object,
rounded: React.PropTypes.bool,
zDepth: React.PropTypes.oneOf([0,1,2,3,4,5])
},
Expand All @@ -27,6 +28,7 @@ var Paper = React.createClass({
innerClassName,
rounded,
zDepth,
innerStyle,
...other } = this.props,
classes = this.getClasses(
'mui-paper ' +
Expand All @@ -41,7 +43,7 @@ var Paper = React.createClass({

return (
<div {...other} className={classes}>
<div ref="innerContainer" className={insideClasses}>
<div ref="innerContainer" className={insideClasses} style={innerStyle}>
{this.props.children}
</div>
</div>
Expand Down
Loading