All files / src/components Element.js

100% Statements 7/7
93.33% Branches 14/15
100% Functions 1/1
100% Lines 7/7
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 40 41 42 43 44 45 46 47 48 49 50 51 52                                  26x       26x 26x             26x 1x         25x         13x                      
/**
 * @copyright   2016, Miles Johnson
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */
 
import React, { PropTypes } from 'react';
 
import type { ElementProps } from '../types';
 
export default function Element({
  attributes = {},
  className,
  children,
  tagName: Tag,
  selfClose = false,
}: ElementProps) {
  const props = {
    ...attributes,
  };
 
  Eif (!selfClose || (selfClose && Tag === 'img')) {
    props.className = [
      'interweave',
      className || '',
      attributes.className || '',
    ].filter(Boolean).join(' ');
  }
 
  if (selfClose) {
    return (
      <Tag {...props} />
    );
  }
 
  return (
    <Tag {...props}>{children || null}</Tag>
  );
}
 
Element.propTypes = {
  attributes: PropTypes.objectOf(PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.number,
    PropTypes.bool,
  ])),
  className: PropTypes.string,
  children: PropTypes.node,
  tagName: PropTypes.string.isRequired,
  selfClose: PropTypes.bool,
};