All files / src/FreezeLayer FreezeLayer.js

100% Statements 8/8
85.71% Branches 12/14
100% Functions 1/1
100% Lines 8/8

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                                                        21x   21x   21x         21x   21x         21x                                                                               11x 11x                
import React from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
import { Container } from '@zohodesk/components/lib/Layout';
import { mergeStyle } from '@zohodesk/utils';
import VelocityAnimationGroup from '@zohodesk/components/lib/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup';
import { useZIndex } from '@zohodesk/components/lib/Provider/ZindexProvider';
import cssJSLogic from './css/cssJSLogic';
import useFreezeLayer from '../Hooks/useFreezeLayer';
import style from './css/FreezeLayer.module.css';
 
export default function FreezeLayer(props) {
  let {
    isActive: propsActive,
    children,
    align,
    childAnimationName,
    palette,
    onClick,
    animationName,
    runOnMount,
    forwardRef,
    isSvgMask,
    needAutoZindex,
    customStyle,
    onAnimateEnter,
    postAnimateStyles,
    onAnimateExit
  } = props;
 
  const finalStyle = mergeStyle(style, customStyle);
 
  const { freezeClass } = cssJSLogic({
    props,
    style: finalStyle
  });
 
  const getNextIndex = useZIndex();
 
  const { isActive, isChildActive, handleClick } = useFreezeLayer({
    isActive: propsActive,
    onClick
  });
 
  return (
    <VelocityAnimationGroup name={animationName && animationName} isActive={isActive} runOnMount={runOnMount}>
      <div
        style={isActive && needAutoZindex ? { zIndex: `${getNextIndex()}` } : {}}
        className={freezeClass}
        onClick={handleClick}
        data-drag-parent={true}
        ref={forwardRef}
      >
        {children && (
          <>
            {childAnimationName ? (
              <VelocityAnimationGroup
                name={childAnimationName}
                isActive={isChildActive}
                enterDelay={palette === 'plain' ? 0 : 300}
                component={Container}
                alignBox='row'
                align={align}
                dataId='reactFreezeLayer'
                onEnterComplete={onAnimateEnter}
                postEnterStyles={postAnimateStyles}
                onExitComplete={onAnimateExit}
              >
                {children}
              </VelocityAnimationGroup>
            ) : isSvgMask ? (
              <>{children}</>
            ) : (
              <Container alignBox='row' align={align} dataId='reactFreezeLayer'>
                {children}
              </Container>
            )}
          </>
        )}
      </div>
    </VelocityAnimationGroup>
  );
}
 
FreezeLayer.propTypes = propTypes;
FreezeLayer.defaultProps = defaultProps;
 
// if (__DOCS__) {
//   FreezeLayer.docs = {
//     componentGroup: 'Atom',
//     folderName: 'General'
//   };
// }