From 465bcc532a1d41cef2d6f31822d5305faeffd033 Mon Sep 17 00:00:00 2001 From: Ragg Date: Sat, 3 Mar 2018 18:42:10 +0900 Subject: [PATCH] Add type for `react-rnd` --- types/react-rnd/index.d.ts | 105 ++++++++++++++++++++++++++++ types/react-rnd/react-rnd-tests.tsx | 4 ++ types/react-rnd/tsconfig.json | 24 +++++++ types/react-rnd/tslint.json | 1 + 4 files changed, 134 insertions(+) create mode 100644 types/react-rnd/index.d.ts create mode 100644 types/react-rnd/react-rnd-tests.tsx create mode 100644 types/react-rnd/tsconfig.json create mode 100644 types/react-rnd/tslint.json diff --git a/types/react-rnd/index.d.ts b/types/react-rnd/index.d.ts new file mode 100644 index 0000000000..24cef31e45 --- /dev/null +++ b/types/react-rnd/index.d.ts @@ -0,0 +1,105 @@ +// Type definitions for react-rnd 7.3 +// Project: https://github.com/bokuweb/react-rnd +// Definitions by: Ragg +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 +import * as React from 'react'; + +type CSSProperties = React.CSSProperties; + +interface HandleClasses { + bottom?: string; + bottomLeft?: string; + bottomRight?: string; + left?: string; + right?: string; + top?: string; + topLeft?: string; + topRight?: string; +} + +interface HandleStyles { + bottom?: CSSProperties; + bottomLeft?: CSSProperties; + bottomRight?: CSSProperties; + left?: CSSProperties; + right?: CSSProperties; + top?: CSSProperties; + topLeft?: CSSProperties; + topRight?: CSSProperties; +} + +type Direction = + | 'bottom' + | 'bottomLeft' + | 'bottomRight' + | 'left' + | 'right' + | 'top' + | 'topLeft' + | 'topRight'; + +interface Position { + x: number; + y: number; +} + +interface Size { + width: number; + height: number; +} + +interface DraggableData { + node: HTMLElement; + x: number; + y: number; + deltaX: number; + deltaY: number; + lastX: number; + lastY: number; +} + +type DraggableEventHandler = (e: MouseEvent | TouchEvent, data: DraggableData) => void|false; + +type ResizeHandler = ( + e: MouseEvent|TouchEvent, + direction: Direction, + ref: HTMLDivElement, + delta: Size, + position: Position +) => void; + +interface Options { + default: { + x?: number; + y?: number; + width?: number|string; + height?: number|string; + }; + className: string; + style: any; + width: number|string; + height: number|string; + minWidth: number|string; + minHeight: number|string; + maxWidth: number|string; + maxHeight: number|string; + z: number; + resizeHandleClasses: HandleClasses; + resizeHandleStyles: HandleStyles; + + lockAspectRatio: boolean; + enableResizing: boolean; + + onResizeStart: () => void; + onResize: () => void; + onResizeStop: ResizeHandler; + + onDragStart: DraggableEventHandler; + onDrag: DraggableEventHandler; + onDragStop: DraggableEventHandler; +} + +declare class Rnd extends React.Component> {} + +export default Rnd; diff --git a/types/react-rnd/react-rnd-tests.tsx b/types/react-rnd/react-rnd-tests.tsx new file mode 100644 index 0000000000..1586daadbf --- /dev/null +++ b/types/react-rnd/react-rnd-tests.tsx @@ -0,0 +1,4 @@ +import * as React from 'react'; +import Rnd from 'react-rnd'; + +; diff --git a/types/react-rnd/tsconfig.json b/types/react-rnd/tsconfig.json new file mode 100644 index 0000000000..b28250424f --- /dev/null +++ b/types/react-rnd/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-rnd-tests.tsx" + ] +} diff --git a/types/react-rnd/tslint.json b/types/react-rnd/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-rnd/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }