Skip to content

Commit

Permalink
Updated menu styling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmrtnz committed Mar 17, 2015
1 parent 17842d6 commit e9cfd1b
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 195 deletions.
3 changes: 3 additions & 0 deletions docs/src/app/components/pages/components/menus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ var mui = require('mui');
var CodeExample = require('../../code-example/code-example.jsx');

var labelMenuItems = [
{ payload: '4', text: 'subheader first child', type: mui.MenuItem.Types.SUBHEADER},
{ payload: '5', text: 'subheader', type: mui.MenuItem.Types.SUBHEADER},
{type: mui.MenuItem.Types.LINK, payload: 'https://github.com/callemall/material-ui', text: 'GitHub'},
{ payload: '1', text: 'ID', data: '1234567890', icon: 'home' },
{ payload: '2', text: 'Type', data: 'Announcement', icon: 'home' },
{ payload: '3', text: 'Caller ID', data: '(123) 456-7890', icon: 'home' }
Expand Down
112 changes: 79 additions & 33 deletions src/js/menu/link-menu-item.jsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,87 @@
var React = require('react');
var Classable = require('../mixins/classable');
var StylePropable = require('../mixins/style-propable');
var CustomVariables = require('../styles/variables/custom-variables');

var LinkMenuItem = React.createClass({

mixins: [Classable],

propTypes: {
index: React.PropTypes.number.isRequired,
payload: React.PropTypes.string.isRequired,
text: React.PropTypes.string.isRequired,
target: React.PropTypes.string,
disabled: React.PropTypes.bool
},

getDefaultProps: function() {
return {
disabled: false
};
},

render: function() {
var classes = this.getClasses('mui-menu-item', {
'mui-is-disabled': this.props.disabled
});
var onClickHandler = (this.props.disabled) ? this._stopLink : undefined;
// Prevent context menu 'Open In New Tab/Window'
var linkAttribute = (this.props.disabled) ? 'data-href' : 'href';
var link = {linkAttribute: this.props.payload};

return (
<a key={this.props.index} className={classes} {...link} target={this.props.target} onClick={onClickHandler}>{this.props.text}</a>
);
},

_stopLink: function(event) {
event.preventDefault();
mixins: [StylePropable],

propTypes: {
index: React.PropTypes.number.isRequired,
payload: React.PropTypes.string.isRequired,
text: React.PropTypes.string.isRequired,
target: React.PropTypes.string,
disabled: React.PropTypes.bool,
className: React.PropTypes.string,
},

getDefaultProps: function() {
return {
disabled: false
};
},

getInitialState: function() {
return {
hovered: false
}
},

/** Styles */
_main: function() { // Same as MenuItem.
var style = this.mergeAndPrefix({
userSelect: 'none',
cursor: 'pointer',
display: 'block',
lineHeight: CustomVariables.menuItemHeight + 'px',
paddingLeft: CustomVariables.menuItemPadding,
paddingRight: CustomVariables.menuItemPadding,
});

if (this.state.hovered && !this.props.disabled) style.backgroundColor = CustomVariables.menuItemHoverColor;
if (this.props.selected) style.color = CustomVariables.menuItemSelectedTextColor;

if (this.props.disabled) {
style.cursor = 'default';
style.color = CustomVariables.disabledColor;
}

return this.mergeAndPrefix(style);
},

render: function() {
var onClickHandler = (this.props.disabled) ? this._stopLink : undefined;
// Prevent context menu 'Open In New Tab/Window'
var linkAttribute = (this.props.disabled) ? 'data-href' : 'href';
var link = {linkAttribute: this.props.payload};

return (
<a
key={this.props.index}
target={this.props.target}
style={this._main()} {...link}
className={this.props.className}
onClick={onClickHandler}
onMouseOver={this._handleMouseOver}
onMouseOut={this._handleMouseOut}>
{this.props.text}
</a>
);
},

_stopLink: function(event) {
event.preventDefault();
},

_handleMouseOver: function(e) {
this.setState({hovered: true});
if (!this.props.disabled && this.props.onMouseOver) this.props.onMouseOver(e);
},

_handleMouseOut: function(e) {
this.setState({hovered: false});
if (!this.props.disabled && this.props.onMouseOut) this.props.onMouseOut(e);
}
});

module.exports = LinkMenuItem;
9 changes: 8 additions & 1 deletion src/js/menu/menu-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var MenuItem = React.createClass({

propTypes: {
index: React.PropTypes.number.isRequired,
className: React.PropTypes.string,
iconClassName: React.PropTypes.string,
iconRightClassName: React.PropTypes.string,
iconStyle: React.PropTypes.object,
Expand Down Expand Up @@ -58,9 +59,14 @@ var MenuItem = React.createClass({
paddingRight: CustomVariables.menuItemPadding,
});

if (this.state.hovered) style.backgroundColor = CustomVariables.menuItemHoverColor;
if (this.state.hovered && !this.props.disabled) style.backgroundColor = CustomVariables.menuItemHoverColor;
if (this.props.selected) style.color = CustomVariables.menuItemSelectedTextColor;

if (this.props.disabled) {
style.cursor = 'default';
style.color = CustomVariables.disabledColor;
}

return style;
},

Expand Down Expand Up @@ -147,6 +153,7 @@ var MenuItem = React.createClass({
<div
key={this.props.index}
style={this._main()}
className={this.props.className}
onTouchTap={this._handleTouchTap}
onClick={this._handleOnClick}
onMouseOver={this._handleMouseOver}
Expand Down
52 changes: 39 additions & 13 deletions src/js/menu/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ var NestedMenuItem = React.createClass({
index: React.PropTypes.number.isRequired,
text: React.PropTypes.string,
menuItems: React.PropTypes.array.isRequired,
menuItemStyle: React.PropTypes.object,
zDepth: React.PropTypes.number,
disabled: React.PropTypes.bool,
onItemClick: React.PropTypes.func,
onItemTap: React.PropTypes.func
onItemTap: React.PropTypes.func,
menuItemStyle: React.PropTypes.object,
},

getDefaultProps: function() {
Expand Down Expand Up @@ -62,17 +62,23 @@ var NestedMenuItem = React.createClass({
color: CustomVariables.dropDownMenuIconColor
}

var {
index,
menuItemStyle,
...other,
} = this.props;

return (
<div style={styles}>
<MenuItem
index={this.props.index}
style={this.props.menuItemStyle}
index={index}
style={menuItemStyle}
iconRightStyle={iconCustomArrowDropRight}
iconRightClassName="muidocs-icon-custom-arrow-drop-right"
onClick={this._onParentItemClick}>
{this.props.text}
</MenuItem>
<Menu
<Menu {...other}
ref="nestedMenu"
menuItems={this.props.menuItems}
onItemClick={this._onMenuItemClick}
Expand Down Expand Up @@ -120,11 +126,16 @@ var Menu = React.createClass({
onItemClick: React.PropTypes.func,
onToggleClick: React.PropTypes.func,
menuItems: React.PropTypes.array.isRequired,
menuItemStyle: React.PropTypes.object,
selectedIndex: React.PropTypes.number,
hideable: React.PropTypes.bool,
visible: React.PropTypes.bool,
zDepth: React.PropTypes.number
zDepth: React.PropTypes.number,
menuItemStyle: React.PropTypes.object,
menuItemStyleSubheader: React.PropTypes.object,
menuItemStyleLink: React.PropTypes.object,
menuItemClassName: React.PropTypes.string,
menuItemClassNameSubheader: React.PropTypes.string,
menuItemClassNameLink: React.PropTypes.string,
},

getInitialState: function() {
Expand All @@ -136,7 +147,7 @@ var Menu = React.createClass({
autoWidth: true,
hideable: false,
visible: true,
zDepth: 1
zDepth: 1,
};
},

Expand Down Expand Up @@ -188,10 +199,10 @@ var Menu = React.createClass({
},

_subheader: function() {
return {
return this.mergeAndPrefix({
paddingLeft: CustomVariables.menuSubheaderPadding,
paddingRight: CustomVariables.menuSubheaderPadding,
}
}, this.props.menuItemStyleSubheader);
},

render: function() {
Expand Down Expand Up @@ -237,10 +248,12 @@ var Menu = React.createClass({
<LinkMenuItem
key={i}
index={i}
payload={menuItem.payload}
target={menuItem.target}
text={menuItem.text}
disabled={isDisabled} />
disabled={isDisabled}
className={this.props.menuItemClassNameLink}
style={this.props.menuItemStyleLink}
payload={menuItem.payload}
target={menuItem.target}/>
);
break;

Expand All @@ -249,13 +262,25 @@ var Menu = React.createClass({
<SubheaderMenuItem
key={i}
index={i}
className={this.props.menuItemClassNameSubheader}
style={this._subheader()}
firstChild={i == 0}
text={menuItem.text} />
);
break;

case MenuItem.Types.NESTED:
var {
ref,
key,
index,
zDepth,
...other
} = this.props;

itemComponent = (
<NestedMenuItem
{...other}
ref={i}
key={i}
index={i}
Expand All @@ -279,6 +304,7 @@ var Menu = React.createClass({
index={i}
icon={menuItem.icon}
data={menuItem.data}
className={this.props.menuItemClassName}
style={this.props.menuItemStyle}
attribute={menuItem.attribute}
number={menuItem.number}
Expand Down
66 changes: 55 additions & 11 deletions src/js/menu/subheader-menu-item.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
var React = require('react');
var StylePropable = require('../mixins/style-propable');
var Typography = require('../styles/core/typography');
var CustomVariables = require('../styles/variables/custom-variables');

var SubheaderMenuItem = React.createClass({

propTypes: {
index: React.PropTypes.number.isRequired,
text: React.PropTypes.string.isRequired
},

render: function() {
return (
<div key={this.props.index} className="mui-subheader">{this.props.text}</div>
);

mixins: [StylePropable],

propTypes: {
index: React.PropTypes.number.isRequired,
text: React.PropTypes.string.isRequired,
firstChild: React.PropTypes.bool,
className: React.PropTypes.string,
},

/** Styles */
_main: function() {

var gutterMini = CustomVariables.spacing.desktopGutterMini;
var subheaderHeight = CustomVariables.spacing.desktopSubheaderHeight;

var style = {
fontSize: '13px',
letterSpacing: 0,
fontWeight: Typography.fontWeightMedium,
color: Typography.textDarkBlack,
margin: 0,
height: subheaderHeight + gutterMini,
lineHeight: subheaderHeight + 'px',
color: CustomVariables.subheaderTextColor,
borderTop: 'solid 1px ' + CustomVariables.subheaderBorderColor,
paddingTop: gutterMini,
marginTop: gutterMini,
};

if (this.props.firstChild) {
style = this.mergeAndPrefix(style, {
height: subheaderHeight,
borderTop: 'none',
paddingTop: 0,
marginTop: 0,
});
}


return this.mergeAndPrefix(style);
},

render: function() {
return (
<div
key={this.props.index}
style={this._main()}
className={this.props.className}>
{this.props.text}
</div>
);
}

});

module.exports = SubheaderMenuItem;
1 change: 0 additions & 1 deletion src/less/components/components.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import "date-picker/date-picker.less";
@import "left-nav.less";
@import "paper.less";
@import "subheader.less";
@import "toolbar.less";
Loading

0 comments on commit e9cfd1b

Please sign in to comment.