-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotRegion.jsx
More file actions
42 lines (35 loc) · 1.04 KB
/
PlotRegion.jsx
File metadata and controls
42 lines (35 loc) · 1.04 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
import React, { useRef } from "react";
import styled from "styled-components";
import { usePlotContext } from "./plot-utils";
const PlotRegionRect = styled.rect``;
export const PlotRegion = ({ fill, draggable, children }) => {
const { left, innerWidth, top, innerHeight, events } = usePlotContext();
const ref = useRef();
let draggableEvents = {};
if (draggable) {
const { onPointerDown, onPointerUp, onPointerMove, ...rest } = events;
draggableEvents = {
onPointerDown: (e) => onPointerDown(e, ref),
onPointerUp: (e) => onPointerUp(e, ref),
onPointerMove: (e) => onPointerMove(e, ref),
...rest,
};
}
return (
<g ref={ref} {...draggableEvents} style={{ cursor: draggable ? "move" : "auto" }}>
<PlotRegionRect
className="plot__region-dragcatcher"
x={left}
y={top}
width={innerWidth}
height={innerHeight}
fill={fill}
/>
{children}
</g>
);
};
PlotRegion.defaultProps = {
fill: "var(--color-background-alt)",
draggable: false,
};