index.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. AnnotationItem.defaultProps = {
  52. page: 0,
  53. title: '',
  54. date: '',
  55. showPageNum: false,
  56. };
  57. export default AnnotationItem;