11import * as React from 'react' ;
2+ import { translateLocationIdxToLookupKey } from '../Model/CellMatrix' ;
23import { Location } from '../Model/InternalModel' ;
34import { State } from '../Model/State' ;
45
5- interface CellFocusProps {
6- state ?: State ;
6+
7+ interface FeaturedCellProps {
78 location : Location ;
8- isHighlight ?: boolean ;
9+ state ?: State ;
910 borderColor ?: string ;
1011 className ?: string ;
1112}
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 ;
1618 if ( ! range ) {
1719 return null ;
1820 }
1921 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 }
3028 />
3129 ) ;
3230}
3331
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+ }
3641
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