import { h, Component, ComponentChildren } from 'preact'; import classes from './MarginalAnnotations.module.scss'; import cls from 'classnames'; import { AnnotationTargetHighlight } from './AnnotationTargetHighlight'; import type { IAnnotation, IAnnotationWithSource } from '../storage/Annotation'; import { WebAnnotation } from 'web-annotation-utils'; interface MarginalAnnotationsProps { appContainer: Node; annotations: IAnnotationWithSource[]; annotationInFocus?: IAnnotationWithSource; toolbarButtons?: ComponentChildren; onUpdateAnnotation: ( id: IAnnotation['_id'], newWebAnnotation: WebAnnotation, ) => Promise; onDeleteAnnotation: (id: IAnnotation['_id']) => Promise; } interface MarginalAnnotationsState { showAll: boolean; } export class MarginalAnnotations extends Component< MarginalAnnotationsProps, MarginalAnnotationsState > { state: MarginalAnnotationsState = { showAll: false }; toggleShowAll = () => { this.setState(({ showAll }) => ({ showAll: !showAll })); }; render( { annotations, annotationInFocus, toolbarButtons, appContainer, onUpdateAnnotation, onDeleteAnnotation, }: MarginalAnnotationsProps, { showAll }: MarginalAnnotationsState, ) { const annotationElements = annotations.map((annotation) => ( )); return (
{toolbarButtons} {(toolbarButtons || annotations.length > 0) && ( )}
{annotationElements}
); } }