-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Side nav - [new component] #1319
Changes from 7 commits
08bb278
be27903
fec3750
2eff3f8
6124e9c
5f8397b
8112090
55bf0b1
d49de78
9657fd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
let React = require('react'); | ||
let { Avatar, | ||
SideNav, | ||
SideNavItem, | ||
SideNavHeader, | ||
SideNavDivider, | ||
SideNavSubheader, | ||
ListItem, | ||
MenuItem, | ||
Styles, | ||
RaisedButton, | ||
FlatButton, | ||
FontIcon, | ||
} = require('material-ui'); | ||
let ComponentDoc = require('../../component-doc'); | ||
|
||
let ActionAssignment = require('svg-icons/action/assignment'); | ||
let ArrowDropRight = require('svg-icons/navigation-arrow-drop-right'); | ||
let ContentInbox = require('svg-icons/content/inbox'); | ||
let ActionInfo = require('svg-icons/action/info'); | ||
|
||
|
||
class SideNavPage extends React.Component { | ||
|
||
render() { | ||
let code = '\n<SideNav ref="dockedSideNav" openType="docked" >' | ||
+'\n <SideNavHeader disabled={true} >' | ||
+'\n HEADER {/*same as primaryText="HEADER"*/}' | ||
+'\n </SideNavHeader>' | ||
+'\n <SideNavItem primaryText="plain text"/>' | ||
+'\n <SideNavItem active={true} primaryText="actived item" />' | ||
+'\n <SideNavItem primaryText="looks better?" />' | ||
+'\n <SideNavDivider />' | ||
+'\n <SideNavSubheader>' | ||
+'\n AWESOME SUBHEADER' | ||
+'\n </SideNavSubheader>' | ||
+'\n <SideNavItem primaryText="even icons" leftIcon={<ContentInbox />} />' | ||
+'\n <SideNavItem primaryText="are supported" rightIcon={<ActionInfo />} />' | ||
+'\n <SideNavItem' | ||
+'\n disabled={true}' | ||
+'\n rightIcon={<ArrowDropRight />}' | ||
+'\n primaryText="And" />' | ||
+'\n <ListItem ' | ||
+'\n primaryText="ListItem" ' | ||
+'\n secondaryText="is also supported!" />' | ||
+'\n <ListItem' | ||
+'\n primaryText="but, there are" ' | ||
+'\n leftAvatar={<Avatar src="images/jsa-128.jpg" />} />' | ||
+'\n <ListItem primaryText="More Waiting" ' | ||
+'\n leftAvatar={<Avatar icon={<ActionAssignment />} backgroundColor="#3f51b5"/>}/>' | ||
+'\n <ListItem ' | ||
+'\n primaryText="For you" ' | ||
+'\n secondaryText="to try and contribute!" />' | ||
+'\n <SideNavItem href="https://github.com/callemall/material-ui" style={{fontSize:18}}>' | ||
+'\n <FontIcon style={exampleFlatButtonIcon} className="muidocs-icon-custom-github"/> <div>GitHub</div>' | ||
+'\n </SideNavItem>' | ||
+'\n</SideNav>\n' | ||
|
||
+'\n<SideNav ref="sideNav" openType="overlay">' | ||
+'\n <SideNavHeader>' | ||
+'\n material ui' | ||
+'\n </SideNavHeader>' | ||
+'\n <SideNavItem primaryText="Get Started"/>' | ||
+'\n <SideNavItem primaryText="Customization" />' | ||
+'\n <SideNavItem active={true}>' | ||
+'\n Components' | ||
+'\n </SideNavItem>' | ||
+'\n <SideNavDivider />' | ||
+'\n <SideNavSubheader>' | ||
+'\n Resources' | ||
+'\n </SideNavSubheader>' | ||
+'\n <SideNavItem primaryText="GitHub" href="https://github.com/callemall/material-ui" />' | ||
+'\n <SideNavItem primaryText="React" href="http://facebook.github.io/react" />' | ||
+'\n <SideNavItem primaryText="Material Design" href="https://www.google.com/design/spec/material-design/introduction.html"/>' | ||
+'\n</SideNav>' | ||
|
||
let componentInfo = [ | ||
{ | ||
name: 'Props', | ||
infoArray: [ | ||
{ | ||
name: 'disableSwipeToOpen', | ||
type: 'bool', | ||
header: 'default: false', | ||
desc: 'Indicates whether swiping sideways when the nav is closed ' + | ||
'should open the nav.' | ||
}, | ||
{ | ||
name: 'docked', | ||
type: 'bool', | ||
header: 'default: true', | ||
desc: 'Indicates that the left nav should be docked. In this state, the ' + | ||
'overlay won\'t show and clicking on a menu item will not close the left nav.' | ||
}, | ||
{ | ||
name: 'header', | ||
type: 'element', | ||
header: 'optional', | ||
desc: 'A react component that will be displayed above all the menu items. ' + | ||
'Usually, this is used for a logo or a profile image.' | ||
}, | ||
{ | ||
name: 'openRight', | ||
type: 'boole', | ||
header: 'default: false', | ||
desc: 'Positions the SideNav to open from the right side.' | ||
}, | ||
{ | ||
name: 'style', | ||
type: 'object', | ||
header: 'optional', | ||
desc: 'Override the inline-styles of SideNav\'s root element.' | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'Methods', | ||
infoArray: [ | ||
{ | ||
name: 'close', | ||
header: 'SideNav.close()', | ||
desc: 'Closes the component, hiding it from view.' | ||
}, | ||
{ | ||
name: 'toggle', | ||
header: 'SideNav.toggle()', | ||
desc: 'Toggles between the open and closed states.' | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'Events', | ||
infoArray: [ | ||
{ | ||
name: 'onChange', | ||
header: 'function(e, selectedIndex, menuItem)', | ||
desc: 'Fired when a menu item is clicked that is not the one currently ' + | ||
'selected. Note that this requires the injectTapEventPlugin component. ' + | ||
'See the "Get Started" section for more detail.' | ||
}, | ||
{ | ||
name: 'onNavOpen', | ||
header: 'function()', | ||
desc: 'Fired when the component is opened' | ||
}, | ||
{ | ||
name: 'onNavClose', | ||
header: 'function()', | ||
desc: 'Fired when the component is closed' | ||
} | ||
] | ||
} | ||
]; | ||
|
||
const exampleFlatButtonIcon = { | ||
height: '100%', | ||
display: 'inline-block', | ||
verticalAlign: 'middle', | ||
float: 'left', | ||
paddingLeft: '12px', | ||
lineHeight: '36px', | ||
color: Styles.Colors.cyan500 | ||
}; | ||
return ( | ||
<ComponentDoc | ||
name="Side Nav" | ||
code={code} | ||
componentInfo={componentInfo}> | ||
|
||
<div> | ||
|
||
<RaisedButton label="Toggle Docked Side Nav" onTouchTap={this._toggleDockedSideNavClick.bind(this)} /><br/><br/> | ||
<RaisedButton label="Show Overlay Side Nav" onTouchTap={this._showOverlaySideNavClick.bind(this)} /> | ||
|
||
<SideNav ref="dockedSideNav" openType='docked' > | ||
<SideNavHeader disabled={true} > | ||
HEADER {/*same as primaryText="HEADER"*/} | ||
</SideNavHeader> | ||
<SideNavItem primaryText="plain text"/> | ||
<SideNavItem active={true} primaryText="actived item" /> | ||
<SideNavItem primaryText="looks better?" /> | ||
<SideNavDivider /> | ||
<SideNavSubheader> | ||
AWESOME SUBHEADER | ||
</SideNavSubheader> | ||
<SideNavItem primaryText="even icons" leftIcon={<ContentInbox />} /> | ||
<SideNavItem primaryText="are supported" rightIcon={<ActionInfo />} /> | ||
<SideNavItem | ||
disabled={true} | ||
rightIcon={<ArrowDropRight />} | ||
primaryText="And" /> | ||
<ListItem | ||
primaryText="ListItem" | ||
secondaryText="is also supported!" /> | ||
<ListItem | ||
primaryText="but, there are" | ||
leftAvatar={<Avatar src="images/jsa-128.jpg" />} /> | ||
<ListItem primaryText="More Waiting" | ||
leftAvatar={<Avatar icon={<ActionAssignment />} backgroundColor="#3f51b5"/>}/> | ||
<ListItem | ||
primaryText="For you" | ||
secondaryText="to try and contribute!" /> | ||
<SideNavItem href="https://github.com/callemall/material-ui" style={{fontSize:18}}> | ||
<FontIcon style={exampleFlatButtonIcon} className="muidocs-icon-custom-github"/> <div>GitHub</div> | ||
</SideNavItem> | ||
|
||
</SideNav> | ||
<SideNav ref="sideNav" openType='overlay'> | ||
<SideNavHeader> | ||
material ui | ||
</SideNavHeader> | ||
<SideNavItem primaryText="Get Started"/> | ||
<SideNavItem primaryText="Customization" /> | ||
<SideNavItem active={true}> | ||
Components | ||
</SideNavItem> | ||
<SideNavDivider /> | ||
<SideNavSubheader> | ||
Resources | ||
</SideNavSubheader> | ||
<SideNavItem primaryText="GitHub" href="https://github.com/callemall/material-ui" /> | ||
<SideNavItem primaryText="React" href="http://facebook.github.io/react" /> | ||
<SideNavItem primaryText="Material Design" href="https://www.google.com/design/spec/material-design/introduction.html"/> | ||
</SideNav> | ||
</div> | ||
|
||
</ComponentDoc> | ||
); | ||
} | ||
|
||
_showOverlaySideNavClick() { | ||
this.refs.sideNav.toggle(); | ||
} | ||
|
||
_toggleDockedSideNavClick() { | ||
this.refs.dockedSideNav.toggle(); | ||
} | ||
|
||
} | ||
|
||
module.exports = SideNavPage; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
SideNav: require('./side-nav'), | ||
SideNavDivider: require('./side-nav-divider'), | ||
SideNavItem: require('./side-nav-item'), | ||
SideNavHeader: require('./side-nav-header'), | ||
SideNavSubheader: require('./side-nav-subheader'), | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
let React = require('react/addons'); | ||
let StylePropable = require('../mixins/style-propable'); | ||
let MenuDivider = require('../menus/menu-divider'); | ||
|
||
let SideNavDivider = React.createClass({ | ||
|
||
mixins: [StylePropable], | ||
|
||
contextTypes: { | ||
muiTheme: React.PropTypes.object, | ||
}, | ||
|
||
render() { | ||
let { | ||
style, | ||
...other, | ||
} = this.props; | ||
|
||
let mergedStyles = this.mergeAndPrefix({ | ||
/*TODO*/ | ||
}, style); | ||
|
||
return ( | ||
<MenuDivider {...other} style={mergedStyles} /> | ||
); | ||
}, | ||
}); | ||
|
||
module.exports = SideNavDivider; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
let React = require('react/addons'); | ||
let StylePropable = require('../mixins/style-propable'); | ||
let MenuItem = require('../lists/list-item'); | ||
|
||
let SideNavHeader = React.createClass({ | ||
|
||
mixins: [StylePropable], | ||
|
||
contextTypes: { | ||
muiTheme: React.PropTypes.object, | ||
}, | ||
|
||
propTypes: { | ||
disabled: React.PropTypes.bool, | ||
lineHeight: React.PropTypes.string, | ||
innerDivStyle: React.PropTypes.object, | ||
insetChildren: React.PropTypes.bool, | ||
}, | ||
|
||
getTheme() { | ||
if(this.context.muiTheme.component.sideNav) | ||
return this.context.muiTheme.component.sideNav; | ||
else | ||
return { | ||
headerItemBackgroundColor: '#2196f3', | ||
headerItemTextColor: '#000000', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you provide here some "default" theme properties? Is there a real case when this.context.muiTheme.component.sideNav is missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my observation, The dark Theme does not have as many proprieties as the light theme. I concern was customized themes, which may not have sideNav defined. |
||
}; | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
disabled: true, | ||
}; | ||
}, | ||
|
||
render() { | ||
let { | ||
disabled, | ||
innerDivStyle, | ||
style, | ||
lineHeight, | ||
...other, | ||
} = this.props; | ||
|
||
let mergedStyles = this.mergeAndPrefix({ | ||
color: this.getTheme().headerItemTextColor, | ||
backgroundColor: this.getTheme().headerItemBackgroundColor, | ||
fontSize: '22px', | ||
lineHeight: lineHeight? lineHeight : '32px', | ||
}, style); | ||
|
||
let mergedInnerDivStyles = this.mergeAndPrefix({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, based in Material Design guidelines there shouldn't be any centered items there, all items have to align left. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My intuition tells me the top header(most likely to be a logo), are usually centered. It is good to know that in Material Design guidelines there shouldn't be any centered items. I will remove it here. |
||
alignItems: 'center', | ||
}, mergedStyles, innerDivStyle); | ||
|
||
return ( | ||
<MenuItem {...other} disabled={disabled} | ||
style={mergedStyles} innerDivStyle={mergedInnerDivStyles}> | ||
{this.props.children} | ||
</MenuItem> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, aside from some customized styles, it just wraps MenuItem. Do you really think this component is required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, this is more like a wrapper with few style changes for now.I think it would be good to have the SideNavItem as a component seperated from MenuItem so we can add more feature latter. |
||
); | ||
}, | ||
}); | ||
|
||
module.exports = SideNavHeader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this component basically should just add some styles to MenuDivider, but for now it does'n do even that. Do you think this component is really needed?