Add types for react-touch

https://github.com/leonaves/react-touch
This commit is contained in:
Grzegorz Kielak
2017-07-10 15:19:01 +02:00
parent fc73cdd92b
commit d14bffff32
4 changed files with 191 additions and 0 deletions

102
types/react-touch/index.d.ts vendored Normal file
View File

@@ -0,0 +1,102 @@
// Type definitions for react-touch 1.8
// Project: https://github.com/leonaves/react-touch
// Definitions by: Grzegorz Kielak <https://github.com/grzesie2k>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
import * as React from "react";
export function defineHold(config?: HoldConfig): HoldableConfig;
export interface HoldConfig {
/** @default 250 */
updateEvery?: number;
/** @default 1000 */
holdFor?: number;
}
/** @see defineHold */
export interface HoldableConfig {
holdProgress(callback: () => void): (updateState: (holdLength: number) => void) => () => void;
holdComplete(callback: () => void): () => () => void;
}
export interface HoldableProps {
/** @see defineHold */
config?: HoldableConfig;
onHoldProgress?(): void;
onHoldComplete?(): void;
onMouseDown?(): void;
onTouchStart?(): void;
}
export class Holdable extends React.Component<HoldableProps, {}> {
}
export interface DraggableStyle {
translateX?: number;
translateY?: number;
top?: number;
left?: number;
right?: number;
bottom?: number;
}
export interface DraggableCallbackArgument extends DraggableStyle {
dx: number;
dy: number;
}
export type DraggableCallback = (argument: DraggableCallbackArgument) => JSX.Element;
export interface DraggableProps {
/**
* An object that defines the initial position of the draggable component.
* You can pass any of the following styles to it
* and they'll be updated and passed back out in the callback with every animation tick.
*/
style: DraggableStyle;
children: DraggableCallback;
}
export class Draggable extends React.Component<DraggableProps, {}> {
}
export function defineSwipe(config?: SwipConfig): SwipeableConfig;
export interface SwipConfig {
/** @default 100 */
swipeDistance?: number;
}
/** @see defineSwipe */
export interface SwipeableConfig {
onSwipeLeft(current: number, initial: number, callback: () => void): void;
onSwipeRight(current: number, initial: number, callback: () => void): void;
onSwipeUp(current: number, initial: number, callback: () => void): void;
onSwipeDown(current: number, initial: number, callback: () => void): void;
}
export interface SwipeableProps {
/** @see defineSwipe */
config?: SwipeableConfig;
onSwipeLeft?(): void;
onSwipeRight?(): void;
onSwipeUp?(): void;
onSwipeDown?(): void;
onMouseDown?(): void;
onTouchStart?(): void;
}
export class Swipeable extends React.Component<SwipeableProps, {}> {
}
export enum moves {UPLEFT, UP, UPRIGHT, LEFT, RIGHT, DOWNRIGHT, DOWN, DOWNLEFT}
export interface CustomGestureProps {
config: moves[];
onGesture(): void;
}
export class CustomGesture extends React.Component<CustomGestureProps, {}> {
}

View File

@@ -0,0 +1,62 @@
import * as React from "react";
import {
CustomGesture,
defineHold, defineSwipe, Draggable, DraggableCallbackArgument, DraggableStyle, Holdable, HoldableConfig,
HoldableProps, HoldConfig, moves, SwipConfig, Swipeable, SwipeableConfig, SwipeableProps
} from "react-touch";
export class HoldableTest extends React.PureComponent<{}> {
render() {
const holdConfig: HoldConfig = {};
const config: HoldableConfig = defineHold(holdConfig);
const props: HoldableProps = {
config,
onHoldComplete() {
return;
}
};
return <Holdable {...props} />;
}
}
export class DraggableTest extends React.PureComponent<{}> {
render() {
const style: DraggableStyle = {};
return <Draggable style={style} children={this.callback} />;
}
private callback = (argument: DraggableCallbackArgument): JSX.Element => {
return <div />;
}
}
export class SwipeableTest extends React.PureComponent<{}> {
render() {
const swipConfig: SwipConfig = {};
const config: SwipeableConfig = defineSwipe(swipConfig);
const props: SwipeableProps = {
config,
onSwipeLeft: this.swipeHandler,
onSwipeUp: this.swipeHandler
};
return <Swipeable {...props}>
<div />
</Swipeable>;
}
private swipeHandler = () => {
return;
}
}
export class CustomGestureTest extends React.PureComponent<{}> {
private move: moves[] = [moves.UPLEFT, moves.RIGHT, moves.DOWNRIGHT];
render() {
return <CustomGesture config={this.move} onGesture={this.handler} />;
}
private handler = () => {
return;
}
}

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"jsx": "react",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"react-touch-tests.tsx"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}