index.tsx 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. import Icon from '../Icon';
  3. import Divider from '../Divider';
  4. import { scrollIntoView } from '../../helpers/utility';
  5. import data from './data';
  6. import { PageNumber, AnnotationBox } from './styled';
  7. type Props = {
  8. type: string;
  9. page?: number;
  10. bdcolor: string;
  11. getText: () => Promise<any>;
  12. showPageNum?: boolean;
  13. transparency: number;
  14. };
  15. const AnnotationItem = ({
  16. type,
  17. page,
  18. showPageNum,
  19. }: Props): React.ReactElement => {
  20. const handleClick = (): void => {
  21. const ele: HTMLElement | null = document.getElementById(`page_${page}`);
  22. if (ele) {
  23. scrollIntoView(ele);
  24. }
  25. };
  26. return (
  27. <>
  28. {showPageNum ? (
  29. <>
  30. <Divider orientation="horizontal" />
  31. <PageNumber>{`Page ${page}`}</PageNumber>
  32. </>
  33. ) : null}
  34. <AnnotationBox onClick={handleClick}>
  35. <Icon glyph={data[type].icon} />
  36. {data[type].text}
  37. </AnnotationBox>
  38. </>
  39. );
  40. };
  41. export default AnnotationItem;