index.tsx 2.0 KB

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