Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding Typescript typings. #38

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>>;