UNPKG

react-pdf-annotations

Version:
70 lines (61 loc) 1.38 kB
// @flow import React, { Component } from "react"; import "../style/Highlight.css"; import type { T_LTWH } from "../types.js"; type Props = { position: { boundingRect: T_LTWH, rects: Array<T_LTWH> }, onClick?: () => void, onMouseOver?: () => void, onMouseOut?: () => void, comment: { emoji: string, text: string }, isScrolledTo: boolean }; class Highlight extends Component<Props> { render() { const { position, onClick, onMouseOver, onMouseOut, comment, isScrolledTo } = this.props; const { rects, boundingRect } = position; return ( <div className={`Highlight ${isScrolledTo ? "Highlight--scrolledTo" : ""}`} > {comment ? ( <div className="Highlight__emoji" style={{ left: 20, top: boundingRect.top }} > {comment.emoji} </div> ) : null} <div className="Highlight__parts"> {rects.map((rect, index) => ( <div onMouseOver={onMouseOver} onMouseOut={onMouseOut} onClick={onClick} key={index} style={rect} className={`Highlight__part`} /> ))} </div> </div> ); } } export default Highlight;