From 621e38bdf5769b2088ba1ca0bee54e844a8b9952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 27 May 2020 11:01:06 +0200 Subject: [PATCH 1/2] feat: expose goto as props --- src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 13a2728..a94e95a 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,10 @@ class Loki extends Component { complete: false }; + _goto(newStep) { + this.setState({ currentStep: newStep }); + } + _back(data) { this.props.onBack && this.props.onBack(data); this.setState({ currentStep: this.state.currentStep - 1 }); @@ -42,7 +46,8 @@ class Loki extends Component { cantBack: this.state.currentStep === 1, isInFinalStep: this.state.currentStep === this.props.steps.length, backHandler: this._back.bind(this), - nextHandler: this._next.bind(this) + nextHandler: this._next.bind(this), + gotoHandler: this._goto.bind(this) }; } @@ -62,7 +67,7 @@ class Loki extends Component { currentStep={this.state.currentStep} totalSteps={this.props.steps.length} step={{ ...step, index: index + 1 }} - goTo={newStep => this.setState({ currentStep: newStep })} + goTo={this._goto.bind(this )} isLokiComplete={this.state.complete} /> )); From 713f8337aeb39078067b3ccca606fc1cea14b8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 27 May 2020 11:01:16 +0200 Subject: [PATCH 2/2] fix: proptypes --- src/index.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index a94e95a..9742546 100644 --- a/src/index.js +++ b/src/index.js @@ -5,12 +5,6 @@ import LokiStep from "./LokiStep"; import LokiStepContainer from "./LokiStepContainer"; class Loki extends Component { - static defaultProps = { - backLabel: "Back", - nextLabel: "Next", - finishLabel: "Finish" - }; - state = { currentStep: 1, stepsDone: [], @@ -157,8 +151,31 @@ class Loki extends Component { } Loki.propTypes = { + backLabel: PropTypes.string, + finishLabel: PropTypes.string, + nextLabel: PropTypes.string, + noActions: PropTypes.bool, + onBack: PropTypes.func, + onFinish: PropTypes.func.isRequired, + onNext: PropTypes.func, + renderActions: PropTypes.func, + renderComponents: PropTypes.func, + renderSteps: PropTypes.func, steps: PropTypes.array.isRequired, - onFinish: PropTypes.func.isRequired }; +Loki.defaultProps = { + backLabel: "Back", + nextLabel: "Next", + finishLabel: "Finish", + onBack: null, + onNext: null, + noActions: false, + onBack: null, + onNext: null, + renderActions: null, + renderComponents: null, + renderSteps: null, +} + export { Loki as default, LokiStepContainer, LokiStep };