Skip to content

Commit a31c5bb

Browse files
committed
Move TS defs to own folder and add tests
1 parent ff67f9c commit a31c5bb

File tree

5 files changed

+133
-1
lines changed

5 files changed

+133
-1
lines changed

Diff for: Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dist/%.js: $(BIN)
3535

3636
test: $(BIN)
3737
@$(BIN)/karma start --single-run
38+
@$(BIN)/tsc -p typings
3839

3940
dev: $(BIN)
4041
script/build-watch

Diff for: package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "make clean build",
1313
"lint": "make lint"
1414
},
15-
"typings": "./index.d.ts",
15+
"typings": "./typings/index.d.ts",
1616
"repository": {
1717
"type": "git",
1818
"url": "https://github.com/mzabriskie/react-draggable.git"
@@ -29,6 +29,8 @@
2929
},
3030
"homepage": "https://github.com/mzabriskie/react-draggable",
3131
"devDependencies": {
32+
"@types/react": "^15.0.23",
33+
"@types/react-dom": "^15.5.0",
3234
"babel-cli": "^6.10.1",
3335
"babel-core": "^6.10.4",
3436
"babel-eslint": "^6.1.2",
@@ -64,6 +66,7 @@
6466
"react-frame-component": "0.6.2",
6567
"semver": "^5.3.0",
6668
"static-server": "^2.0.3",
69+
"typescript": "^2.3.2",
6770
"uglify-js": "^2.7.0",
6871
"webpack": "^1.13.1",
6972
"webpack-dev-server": "^1.14.1"

Diff for: typings/index.d.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
declare module 'react-draggable' {
2+
import * as React from 'react';
3+
4+
export interface DraggableBounds {
5+
left: number
6+
right: number
7+
top: number
8+
bottom: number
9+
}
10+
11+
export interface DraggableProps extends DraggableCoreProps {
12+
axis: 'both' | 'x' | 'y' | 'none',
13+
bounds: DraggableBounds | string | false ,
14+
defaultClassName: string,
15+
defaultClassNameDragging: string,
16+
defaultClassNameDragged: string,
17+
defaultPosition: ControlPosition,
18+
position: ControlPosition
19+
}
20+
21+
export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void | false;
22+
23+
export interface DraggableData {
24+
node: HTMLElement,
25+
x: number, y: number,
26+
deltaX: number, deltaY: number,
27+
lastX: number, lastY: number
28+
}
29+
30+
export type ControlPosition = {x: number, y: number};
31+
32+
export interface DraggableCoreProps {
33+
allowAnyClick: boolean,
34+
cancel: string,
35+
disabled: boolean,
36+
enableUserSelectHack: boolean,
37+
offsetParent: HTMLElement,
38+
grid: [number, number],
39+
handle: string,
40+
onStart: DraggableEventHandler,
41+
onDrag: DraggableEventHandler,
42+
onStop: DraggableEventHandler,
43+
onMouseDown: (e: MouseEvent) => void
44+
}
45+
46+
export default class Draggable extends React.Component<Partial<DraggableProps>, {}> {
47+
static defaultProps : DraggableProps;
48+
}
49+
50+
export class DraggableCore extends React.Component<Partial<DraggableCoreProps>, {}> {
51+
static defaultProps : DraggableCoreProps;
52+
}
53+
}

Diff for: typings/test.tsx

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as React from 'react';
2+
import * as ReactDOM from 'react-dom';
3+
import Draggable, {DraggableCore} from 'react-draggable';
4+
5+
const root = document.getElementById('root')
6+
7+
function handleStart() {}
8+
function handleDrag() {}
9+
function handleStop() {}
10+
function handleMouseDown() {}
11+
12+
ReactDOM.render(
13+
<Draggable
14+
axis="y"
15+
handle=".handle"
16+
cancel=".cancel"
17+
grid={[10, 10]}
18+
onStart={handleStart}
19+
onDrag={handleDrag}
20+
onStop={handleStop}
21+
offsetParent={document.body}
22+
allowAnyClick={true}
23+
onMouseDown={handleMouseDown}
24+
disabled={true}
25+
enableUserSelectHack={false}
26+
bounds={false}
27+
defaultClassName={'draggable'}
28+
defaultClassNameDragging={'dragging'}
29+
defaultClassNameDragged={'dragged'}
30+
defaultPosition={{x: 0, y: 0}}
31+
position={{x: 50, y: 50}}>
32+
<div className="foo bar">
33+
<div className="handle"/>
34+
<div className="cancel"/>
35+
</div>
36+
</Draggable>,
37+
root
38+
);
39+
40+
ReactDOM.render(
41+
<DraggableCore
42+
handle=".handle"
43+
cancel=".cancel"
44+
allowAnyClick={true}
45+
disabled={true}
46+
onMouseDown={handleMouseDown}
47+
grid={[10, 10]}
48+
onStart={handleStart}
49+
onDrag={handleDrag}
50+
onStop={handleStop}
51+
offsetParent={document.body}
52+
enableUserSelectHack={false}>
53+
<div className="foo bar">
54+
<div className="handle"/>
55+
<div className="cancel"/>
56+
</div>
57+
</DraggableCore>,
58+
root
59+
);
60+
61+
62+
ReactDOM.render(<Draggable><div/></Draggable>, root);
63+
64+
ReactDOM.render(<DraggableCore><div/></DraggableCore>, root);

Diff for: typings/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"noEmit": true,
4+
"jsx": "preserve",
5+
"strict": true
6+
},
7+
"files": [
8+
"index.d.ts",
9+
"test.tsx"
10+
]
11+
}

0 commit comments

Comments
 (0)