-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathCornerIndicator.tsx
More file actions
52 lines (49 loc) · 1.32 KB
/
CornerIndicator.tsx
File metadata and controls
52 lines (49 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as React from "react";
import classNames from "classnames";
import * as Actions from "./actions";
import * as Selection from "./selection";
import * as Types from "./types";
import useDispatch from "./use-dispatch";
import useSelector from "./use-selector";
const CornerIndicator: Types.CornerIndicatorComponent = ({
selected,
onSelect,
width,
}) => {
const handleClick = React.useCallback(() => {
onSelect();
}, [onSelect]);
return (
<div
role="columnheader"
className={classNames("Spreadsheet__header", {
"Spreadsheet__header--selected": selected,
})}
onClick={handleClick}
tabIndex={0}
style={{ width }}
/>
);
};
export default CornerIndicator;
export const enhance = (
CornerIndicatorComponent: Types.CornerIndicatorComponent
): React.FC<Omit<Types.CornerIndicatorProps, "selected" | "onSelect">> => {
return function CornerIndicatorWrapper(props) {
const dispatch = useDispatch();
const selectEntireTable = React.useCallback(
() => dispatch(Actions.selectEntireTable()),
[dispatch]
);
const selected = useSelector((state) =>
Selection.isEntireTable(state.selected)
);
return (
<CornerIndicatorComponent
{...props}
selected={selected}
onSelect={selectEntireTable}
/>
);
};
};