Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eitan Elbaz committed Oct 25, 2021
2 parents cd7b304 + 896d761 commit 1c7f77f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-grand-tour",
"version": "0.6.1",
"version": "0.7.0",
"description": "",
"main": "./build/index.js",
"typings": "./typings/index.d.ts",
Expand Down
19 changes: 16 additions & 3 deletions src/ReactGrandTour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ReactGrandTour: React.FC<Props> = ({
open: defaultOpen = false,
onClose,
onOpen,
onStepChange,
steps: defaultSteps = [],
openAt = 0,
scrollIntoViewOptions = { behavior: 'smooth', block: 'center' },
Expand Down Expand Up @@ -95,11 +96,23 @@ const ReactGrandTour: React.FC<Props> = ({

const changeStep = useCallback(
(step: number) => {
if (step >= 0 && step < allSteps.length) {
setCurrentIndex(step);
if (steps) {
const currentStep = Number(currentIndex);
if (step >= 0 && step < steps.length) {
setCurrentIndex(step);
if (onStepChange) {
onStepChange({
fromStepIndex: currentStep,
toStepIndex: step,
totalSteps: steps.length,
fromStep: steps[currentStep],
toStep: steps[step],
});
}
}
}
},
[allSteps.length],
[steps, onStepChange, currentIndex],
);
const openTour = useCallback(
(atStep = 0, withSteps?: ReactGrandTourStep[]) => {
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type ReactGrandTourProps = {
open?: boolean;
onOpen?: () => void;
onClose?: (reason: ReactGrandTourCloseReason) => void;
onStepChange?: (props: OnStepChangeProps) => void;
openAt?: number;
steps?: ReactGrandTourStep[];
scrollIntoViewOptions?: ScrollIntoViewOptions;
Expand Down Expand Up @@ -60,6 +61,15 @@ export type ReactGrandTourShortcuts = {
prevStep?: string[];
};

export type OnStepChangeProps = {
fromStepIndex: number;
toStepIndex: number;
totalSteps: number;

fromStep: ReactGrandTourStep;
toStep: ReactGrandTourStep;
};

export type ReactGrandTourCloseReason = 'backdrop' | 'close-btn' | 'escape';

export type ReactGrandTourContextType = {
Expand Down

0 comments on commit 1c7f77f

Please sign in to comment.