All files / color-circle/src Point.tsx

100% Statements 7/7
100% Branches 6/6
100% Functions 3/3
100% Lines 7/7

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                    24x 24x 2x     24x 1x     24x                     24x                                                          
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'];
  className?: string;
}
 
export default function Point({ style, className, title, checked, color, onClick, rectProps }: PointProps) {
  const btn = useRef<HTMLDivElement>(null);
  const handleMouseEnter = useCallback(() => {
    btn.current!.style['transform'] = 'scale(1.2)';
  }, []);
 
  const handleMouseLeave = useCallback(() => {
    btn.current!.style['transform'] = 'scale(1)';
  }, []);
 
  const styleWrapper = {
    '--circle-point-background-color': '#fff',
    height: checked ? '100%' : 0,
    width: checked ? '100%' : 0,
    borderRadius: '50%',
    backgroundColor: 'var(--circle-point-background-color)',
    boxSizing: 'border-box',
    transition: 'height 100ms ease 0s, width 100ms ease 0s',
    ...rectProps!.style,
  } as CSSProperties;
 
  return (
    <div
      ref={btn}
      onClick={onClick}
      onMouseEnter={handleMouseEnter}
      onMouseLeave={handleMouseLeave}
      title={title}
      className={className}
      style={{
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        width: 28,
        height: 28,
        padding: 3,
        borderRadius: '50%',
        marginRight: 12,
        marginBottom: 12,
        boxSizing: 'border-box',
        transform: 'scale(1)',
        boxShadow: `${color} 0px 0px ${checked ? 5 : 0}px`,
        transition: 'transform 100ms ease 0s, box-shadow 100ms ease 0s',
        ...style,
      }}
    >
      <div {...rectProps} style={styleWrapper} />
    </div>
  );
}