Skip to content

Commit 2a91bd5

Browse files
author
monkeydri
committed
add stayInSuccessState and stayInErrorState props
1 parent 23f8e83 commit 2a91bd5

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,25 @@ Put the button in the disabled state.
153153

154154
Put the button in the normal state.
155155

156-
##### success([callback, dontGoBackToNormal])
156+
##### success([callback, stayInSuccessState])
157157

158158
Put the button in the success state. Call the callback or the onSuccess prop when going back to the normal state.
159-
Use `dontGoBackToNormal` flag to keep the button in success state (default is `false` so the button goes back to normal state after `durationSuccess`).
159+
Use `stayInSuccessState` flag to keep the button in success state (default is `false` so the button goes back to normal state after `durationSuccess`).
160160

161-
##### error([callback, error, dontGoBackToNormal])
161+
##### error([callback, error, stayInErrorState])
162162

163163
Put the button in the error state. Call the callback or the onError prop (with `error` argument) when going back to the normal state.
164-
Use `dontGoBackToNormal` flag to keep the button in error state (default is `false` so the button goes back to normal state after `durationError`).
164+
Use `stayInErrorState` flag to keep the button in error state (default is `false` so the button goes back to normal state after `durationError`).
165+
166+
##### stayInSuccessState
167+
168+
Keep the button in success state after setting state to "success" or calling `success()` method (regardless of `stayInSuccessState` argument value).
169+
default is `false`
170+
171+
##### stayInErrorState
172+
173+
Keep the button in error state after setting state to "error" or calling `error()` method (regardless of `stayInErrorState` argument value).
174+
default is `false`
165175

166176
## Styles
167177

src/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const ProgressButton = createReactClass({
2222
onSuccess: PropTypes.func,
2323
state: PropTypes.oneOf(Object.keys(STATE).map(k => STATE[k])),
2424
type: PropTypes.string,
25-
shouldAllowClickOnLoading: PropTypes.bool
25+
shouldAllowClickOnLoading: PropTypes.bool,
26+
stayInSuccessState: PropTypes.bool,
27+
stayInErrorState: PropTypes.bool
2628
},
2729

2830
getDefaultProps () {
@@ -34,7 +36,9 @@ const ProgressButton = createReactClass({
3436
onClick () {},
3537
onError () {},
3638
onSuccess () {},
37-
shouldAllowClickOnLoading: false
39+
shouldAllowClickOnLoading: false,
40+
stayInSuccessState: false,
41+
stayInErrorState: false
3842
}
3943
},
4044

@@ -159,19 +163,19 @@ const ProgressButton = createReactClass({
159163
this.setState({currentState: STATE.DISABLED})
160164
},
161165

162-
success (callback, dontRemove = false) {
166+
success (callback, stayInSuccessState = false) {
163167
this.setState({currentState: STATE.SUCCESS})
164168
this._timeout = setTimeout(() => {
165-
if (!dontRemove) { this.setState({currentState: STATE.NOTHING}) }
169+
if (!stayInSuccessState || !this.props.stayInSuccessState) { this.setState({currentState: STATE.NOTHING}) }
166170
callback = callback || this.props.onSuccess
167171
if (typeof callback === 'function') { callback() }
168172
}, this.props.durationSuccess)
169173
},
170174

171-
error (callback, err, dontRemove = false) {
175+
error (callback, err, stayInErrorState = false) {
172176
this.setState({currentState: STATE.ERROR})
173177
this._timeout = setTimeout(() => {
174-
if (!dontRemove) { this.setState({currentState: STATE.NOTHING}) }
178+
if (!stayInErrorState || !this.props.stayInErrorState) { this.setState({currentState: STATE.NOTHING}) }
175179
callback = callback || this.props.onError
176180
if (typeof callback === 'function') { callback(err) }
177181
}, this.props.durationError)

0 commit comments

Comments
 (0)