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

Use the spread operator for properties #1910

Merged
merged 2 commits into from
Oct 20, 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
46 changes: 28 additions & 18 deletions src/app-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const AppBar = React.createClass({
getInitialState () {
return {
muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme),
};
};
},

//to update theme inside state whenever a new theme is passed down
Expand Down Expand Up @@ -133,15 +133,28 @@ const AppBar = React.createClass({
},

render() {
let props = this.props;
let {
title,
iconStyleRight,
showMenuIconButton,
iconElementLeft,
iconElementRight,
iconClassNameLeft,
iconClassNameRight,
className,
style,
zDepth,
children,
...other,
} = this.props;

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

if (title) {
Expand All @@ -152,9 +165,7 @@ const AppBar = React.createClass({
<div style={this.prepareStyles(styles.mainElement)}>{title}</div>;
}

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

if (showMenuIconButton) {
if (iconElementLeft) {
switch (iconElementLeft.type.displayName) {
case 'IconButton':
Expand All @@ -170,22 +181,20 @@ const AppBar = React.createClass({
</div>
);
} else {
let child = (props.iconClassNameLeft) ? '' : <NavigationMenu style={this.mergeStyles(styles.iconButton.iconStyle)}/>;
let child = (iconClassNameLeft) ? '' : <NavigationMenu style={this.mergeStyles(styles.iconButton.iconStyle)}/>;
menuElementLeft = (
<IconButton
style={this.mergeStyles(styles.iconButton.style)}
iconStyle={this.mergeStyles(styles.iconButton.iconStyle)}
iconClassName={props.iconClassNameLeft}
iconClassName={iconClassNameLeft}
onTouchTap={this._onLeftIconButtonTouchTap}>
{child}
</IconButton>
);
}
}

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

if (iconElementRight) {
switch (iconElementRight.type.displayName) {
case 'IconMenu':
case 'IconButton':
Expand All @@ -206,27 +215,28 @@ const AppBar = React.createClass({
{iconElementRight}
</div>
);
} else if (props.iconClassNameRight) {
} else if (iconClassNameRight) {
menuElementRight = (
<IconButton
style={iconRightStyle}
iconStyle={this.mergeStyles(styles.iconButton.iconStyle)}
iconClassName={props.iconClassNameRight}
iconClassName={iconClassNameRight}
onTouchTap={this._onRightIconButtonTouchTap}>
</IconButton>
);
}

return (
<Paper
{...other}
rounded={false}
className={props.className}
style={this.mergeStyles(styles.root, props.style)}
zDepth={props.zDepth}>
className={className}
style={this.mergeStyles(styles.root, style)}
zDepth={zDepth}>
{menuElementLeft}
{titleElement}
{menuElementRight}
{props.children}
{children}
</Paper>
);
},
Expand Down
56 changes: 35 additions & 21 deletions src/drop-down-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,22 @@ const DropDownMenu = React.createClass({
},

render() {
let _this = this;
const {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no needed anymore with the arrow function.

autoWidth,
className,
onFocus,
onBlur,
style,
displayMember,
valueMember,
valueLink,
labelStyle,
iconStyle,
underlineStyle,
menuItemStyle,
...other,
} = this.props;

let styles = this.getStyles();
let selectedIndex = this._isControlled() ? null : this.state.selectedIndex;
let displayValue = "";
Expand All @@ -180,58 +195,57 @@ const DropDownMenu = React.createClass({
console.assert(!!this.props.menuItems[selectedIndex], 'SelectedIndex of ' + selectedIndex + ' does not exist in menuItems.');
}
}
else {
if (this.props.valueMember && this._isControlled()) {
let value = this.props.hasOwnProperty('value') ? this.props.value : this.props.valueLink.value;
if (value !== null && value !== undefined) {
for (let i = 0; i < this.props.menuItems.length; i++) {
if (this.props.menuItems[i][this.props.valueMember] === value) {
selectedIndex = i;
}
else if (valueMember && this._isControlled()) {
let value = this.props.hasOwnProperty('value') ? this.props.value : valueLink.value;
if (value !== null && value !== undefined) {
for (let i = 0; i < this.props.menuItems.length; i++) {
if (this.props.menuItems[i][valueMember] === value) {
selectedIndex = i;
}
}
}
}

let selectedItem = this.props.menuItems[selectedIndex];
if (selectedItem) {
displayValue = selectedItem[this.props.displayMember];
displayValue = selectedItem[displayMember];
}

let menuItems = this.props.menuItems.map((item) => {
item.text = item[_this.props.displayMember];
item.payload = item[_this.props.valueMember];
item.text = item[displayMember];
item.payload = item[valueMember];
return item;
});

return (
<div
{...other}
ref="root"
onKeyDown={this._onKeyDown}
onFocus={this.props.onFocus}
onBlur={this.props.onBlur}
className={this.props.className}
onFocus={onFocus}
onBlur={onBlur}
className={className}
style={this.prepareStyles(
styles.root,
this.state.open && styles.rootWhenOpen,
this.props.style)} >
style)} >

<ClearFix style={this.mergeStyles(styles.control)} onTouchTap={this._onControlClick}>
<Paper style={this.mergeStyles(styles.controlBg)} zDepth={0} />
<div style={this.prepareStyles(styles.label, this.state.open && styles.labelWhenOpen, this.props.labelStyle)}>
<div style={this.prepareStyles(styles.label, this.state.open && styles.labelWhenOpen, labelStyle)}>
{displayValue}
</div>
<DropDownArrow style={this.mergeStyles(styles.icon, this.props.iconStyle)}/>
<div style={this.prepareStyles(styles.underline, this.props.underlineStyle)}/>
<DropDownArrow style={this.mergeStyles(styles.icon, iconStyle)}/>
<div style={this.prepareStyles(styles.underline, underlineStyle)}/>
</ClearFix>

<Menu
ref="menuItems"
autoWidth={this.props.autoWidth}
autoWidth={autoWidth}
selectedIndex={selectedIndex}
menuItems={menuItems}
style={styles.menu}
menuItemStyle={this.mergeStyles(styles.menuItem, this.props.menuItemStyle)}
menuItemStyle={this.mergeStyles(styles.menuItem, menuItemStyle)}
hideable={true}
visible={this.state.open}
onRequestClose={this._onMenuRequestClose}
Expand Down