From a31c5bbfc965b03ffbd5c8d00a175a79ef8aa469 Mon Sep 17 00:00:00 2001 From: sa Date: Sat, 29 Apr 2017 01:45:04 -0400 Subject: [PATCH] Move TS defs to own folder and add tests --- Makefile | 1 + package.json | 5 +++- typings/index.d.ts | 53 +++++++++++++++++++++++++++++++++++ typings/test.tsx | 64 +++++++++++++++++++++++++++++++++++++++++++ typings/tsconfig.json | 11 ++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 typings/index.d.ts create mode 100644 typings/test.tsx create mode 100644 typings/tsconfig.json diff --git a/Makefile b/Makefile index 644c04a1..f0109563 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ dist/%.js: $(BIN) test: $(BIN) @$(BIN)/karma start --single-run + @$(BIN)/tsc -p typings dev: $(BIN) script/build-watch diff --git a/package.json b/package.json index 0a66a3ab..73236ae4 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "build": "make clean build", "lint": "make lint" }, - "typings": "./index.d.ts", + "typings": "./typings/index.d.ts", "repository": { "type": "git", "url": "https://github.com/mzabriskie/react-draggable.git" @@ -29,6 +29,8 @@ }, "homepage": "https://github.com/mzabriskie/react-draggable", "devDependencies": { + "@types/react": "^15.0.23", + "@types/react-dom": "^15.5.0", "babel-cli": "^6.10.1", "babel-core": "^6.10.4", "babel-eslint": "^6.1.2", @@ -64,6 +66,7 @@ "react-frame-component": "0.6.2", "semver": "^5.3.0", "static-server": "^2.0.3", + "typescript": "^2.3.2", "uglify-js": "^2.7.0", "webpack": "^1.13.1", "webpack-dev-server": "^1.14.1" diff --git a/typings/index.d.ts b/typings/index.d.ts new file mode 100644 index 00000000..ae56fdeb --- /dev/null +++ b/typings/index.d.ts @@ -0,0 +1,53 @@ +declare module 'react-draggable' { + import * as React from 'react'; + + export interface DraggableBounds { + left: number + right: number + top: number + bottom: number + } + + export interface DraggableProps extends DraggableCoreProps { + axis: 'both' | 'x' | 'y' | 'none', + bounds: DraggableBounds | string | false , + defaultClassName: string, + defaultClassNameDragging: string, + defaultClassNameDragged: string, + defaultPosition: ControlPosition, + position: ControlPosition + } + + export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void | false; + + export interface DraggableData { + node: HTMLElement, + x: number, y: number, + deltaX: number, deltaY: number, + lastX: number, lastY: number + } + + export type ControlPosition = {x: number, y: number}; + + export interface DraggableCoreProps { + allowAnyClick: boolean, + cancel: string, + disabled: boolean, + enableUserSelectHack: boolean, + offsetParent: HTMLElement, + grid: [number, number], + handle: string, + onStart: DraggableEventHandler, + onDrag: DraggableEventHandler, + onStop: DraggableEventHandler, + onMouseDown: (e: MouseEvent) => void + } + + export default class Draggable extends React.Component, {}> { + static defaultProps : DraggableProps; + } + + export class DraggableCore extends React.Component, {}> { + static defaultProps : DraggableCoreProps; + } +} diff --git a/typings/test.tsx b/typings/test.tsx new file mode 100644 index 00000000..64f6d998 --- /dev/null +++ b/typings/test.tsx @@ -0,0 +1,64 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import Draggable, {DraggableCore} from 'react-draggable'; + +const root = document.getElementById('root') + +function handleStart() {} +function handleDrag() {} +function handleStop() {} +function handleMouseDown() {} + +ReactDOM.render( + +
+
+
+
+ , + root +); + +ReactDOM.render( + +
+
+
+
+ , + root +); + + +ReactDOM.render(
, root); + +ReactDOM.render(
, root); diff --git a/typings/tsconfig.json b/typings/tsconfig.json new file mode 100644 index 00000000..9ad2ddb3 --- /dev/null +++ b/typings/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "noEmit": true, + "jsx": "preserve", + "strict": true + }, + "files": [ + "index.d.ts", + "test.tsx" + ] +} \ No newline at end of file