index.tsx 1.5 KB

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