diff --git a/README.md b/README.md index 982de25..830648a 100755 --- a/README.md +++ b/README.md @@ -139,6 +139,16 @@ Id of the form to submit (useful if the button is not directly inside the form). Whether click event should bubble when in loading state +##### stayInSuccessState + +Keep the button in success state after setting state to "success" or calling `success()` method (regardless of `stayInSuccessState` argument value). +default is `false` + +##### stayInErrorState + +Keep the button in error state after setting state to "error" or calling `error()` method (regardless of `stayInErrorState` argument value). +default is `false` + ### Methods ##### loading() @@ -153,15 +163,16 @@ Put the button in the disabled state. Put the button in the normal state. -##### success([callback, dontGoBackToNormal]) +##### success([callback, stayInSuccessState]) Put the button in the success state. Call the callback or the onSuccess prop when going back to the normal state. -Use `dontGoBackToNormal` flag to keep the button in success state (default is `false` so the button goes back to normal state after `durationSuccess`). +Use `stayInSuccessState` flag to keep the button in success state (default is `false` so the button goes back to normal state after `durationSuccess`). -##### error([callback, error, dontGoBackToNormal]) +##### error([callback, error, stayInErrorState]) Put the button in the error state. Call the callback or the onError prop (with `error` argument) when going back to the normal state. -Use `dontGoBackToNormal` flag to keep the button in error state (default is `false` so the button goes back to normal state after `durationError`). +Use `stayInErrorState` flag to keep the button in error state (default is `false` so the button goes back to normal state after `durationError`). + ## Styles diff --git a/src/index.js b/src/index.js index 3e3a6d6..fefc4cb 100644 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,9 @@ const ProgressButton = createReactClass({ onSuccess: PropTypes.func, state: PropTypes.oneOf(Object.keys(STATE).map(k => STATE[k])), type: PropTypes.string, - shouldAllowClickOnLoading: PropTypes.bool + shouldAllowClickOnLoading: PropTypes.bool, + stayInSuccessState: PropTypes.bool, + stayInErrorState: PropTypes.bool }, getDefaultProps () { @@ -34,7 +36,9 @@ const ProgressButton = createReactClass({ onClick () {}, onError () {}, onSuccess () {}, - shouldAllowClickOnLoading: false + shouldAllowClickOnLoading: false, + stayInSuccessState: false, + stayInErrorState: false } }, @@ -159,19 +163,19 @@ const ProgressButton = createReactClass({ this.setState({currentState: STATE.DISABLED}) }, - success (callback, dontRemove = false) { + success (callback, stayInSuccessState = false) { this.setState({currentState: STATE.SUCCESS}) this._timeout = setTimeout(() => { - if (!dontRemove) { this.setState({currentState: STATE.NOTHING}) } + if (!stayInSuccessState || !this.props.stayInSuccessState) { this.setState({currentState: STATE.NOTHING}) } callback = callback || this.props.onSuccess if (typeof callback === 'function') { callback() } }, this.props.durationSuccess) }, - error (callback, err, dontRemove = false) { + error (callback, err, stayInErrorState = false) { this.setState({currentState: STATE.ERROR}) this._timeout = setTimeout(() => { - if (!dontRemove) { this.setState({currentState: STATE.NOTHING}) } + if (!stayInErrorState || !this.props.stayInErrorState) { this.setState({currentState: STATE.NOTHING}) } callback = callback || this.props.onError if (typeof callback === 'function') { callback(err) } }, this.props.durationError)