-
Notifications
You must be signed in to change notification settings - Fork 534
Expand file tree
/
Copy pathvictory-cursor-container.tsx
More file actions
56 lines (50 loc) · 1.81 KB
/
victory-cursor-container.tsx
File metadata and controls
56 lines (50 loc) · 1.81 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
53
54
55
56
import React from "react";
import { VictoryEventHandler } from "victory-core";
import {
useVictoryCursorContainer,
CursorHelpers,
VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS,
VictoryCursorContainerProps,
} from "victory-cursor-container";
import { VictoryLabel } from "./victory-label";
import { VictoryContainer } from "./victory-container";
import { LineSegment } from "./victory-primitives/line-segment";
export interface VictoryCursorContainerNativeProps
extends VictoryCursorContainerProps {
disableContainerEvents?: boolean;
onTouchStart?: VictoryEventHandler;
onTouchEnd?: VictoryEventHandler;
}
export const VictoryCursorContainer = (
initialProps: VictoryCursorContainerNativeProps,
) => {
const { props, children } = useVictoryCursorContainer({
...initialProps,
cursorLabelComponent: initialProps.cursorLabelComponent ?? <VictoryLabel />,
cursorComponent: initialProps.cursorComponent ?? <LineSegment />,
});
return <VictoryContainer {...props}>{children}</VictoryContainer>;
};
VictoryCursorContainer.role = "container";
VictoryCursorContainer.defaultEvents = (
initialProps: VictoryCursorContainerNativeProps,
) => {
const props = { ...VICTORY_CURSOR_CONTAINER_DEFAULT_PROPS, ...initialProps };
const createEventHandler =
(handler: VictoryEventHandler, disabled?: boolean): VictoryEventHandler =>
// eslint-disable-next-line max-params
(event, targetProps, eventKey, context) =>
disabled || props.disable
? {}
: handler(event, { ...props, ...targetProps }, eventKey, context);
return [
{
target: "parent",
eventHandlers: {
onTouchStart: createEventHandler(CursorHelpers.onMouseMove),
onTouchMove: createEventHandler(CursorHelpers.onMouseMove),
onTouchEnd: createEventHandler(CursorHelpers.onTouchEnd),
},
},
];
};