All files / src/FormAction FormAction.js

65.51% Statements 19/29
45% Branches 18/40
25% Functions 2/8
65.51% Lines 19/29

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          8x     8x     8x           45x 45x 45x 45x 45x 44x   44x   44x   44x     44x       45x   45x   45x 45x                                                                                                         8x   8x              
import React from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
import style from './FormAction.module.css';
import { Container, Box } from '@zohodesk/components/lib/Layout';
export const LeftSide = (props) => {
  props.children;
};
export const RightSide = (props) => {
  props.children;
};
export const Center = (props) => {
  props.children;
};
 
export default class FormAction extends React.Component {
  render() {
    let { size, children, paddingLeftSize, paddingRightClass, dataSelectorId } = this.props;
    let leftbuttonGroup = [],
      rightbuttonGroup = [],
      centerbuttonGroup = [];
    React.Children.map(children, (child) => {
      Iif (!child) {
        return child;
      } else Iif (child.type === LeftSide) {
        leftbuttonGroup = leftbuttonGroup.concat(child.props.children);
      } else Iif (child.type === RightSide) {
        rightbuttonGroup = rightbuttonGroup.concat(child.props.children);
      } else Iif (child.type === Center) {
        centerbuttonGroup = centerbuttonGroup.concat(child.props.children);
      } else {
        leftbuttonGroup.push(child);
      }
    });
 
    let hasLeftChild = leftbuttonGroup.length > 0;
 
    let hasRightChild = rightbuttonGroup.length > 0;
 
    let hasCenterChild = centerbuttonGroup.length > 0;
    return (
      <div className={style.wrapperDiv} data-selector-id={dataSelectorId}>
        <Container
          alignBox='row'
          isCover={false}
          align={hasCenterChild ? 'around' : hasRightChild && !hasLeftChild ? 'right' : null}
          className={`
                        ${`${style.footerParent} ${
                          hasCenterChild ? '' : style[`${paddingLeftSize ? paddingLeftSize : size}Padding`]
                        } ${paddingRightClass}`}
 
                        ${style[`${size}Footer`]}
                    `}
        >
          {hasLeftChild ? (
            <Box flexible={hasRightChild ? true : false} shrink={!hasRightChild && hasLeftChild ? true : false}>
              {leftbuttonGroup.length > 1
                ? leftbuttonGroup.map((item, index) => (
                    <div className={style.marginRight} key={index}>
                      {item}
                    </div>
                  ))
                : leftbuttonGroup[0]}
            </Box>
          ) : null}
          {hasRightChild ? (
            <Box shrink={hasRightChild && !hasLeftChild ? true : false}>
              {rightbuttonGroup.length > 1
                ? rightbuttonGroup.map((item, index) => (
                    <div className={style.marginRight} key={index}>
                      {item}
                    </div>
                  ))
                : rightbuttonGroup[0]}
            </Box>
          ) : null}
          {hasCenterChild ? (
            <Box>
              {centerbuttonGroup.length > 1
                ? centerbuttonGroup.map((item, index) => (
                    <div className={style.marginRight} key={index}>
                      {item}
                    </div>
                  ))
                : centerbuttonGroup[0]}
            </Box>
          ) : null}
        </Container>
      </div>
    );
  }
}
 
FormAction.propTypes = propTypes;
 
FormAction.defaultProps = defaultProps;
 
// if (__DOCS__) {
//   FormAction.docs = {
//     componentGroup: 'Atom'
//   };
// }