1.0.23 • Published 9 months ago

tour-navigator v1.0.23

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Tour Navigator

Tour Navigator is a React package designed to facilitate the creation of customizable tours for React websites.

Installation

To install Tour Navigator, you can use npm or yarn:

npm install tour-navigator 
# or 
yarn add tour-navigator

Usage

import TourNavigator from 'tour-navigator';
import { Align, Position } from "tour-navigator/lib/TourNavigator/types";

// Define your steps
const steps = [
  {
    selector: '.step1',
    data: { /* Step data */ },
    position: Position.LEFT,
    align: Align.START
  },
  {
    selector: '.step2',
    data: { /* Step data */ },
    position: Position.BOTTOM,
    align: Align.CENTER
  },
  // Add more steps as needed
];

// Set up Tour Navigator with your steps
<TourNavigator
  id="my-tour"
  steps={steps}
/>

Demo

Check out the live demo here.

CodeSandbox Example

For a live interactive example, you can check out this CodeSandbox.

PropTypeDescriptionDefault
idstringUnique identifier for the tour.___tournavigator-${Date.now()}
maskRadiusnumberRadius of the mask around highlighted elements.5
maskPaddingnumberPadding around the mask.5
maskOpacitynumberOpacity of the mask.1
maskStyleCSSPropertiesCustom CSS styles for the mask.
maskStyleDuringScrollCSSPropertiesCustom CSS styles for the mask during scroll.
startAtnumberIndex of the step to start the tour at.0
maskHelperDistancenumberDistance between the mask and the helper element.10
screenHelperDistancenumberDistance between the screen and the helper element.10
onAfterOpen(() => void) | nullCallback function triggered after the tour starts.null
onBeforeClose(() => void) | nullCallback function triggered before the tour ends.null
stepsStep[]Array of steps defining the tour.[]
helper((props: HelperProps) => ReactNode) | nullCustom helper component for each step.null
isOpenbooleanFlag to control the visibility of the tour.true
onRequestClose((params: {event: MouseEvent | PointerEvent, isMask: boolean, isOverlay: boolean}) => void) | nullCallback function triggered when the tour is closed.null
onNext((props: HelperProps) => void) | nullCallback function triggered when the "Next" button is clicked.null
onPrev((props: HelperProps) => void) | nullCallback function triggered when the "Prev" button is clicked.null
onMove((props: HelperProps) => void) | nullCallback function triggered when the tour moves to the next step.null
scrollBehavior'smooth' | 'auto'Defines the scroll behavior when moving to a new step.'auto'
resizeListenerbooleanFlag to enable/disable resize listener.true
scrollListenerbooleanFlag to enable/disable scroll listener.true
mutationObserveMutationObserverConfigConfiguration for mutation observer to watch changes in DOM.
overlayFillstringFill color of the overlay.'black'
overlayOpacitynumberOpacity of the overlay.0.5
overlay((props: OverlayProps) => ReactNode) | nullCustom overlay component.null
classNamestringCustom CSS class for the Tour Navigator component.
styleCSSPropertiesCustom CSS styles for the Tour Navigator component.
renderOverlaybooleanFlag to enable/disable rendering of the overlay.true
renderHelperbooleanFlag to enable/disable rendering of the helper component.true
renderElementHTMLElement | stringThe element in which the Tour Navigator will be rendered.
scrollingElementHTMLElement | Document | Element | stringThe element used for scrolling.
waitForElementRenderedbooleanWorks only when mutationObserver provided,

Step

 Tour Navigator

Tour Navigator is a React package designed to facilitate the creation of customizable tours for React websites.

## Installation

To install Tour Navigator, you can use npm or yarn:

```bash
npm install tour-navigator 
# or 
yarn add tour-navigator

Usage

import TourNavigator from 'tour-navigator';
import { Align, Position } from "tour-navigator/lib/TourNavigator/types";

// Define your steps
const steps = [
  {
    selector: '.step1',
    data: { /* Step data */ },
    position: Position.LEFT,
    align: Align.START
  },
  {
    selector: '.step2',
    data: { /* Step data */ },
    position: Position.BOTTOM,
    align: Align.CENTER
  },
  // Add more steps as needed
];

// Set up Tour Navigator with your steps
<TourNavigator
  id="my-tour"
  steps={steps}
/>

Demo

Check out the live demo here.

CodeSandbox Example

For a live interactive example, you can check out this CodeSandbox.

PropTypeDescriptionDefault
idstringUnique identifier for the tour.___tournavigator-${Date.now()}
maskRadiusnumberRadius of the mask around highlighted elements.5
maskPaddingnumberPadding around the mask.5
maskOpacitynumberOpacity of the mask.1
maskStyleCSSPropertiesCustom CSS styles for the mask.
maskStyleDuringScrollCSSPropertiesCustom CSS styles for the mask during scroll.
startAtnumberIndex of the step to start the tour at.0
maskHelperDistancenumberDistance between the mask and the helper element.10
screenHelperDistancenumberDistance between the screen and the helper element.10
onAfterOpen(() => void) | nullCallback function triggered after the tour starts.null
onBeforeClose(() => void) | nullCallback function triggered before the tour ends.null
stepsStep[]Array of steps defining the tour.[]
helper((props: HelperProps) => ReactNode) | nullCustom helper component for each step.null
isOpenbooleanFlag to control the visibility of the tour.true
onRequestClose((params: {event: MouseEvent | PointerEvent, isMask: boolean, isOverlay: boolean}) => void) | nullCallback function triggered when the tour is closed.null
onNext((props: HelperProps) => void) | nullCallback function triggered when the "Next" button is clicked.null
onPrev((props: HelperProps) => void) | nullCallback function triggered when the "Prev" button is clicked.null
onMove((props: HelperProps) => void) | nullCallback function triggered when the tour moves to the next step.null
scrollBehavior'smooth' | 'auto'Defines the scroll behavior when moving to a new step.'auto'
resizeListenerbooleanFlag to enable/disable resize listener.true
scrollListenerbooleanFlag to enable/disable scroll listener.true
mutationObserveMutationObserverConfigConfiguration for mutation observer to watch changes in DOM.
overlayFillstringFill color of the overlay.'black'
overlayOpacitynumberOpacity of the overlay.0.5
overlay((props: OverlayProps) => ReactNode) | nullCustom overlay component.null
classNamestringCustom CSS class for the Tour Navigator component.
styleCSSPropertiesCustom CSS styles for the Tour Navigator component.
renderOverlaybooleanFlag to enable/disable rendering of the overlay.true
renderHelperbooleanFlag to enable/disable rendering of the helper component.true
renderElementHTMLElement | stringThe element in which the Tour Navigator will be rendered.
scrollingElementHTMLElement | Document | Element | stringThe element used for scrolling.
waitForElementRenderedbooleanWorks only when mutationObserver provided,

Step

type IntersectionOption = {
  root?: Element | Document | string | null; // Default: null
  rootMargin?: string; // Default: dynamically adjusted
  threshold?: number; // Default: dynamically adjusted
}
  
type Step = {
  selector: string;
  align?: Align,
  position?: Position | [Position, Position, Position, Position];
  data: any,
  scrollIntoView?: boolean;  // Default: true (Whether scroll to view element or not)
  intersectionOption?: IntersectionOption | (intersectionOption: IntersectionOption) => IntersectionOption;
}

HelperProps

type HelperProps = {
    id?: string;
    currentStep: Step | null;
    target: HTMLElement | null;
    currentStepIndex: number;
    previousStepIndex: number;
    steps: Step[];
    isScrollingIntoView: boolean; // Whether scrolling element into view or not
    focus: (scrollBehavior?: 'auto' | 'smooth') => void; // programmatically focus current targe, In case it loses
    goto: (stepIndex: number) => void; // goto any specific steps
    next: () => void;
    prev: () => void;
    onRequestClose: ((params: {event: MouseEvent | PointerEvent, isMask: boolean, isOverlay: boolean}) => void) | null
}

Passing Ref to TourNavigator

Since TourNavigator is a class component, you can use ref to access various built-in methods directly for enhanced customization.

This README provides an overview of the package, its usage, props, and default props. Let me know if you need further modifications or additions!

License

This project is licensed under the MIT.

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.22

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.23

9 months ago

1.0.11

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago