All files / components/text d-list.jsx

100% Statements 11/11
100% Branches 10/10
100% Functions 2/2
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39          2x   4x 4x 2x 2x   4x   2x                     1x             1x            
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;