UNPKG

1.98 kBPlain TextView Raw
1import * as React from "react";
2
3export const LEFT = "Left";
4export const RIGHT = "Right";
5export const UP = "Up";
6export const DOWN = "Down";
7export type HandledEvents = React.MouseEvent | TouchEvent | MouseEvent;
8export type Vector2 = [number, number];
9export type SwipeDirections =
10 | typeof LEFT
11 | typeof RIGHT
12 | typeof UP
13 | typeof DOWN;
14export 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
27export type SwipeCallback = (eventData: SwipeEventData) => void;
28export type TapCallback = ({ event }: { event: HandledEvents }) => void;
29
30export type SwipeableCallbacks = {
31 // Event handler/callbacks
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// Configuration Options
43export interface ConfigurationOptions {
44 delta: number;
45 preventDefaultTouchmoveEvent: boolean;
46 rotationAngle: number;
47 trackMouse: boolean;
48 trackTouch: boolean;
49}
50
51export type SwipeableProps = Partial<SwipeableCallbacks & ConfigurationOptions>;
52
53export type SwipeablePropsWithDefaultOptions = Partial<SwipeableCallbacks> &
54 ConfigurationOptions;
55
56export interface SwipeableHandlers {
57 ref(element: HTMLElement | null): void;
58 onMouseDown?(event: React.MouseEvent): void;
59}
60
61export 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
72export type StateSetter = (
73 state: SwipeableState,
74 props: SwipeablePropsWithDefaultOptions
75) => SwipeableState;
76export type Setter = (stateSetter: StateSetter) => void;
77export type AttachTouch = (el: HTMLElement, passive: boolean) => () => void;