From ad90a2363e298fb5ebbdd4410aadd501ab513b9f Mon Sep 17 00:00:00 2001 From: Benji Parish Date: Tue, 25 Sep 2018 10:27:28 -0500 Subject: [PATCH] feat: Adding Typescript typings. --- package.json | 3 ++- types/index.d.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 types/index.d.ts diff --git a/package.json b/package.json index 5cc723c..740ac84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-router-navigation-prompt", - "version": "1.6.6", + "version": "1.6.7", "description": "A replacement component for the react-router ``. Allows for more flexible dialogs.", "scripts": { "build": "webpack", @@ -32,6 +32,7 @@ "jsnext:main": "es/index.js", "main": "es/index.js", "module": "es/index.js", + "typings": "types/index.d.ts", "homepage": "https://github.com/ZacharyRSmith/react-router-navigation-prompt#readme", "peerDependencies": { "react": ">= 15", diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..f763ee5 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,44 @@ +import * as React from 'react'; +import * as H from 'history'; +import { RouteComponentProps, Omit } from 'react-router'; + +declare module 'react-router-navigation-prompt' { + export interface ChildData { + isActive: boolean; + onCancel: () => void; + onConfirm: () => void; + } + + export interface NavigationPromptProps extends RouteComponentProps { + children: (data: ChildData) => React.ReactNode; + when: boolean | ((currentLocation: H.Location, nextLocation?: H.Location) => boolean); + afterCancel?: () => void; + afterConfirm?: () => void; + beforeCancel?: () => void; + beforeConfirm?: () => void; + renderIfNotActive?: boolean; + disableNative?: boolean; + } + + interface NavigationPromptState { + action?: H.Action; + nextLocation?: H.Location; + isActive: boolean; + unblock: () => void; + } + + export class NavigationPrompt extends React.Component { + _prevUserAction: string; + _isMounted: boolean; + + block(nextLocation: H.Location, action: H.Action): boolean; + navigateToNextLocation(cb: () => void): void; + onCancel(): void; + onConfirm(): void; + onBeforeUnload(e: any): string + when(nextLocation?: H.Location): boolean; + } +} + +// This is for the withRouter HOC being used as the default export. +export default function NavigationPrompt(): React.Component>>;