-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathtypes.ts
More file actions
82 lines (73 loc) · 2.13 KB
/
types.ts
File metadata and controls
82 lines (73 loc) · 2.13 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import * as React from "react";
export const LEFT = "Left";
export const RIGHT = "Right";
export const UP = "Up";
export const DOWN = "Down";
export type HandledEvents = React.MouseEvent | TouchEvent | MouseEvent;
export type Vector2 = [number, number];
export type SwipeDirections =
| typeof LEFT
| typeof RIGHT
| typeof UP
| typeof DOWN;
export interface SwipeEventData {
absX: number;
absY: number;
deltaX: number;
deltaY: number;
dir: SwipeDirections;
event: HandledEvents;
first: boolean;
initial: Vector2;
velocity: number;
vxvy: Vector2;
}
export type SwipeCallback = (eventData: SwipeEventData) => void;
export type TapCallback = ({ event }: { event: HandledEvents }) => void;
export type SwipeableCallbacks = {
// Event handler/callbacks
onSwipeStart: SwipeCallback;
onSwiped: SwipeCallback;
onSwipedDown: SwipeCallback;
onSwipedLeft: SwipeCallback;
onSwipedRight: SwipeCallback;
onSwipedUp: SwipeCallback;
onSwiping: SwipeCallback;
onTap: TapCallback;
};
// Configuration Options
export type ConfigurationOptionDelta =
| number
| { [key in Lowercase<SwipeDirections>]?: number };
export interface ConfigurationOptions {
delta: ConfigurationOptionDelta;
preventDefaultTouchmoveEvent: boolean;
preventMixDirections: boolean;
rotationAngle: number;
trackMouse: boolean;
trackTouch: boolean;
}
export type SwipeableProps = Partial<SwipeableCallbacks & ConfigurationOptions>;
export type SwipeablePropsWithDefaultOptions = Partial<SwipeableCallbacks> &
ConfigurationOptions;
export interface SwipeableHandlers {
ref(element: HTMLElement | null): void;
onMouseDown?(event: React.MouseEvent): void;
}
export type SwipeableState = {
cleanUpTouch?: () => void;
el?: HTMLElement;
eventData?: SwipeEventData;
first: boolean;
initial: Vector2;
start: number;
swiping: boolean;
xy: Vector2;
initialDirection: null | SwipeDirections;
};
export type StateSetter = (
state: SwipeableState,
props: SwipeablePropsWithDefaultOptions
) => SwipeableState;
export type Setter = (stateSetter: StateSetter) => void;
export type AttachTouch = (el: HTMLElement, passive: boolean) => () => void;