2017-04-17 17:14:17 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-05-22 20:08:47 +03:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import { themr } from 'react-css-themr';
|
2017-01-26 20:05:32 +03:00
|
|
|
import { LIST } from '../identifiers';
|
|
|
|
import { FontIcon } from '../font_icon/FontIcon';
|
|
|
|
import InjectAvatar from '../avatar/Avatar';
|
|
|
|
import InjectListItemContent from './ListItemContent';
|
|
|
|
import InjectListItemActions from './ListItemActions';
|
2016-01-26 16:59:57 +03:00
|
|
|
|
2016-05-29 21:59:54 +03:00
|
|
|
const factory = (Avatar, ListItemContent, ListItemActions) => {
|
|
|
|
const ListItemLayout = (props) => {
|
|
|
|
const className = classnames(props.theme.item, {
|
|
|
|
[props.theme.disabled]: props.disabled,
|
2017-01-26 20:05:32 +03:00
|
|
|
[props.theme.selectable]: props.selectable,
|
2016-05-29 21:59:54 +03:00
|
|
|
}, props.className);
|
2016-01-26 16:59:57 +03:00
|
|
|
|
2016-05-29 21:59:54 +03:00
|
|
|
const leftActions = [
|
2017-01-26 20:05:32 +03:00
|
|
|
props.leftIcon && <FontIcon value={props.leftIcon} key="leftIcon" />,
|
|
|
|
props.avatar && <Avatar image={props.avatar} key="avatar" />,
|
|
|
|
...props.leftActions,
|
2016-05-29 21:59:54 +03:00
|
|
|
];
|
|
|
|
const rightActions = [
|
2017-01-26 20:05:32 +03:00
|
|
|
props.rightIcon && <FontIcon value={props.rightIcon} key="rightIcon" />,
|
|
|
|
...props.rightActions,
|
2016-05-29 21:59:54 +03:00
|
|
|
];
|
2017-01-26 20:05:32 +03:00
|
|
|
const emptyActions = item => !item[0] && !item[1] && !item[2];
|
|
|
|
const content = props.itemContent || (
|
|
|
|
<ListItemContent theme={props.theme} caption={props.caption} legend={props.legend} />
|
|
|
|
);
|
2016-01-26 16:59:57 +03:00
|
|
|
|
2016-05-29 21:59:54 +03:00
|
|
|
return (
|
|
|
|
<span className={className}>
|
2017-01-26 20:05:32 +03:00
|
|
|
{!emptyActions(leftActions) > 0 && <ListItemActions type="left" theme={props.theme}>{leftActions}</ListItemActions>}
|
2016-05-29 21:59:54 +03:00
|
|
|
{content}
|
2017-01-26 20:05:32 +03:00
|
|
|
{!emptyActions(rightActions) > 0 && <ListItemActions type="right" theme={props.theme}>{rightActions}</ListItemActions>}
|
2016-05-29 21:59:54 +03:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
2016-01-26 16:59:57 +03:00
|
|
|
|
2016-05-29 21:59:54 +03:00
|
|
|
ListItemLayout.propTypes = {
|
2016-05-29 22:11:04 +03:00
|
|
|
avatar: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
PropTypes.element,
|
2016-05-29 21:59:54 +03:00
|
|
|
]),
|
2017-08-02 19:08:28 +03:00
|
|
|
caption: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.node,
|
|
|
|
]),
|
2016-05-29 22:11:04 +03:00
|
|
|
className: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
itemContent: PropTypes.element,
|
2017-01-26 20:05:32 +03:00
|
|
|
leftActions: PropTypes.arrayOf(PropTypes.node),
|
2016-05-29 22:11:04 +03:00
|
|
|
leftIcon: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
PropTypes.element,
|
2016-05-29 21:59:54 +03:00
|
|
|
]),
|
2017-08-02 19:08:28 +03:00
|
|
|
legend: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.node,
|
|
|
|
]),
|
2017-01-26 20:05:32 +03:00
|
|
|
rightActions: PropTypes.arrayOf(PropTypes.node),
|
2016-05-29 22:11:04 +03:00
|
|
|
rightIcon: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
PropTypes.element,
|
2016-05-29 21:59:54 +03:00
|
|
|
]),
|
2016-05-29 22:11:04 +03:00
|
|
|
selectable: PropTypes.bool,
|
|
|
|
theme: PropTypes.shape({
|
2016-06-04 00:44:33 +03:00
|
|
|
disabled: PropTypes.string,
|
|
|
|
item: PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
selectable: PropTypes.string,
|
2016-05-29 21:59:54 +03:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
ListItemLayout.defaultProps = {
|
|
|
|
disabled: false,
|
2017-01-26 20:05:32 +03:00
|
|
|
selectable: false,
|
2016-05-29 21:59:54 +03:00
|
|
|
};
|
2016-01-26 16:59:57 +03:00
|
|
|
|
2016-05-29 21:59:54 +03:00
|
|
|
return ListItemLayout;
|
2016-01-26 16:59:57 +03:00
|
|
|
};
|
|
|
|
|
2016-05-29 21:59:54 +03:00
|
|
|
const ListItemLayout = factory(InjectAvatar, InjectListItemContent, InjectListItemActions);
|
|
|
|
export default themr(LIST)(ListItemLayout);
|
|
|
|
export { factory as listItemLayoutFactory };
|
|
|
|
export { ListItemLayout };
|