From 6ea17025c3d5d5b50df1b9cd995b08a405bbed86 Mon Sep 17 00:00:00 2001 From: Mike Ragalie Date: Mon, 31 Dec 2018 12:04:52 -0500 Subject: [PATCH] Implement type definitions --- package.json | 2 ++ src/ReactCursorPosition.d.ts | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/ReactCursorPosition.d.ts diff --git a/package.json b/package.json index 914766e0..246a5684 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "test-ci": "npm run test && npm run coveralls", "coveralls": "npm run test-coverage && cat ./coverage/lcov.info | coveralls" }, + "typings": "./src/ReactCursorPosition.d.ts", "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.0", @@ -83,6 +84,7 @@ "react": "~0.14.9 || ^15.0.0 || ^16.0.0" }, "dependencies": { + "@types/react": "^16.7.18", "object-assign": "^4.1.1", "object.omit": "^3.0.0", "prop-types": "^15.6.0" diff --git a/src/ReactCursorPosition.d.ts b/src/ReactCursorPosition.d.ts new file mode 100644 index 00000000..06509e47 --- /dev/null +++ b/src/ReactCursorPosition.d.ts @@ -0,0 +1,58 @@ +import React, { ReactPropTypes } from 'react'; + +interface DetectedEnvironment { + isMouseDetected: boolean; + isTouchDetected: boolean; +} + +interface ElementDimensions { + width: number; + height: number; +} + +interface Position { + x: number; + y: number; +} + +interface CursorPositionGeneratedProps { + detectedEnvironment: DetectedEnvironment; + elementDimensions: ElementDimensions; + isActive: boolean; + isPositionOutside: boolean; + position: Position; +} + +interface CursorPositionOptionsProps { + // TODO: Make these more specific + activationInteractionMouse?: string; + activationInteractionTouch?: string; + children: (CursorPositionOutputProps) => React.ReactElement | null; + className?: string; + hoverDelayInMs?: number; + isEnabled?: boolean; + mapChildProps?: (CursorPositionGeneratedProps) => object; + onActivationChanged?: ({isActive: boolean}) => void; + onDetectedEnvironmentChanged?: (DetectedEnvironment) => void; + onPositionChanged?: (CursorPositionGeneratedProps) => void; + pressDurationInMs?: number; + pressMoveThreshold?: number; + shouldDecorateChildren?: boolean; + shouldStopTouchMovePropagation?: boolean; + style?: object; + tapDurationInMs?: number; + tapMoveThreshold?: number; +} + +export interface CursorPositionOutputProps extends CursorPositionGeneratedProps { + [property:string]: any; +} + +export interface CursorPositionInputProps extends CursorPositionOptionsProps { + [property:string]: any; +} + +declare class ReactCursorPosition extends React.Component { +} + +export default ReactCursorPosition;