react-toolbox/components/list/ListItemActions.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2016-05-29 22:11:04 +03:00
import React, { PropTypes } from 'react';
2016-05-22 20:08:47 +03:00
import { themr } from 'react-css-themr';
2017-01-26 20:05:32 +03:00
import { LIST } from '../identifiers';
import InjectListItemAction from './ListItemAction';
2016-05-29 21:59:54 +03:00
const factory = (ListItemAction) => {
2017-01-26 20:05:32 +03:00
const ListItemActions = ({ type, children, theme }) => {
2016-05-29 21:59:54 +03:00
const validChildren = React.Children.toArray(children).filter(c => (
React.isValidElement(c)
));
2016-05-29 21:59:54 +03:00
return (
<span className={theme[type]}>
2017-01-26 20:05:32 +03:00
{validChildren.map((action, i) => (
<ListItemAction key={i} theme={theme} action={action} /> // eslint-disable-line
))}
2016-05-29 21:59:54 +03:00
</span>
);
};
ListItemActions.propTypes = {
2017-01-26 20:05:32 +03:00
children: PropTypes.node,
2016-05-29 22:11:04 +03:00
theme: PropTypes.shape({
left: PropTypes.string,
2017-01-26 20:05:32 +03:00
right: PropTypes.string,
2016-05-29 21:59:54 +03:00
}),
2017-01-26 20:05:32 +03:00
type: PropTypes.oneOf(['left', 'right']),
2016-05-29 21:59:54 +03:00
};
2016-05-29 21:59:54 +03:00
return ListItemActions;
};
2016-05-29 21:59:54 +03:00
const ListItemActions = factory(InjectListItemAction);
export default themr(LIST)(ListItemActions);
export { factory as listItemActionsFactory };
export { ListItemActions };