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 type ConfigurationOptionDelta =
|
44 | | number
|
45 | | { [key in Lowercase<SwipeDirections>]?: number };
|
46 | export interface ConfigurationOptions {
|
47 | delta: ConfigurationOptionDelta;
|
48 | preventDefaultTouchmoveEvent: boolean;
|
49 | rotationAngle: number;
|
50 | trackMouse: boolean;
|
51 | trackTouch: boolean;
|
52 | }
|
53 |
|
54 | export type SwipeableProps = Partial<SwipeableCallbacks & ConfigurationOptions>;
|
55 |
|
56 | export type SwipeablePropsWithDefaultOptions = Partial<SwipeableCallbacks> &
|
57 | ConfigurationOptions;
|
58 |
|
59 | export interface SwipeableHandlers {
|
60 | ref(element: HTMLElement | null): void;
|
61 | onMouseDown?(event: React.MouseEvent): void;
|
62 | }
|
63 |
|
64 | export type SwipeableState = {
|
65 | cleanUpTouch?: () => void;
|
66 | el?: HTMLElement;
|
67 | eventData?: SwipeEventData;
|
68 | first: boolean;
|
69 | initial: Vector2;
|
70 | start: number;
|
71 | swiping: boolean;
|
72 | xy: Vector2;
|
73 | };
|
74 |
|
75 | export type StateSetter = (
|
76 | state: SwipeableState,
|
77 | props: SwipeablePropsWithDefaultOptions
|
78 | ) => SwipeableState;
|
79 | export type Setter = (stateSetter: StateSetter) => void;
|
80 | export type AttachTouch = (el: HTMLElement, passive: boolean) => () => void;
|