index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react';
  2. import OuterRect from '../OuterRect';
  3. import SvgShapeElement from '../SvgShapeElement';
  4. import { rectCalc, parsePositionForBackend } from '../../helpers/position';
  5. import { AnnotationContainer } from '../../global/otherStyled';
  6. const Note: React.SFC<AnnotationElementPropsType> = ({
  7. id,
  8. obj_type,
  9. obj_attr: {
  10. bdcolor = '',
  11. fcolor = '',
  12. bdwidth = 0,
  13. transparency = 0,
  14. ftransparency = 0,
  15. position,
  16. },
  17. scale,
  18. viewport,
  19. isCollapse,
  20. onUpdate,
  21. }: AnnotationElementPropsType) => {
  22. const annotRect = rectCalc(position as PositionType, viewport.height, scale);
  23. const handleScaleOrMove = ({
  24. top,
  25. left,
  26. width = 0,
  27. height = 0,
  28. }: CoordType): void => {
  29. const newPosition = {
  30. top,
  31. left,
  32. bottom: top + (height || annotRect.height),
  33. right: left + (width || annotRect.width),
  34. };
  35. onUpdate({
  36. position: parsePositionForBackend(
  37. obj_type,
  38. newPosition,
  39. viewport.height,
  40. scale
  41. ),
  42. });
  43. };
  44. const actualbdwidth = bdwidth * scale;
  45. const actualWidth = annotRect.width;
  46. const actualHeight = annotRect.height;
  47. return (
  48. <>
  49. <AnnotationContainer
  50. id={id}
  51. top={`${annotRect.top}px`}
  52. left={`${annotRect.left}px`}
  53. width={`${actualWidth}px`}
  54. height={`${actualHeight}px`}
  55. >
  56. <SvgShapeElement
  57. shape={obj_type}
  58. width={actualWidth}
  59. height={actualHeight}
  60. bdcolor={bdcolor}
  61. transparency={transparency}
  62. bdwidth={actualbdwidth}
  63. fcolor={fcolor}
  64. ftransparency={ftransparency}
  65. />
  66. </AnnotationContainer>
  67. {!isCollapse ? (
  68. <OuterRect
  69. top={annotRect.top}
  70. left={annotRect.left}
  71. width={actualWidth}
  72. height={actualHeight}
  73. onMove={handleScaleOrMove}
  74. onScale={handleScaleOrMove}
  75. />
  76. ) : (
  77. ''
  78. )}
  79. </>
  80. );
  81. };
  82. export default Note;