-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom feature for highlighting cell
- Loading branch information
1 parent
8e5f151
commit f71d117
Showing
9 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from "react"; | ||
import classnames from "classnames"; | ||
import useSelector from "./use-selector"; | ||
import { getCellDimensions } from "./util"; | ||
import {Highlight} from "./highlight"; | ||
|
||
/** | ||
* A component that highlights a cell by taking a specific cell coordinate (`point`) and `color` value | ||
* Like ActiveCell, it captures the position and size (cell bounding) to display the highlight. | ||
*/ | ||
type HighlightCellComponentProps ={ | ||
highLight: Highlight; | ||
} | ||
const HighlightCell: React.FC<HighlightCellComponentProps> = ({ highLight }) => { | ||
const { point, color } = highLight; | ||
const rootRef = React.useRef<HTMLDivElement>(null); | ||
|
||
const dimensions = useSelector((state) => | ||
getCellDimensions(point, state.rowDimensions, state.columnDimensions) | ||
); | ||
|
||
const hidden = !dimensions; | ||
if (hidden) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
ref={rootRef} | ||
className={classnames( | ||
"Spreadsheet__highlight-cell" | ||
)} | ||
style={{ | ||
...dimensions, | ||
borderColor: color, | ||
}} | ||
tabIndex={0} | ||
/> | ||
); | ||
}; | ||
|
||
const HighlightCellContainer: React.FC = () => { | ||
const highlights = useSelector((state) => state.highlights); | ||
|
||
return ( | ||
<> | ||
{highlights.map((highlight, index) => ( | ||
<HighlightCell key={index} highLight={highlight} /> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
export default HighlightCellContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Point} from "./point"; | ||
|
||
/** A highlight in the spreadsheet */ | ||
export type Highlight = { | ||
point: Point; | ||
color: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters