1 | import * as React from "react";
|
2 |
|
3 | export const LEFT = "Left";
|
4 | export const RIGHT = "Right";
|
5 | export const UP = "Up";
|
6 | export const DOWN = "Down";
|
7 | export type HandledEvents = React.MouseEvent | TouchEvent | MouseEvent;
|
8 | export type Vector2 = [number, number];
|
9 | export type SwipeDirections =
|
10 | | typeof LEFT
|
11 | | typeof RIGHT
|
12 | | typeof UP
|
13 | | typeof DOWN;
|
14 | export interface SwipeEventData {
|
15 | absX: number;
|
16 | absY: number;
|
17 | deltaX: number;
|
18 | deltaY: number;
|
19 | dir: SwipeDirections;
|
20 | event: HandledEvents;
|
21 | first: boolean;
|
22 | initial: Vector2;
|
23 | velocity: number;
|
24 | vxvy: Vector2;
|
25 | }
|
26 |
|
27 | export type SwipeCallback = (eventData: SwipeEventData) => void;
|
28 | export type TapCallback = ({ event }: { event: HandledEvents }) => void;
|
29 |
|
30 | export type SwipeableCallbacks = {
|
31 |
|
32 | onSwipeStart: SwipeCallback;
|
33 | onSwiped: SwipeCallback;
|
34 | onSwipedDown: SwipeCallback;
|
35 | onSwipedLeft: SwipeCallback;
|
36 | onSwipedRight: SwipeCallback;
|
37 | onSwipedUp: SwipeCallback;
|
38 | onSwiping: SwipeCallback;
|
39 | onTap: TapCallback;
|
40 | };
|
41 |
|
42 |
|
43 | export interface ConfigurationOptions {
|
44 | delta: number;
|
45 | preventDefaultTouchmoveEvent: boolean;
|
46 | rotationAngle: number;
|
47 | trackMouse: boolean;
|
48 | trackTouch: boolean;
|
49 | }
|
50 |
|
51 | export type SwipeableProps = Partial<SwipeableCallbacks & ConfigurationOptions>;
|
52 |
|
53 | export type SwipeablePropsWithDefaultOptions = Partial<SwipeableCallbacks> &
|
54 | ConfigurationOptions;
|
55 |
|
56 | export interface SwipeableHandlers {
|
57 | ref(element: HTMLElement | null): void;
|
58 | onMouseDown?(event: React.MouseEvent): void;
|
59 | }
|
60 |
|
61 | export type SwipeableState = {
|
62 | cleanUpTouch?: () => void;
|
63 | el?: HTMLElement;
|
64 | eventData?: SwipeEventData;
|
65 | first: boolean;
|
66 | initial: Vector2;
|
67 | start: number;
|
68 | swiping: boolean;
|
69 | xy: Vector2;
|
70 | };
|
71 |
|
72 | export type StateSetter = (
|
73 | state: SwipeableState,
|
74 | props: SwipeablePropsWithDefaultOptions
|
75 | ) => SwipeableState;
|
76 | export type Setter = (stateSetter: StateSetter) => void;
|
77 | export type AttachTouch = (el: HTMLElement, passive: boolean) => () => void;
|