import React from 'react';
import PropTypes from 'prop-types';
class DList extends React.Component {
render() {
const contents = this.props.items.map((item, i) => {
let listItem;
const isElement = Object.keys(item).indexOf('type') >= 0;
if (!isElement) {
if (item.dt) { listItem = <dt className={item.theme} key={i}>{item.dt}</dt>; }
if (item.dd) { listItem = <dd className={item.theme} key={i}>{item.dd}</dd>; }
}
return isElement ? item : listItem;
});
return (
<dl
id={this.props.id}
className={`${this.props.theme} ${this.props.horizontal ? 'dl-horizontal' : ''}`}
>
{contents}
</dl>
);
}
}
DList.propTypes = {
id: PropTypes.string,
theme: PropTypes.string,
items: PropTypes.array,
horizontal: PropTypes.bool
};
DList.defaultProps = {
items: [],
horizontal: false
};
export default DList;
|