react-router-navigation-prompt
Advanced tools
Comparing version 1.4.0 to 1.5.0
{ | ||
"name": "react-router-navigation-prompt", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "A replacement component for the react-router `<Prompt/>`. Allows for more flexible dialogs.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
/* @flow */ | ||
import React from 'react'; | ||
import {withRouter} from 'react-router-dom'; | ||
import type {HistoryAction, Location, RouterHistory} from 'react-router-dom'; | ||
import type {HistoryAction, Location, Match, RouterHistory} from 'react-router-dom'; | ||
@@ -12,5 +12,7 @@ declare type PropsT = { | ||
children: (data: {isActive: bool, onCancel: Function, onConfirm: Function}) => React$Element<*>, | ||
match: Match, | ||
history: RouterHistory, | ||
location: Location, | ||
renderIfNotActive: bool, | ||
when: bool | ||
when: bool | (Location, ?Location) => bool | ||
}; | ||
@@ -50,2 +52,3 @@ declare type StateT = { | ||
(this:Object).onConfirm = this.onConfirm.bind(this); | ||
(this:Object).when = this.when.bind(this); | ||
@@ -65,3 +68,3 @@ this.state = {...initState, unblock: props.history.block(this.block)}; | ||
block(nextLocation, action) { | ||
if (this.props.when) { | ||
if (this.when(nextLocation)) { | ||
this.setState({ | ||
@@ -73,3 +76,3 @@ action, | ||
} | ||
return !this.props.when; | ||
return !this.when(nextLocation); | ||
} | ||
@@ -116,3 +119,3 @@ | ||
onBeforeUnload(e) { | ||
if (!this.props.when) return; | ||
if (!this.when()) return; | ||
const msg = 'Do you want to leave this site?\n\nChanges you made may not be saved.'; | ||
@@ -123,2 +126,10 @@ e.returnValue = msg; | ||
when(nextLocation?: Location) { | ||
if (typeof this.props.when === 'function') { | ||
return this.props.when(this.props.location, nextLocation); | ||
} else { | ||
return this.props.when; | ||
} | ||
} | ||
render() { | ||
@@ -125,0 +136,0 @@ if (!this.state.isActive && !this.props.renderIfNotActive) return null; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
406237
9767