All files / Layout Container.js

62.5% Statements 25/40
56.25% Branches 9/16
75% Functions 3/4
62.5% Lines 25/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119                      56x 56x 56x         56x 37x   19x   56x       56x           56x 56x   56x                         56x                 56x 56x                       56x 56x     56x                     56x                   56x       56x       56x 56x               56x     2x 2x  
import React from 'react';
import { ContainerProps as propTypes } from './props/propTypes';
import { ContainerDefaultProps as defaultProps } from './props/defaultProps';
/* eslint css-modules/no-unused-class: 0 */
import { createProps, getClass, setProps } from './utils';
import style from './Layout.module.css';
 
/* eslint-disable  react/no-unused-prop-types*/
 
function getContainerClassNames(props) {
  const { hidden, className, isInline, isCover, alignBox, alignContent, wrap, align, scroll, preventParentScroll } =
    props;
  const modificators = [className];
  Iif (hidden) {
    hidden.forEach((key) => {
      modificators.push(getClass(style, `hidden-screen-${key}`));
    });
  }
  if (isInline) {
    modificators.push(getClass(style, 'inflex'));
  } else {
    modificators.push(getClass(style, 'flex'));
  }
  Iif (isCover) {
    modificators.push(getClass(style, 'cover'));
  }
 
  let alignBoxClassMapping = {
    row: 'rowdir',
    column: 'coldir',
    'row-reverse': 'rowReverse',
    'column-reverse': 'colReverse'
  };
  let alignClass = alignBoxClassMapping[alignBox];
  modificators.push(getClass(style, alignClass));
 
  Iif (alignContent) {
    let alignContentClassMapping = {
      start: 'alignStart',
      end: 'alignEnd',
      center: 'alignCenter',
      around: 'alignAround',
      between: 'alignBetween'
    };
 
    let alignContentClass = alignContentClassMapping[alignContent];
    modificators.push(getClass(style, alignContentClass));
  }
 
  Iif (wrap) {
    let wrapClassMapping = {
      wrap: 'wrap',
      'wrap-reverse': 'wrapReverse'
    };
    let wrapClass = wrapClassMapping[wrap];
    modificators.push(getClass(style, wrapClass));
  }
 
  Eif (align) {
    let alignClassMapping = {
      horizontal: 'hCenter',
      vertical: 'vCenter',
      both: 'both',
      between: 'between',
      around: 'around',
      right: 'right',
      left: 'left',
      top: 'top',
      bottom: 'bottom',
      baseline: 'baseline'
    };
    let alignClass = alignClassMapping[align];
    modificators.push(getClass(style, alignClass));
  }
 
  Iif (scroll) {
    let scrollClassMapping = {
      horizontal: 'scrollx',
      vertical: 'scrolly',
      both: 'scrollboth',
      none: 'scrollnone'
    };
    let scrollClass = scrollClassMapping[scroll];
    modificators.push(getClass(style, scrollClass));
  }
 
  Iif (preventParentScroll) {
    let ParentScrollClassMapping = {
      horizontal: 'preventScrollBubbleX',
      vertical: 'preventScrollBubbleY',
      both: 'preventScrollBubbleBoth'
    };
    let parentScrollClass = ParentScrollClassMapping[preventParentScroll];
    modificators.push(getClass(style, parentScrollClass));
  }
 
  return modificators;
}
 
function getContainerProps(props) {
  return createProps(propTypes, props, getContainerClassNames(props));
}
 
export default function Container(props) {
  let { tagName } = props;
  let componentProps = setProps({ ...getContainerProps(props) }, props, {
    isScrollAttribute: 'data-scroll',
    eleRef: 'ref',
    dataId: 'data-id',
    testId: 'data-test-id',
    tourId: 'data-tour',
    dataSelectorId: 'data-selector-id'
  });
  return React.createElement(tagName, componentProps);
}
 
Container.propTypes = propTypes;
Container.defaultProps = defaultProps;