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 List/ListItem components from mui #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
31 changes: 15 additions & 16 deletions app/components/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Owner

Choose a reason for hiding this comment

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

import List from 'material-ui/lib/lists/list';


export default class extends React.Component {
static propTypes = {
Copy link
Owner

Choose a reason for hiding this comment

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

As much as I like the static keyword, it's too experimental right now. Just do as the other components do and explicitly set the statics on the constructor.

Classes will be getting replaced with stamps soon enough. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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: 150714/150556.048, [log,info], data: Server running at: http://localhost:8080 Warning: propTypes was defined as an instance property on _default. Use a static property to define propTypes instead. Warning: React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for composite components).

Well I think we should stick with static.

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?

Copy link
Owner

Choose a reason for hiding this comment

The 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.

Well I think we should stick with static.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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. List is the same as the one from material-ui, so there will be a conflict 😢

That's why I am using static in this component and not on the other one

Copy link
Owner

Choose a reason for hiding this comment

The 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 List.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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: {
Expand Down Expand Up @@ -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}
Expand All @@ -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;
160 changes: 52 additions & 108 deletions app/components/ListItem.jsx
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';
Copy link
Owner

Choose a reason for hiding this comment

The 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 = {
Copy link
Owner

Choose a reason for hiding this comment

The 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;
38 changes: 38 additions & 0 deletions app/components/ListItemAvatar.jsx
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;
5 changes: 2 additions & 3 deletions app/style/themes/default-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ export default {
hoverColor: colors.red300,
},
listItem: {
borderColor: '#EBEBEB',
color: colorManipulator.fade('rgba(0, 0, 0, .035)', 0),
hoverColor: 'rgba(0, 0, 0, .035)',
borderColor: colorManipulator.fade(palette.borderColor, 0.3),
color: colors.fullBlack,
},
};

Expand Down
2 changes: 1 addition & 1 deletion config/webpack/makeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (options) {
var entry = path.join(__dirname, '..', '..', 'app', options.prerender ? 'utils/prerender' : 'app');

var loaders = {
jsx: options.hotComponents ? ['react-hot-loader', 'babel-loader?stage=1'] : 'babel-loader?stage=1',
jsx: options.hotComponents ? ['react-hot-loader', 'babel-loader?stage=0'] : 'babel-loader?stage=0',
png: 'url-loader?limit=10000',
html: 'html-loader'
};
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"dev-server": "webpack --config config/webpack/prerender.config.js & webpack-dev-server --config config/webpack/devServer.config.js --progress --colors --hot --inline",
"dev": "babel-node --ignore 'node_modules','build','app' config/serverDev",
"lint": "eslint --ext .js,.jsx app/ config/ lib/ test/ server.js",
"postinstall": "babel --stage 1 ./node_modules/material-ui/src --out-dir ./node_modules/material-ui/lib",
"prod": "babel-node --ignore 'node_modules','build','app' config/serverProd",
"test": "npm run lint && npm run test-jsx && npm run test-js",
"test-js": "mocha ./test/lib ./test/app/actions ./test/app/stores --compilers js:babel/register",
"test-jsx": "mochify node_modules/babel/polyfill ./test/app/components/* --reporter spec --transform [ babelify --stage 1 --ignore 'node_modules'] --extension .jsx"
"test-jsx": "mochify node_modules/babel/polyfill ./test/app/components/* --reporter spec --transform [ babelify --stage 0 --ignore 'node_modules'] --extension .jsx"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -46,7 +47,7 @@
"leaflet.markercluster": "Leaflet/Leaflet.markercluster#v0.4.0-hotfix.1",
"less": "^2.5.1",
"less-loader": "^2.2.0",
"material-ui": "0.9.0",
"material-ui": "ababol/material-ui.git",
"react": "^0.13.3",
"react-hot-loader": "^1.2.7",
"react-leaflet": "^0.6.2",
Expand Down