All files / color-github/src Point.tsx

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 13/13

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                1x                   53x 53x 2x 2x 2x     53x 2x 1x 1x 1x       53x                   53x                                              
import React, { CSSProperties, useCallback } from 'react';
import { SwatchRectRenderProps, SwatchProps } from '@uiw/react-color-swatch';
import { useRef } from 'react';
 
interface PointProps extends SwatchRectRenderProps {
  rectProps?: SwatchProps['rectProps'];
}
 
const defalutStyle: CSSProperties = {
  marginRight: 0,
  marginBottom: 0,
  borderRadius: 0,
  boxSizing: 'border-box',
  height: 25,
  width: 25,
};
 
export default function Point({ style, title, checked, color, onClick, rectProps }: PointProps) {
  const btn = useRef<HTMLDivElement>(null);
  const handleMouseEnter = useCallback(() => {
    btn.current!.style['zIndex'] = '2';
    btn.current!.style['outline'] = '#fff solid 2px';
    btn.current!.style['boxShadow'] = 'rgb(0 0 0 / 25%) 0 0 5px 2px';
  }, []);
 
  const handleMouseLeave = useCallback(() => {
    if (!checked) {
      btn.current!.style['zIndex'] = '0';
      btn.current!.style['outline'] = 'initial';
      btn.current!.style['boxShadow'] = 'initial';
    }
  }, [checked]);
 
  const rectStyle = checked
    ? {
        zIndex: 1,
        outline: '#fff solid 2px',
        boxShadow: 'rgb(0 0 0 / 25%) 0 0 5px 2px',
      }
    : {
        zIndex: 0,
      };
 
  return (
    <div
      ref={btn}
      title={title}
      {...rectProps}
      onClick={onClick}
      onMouseEnter={handleMouseEnter}
      onMouseLeave={handleMouseLeave}
      style={{
        ...style,
        marginRight: 0,
        marginBottom: 0,
        borderRadius: 0,
        boxSizing: 'border-box',
        height: 25,
        width: 25,
        ...defalutStyle,
        ...rectStyle,
        ...rectProps?.style,
      }}
    ></div>
  );
}