1
1
import * as React from 'react' ;
2
+ import { translateLocationIdxToLookupKey } from '../Model/CellMatrix' ;
2
3
import { Location } from '../Model/InternalModel' ;
3
4
import { State } from '../Model/State' ;
4
5
5
- interface CellFocusProps {
6
- state ?: State ;
6
+
7
+ interface FeaturedCellProps {
7
8
location : Location ;
8
- isHighlight ?: boolean ;
9
+ state ?: State ;
9
10
borderColor ?: string ;
10
11
className ?: string ;
11
12
}
12
- export const Highlight : React . FC < CellFocusProps > = ( { borderColor, isHighlight, location, className, state } ) => {
13
- const colIdx = location . column . idx ;
14
- const rowIdx = location . row . idx ;
15
- const range = state ?. cellMatrix . rangesToRender [ state . cellMatrix . getLocationToFindRangeByIds ( colIdx , rowIdx ) ] ?. range ;
13
+
14
+ export const CellHighlight : React . FC < FeaturedCellProps > = ( { borderColor, location, className, state } ) => {
15
+ const { idx : colIdx } = location . column ;
16
+ const { idx : rowIdx } = location . row ;
17
+ const range = state ?. cellMatrix . rangesToRender [ translateLocationIdxToLookupKey ( colIdx , rowIdx ) ] ?. range ;
16
18
if ( ! range ) {
17
19
return null ;
18
20
}
19
21
return (
20
- < div
21
- key = { borderColor }
22
- className = { `${ isHighlight ? 'rg-cell-highlight' : 'rg-cell-focus' } ${ className || '' } ` }
23
- style = { {
24
- top : location . row . top - ( location . row . top === 0 ? 0 : 1 ) ,
25
- left : location . column . left - ( location . column . left === 0 ? 0 : 1 ) ,
26
- width : range . width + ( location . column . left === 0 ? 0 : 1 ) ,
27
- height : range . height + ( location . row . top === 0 ? 0 : 1 ) ,
28
- borderColor : `${ borderColor } ` ,
29
- } }
22
+ < FeaturedCell
23
+ location = { location }
24
+ className = { `rg-cell-highlight ${ className || '' } ` }
25
+ borderColor = { borderColor }
26
+ width = { range . width }
27
+ height = { range . height }
30
28
/>
31
29
) ;
32
30
}
33
31
34
- // TODO make HOC for highlights
35
- export const CellFocus : React . FC < CellFocusProps > = ( { borderColor, isHighlight, location, className } ) => {
32
+ export const CellFocus : React . FC < FeaturedCellProps > = ( { borderColor, location, className } ) => {
33
+ return < FeaturedCell
34
+ location = { location }
35
+ className = { `rg-cell-focus ${ className || '' } ` }
36
+ borderColor = { borderColor }
37
+ width = { location . column . width }
38
+ height = { location . row . height }
39
+ />
40
+ }
36
41
37
- return (
38
- < div
39
- key = { borderColor }
40
- className = { `${ isHighlight ? 'rg-cell-highlight' : 'rg-cell-focus' } ${ className || '' } ` }
41
- style = { {
42
- top : location . row . top - ( location . row . top === 0 ? 0 : 1 ) ,
43
- left : location . column . left - ( location . column . left === 0 ? 0 : 1 ) ,
44
- width : location . column . width + ( location . column . left === 0 ? 0 : 1 ) ,
45
- height : location . row . height + ( location . row . top === 0 ? 0 : 1 ) ,
46
- borderColor : `${ borderColor } ` ,
47
- } }
48
- />
49
- ) ;
50
- }
42
+ const FeaturedCell : React . FC < FeaturedCellProps & { width : number , height : number } > =
43
+ ( { className, location, borderColor, height, width } ) => {
44
+ return (
45
+ < div
46
+ className = { className }
47
+ style = { {
48
+ top : location . row . top - ( location . row . top === 0 ? 0 : 1 ) ,
49
+ left : location . column . left - ( location . column . left === 0 ? 0 : 1 ) ,
50
+ width : width + ( location . column . left === 0 ? 0 : 1 ) ,
51
+ height : height + ( location . row . top === 0 ? 0 : 1 ) ,
52
+ borderColor : `${ borderColor } ` ,
53
+ } }
54
+ />
55
+ )
56
+ }
0 commit comments