index.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import dayjs from 'dayjs';
  3. import Icon from '../Icon';
  4. import Divider from '../Divider';
  5. import { scrollIntoView } from '../../helpers/utility';
  6. import data from './data';
  7. import { PageNumber, AnnotationBox, Group } from './styled';
  8. type Props = {
  9. type: string;
  10. page?: number;
  11. title?: string;
  12. date?: string;
  13. showPageNum?: boolean;
  14. };
  15. const AnnotationItem = ({
  16. type,
  17. title,
  18. date,
  19. page,
  20. showPageNum,
  21. }: Props): React.ReactElement => {
  22. const handleClick = (): void => {
  23. const ele: HTMLElement = document.getElementById(
  24. `page_${page}`
  25. ) as HTMLElement;
  26. scrollIntoView(ele);
  27. };
  28. return (
  29. <>
  30. {showPageNum ? (
  31. <>
  32. <Divider orientation="horizontal" />
  33. <PageNumber>{`Page ${page}`}</PageNumber>
  34. </>
  35. ) : null}
  36. <AnnotationBox onClick={handleClick}>
  37. <Group>
  38. <Icon glyph={data[type].icon} />
  39. {data[type].text}
  40. </Group>
  41. <Group>
  42. <span>{title || ''}</span>
  43. <span>
  44. {date && dayjs(date?.replace('_', ' ')).format('YYYY/MM/DD HH:mm')}
  45. </span>
  46. </Group>
  47. </AnnotationBox>
  48. </>
  49. );
  50. };
  51. export default AnnotationItem;