Skip to content

Commit

Permalink
renaming the state and the toggle function
Browse files Browse the repository at this point in the history
  • Loading branch information
mollfpr committed Jun 4, 2022
1 parent 992d302 commit 356db33
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/components/withDelayToggleButtonState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import getComponentDisplayName from '../libs/getComponentDisplayName';

const withDelayToggleButtonStatePropTypes = {
/** A value whether the button state is complete */
isButtonStateComplete: PropTypes.bool.isRequired,
isDelayButtonStateComplete: PropTypes.bool.isRequired,

/** A function to call to change the complete state */
toggleButtonStateComplete: PropTypes.func.isRequired,
toggleDelayButtonState: PropTypes.func.isRequired,
};

export default function (WrappedComponent) {
Expand All @@ -16,9 +16,9 @@ export default function (WrappedComponent) {
super(props);

this.state = {
isButtonStateComplete: false,
isDelayButtonStateComplete: false,
};
this.toggleButtonStateComplete = this.toggleButtonStateComplete.bind(this);
this.toggleDelayButtonState = this.toggleDelayButtonState.bind(this);
}

componentWillUnmount() {
Expand All @@ -30,29 +30,31 @@ export default function (WrappedComponent) {
}

/**
* @param {Boolean} [resetAfterDelay=true] Impose delay before toggling state
* @param {Boolean} [resetAfterDelay] Impose delay before toggling state
*/
toggleButtonStateComplete(resetAfterDelay = true) {
toggleDelayButtonState(resetAfterDelay) {
this.setState({
isButtonStateComplete: true,
isDelayButtonStateComplete: true,
});

if (resetAfterDelay) {
this.resetButtonStateCompleteTimer = setTimeout(() => {
this.setState({
isButtonStateComplete: false,
});
}, 1800);
if (!resetAfterDelay) {
return;
}

this.resetButtonStateCompleteTimer = setTimeout(() => {
this.setState({
isDelayButtonStateComplete: false,
});
}, 1800);
}

render() {
return (
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...this.props}
isButtonStateComplete={this.state.isButtonStateComplete}
toggleButtonStateComplete={this.toggleButtonStateComplete}
isDelayButtonStateComplete={this.state.isDelayButtonStateComplete}
toggleDelayButtonState={this.toggleDelayButtonState}
/>
);
}
Expand Down

0 comments on commit 356db33

Please sign in to comment.