index.tsx 2.0 KB

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