react-wizard-primitive
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -1,18 +0,29 @@ | ||
## 2.0.0 (June 15, 2019) | ||
# Changelog | ||
Starting with version `2.1.0` this project uses [semantic-release](https://github.com/semantic-release/semantic-release). | ||
The changelog will be updated [with Github releases](https://github.com/Jibbedi/react-wizard-primitive/releases). | ||
## Previous Releases | ||
### 2.0.0 (June 15, 2019) | ||
- breaking change: `hasBeenActive` is now false on first render. To achieve the previous behaviour you can modify your code to `hasBeenActive || isActive` | ||
- breaking change: `maxVisitedStepIndex` has been renamed to `maxActivatedStepIndex` and will not include the currently active step if it's first rendered. To achieve the previous behaviour you can modify your code to `Math.max(maxActivatedStepIndex, activeStepIndex)` | ||
## 1.2.0 (February 10, 2019) | ||
### 1.2.0 (February 10, 2019) | ||
- feature: Added routing support. See README#Routing for details. | ||
## 1.1.2 (February 9, 2019) | ||
### 1.1.2 (February 9, 2019) | ||
- bugfix: wizard step in a nested component now recieves correct wizard step on rerenders | ||
- fixed spelling / grammar in README | ||
## 1.1.1 (February 8, 2019) | ||
### 1.1.1 (February 8, 2019) | ||
- added live examples in README | ||
- fixed spelling / grammar in README | ||
## 1.1.0 (February 6, 2019) | ||
- added support for _moveToStep_ and _resetToStep_ functions in useWizard and Wizard component, which were previously only available at step level. | ||
### 1.1.0 (February 6, 2019) | ||
- added support for _moveToStep_ and _resetToStep_ functions in useWizard and Wizard component, which were previously only available at step level. |
@@ -5,8 +5,15 @@ import React, { FunctionComponent } from "react"; | ||
} | ||
export interface StepNavigationOptions { | ||
skipOnChangeHandler?: boolean; | ||
} | ||
interface InternalGoToStepOptions { | ||
resetMaxStepIndex?: boolean; | ||
} | ||
declare type GoToStepOptions = InternalGoToStepOptions & StepNavigationOptions; | ||
export interface UseWizard { | ||
activeStepIndex: number; | ||
maxActivatedStepIndex: number; | ||
goToStep: (stepIndex: number) => void; | ||
moveToStep: (stepIndex: number) => void; | ||
resetToStep: (stepIndex: number) => void; | ||
goToStep: (stepIndex: number, options?: StepNavigationOptions) => void; | ||
moveToStep: (stepIndex: number, options?: StepNavigationOptions) => void; | ||
resetToStep: (stepIndex: number, options?: StepNavigationOptions) => void; | ||
nextStep: () => void; | ||
@@ -30,2 +37,3 @@ previousStep: () => void; | ||
}) => void; | ||
declare type GoToStep = (stepIndex: number, options?: GoToStepOptions) => void; | ||
export interface UseWizardProps { | ||
@@ -38,10 +46,8 @@ initialStepIndex?: number; | ||
maxActivatedStepIndex: number; | ||
goToStep: (stepIndex: number, { resetMaxStepIndex }?: { | ||
resetMaxStepIndex?: boolean | undefined; | ||
}) => void; | ||
goToStep: GoToStep; | ||
nextStep: () => void; | ||
previousStep: () => void; | ||
getStep: (options?: GetStepOptions | undefined) => Step; | ||
moveToStep: (stepIndex: number) => void; | ||
resetToStep: (stepIndex: number) => void; | ||
moveToStep: (stepIndex: number, options?: StepNavigationOptions | undefined) => void; | ||
resetToStep: (stepIndex: number, options?: StepNavigationOptions | undefined) => void; | ||
}; | ||
@@ -48,0 +54,0 @@ export interface WizardProps { |
@@ -55,3 +55,3 @@ import React, { useState, useEffect, useContext, useRef } from 'react'; | ||
}; | ||
const goToStep = (stepIndex, { resetMaxStepIndex = false } = {}) => { | ||
const goToStep = (stepIndex, { resetMaxStepIndex = false, skipOnChangeHandler = false } = {}) => { | ||
if (activeStepIndex !== stepIndex) { | ||
@@ -61,3 +61,3 @@ const newMaxStepIndex = resetMaxStepIndex | ||
: Math.max(activeStepIndex, maxActivatedStepIndex); | ||
onChange && | ||
if (onChange && !skipOnChangeHandler) { | ||
onChange({ | ||
@@ -68,2 +68,3 @@ previousStepIndex: activeStepIndex, | ||
}); | ||
} | ||
setActiveStepIndex(stepIndex); | ||
@@ -79,7 +80,7 @@ setMaxActivatedStepIndex(newMaxStepIndex); | ||
}; | ||
const moveToStep = (stepIndex) => { | ||
goToStep(stepIndex); | ||
const moveToStep = (stepIndex, options) => { | ||
goToStep(stepIndex, Object.assign({}, options)); | ||
}; | ||
const resetToStep = (stepIndex) => { | ||
goToStep(stepIndex, { resetMaxStepIndex: true }); | ||
const resetToStep = (stepIndex, options) => { | ||
goToStep(stepIndex, Object.assign({ resetMaxStepIndex: true }, options)); | ||
}; | ||
@@ -86,0 +87,0 @@ return { |
@@ -62,3 +62,3 @@ 'use strict'; | ||
}; | ||
const goToStep = (stepIndex, { resetMaxStepIndex = false } = {}) => { | ||
const goToStep = (stepIndex, { resetMaxStepIndex = false, skipOnChangeHandler = false } = {}) => { | ||
if (activeStepIndex !== stepIndex) { | ||
@@ -68,3 +68,3 @@ const newMaxStepIndex = resetMaxStepIndex | ||
: Math.max(activeStepIndex, maxActivatedStepIndex); | ||
onChange && | ||
if (onChange && !skipOnChangeHandler) { | ||
onChange({ | ||
@@ -75,2 +75,3 @@ previousStepIndex: activeStepIndex, | ||
}); | ||
} | ||
setActiveStepIndex(stepIndex); | ||
@@ -86,7 +87,7 @@ setMaxActivatedStepIndex(newMaxStepIndex); | ||
}; | ||
const moveToStep = (stepIndex) => { | ||
goToStep(stepIndex); | ||
const moveToStep = (stepIndex, options) => { | ||
goToStep(stepIndex, Object.assign({}, options)); | ||
}; | ||
const resetToStep = (stepIndex) => { | ||
goToStep(stepIndex, { resetMaxStepIndex: true }); | ||
const resetToStep = (stepIndex, options) => { | ||
goToStep(stepIndex, Object.assign({ resetMaxStepIndex: true }, options)); | ||
}; | ||
@@ -93,0 +94,0 @@ return { |
{ | ||
"name": "react-wizard-primitive", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A react wizard primitive without UI restrictions - hooks and render props API available!", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -124,12 +124,16 @@ <h1 align="center"> | ||
> function(stepIndex : number) | ||
> function(stepIndex : number, options? : {skipOnChangeHandler?: boolean}) | ||
Move to step with index _stepIndex_ | ||
You can pass in options to control if the _onChange_ handler should be called for this operation. | ||
#### resetToStep | ||
> function(stepIndex : number) | ||
> function(stepIndex : number, options? : {skipOnChangeHandler?: boolean}) | ||
Move to step with index _stepIndex_. Set _hasBeenActive_ for all following steps as well as the new step to false. | ||
You can pass in options to control if the _onChange_ handler should be called for this operation. | ||
#### getStep | ||
@@ -392,2 +396,3 @@ | ||
<td align="center"><a href="https://github.com/kaYcee"><img src="https://avatars1.githubusercontent.com/u/1464822?v=4" width="100px;" alt="kaYcee"/><br /><sub><b>kaYcee</b></sub></a><br /><a href="#ideas-kaYcee" title="Ideas, Planning, & Feedback">🤔</a></td> | ||
<td align="center"><a href="https://github.com/kaldebert"><img src="https://avatars2.githubusercontent.com/u/10433270?v=4" width="100px;" alt="Kevin Aldebert"/><br /><sub><b>Kevin Aldebert</b></sub></a><br /><a href="#ideas-kaldebert" title="Ideas, Planning, & Feedback">🤔</a></td> | ||
</tr> | ||
@@ -394,0 +399,0 @@ </table> |
28755
305
400