mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-19 16:49:45 +08:00
102
types/react-touch/index.d.ts
vendored
Normal file
102
types/react-touch/index.d.ts
vendored
Normal 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, {}> {
|
||||
}
|
||||
62
types/react-touch/react-touch-tests.tsx
Normal file
62
types/react-touch/react-touch-tests.tsx
Normal 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;
|
||||
}
|
||||
}
|
||||
24
types/react-touch/tsconfig.json
Normal file
24
types/react-touch/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
3
types/react-touch/tslint.json
Normal file
3
types/react-touch/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user