UNPKG

4.08 kBTypeScriptView Raw
1/**
2 * @fileOverview Brush
3 */
4import React, { PureComponent, ReactElement, TouchEvent, SVGProps } from 'react';
5import { ScalePoint } from 'victory-vendor/d3-scale';
6import { Padding, DataKey } from '../util/types';
7type BrushTravellerType = ReactElement<SVGElement> | ((props: any) => ReactElement<SVGElement>);
8interface BrushStartEndIndex {
9 startIndex?: number;
10 endIndex?: number;
11}
12interface InternalBrushProps {
13 x?: number;
14 y?: number;
15 width?: number;
16 data?: any[];
17 updateId?: string | number;
18}
19interface BrushProps extends InternalBrushProps {
20 className?: string;
21 ariaLabel?: string;
22 height: number;
23 travellerWidth?: number;
24 traveller?: BrushTravellerType;
25 gap?: number;
26 padding?: Padding;
27 dataKey?: DataKey<any>;
28 startIndex?: number;
29 endIndex?: number;
30 tickFormatter?: (value: any, index: number) => string | number;
31 children?: ReactElement;
32 onChange?: (newIndex: BrushStartEndIndex) => void;
33 onDragEnd?: (newIndex: BrushStartEndIndex) => void;
34 leaveTimeOut?: number;
35 alwaysShowText?: boolean;
36}
37export type Props = Omit<SVGProps<SVGElement>, 'onChange'> & BrushProps;
38type BrushTravellerId = 'startX' | 'endX';
39interface State {
40 isTravellerMoving?: boolean;
41 isTravellerFocused?: boolean;
42 isSlideMoving?: boolean;
43 startX?: number;
44 endX?: number;
45 slideMoveStartX?: number;
46 movingTravellerId?: BrushTravellerId;
47 isTextActive?: boolean;
48 brushMoveStartX?: number;
49 scale?: ScalePoint<number>;
50 scaleValues?: number[];
51 prevData?: any[];
52 prevWidth?: number;
53 prevX?: number;
54 prevTravellerWidth?: number;
55 prevUpdateId?: string | number;
56}
57export declare class Brush extends PureComponent<Props, State> {
58 static displayName: string;
59 static defaultProps: {
60 height: number;
61 travellerWidth: number;
62 gap: number;
63 fill: string;
64 stroke: string;
65 padding: {
66 top: number;
67 right: number;
68 bottom: number;
69 left: number;
70 };
71 leaveTimeOut: number;
72 alwaysShowText: boolean;
73 };
74 constructor(props: Props);
75 leaveTimer?: number;
76 travellerDragStartHandlers?: Record<BrushTravellerId, (event: React.MouseEvent<SVGGElement> | TouchEvent<SVGGElement>) => void>;
77 static renderDefaultTraveller(props: any): React.JSX.Element;
78 static renderTraveller(option: BrushTravellerType, props: any): React.JSX.Element;
79 static getDerivedStateFromProps(nextProps: Props, prevState: State): State;
80 componentWillUnmount(): void;
81 static getIndexInRange(valueRange: number[], x: number): number;
82 getIndex({ startX, endX }: {
83 startX: number;
84 endX: number;
85 }): {
86 startIndex: number;
87 endIndex: number;
88 };
89 getTextOfTick(index: number): any;
90 handleDrag: (e: React.Touch | React.MouseEvent<SVGGElement> | MouseEvent) => void;
91 handleTouchMove: (e: TouchEvent<SVGGElement>) => void;
92 attachDragEndListener(): void;
93 detachDragEndListener(): void;
94 handleDragEnd: () => void;
95 handleLeaveWrapper: () => void;
96 handleEnterSlideOrTraveller: () => void;
97 handleLeaveSlideOrTraveller: () => void;
98 handleSlideDragStart: (e: TouchEvent<SVGRectElement> | React.MouseEvent<SVGRectElement>) => void;
99 handleSlideDrag(e: React.Touch | React.MouseEvent<SVGGElement> | MouseEvent): void;
100 handleTravellerDragStart(id: BrushTravellerId, e: React.MouseEvent<SVGGElement> | TouchEvent<SVGGElement>): void;
101 handleTravellerMove(e: React.Touch | React.MouseEvent<SVGGElement> | MouseEvent): void;
102 handleTravellerMoveKeyboard(direction: 1 | -1, id: BrushTravellerId): void;
103 renderBackground(): React.JSX.Element;
104 renderPanorama(): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
105 renderTravellerLayer(travellerX: number, id: BrushTravellerId): React.JSX.Element;
106 renderSlide(startX: number, endX: number): React.JSX.Element;
107 renderText(): React.JSX.Element;
108 render(): React.JSX.Element;
109}
110export {};