All files / src/Separator Separator.js

100% Statements 12/12
100% Branches 25/25
100% Functions 4/4
100% Lines 11/11

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                20x       20x 20x 62x 20x                 60x 59x 21x               38x                                                             1x 1x  
import React from 'react';
import { Container, Box } from '@zohodesk/components/lib/Layout';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
import style from './Separator.module.css';
 
export default class Separator extends React.Component {
  constructor(props) {
    super(props);
  }
 
  render() {
    const { children, type, customSeparatorType, palette, wrap, shrink, aligndirection, customClass } = this.props;
    const { customWrapper, customSeparator, customChildren } = customClass;
    const data = children.filter((el) => el !== null && el !== undefined && el !== false);
    return (
      <Container
        alignBox={aligndirection}
        align={aligndirection === 'row' ? 'vertical' : ''}
        wrap={wrap}
        isCover={false}
        className={`${style.varClass} ${customWrapper}`}
      >
        {data.map((child, i) => {
          if (child) {
            if (data.length - 1 == i || aligndirection == 'column') {
              return (
                child && (
                  <Box shrink={shrink} key={i} className={customChildren}>
                    {child}
                  </Box>
                )
              );
            }
            return (
              child && (
                <React.Fragment key={i}>
                  <Box shrink={shrink} key={i} className={customChildren}>
                    {child}
                  </Box>
                  <Box
                    className={`${style.separator} ${style[palette]} ${
                      customSeparatorType ? '' : style[type]
                    } ${customSeparator} `}
                    key={i}
                  >
                    {customSeparatorType
                      ? customSeparatorType
                      : type == 'slash'
                      ? '/'
                      : type == 'arrow'
                      ? '>'
                      : type == 'comma'
                      ? ','
                      : '\u2022'}
                  </Box>
                </React.Fragment>
              )
            );
          }
        })}
      </Container>
    );
  }
}
Separator.defaultProps = defaultProps;
Separator.propTypes = propTypes;