import React, { useEffect, useState } from 'react'; import Divider from '../Divider'; import Markup from '../Markup'; import { scrollIntoView } from '../../helpers/utility'; import { PageNumber, AnnotationBox, Content, Inner, Text, } from './styled'; type Props = { type: string; page?: number; bdcolor: string; getText: () => Promise; showPageNum?: boolean; transparency: number; } const AnnotationItem = ({ type, page, showPageNum, bdcolor, getText, transparency, }: Props): React.ReactElement => { const [content, setContent] = useState([]); const handleClick = (): void => { const ele: HTMLElement | null = document.getElementById(`page_${page}`); if (ele) { scrollIntoView(ele); } }; useEffect(() => { getText().then((text) => { let textArray = []; if (text.includes(' ')) { textArray = text.split(' '); } else { textArray = text.match(/.{1,12}/g); } setContent(textArray); }); }, []); return ( <> {showPageNum && } {showPageNum && {`Page ${page}`}} { content.length && content.map((textContent: string, index: number): any => { const key = `key_${index}`; return textContent ? ( {textContent} ) : null; }) } ); }; export default AnnotationItem;