1
- import React , { Component } from "react" ;
2
-
3
1
import { Rnd } from "react-rnd" ;
4
2
import { getPageFromElement } from "../lib/pdfjs-dom" ;
5
-
6
3
import styles from "../style/AreaHighlight.module.css" ;
7
-
8
4
import type { LTWHP , ViewportHighlight } from "../types" ;
9
5
10
6
interface Props {
@@ -13,55 +9,54 @@ interface Props {
13
9
isScrolledTo : boolean ;
14
10
}
15
11
16
- export class AreaHighlight extends Component < Props > {
17
- render ( ) {
18
- const { highlight, onChange, isScrolledTo, ...otherProps } = this . props ;
19
-
20
- return (
21
- < div
22
- className = { `${ styles . areaHighlight } ${
23
- isScrolledTo ? styles . scrolledTo : ""
24
- } `}
25
- >
26
- < Rnd
27
- className = { styles . part }
28
- onDragStop = { ( _ , data ) => {
29
- const boundingRect : LTWHP = {
30
- ...highlight . position . boundingRect ,
31
- top : data . y ,
32
- left : data . x ,
33
- } ;
34
-
35
- onChange ( boundingRect ) ;
36
- } }
37
- onResizeStop = { ( _mouseEvent , _direction , ref , _delta , position ) => {
38
- const boundingRect : LTWHP = {
39
- top : position . y ,
40
- left : position . x ,
41
- width : ref . offsetWidth ,
42
- height : ref . offsetHeight ,
43
- pageNumber : getPageFromElement ( ref ) ?. number || - 1 ,
44
- } ;
45
-
46
- onChange ( boundingRect ) ;
47
- } }
48
- position = { {
49
- x : highlight . position . boundingRect . left ,
50
- y : highlight . position . boundingRect . top ,
51
- } }
52
- size = { {
53
- width : highlight . position . boundingRect . width ,
54
- height : highlight . position . boundingRect . height ,
55
- } }
56
- onClick = { ( event : Event ) => {
57
- event . stopPropagation ( ) ;
58
- event . preventDefault ( ) ;
59
- } }
60
- { ...otherProps }
61
- />
62
- </ div >
63
- ) ;
64
- }
12
+ export function AreaHighlight ( {
13
+ highlight,
14
+ onChange,
15
+ isScrolledTo,
16
+ ...otherProps
17
+ } : Props ) {
18
+ return (
19
+ < div
20
+ className = { `${ styles . areaHighlight } ${
21
+ isScrolledTo ? styles . scrolledTo : ""
22
+ } `}
23
+ >
24
+ < Rnd
25
+ className = { styles . part }
26
+ onDragStop = { ( _ , data ) => {
27
+ const boundingRect : LTWHP = {
28
+ ...highlight . position . boundingRect ,
29
+ top : data . y ,
30
+ left : data . x ,
31
+ } ;
32
+ onChange ( boundingRect ) ;
33
+ } }
34
+ onResizeStop = { ( _mouseEvent , _direction , ref , _delta , position ) => {
35
+ const boundingRect : LTWHP = {
36
+ top : position . y ,
37
+ left : position . x ,
38
+ width : ref . offsetWidth ,
39
+ height : ref . offsetHeight ,
40
+ pageNumber : getPageFromElement ( ref ) ?. number || - 1 ,
41
+ } ;
42
+ onChange ( boundingRect ) ;
43
+ } }
44
+ position = { {
45
+ x : highlight . position . boundingRect . left ,
46
+ y : highlight . position . boundingRect . top ,
47
+ } }
48
+ size = { {
49
+ width : highlight . position . boundingRect . width ,
50
+ height : highlight . position . boundingRect . height ,
51
+ } }
52
+ onClick = { ( event : React . MouseEvent ) => {
53
+ event . stopPropagation ( ) ;
54
+ event . preventDefault ( ) ;
55
+ } }
56
+ { ...otherProps }
57
+ />
58
+ </ div >
59
+ ) ;
65
60
}
66
61
67
62
export default AreaHighlight ;
0 commit comments