Skip to content

Commit

Permalink
feat: Adding Typescript typings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benji Parish authored and Benji Parish committed Sep 25, 2018
1 parent 638db4b commit ad90a23
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 `<Prompt/>`. Allows for more flexible dialogs.",
"scripts": {
"build": "webpack",
Expand Down Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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<NavigationPromptProps, NavigationPromptState> {
_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<Omit<NavigationPromptProps, keyof RouteComponentProps<any>>>;

0 comments on commit ad90a23

Please sign in to comment.