All files / lib/TabContent index.js

100% Statements 8/8
100% Branches 2/2
100% Functions 2/2
100% Lines 8/8
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                    89x 17x   17x 31x         17x     89x             89x         89x      
import React from 'react';
import PropTypes from 'prop-types';
 
/**
 * TabContent helps organize the TabPanes and provides the Tab-content CSS wrapper;
 * @param props
 * @returns {XML}
 * @constructor
 */
 
const TabContent = props => {
  const { children, activeIndex } = props;
 
  const setPanels = React.Children.map(children, (child, idx) => {
    return React.cloneElement(child, {
      active: activeIndex === idx ? true : false,
    });
  });
 
  return <div className={`cui-tab__content`}>{setPanels}</div>;
};
 
TabContent.propTypes = {
  /** @prop Determines the initial active index | null */
  activeIndex: PropTypes.number,
  /** @prop Children nodes to render inside TabContent | null */
  children: PropTypes.node,
};
 
TabContent.defaultProps = {
  activeIndex: null,
  children: null,
};
 
TabContent.displayName = 'TabContent';
 
export default TabContent;