forked from ZacharyRSmith/react-router-navigation-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ZacharyRSmith#38 from bparish628/chore/typescript-…
…typings feat: Adding Typescript typings.
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>>; |