/
components.tsx
executable file
·50 lines (45 loc) · 1.24 KB
/
components.tsx
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
import * as React from "react";
import { OverlayTrigger, Tooltip, Card } from "react-bootstrap";
export const Tip: React.FC<{
tip: string;
children: JSX.Element;
placement?: "top" | "bottom";
}> = ({ tip, children, placement = "top" }) => (
<OverlayTrigger
placement={placement}
delay={{ show: 400, hide: 400 }}
overlay={props => (
<Tooltip {...props} show={props.show.toString()}>
{tip}
</Tooltip>
)}
>
{children}
</OverlayTrigger>
);
export const FocusableCard: React.FC<{
children: JSX.Element;
className?: string;
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
style?: React.CSSProperties;
}> = ({ children, className, onClick, style }) => {
const [focus, setFocus] = React.useState(false);
let baseStyle: React.CSSProperties = { borderRadius: "2px" };
if (style) baseStyle = { ...baseStyle, ...style };
if (focus) baseStyle = { ...baseStyle, backgroundColor: "rgb(245, 248, 250)", cursor: "pointer" };
return (
<Card
onMouseEnter={() => {
setFocus(true);
}}
onMouseLeave={() => {
setFocus(false);
}}
style={baseStyle}
className={className}
onClick={onClick}
>
{children}
</Card>
);
};