All files / Layout Box.js

57.5% Statements 23/40
57.69% Branches 15/26
75% Functions 3/4
57.5% Lines 23/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                    75x 75x 75x 19x 19x 56x     75x     75x     75x     75x     75x   75x         75x       75x                   75x                     75x                   75x       75x       75x 75x               75x     2x 2x  
import React from 'react';
import { BoxProps as propTypes } from './props/propTypes';
import { BoxDefaultProps 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 getBoxClassNames(props) {
  const { hidden, className, flexible, adjust, isFirst, isLast, shrink, column, align, scroll, preventParentScroll } =
    props;
  const modificators = [className];
  if (flexible && !adjust) {
    modificators.push(getClass(style, 'grow'));
    modificators.push(getClass(style, 'basis'));
  } else Iif (flexible && adjust) {
    modificators.push(getClass(style, 'grow'));
  }
  Iif (isFirst) {
    modificators.push(getClass(style, 'first'));
  }
  Iif (isLast) {
    modificators.push(getClass(style, 'last'));
  }
  Iif (adjust) {
    modificators.push(getClass(style, 'basisAuto'));
  }
  Iif (shrink) {
    modificators.push(getClass(style, 'shrinkOn'));
  } else {
    modificators.push(getClass(style, 'shrinkOff'));
  }
  Iif (hidden) {
    hidden.forEach((key) => {
      modificators.push(getClass(style, `hidden-screen-${key}`));
    });
  }
  Iif (column) {
    modificators.push(getClass(style, `col-${column}`));
  }
 
  Iif (align) {
    let alignClassMapping = {
      start: 'selfStart',
      end: 'selfEnd',
      center: 'selfCenter'
    };
    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 getBoxProps(props) {
  return createProps(propTypes, props, getBoxClassNames(props));
}
 
export default function Box(props) {
  let { tagName } = props;
  let componentProps = setProps({ ...getBoxProps(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);
}
 
Box.propTypes = propTypes;
Box.defaultProps = defaultProps;