Skip to content

[Button] Fix and add missing labelPosition #2014

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

Merged
merged 1 commit into from
Nov 3, 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
28 changes: 26 additions & 2 deletions docs/src/app/components/pages/components/buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export default class ButtonPage extends React.Component {
header: 'optional',
desc: 'Override the inline-styles of the button\'s label element.',
},
{
name: 'labelPosition',
type: 'oneOf ["before", "after"]',
header: 'default: "before"',
desc: 'Place label before or after the passed children',
},
{
name: 'linkButton',
type: 'bool',
Expand Down Expand Up @@ -319,7 +325,6 @@ export default class ButtonPage extends React.Component {
height: '100%',
display: 'inline-block',
verticalAlign: 'middle',
float: 'left',
paddingLeft: '12px',
lineHeight: '36px',
color: Colors.cyan500,
Expand Down Expand Up @@ -375,7 +380,17 @@ export default class ButtonPage extends React.Component {
<FlatButton
linkButton={true}
href="https://github.com/callemall/material-ui"
secondary={true} label="GitHub"
secondary={true}
label="GitHub"
labelStyle={styles.buttonLabel}>
<FontIcon style={styles.exampleFlatButtonIcon} className="muidocs-icon-custom-github"/>
</FlatButton>
</div>
<div style={styles.container}>
<FlatButton
secondary={true}
label="Label after"
labelPosition="after"
labelStyle={styles.buttonLabel}>
<FontIcon style={styles.exampleFlatButtonIcon} className="muidocs-icon-custom-github"/>
</FlatButton>
Expand Down Expand Up @@ -420,6 +435,15 @@ export default class ButtonPage extends React.Component {
<FontIcon style={styles.exampleButtonIcon} className="muidocs-icon-custom-github"/>
</RaisedButton>
</div>
<div style={styles.container}>
<RaisedButton
secondary={true}
label="Label after"
labelPosition="after"
labelStyle={styles.buttonLabel}>
<FontIcon style={styles.exampleButtonIcon} className="muidocs-icon-custom-github"/>
</RaisedButton>
</div>
<div style={styles.container}>
<RaisedButton label="Disabled" disabled={true} />
</div>
Expand Down
26 changes: 15 additions & 11 deletions docs/src/app/components/raw-code/flat-button-code.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
//Flat Buttons
<FlatButton label="Default" />

<FlatButton label="Primary" primary={true} />

<FlatButton label="Secondary" secondary={true} />
<div style={styles.container}>
<FlatButton primary={true} label="Choose an Image">
<input type="file" id="imageButton" style={styles.exampleImageInput}></input>
</FlatButton>
</div>
<div style={styles.container}>
<FlatButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="GitHub">
<FontIcon style={styles.exampleFlatButtonIcon} className="muidocs-icon-custom-github"/>
</FlatButton>
</div>

<FlatButton primary={true} label="Choose an Image">
<input type="file" id="imageButton" style={styles.exampleImageInput} />
</FlatButton>

<FlatButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="GitHub">
<FontIcon style={styles.exampleFlatButtonIcon} className="muidocs-icon-custom-github" />
</FlatButton>

<FlatButton secondary={true} label="Label after" labelPosition="after">
<FontIcon style={styles.exampleFlatButtonIcon} className="muidocs-icon-custom-github" />
</FlatButton>

<FlatButton label="Disabled" disabled={true} />
27 changes: 15 additions & 12 deletions docs/src/app/components/raw-code/raised-button-code.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
//Raised Buttons
<RaisedButton label="Default" />

<RaisedButton label="Primary" primary={true} />

<RaisedButton label="Secondary" secondary={true} />
<div style={styles.container}>
<RaisedButton primary={true} label="Choose an Image">
<input type="file" style={styles.exampleImageInput}></input>
</RaisedButton>
</div>
<div style={styles.container}>
<RaisedButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="Github">
<FontIcon style={styles.exampleButtonIcon} className="muidocs-icon-custom-github"/>
</RaisedButton>
</div>
<RaisedButton label="Disabled" disabled={true} />

<RaisedButton primary={true} label="Choose an Image">
<input type="file" style={styles.exampleImageInput} />
</RaisedButton>

<RaisedButton linkButton={true} href="https://github.com/callemall/material-ui" secondary={true} label="Github">
<FontIcon style={styles.exampleButtonIcon} className="muidocs-icon-custom-github" />
</RaisedButton>

<RaisedButton secondary={true} label="Label after" labelPosition="after">
<FontIcon style={styles.exampleButtonIcon} className="muidocs-icon-custom-github" />
</RaisedButton>

<RaisedButton label="Disabled" disabled={true} />
16 changes: 11 additions & 5 deletions src/flat-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ const FlatButton = React.createClass({
disabled: React.PropTypes.bool,
hoverColor: React.PropTypes.string,
label: validateLabel,
labelPosition: React.PropTypes.oneOf(['before', 'after']),
labelPosition: React.PropTypes.oneOf([
'before',
'after',
]),
labelStyle: React.PropTypes.object,
onKeyboardFocus: React.PropTypes.func,
onMouseEnter: React.PropTypes.func,
Expand All @@ -81,7 +84,7 @@ const FlatButton = React.createClass({
getDefaultProps() {
return {
labelStyle: {},
labelPosition: 'before',
labelPosition: 'before', // Should be after but we keep it like for now (prevent breaking changes)
onKeyboardFocus: () => {},
onMouseEnter: () => {},
onMouseLeave: () => {},
Expand Down Expand Up @@ -123,7 +126,7 @@ const FlatButton = React.createClass({
secondary,
style,
...other,
} = this.props;
} = this.props;

const {
buttonColor,
Expand Down Expand Up @@ -172,11 +175,14 @@ const FlatButton = React.createClass({
const labelElement = label ? (
<FlatButtonLabel label={label} style={labelStyle} />
) : undefined;

// Place label before or after children.
const childrenFragment = labelPosition === 'before' ? { labelElement, children } : { children, labelElement };
const childrenFragment = labelPosition === 'before' ?
{ labelElement, children }
:
{ children, labelElement };
const enhancedButtonChildren = Children.create(childrenFragment);


return (
<EnhancedButton
{...other}
Expand Down
29 changes: 25 additions & 4 deletions src/raised-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const ReactDOM = require('react-dom');
const StylePropable = require('./mixins/style-propable');
const Transitions = require('./styles/transitions');
const ColorManipulator = require('./utils/color-manipulator');
const Children = require('./utils/children');
const Typography = require('./styles/typography');
const EnhancedButton = require('./enhanced-button');
const Paper = require('./paper');
Expand Down Expand Up @@ -40,6 +41,10 @@ const RaisedButton = React.createClass({
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
label: validateLabel,
labelPosition: React.PropTypes.oneOf([
'before',
'after',
]),
onMouseDown: React.PropTypes.func,
onMouseUp: React.PropTypes.func,
onMouseLeave: React.PropTypes.func,
Expand All @@ -55,6 +60,12 @@ const RaisedButton = React.createClass({
fullWidth: React.PropTypes.bool,
},

getDefaultProps: function() {
return {
labelPosition: 'before', // Should be after but we keep it like for now (prevent breaking changes)
};
},

getInitialState() {
let zDepth = this.props.disabled ? 0 : 1;
return {
Expand Down Expand Up @@ -160,18 +171,22 @@ const RaisedButton = React.createClass({

render() {
let {
children,
disabled,
label,
labelPosition,
labelStyle,
primary,
secondary,
...other } = this.props;
...other,
} = this.props;

let styles = this.getStyles();

let labelElement;
if (label) {
labelElement = (
<span style={this.prepareStyles(styles.label, this.props.labelStyle)}>
<span style={this.prepareStyles(styles.label, labelStyle)}>
{label}
</span>
);
Expand All @@ -190,6 +205,13 @@ const RaisedButton = React.createClass({
onKeyboardFocus: this._handleKeyboardFocus,
};

// Place label before or after children.
const childrenFragment = labelPosition === 'before' ?
{ labelElement, children }
:
{ children, labelElement };
const enhancedButtonChildren = Children.create(childrenFragment);

return (
<Paper
style={this.mergeStyles(styles.root, this.props.style)}
Expand All @@ -208,8 +230,7 @@ const RaisedButton = React.createClass({
styles.overlay,
(this.state.hovered && !this.props.disabled) && styles.overlayWhenHovered
)}>
{labelElement}
{this.props.children}
{enhancedButtonChildren}
</div>
</EnhancedButton>
</Paper>
Expand Down