import React from 'react';
import PropTypes from 'prop-types';
class List extends React.Component {
render() {
const contents = this.props.items.map((item, i) => {
const obj = {};
const isElement = Object.keys(item).indexOf('type') >= 0;
if (typeof item === 'string') {
obj.content = item;
} else if (!isElement) {
obj.content = item.content;
obj.theme = item.theme;
}
return !isElement ? (
<li key={i} className={obj.theme}>{obj.content}</li>
) : item;
});
const list = this.props.ordered ? (
<ol
id={this.props.id}
className={`${this.props.unstyled ? 'list-unstyled' : ''} ${this.props.inline ? 'list-inline' : ''} ${this.props.theme ? this.props.theme : ''}`}
>
{contents}
</ol>
) : (
<ul
id={this.props.id}
className={`${this.props.unstyled ? 'list-unstyled' : ''} ${this.props.inline ? 'list-inline' : ''} ${this.props.theme ? this.props.theme : ''}`}
>
{contents}
</ul>
);
return list;
}
}
List.propTypes = {
id: PropTypes.string,
theme: PropTypes.string,
items: PropTypes.array,
ordered: PropTypes.bool,
unstyled: PropTypes.bool,
inline: PropTypes.bool
};
List.defaultProps = {
items: [],
ordered: false,
unstyled: false,
inline: false
};
export default List;
|