index.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* eslint-disable jsx-a11y/mouse-events-have-key-events */
  2. import React from 'react';
  3. import AnnotationOptions from '../AnnotationOptions';
  4. import Markup from '../Markup';
  5. import { rectCalc } from '../../helpers/position';
  6. import { strip } from '../../helpers/utility';
  7. import { Popper } from './styled';
  8. const Highlight: React.SFC<AnnotationElementPropsType> = ({
  9. id,
  10. obj_type,
  11. obj_attr: { page, position, bdcolor, transparency },
  12. isCovered,
  13. mousePosition,
  14. isCollapse,
  15. onUpdate,
  16. onDelete,
  17. scale,
  18. viewport,
  19. onMouseOver,
  20. onMouseOut,
  21. }: AnnotationElementPropsType) => (
  22. <>
  23. {Array.isArray(position) &&
  24. position.map((ele: any, index: number) => {
  25. const annotRect = rectCalc(ele, viewport.height, scale);
  26. return (
  27. <Markup
  28. id={id}
  29. key={`block_${page + index}`}
  30. position={{
  31. top: `${annotRect.top.toFixed(2)}px`,
  32. left: `${annotRect.left.toFixed(2)}px`,
  33. width: `${annotRect.width.toFixed(2)}px`,
  34. height: `${annotRect.height.toFixed(2)}px`,
  35. }}
  36. bdcolor={bdcolor || ''}
  37. opacity={transparency || 0}
  38. markupType={obj_type}
  39. isCovered={isCovered}
  40. scale={scale}
  41. onMouseOver={onMouseOver}
  42. onMouseOut={onMouseOut}
  43. />
  44. );
  45. })}
  46. {!isCollapse ? (
  47. <Popper position={mousePosition}>
  48. <AnnotationOptions
  49. onUpdate={onUpdate}
  50. onDelete={onDelete}
  51. colorProps={bdcolor}
  52. opacityProps={transparency ? strip(transparency * 100) : 0}
  53. />
  54. </Popper>
  55. ) : null}
  56. </>
  57. );
  58. export default Highlight;