All files / src/lookup/header/ModuleHeader ModuleHeader.js

100% Statements 10/10
61.53% Branches 8/13
100% Functions 1/1
100% Lines 10/10

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                                                                          1x   1x 1x   1x                                                                                       1x 1x   1x 1x 1x 1x    
/*** Libraries ***/
import React, { memo, useRef } from 'react';
import { defaultProps } from './props/defaultProps';
import { propTypes } from './props/propTypes';
/*** Components ***/
import Title from '../Title/Title';
import Close from '../Close/Close';
import Search from '../Search/Search';
import { Container, Box } from '@zohodesk/components/lib/Layout';
 
/*** CSS ***/
import commonStyle from '../lookupHeaderCommon.module.css';
import commonResponsive from '../lookupHeaderCommonResponsive.module.css';
 
//customHooks
import useDragger from '../../../Hooks/Dragger/useDragger';
/*eslint-disable react/forbid-component-props */
 
function ModuleHeader(props) {
  const {
    title = '',
    needSearch = false,
    onLookupClose,
    searchStr = '',
    onSearch,
    onSearchChange,
    searchPlaceHolder,
    needOnTypeSearch,
    getSearchBoxRef,
    miniDescription,
    dataId,
    closeTitle,
    onSearchKeyDown,
    palette,
    dragBoundaryLimit,
    children,
    childNearTitle
  } = props;
 
  const dragRef = useRef(null); //dragRef
  useDragger({ isActive: true, ChildRef: dragRef, boundaryLimit: dragBoundaryLimit }); //custom Hook
 
  return (
    <Container
      align='vertical'
      alignBox='row'
      className={`${commonStyle.container} ${commonStyle[`${palette}`]}`}
      isCover={false}
      wrap='wrap'
      dataId={dataId}
      data-drag-hook='true'
      eleRef={dragRef}
    >
      {childNearTitle ? childNearTitle : ''}
 
      <Box flexible>
        <div className={commonStyle.title}>
          <Title text={title} />
        </div>
        {miniDescription && <div className={commonStyle.para}>{miniDescription}</div>}
      </Box>
 
      {needSearch && (
        <Box className={`${commonStyle.searchContainer} ${commonResponsive.searchContainer}`}>
          <Search
            onSearch={onSearch}
            searchStr={searchStr}
            onChange={onSearchChange}
            placeHolder={searchPlaceHolder}
            dataId='search'
            needOnTypeSearch={needOnTypeSearch}
            getRef={getSearchBoxRef}
            onKeyDown={onSearchKeyDown}
          />
        </Box>
      )}
      {children ? children : ''}
      {onLookupClose ? (
        <div className={commonStyle.closeContainer}>
          <Close dataId='close' onClose={onLookupClose} title={closeTitle} />
        </div>
      ) : null}
    </Container>
  );
}
 
ModuleHeader.propTypes = propTypes;
ModuleHeader.defaultProps = defaultProps;
 
const MemoizedModuleHeader = memo(ModuleHeader);
MemoizedModuleHeader.propTypes = propTypes;
MemoizedModuleHeader.defaultProps = defaultProps;
MemoizedModuleHeader.displayName = 'ModuleHeader';
export default MemoizedModuleHeader;