From 36f04ccaffabe04b9adcfb7a0bdd8d12dc1f7ac2 Mon Sep 17 00:00:00 2001 From: Gil Barbara Date: Tue, 9 Apr 2024 10:28:49 -0300 Subject: [PATCH] Add optional "data" to step --- src/types/components.ts | 4 ++++ test/__fixtures__/CustomOptions.tsx | 19 ++++++++++++++----- test/tours/custom-options.spec.tsx | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/types/components.ts b/src/types/components.ts index cbbcc422..23a4f68f 100644 --- a/src/types/components.ts +++ b/src/types/components.ts @@ -222,6 +222,10 @@ export type Step = Simplify< * The tooltip's body. */ content: ReactNode; + /** + * Additional data you can set to the step. + */ + data?: any; /** * Don't show the Beacon before the tooltip. * @default false diff --git a/test/__fixtures__/CustomOptions.tsx b/test/__fixtures__/CustomOptions.tsx index caff9be2..72262abf 100644 --- a/test/__fixtures__/CustomOptions.tsx +++ b/test/__fixtures__/CustomOptions.tsx @@ -2,10 +2,12 @@ import { useReducer } from 'react'; import { standardSteps } from './steps'; -import Joyride, { STATUS, Status } from '../../src'; +import Joyride, { LIFECYCLE, STATUS, Status } from '../../src'; import { CallBackProps, Props, Step } from '../../src/types'; -interface CustomOptionsProps extends Omit {} +interface CustomOptionsProps extends Omit { + finishedCallback: () => void; +} interface State { index: number; @@ -28,11 +30,14 @@ const tourSteps = [ target: '.outro h2 span', placement: 'top' as const, content: "Text only steps — Because sometimes you don't really need a proper heading", + data: { + last: true, + }, }, ]; -export default function CutomOptionss(props: Omit) { - const { callback, ...rest } = props; +export default function CustomOptions(props: Omit) { + const { callback, finishedCallback, ...rest } = props; const [{ run, steps }, setState] = useReducer( (previousState: State, nextState: Partial) => ({ ...previousState, @@ -50,7 +55,7 @@ export default function CutomOptionss(props: Omit { - const { status } = data; + const { lifecycle, status, step } = data; if (([STATUS.FINISHED, STATUS.SKIPPED] as Array).includes(status)) { setState({ run: false }); @@ -59,6 +64,10 @@ export default function CutomOptionss(props: Omit Custom Options', () => { render( { mockGetPopper(popper, type); @@ -147,5 +149,6 @@ describe('Joyride > Custom Options', () => { ); expect(mockGetPopper).toHaveBeenCalledTimes(8); + expect(mockFinishedCallback).toHaveBeenCalledTimes(1); }); });