-
Notifications
You must be signed in to change notification settings - Fork 17
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 List/ListItem components from mui #20
base: master
Are you sure you want to change the base?
Changes from 2 commits
8c07ad9
920dc5d
de30ec3
165b0f7
066e9f3
b203d3b
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 |
---|---|---|
|
@@ -4,8 +4,19 @@ import React from 'react'; | |
import ListItem from './ListItem'; | ||
import ReactCSSTransitionGroup from './TimeoutTransitionGroup'; | ||
import { mergeAndPrefix } from '../utils/stylePropable'; | ||
import { List } from 'material-ui'; | ||
|
||
export default class extends React.Component { | ||
static propTypes = { | ||
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. As much as I like the Classes will be getting replaced with stamps soon enough. :) 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. Do you mean like this? constructor(props) {
super(props);
this.propTypes = {
itemData: React.PropTypes.array,
onClick: React.PropTypes.func,
style: React.PropTypes.object,
};
this.defaultProps = {
style: {},
};
} Console output: Well I think we should stick with https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#es7-property-initializers Even if it's highly experimental nop? I mean, if it is working and the code is more readable. What could be better? 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. No, that is not applying the statics to the constructor, that is applying statics to the component instance. Take a look at the other components in this project and read FB's React blog post about how to use ES6 classes.
If we were sticking with ES6 classes I would agree. But as soon as this PR gets accepted I will be making the components stamps. Take a look at PR #19. 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. Yep but the problem with this solution is that the component name e.g. That's why I am using static in this component and not on the other one 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. Just name the class something different then. The component itself can still be named 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. Okay done |
||
itemData: React.PropTypes.array, | ||
onClick: React.PropTypes.func, | ||
style: React.PropTypes.object, | ||
}; | ||
|
||
static defaultProps = { | ||
style: {}, | ||
}; | ||
|
||
class List extends React.Component { | ||
_getStyles() { | ||
return { | ||
root: { | ||
|
@@ -40,7 +51,7 @@ class List extends React.Component { | |
let styles = this._getStyles(); | ||
|
||
return ( | ||
<ul style={mergeAndPrefix(styles.root, this.props.style)}> | ||
<List style={mergeAndPrefix(styles.root, this.props.style)}> | ||
<ReactCSSTransitionGroup | ||
enterTimeout={1000} | ||
leaveTimeout={0} | ||
|
@@ -53,24 +64,12 @@ class List extends React.Component { | |
icon={obj.user.profile_picture} | ||
key={obj.id} | ||
onClick={this.props.onClick ? this.props.onClick.bind(null, obj) : undefined} | ||
title={obj.user.full_name.trim() || '-'} | ||
primaryText={obj.user.full_name.trim() || '-'} | ||
/> | ||
); | ||
})} | ||
</ReactCSSTransitionGroup> | ||
</ul> | ||
</List> | ||
); | ||
} | ||
} | ||
|
||
List.propTypes = { | ||
itemData: React.PropTypes.array, | ||
onClick: React.PropTypes.func, | ||
style: React.PropTypes.object, | ||
}; | ||
|
||
List.defaultProps = { | ||
style: {}, | ||
}; | ||
|
||
export default List; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,141 +1,85 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import Paper from 'material-ui/lib/paper'; | ||
import transitions from 'material-ui/lib/styles/transitions'; | ||
import typography from 'material-ui/lib/styles/typography'; | ||
import { | ||
ListDivider, | ||
ListItem, | ||
} from 'material-ui'; | ||
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. import { ListDivider, ListItem } from 'material-ui/lib/lists'; |
||
import ListItemAvatar from './ListItemAvatar'; | ||
import { mergeAndPrefix } from '../utils/stylePropable'; | ||
|
||
class ListItem extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
export default class extends React.Component { | ||
static contextTypes = { | ||
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. Remove as mentioned above. |
||
muiTheme: React.PropTypes.object, | ||
}; | ||
|
||
this.state = {hovered: false}; | ||
} | ||
static propTypes = { | ||
description: React.PropTypes.string, | ||
icon: React.PropTypes.string, | ||
onClick: React.PropTypes.func, | ||
primaryText: React.PropTypes.string, | ||
}; | ||
|
||
static defaultProps = { | ||
description: '', | ||
primaryText: '', | ||
}; | ||
|
||
_getStyles() { | ||
const theme = this.context.muiTheme.component.listItem; | ||
|
||
let backgroundColor = theme.color; | ||
if (this.state.hovered) { | ||
backgroundColor = this.props.hoverColor || theme.hoverColor; | ||
} | ||
|
||
return { | ||
root: { | ||
backgroundColor, | ||
cursor: 'pointer', | ||
height: '72px', | ||
transition: transitions.easeOut(), | ||
primaryText: { | ||
fontSize: '0.8em', | ||
fontWeight: typography.fontWeightMedium, | ||
color: theme.color, | ||
}, | ||
icon: { | ||
root: { | ||
position: 'absolute', | ||
marginLeft: '16px', | ||
marginTop: '19px', | ||
}, | ||
paper: { | ||
overflow: 'hidden', | ||
height: '40px', | ||
}, | ||
image: { | ||
width: '40px', | ||
}, | ||
description: { | ||
marginTop: '-4px', | ||
fontSize: '0.75em', | ||
color: theme.color, | ||
}, | ||
content: { | ||
root: { | ||
paddingLeft: '72px', | ||
paddingRight: '16px', | ||
whiteSpace: 'nowrap', | ||
textOverflow: 'ellipsis', | ||
overflow: 'hidden', | ||
}, | ||
title: { | ||
paddingTop: '20px', | ||
fontSize: '1.2em', | ||
fontWeight: typography.fontWeightMedium, | ||
}, | ||
description: { | ||
marginTop: '-4px', | ||
fontSize: '0.75em', | ||
}, | ||
divider: { | ||
backgroundColor: theme.borderColor, | ||
paddingTop: '0.1px', | ||
}, | ||
borderBottom: { | ||
position: 'absolute', | ||
marginTop: '16px', | ||
right: '0', | ||
left: '72px', | ||
borderBottom: `1px solid ${theme.borderColor}`, | ||
overflow: { | ||
textOverflow: 'ellipsis', | ||
overflow: 'hidden', | ||
width: '190px', | ||
display: 'inline-block', | ||
whiteSpace: 'nowrap', | ||
}, | ||
}; | ||
} | ||
|
||
_handleMouseOver(e) { | ||
this.setState({hovered: true}); | ||
if (this.props.onMouseOver) { | ||
this.props.onMouseOver(e); | ||
} | ||
} | ||
|
||
_handleMouseOut(e) { | ||
this.setState({hovered: false}); | ||
if (this.props.onMouseOut) { | ||
this.props.onMouseOut(e); | ||
} | ||
} | ||
|
||
render() { | ||
const styles = this._getStyles(); | ||
/* eslint-disable */ | ||
const { | ||
description, | ||
icon, | ||
onMouseOut, | ||
onMouseOver, | ||
title, | ||
primaryText, | ||
onClick, | ||
...other | ||
} = this.props; | ||
/* eslint-enable */ | ||
|
||
return ( | ||
<li | ||
{...other} | ||
onMouseOut={this._handleMouseOut.bind(this)} | ||
onMouseOver={this._handleMouseOver.bind(this)} | ||
style={mergeAndPrefix(styles.root)} | ||
> | ||
<div className='icon' style={styles.icon.root}> | ||
<Paper circle={true} style={styles.icon.paper} zDepth={0} > | ||
<img src={icon} style={styles.icon.image} /> | ||
</Paper> | ||
</div> | ||
<div className='content' style={styles.content.root}> | ||
<div dangerouslySetInnerHTML={{__html: title}} style={styles.content.title} ></div> | ||
<div dangerouslySetInnerHTML={{__html: description}} style={styles.content.description} ></div> | ||
</div> | ||
<div className='border-bottom' style={styles.borderBottom} /> | ||
</li> | ||
<div onClick={onClick}> | ||
<ListItem | ||
{...other} | ||
leftAvatar={<ListItemAvatar className='icon' src={icon} />} | ||
primaryText={ | ||
<div dangerouslySetInnerHTML={{__html: primaryText}} style={mergeAndPrefix(styles.overflow, styles.primaryText)}></div> | ||
} | ||
secondaryText={ | ||
<div className='content' dangerouslySetInnerHTML={{__html: description}} style={mergeAndPrefix(styles.overflow, styles.description)} ></div> | ||
} | ||
/> | ||
<ListDivider className='border-bottom' inset={true} style={styles.divider} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ListItem.contextTypes = { | ||
muiTheme: React.PropTypes.object, | ||
}; | ||
|
||
ListItem.propTypes = { | ||
description: React.PropTypes.string, | ||
hoverColor: React.PropTypes.string, | ||
icon: React.PropTypes.string, | ||
onClick: React.PropTypes.func, | ||
onMouseOut: React.PropTypes.func, | ||
onMouseOver: React.PropTypes.func, | ||
title: React.PropTypes.string, | ||
}; | ||
|
||
ListItem.defaultProps = { | ||
description: '', | ||
title: '', | ||
}; | ||
|
||
export default ListItem; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import { Avatar } from 'material-ui'; | ||
|
||
class ListItemAvatar extends React.Component { | ||
_getStyles() { | ||
return { | ||
border: 'none', | ||
position: 'absolute', | ||
top: '16px', | ||
left: '16px', | ||
width: '38px', | ||
height: '38px', | ||
}; | ||
} | ||
|
||
render() { | ||
const style = this._getStyles(); | ||
|
||
return ( | ||
<Avatar | ||
{...this.props} | ||
style={style} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
ListItemAvatar.contextTypes = { | ||
muiTheme: React.PropTypes.object, | ||
}; | ||
|
||
ListItemAvatar.propTypes = { | ||
src: React.PropTypes.string, | ||
}; | ||
|
||
export default ListItemAvatar; |
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.