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

Improve composability of AppBar with IconButton, SvgIcon, FlatButton and FloatingActionButton #967

Merged
merged 4 commits into from
Jun 28, 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
21 changes: 19 additions & 2 deletions docs/src/app/components/pages/components/app-bar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
let React = require('react');
let { AppBar, DropDownMenu } = require('material-ui');
let IconButton = require('icon-button');
let NavigationClose = require('svg-icons/navigation/close');
let FlatButton = require('flat-button');
let ComponentDoc = require('../../component-doc');


Expand All @@ -9,7 +12,14 @@ class AppBarPage extends React.Component {
super(props);

this.code =
'<AppBar title=\'Title\' iconClassNameRight="muidocs-icon-navigation-expand-more"/>';
'<AppBar\n' +
' title="Title"\n' +
' iconClassNameRight="muidocs-icon-navigation-expand-more" />\n' +
'\n' +
'<AppBar\n' +
' title="Title"\n' +
' iconElementLeft={<IconButton><NavigationClose /></IconButton>}\n' +
' iconElementRight={<FlatButton label="Save" />} />';

this.desc = 'App bars are a collection of components placed as a static ' +
'header for an application. It is used for navigation, search ' +
Expand Down Expand Up @@ -110,7 +120,14 @@ class AppBarPage extends React.Component {
code={this.code}
desc={this.desc}
componentInfo={this.componentInfo}>
<AppBar title='Title' iconClassNameRight="muidocs-icon-navigation-expand-more"/>
<AppBar
title="Title"
iconClassNameRight="muidocs-icon-navigation-expand-more" />
<br />
<AppBar
title="Title"
iconElementLeft={<IconButton><NavigationClose /></IconButton>}
iconElementRight={<FlatButton label="Save" />} />
</ComponentDoc>
);
}
Expand Down
33 changes: 24 additions & 9 deletions docs/src/app/components/pages/components/buttons.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let React = require('react');
let ComponentDoc = require('../../component-doc');
let mui = require('material-ui');
let ToggleStar = require('svg-icons/toggle/star');

let {
ClearFix,
Expand Down Expand Up @@ -58,13 +59,21 @@ class ButtonPage extends React.Component {

this.codeFloatingActionButton =
'//Floating Action Buttons\n' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" />\n' +
'<FloatingActionButton>\n' +
' <ToggleStar />\n' +
'</FloatingActionButton>\n' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" mini={true} />\n' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" disabled={true} />\n' +
'<FloatingActionButton iconClassName="muidocs-icon-custom-github" linkButton={true} href="https://github.com/callemall/material-ui" mini={true} secondary={true}/>' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" mini={true} disabled={true} />\n' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" secondary={true} />\n' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" mini={true} secondary={true} />';
'\n' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" secondary={true}>\n' +
'<FloatingActionButton secondary={true} mini={true} linkButton={true}\n' +
' href="https://github.com/callemall/material-ui" />\n' +
' <ToggleStar />\n' +
'</FloatingActionButton>\n' +
'\n' +
'<FloatingActionButton disabled={true}>\n' +
' <FontIcon className="muidocs-icon-action-grade" />\n' +
'</FloatingActionButton>\n' +
'<FloatingActionButton iconClassName="muidocs-icon-action-grade" disabled={true} mini={true} />\n';

this.desc = 'This component generates a button element and all props except for ' +
'the custom props below will be passed down to the button element. Also, ' +
Expand Down Expand Up @@ -438,7 +447,9 @@ class ButtonPage extends React.Component {
componentInfo={this.componentInfo.slice(2)}>
<div style={styles.groupFloatingAction}>
<div style={styles.container}>
<FloatingActionButton iconClassName="muidocs-icon-action-grade" />
<FloatingActionButton>
<ToggleStar />
</FloatingActionButton>
</div>
<div style={styles.container}>
<FloatingActionButton iconClassName="muidocs-icon-action-grade" mini={true} />
Expand All @@ -449,12 +460,16 @@ class ButtonPage extends React.Component {
<FloatingActionButton iconClassName="muidocs-icon-action-grade" secondary={true} />
</div>
<div style={styles.container}>
<FloatingActionButton iconClassName="muidocs-icon-action-grade" mini={true} secondary={true} />
<FloatingActionButton mini={true} secondary={true}>
<ToggleStar />
</FloatingActionButton>
</div>
</div>
<div style={styles.groupFloatingAction}>
<div style={styles.container}>
<FloatingActionButton iconClassName="muidocs-icon-action-grade" disabled={true} />
<FloatingActionButton disabled={true}>
<FontIcon className="muidocs-icon-action-grade" />
</FloatingActionButton>
</div>
<div style={styles.container}>
<FloatingActionButton iconClassName="muidocs-icon-action-grade" mini={true} disabled={true} />
Expand Down
87 changes: 63 additions & 24 deletions src/app-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,28 @@ let AppBar = React.createClass({
},

componentDidMount() {
if (process.env.NODE_ENV !== 'production' &&
this.props.iconElementLeft &&
this.props.iconClassNameLeft) {

console.warn(
'Properties iconClassNameLeft and iconElementLeft cannot be simultaneously ' +
'defined. Please use one or the other.'
);
if (process.env.NODE_ENV !== 'production') {
if (this.props.iconElementLeft && this.props.iconClassNameLeft) {
console.warn(
'Properties iconClassNameLeft and iconElementLeft cannot be simultaneously ' +
'defined. Please use one or the other.'
);
}

if (this.props.iconElementRight && this.props.iconClassNameRight) {
console.warn(
'Properties iconClassNameRight and iconElementRight cannot be simultaneously ' +
'defined. Please use one or the other.'
);
}
}
},

getStyles() {
let spacing = this.context.muiTheme.spacing;
let themeVariables = this.context.muiTheme.component.appBar;
let iconButtonSize = this.context.muiTheme.component.button.iconButtonSize;
let flatButtonSize = 36;
let styles = {
root: {
zIndex: 5,
Expand Down Expand Up @@ -88,20 +95,26 @@ let AppBar = React.createClass({
fill: themeVariables.textColor,
color: themeVariables.textColor
}
}
},
flatButton: {
color: themeVariables.textColor,
backgroundColor: 'transparent',
marginTop: (iconButtonSize - flatButtonSize) / 2 + 2,
},
};
return styles;
},

render() {
let props = this.props;
let menuElementLeft;
let menuElementRight;
let styles = this.getStyles();
let title = this.props.title;
let title = props.title;
let iconRightStyle = this.mergeAndPrefix(styles.iconButton.style, {
marginRight: -16,
marginLeft: 'auto'
}, this.props.iconStyleRight);
}, props.iconStyleRight);
let titleElement;

if (title) {
Expand All @@ -112,38 +125,64 @@ let AppBar = React.createClass({
<div style={this.mergeAndPrefix(styles.mainElement)}>{title}</div>;
}

if (this.props.showMenuIconButton) {
if (this.props.iconElementLeft) {
if (props.showMenuIconButton) {
let iconElementLeft = props.iconElementLeft;

if (iconElementLeft) {
switch (iconElementLeft.type.displayName) {
case 'IconButton':
iconElementLeft = React.cloneElement(iconElementLeft, {
iconStyle: this.mergeAndPrefix(styles.iconButton.iconStyle)
});
break;
}

menuElementLeft = (
<div style={styles.iconButton.style}>
{this.props.iconElementLeft}
{iconElementLeft}
</div>
);
} else {
let child = (this.props.iconClassNameLeft) ? '' : <NavigationMenu style={this.mergeAndPrefix(styles.iconButton.iconStyle)}/>;
let child = (props.iconClassNameLeft) ? '' : <NavigationMenu style={this.mergeAndPrefix(styles.iconButton.iconStyle)}/>;
menuElementLeft = (
<IconButton
style={this.mergeAndPrefix(styles.iconButton.style)}
iconStyle={this.mergeAndPrefix(styles.iconButton.iconStyle)}
iconClassName={this.props.iconClassNameLeft}
iconClassName={props.iconClassNameLeft}
onTouchTap={this._onLeftIconButtonTouchTap}>
{child}
</IconButton>
);
}

if (this.props.iconElementRight) {
if (props.iconElementRight) {
let iconElementRight = props.iconElementRight;

switch (iconElementRight.type.displayName) {
case 'IconButton':
iconElementRight = React.cloneElement(iconElementRight, {
iconStyle: this.mergeAndPrefix(styles.iconButton.iconStyle)
});
break;

case 'FlatButton':
iconElementRight = React.cloneElement(iconElementRight, {
style: this.mergeStyles(styles.flatButton, iconElementRight.props.style)
});
break;
}

menuElementRight = (
<div style={iconRightStyle}>
{this.props.iconElementRight}
{iconElementRight}
</div>
);
} else if (this.props.iconClassNameRight) {
} else if (props.iconClassNameRight) {
menuElementRight = (
<IconButton
style={iconRightStyle}
iconStyle={this.mergeAndPrefix(styles.iconButton.iconStyle)}
iconClassName={this.props.iconClassNameRight}
iconClassName={props.iconClassNameRight}
onTouchTap={this._onRightIconButtonTouchTap}>
</IconButton>
);
Expand All @@ -153,13 +192,13 @@ let AppBar = React.createClass({
return (
<Paper
rounded={false}
className={this.props.className}
style={this.mergeAndPrefix(styles.root, this.props.style)}
zDepth={this.props.zDepth}>
className={props.className}
style={this.mergeAndPrefix(styles.root, props.style)}
zDepth={props.zDepth}>
{menuElementLeft}
{titleElement}
{menuElementRight}
{this.props.children}
{props.children}
</Paper>
);
},
Expand Down
Loading