index.tsx 1.5 KB

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