Code Monkey home page Code Monkey logo

driverjs-react's Introduction

Driver.js React

Driver.js library port for React.

Getting Started

Installing

Yarn:

yarn add driverjs-react

Npm:

npm install driverjs-react

Using

Basic usage example

Import into your React project provider DriverProvider:

import React from 'react';
import { createRoot } from 'react-dom/client';
import { DriverProvider, DriverOptionsType } from 'driverjs-react';
import { DriverJsReactContainer } from './DriverJsReactContainer';

export const driverOptions: DriverOptionsType = {
  showProgress: true,
  allowClose: false,
};

const container = document.getElementById('root');

if (container) {
  const root = createRoot(container);

  root.render(
        <DriverProvider driverOptions={driverOptions}>
            <DriverJsReactContainer />
        </DriverProvider>
  );
}

In your container (for example DriverJsReactContainer) import hook useDriver and used StepComponent.
StepComponent has required prop stepIndex, which allows you to specify the order of steps:

import React, { FC } from 'react';
import { StepComponent, useDriver } from 'driverjs-react';

export const DriverJsReactContainer: FC = () => {
    const { driver } = useDriver();

    const onShowTour = () => {
        if (driver) {
            driver.drive();
        }
    };

    return (
        <div>
            <StepComponent key={0} stepIndex={0} popover={{ title: 'Title Tour Example 1', description: 'Description Tour Example 1' }}>
                <div>tour-example-1</div>
            </StepComponent>

            <StepComponent key={1} stepIndex={1} popover={{ title: 'Title Tour Example 2', description: 'Description Tour Example 2' }}>
                <div>tour-example-2</div>
            </StepComponent>

            <StepComponent key={2} stepIndex={2} popover={{ title: 'Title Tour Example 3', description: 'Description Tour Example 3' }}>
                <div>tour-example-3</div>
            </StepComponent>

            <StepComponent key={3} stepIndex={3} popover={{ title: 'Title Tour Example 4', description: 'Description Tour Example 4' }}>
                <div>tour-example-4</div>
            </StepComponent>
            <button onClick={onShowTour}>Show tour</button>
        </div>
    );
};
Or, you can use it like this: Import into your React project provider DriverProvider:
import React from 'react';
import { createRoot } from 'react-dom/client';
import { DriverProvider, DriverOptionsType } from 'driverjs-react';
import { DriverJsReactContainer } from './DriverJsReactContainer';

export const driverOptions: DriverOptionsType = {
  showProgress: true,
  allowClose: false,
  steps: [
    { element: '#tour-example-1', popover: { title: 'Title Tour Example 1', description: 'Description Tour Example 1' } },
    { element: '#tour-example-2', popover: { title: 'Title Tour Example 2', description: 'Description Tour Example 2' } },
    { element: '#tour-example-3', popover: { title: 'Title Tour Example 3', description: 'Description Tour Example 3' } },
    { element: '#tour-example-4', popover: { title: 'Title Tour Example 4', description: 'Description Tour Example 4' } },
  ],
};

const container = document.getElementById('root');

if (container) {
  const root = createRoot(container);

  root.render(
        <DriverProvider driverOptions={driverOptions}>
            <DriverJsReactContainer />
        </DriverProvider>
  );
}

In your container (for example DriverJsReactContainer) import hook useDriver and init tour:

import React, { FC, useEffect } from 'react';
import { useDriver } from 'driverjs-react';

export const DriverJsReactContainer: FC = () => {
  const { driver } = useDriver();

  const onShowTour = () => {
    if (driver) {
      driver.drive();
    }
  };

  useEffect(() => {
    onShowTour();
  }, [driver]);

  return (
      <div>
          <div id="tour-example-1">tour-example-1</div>
          <div id="tour-example-2">tour-example-2</div>
          <div id="tour-example-3">tour-example-3</div>
          <div id="tour-example-4">tour-example-4</div>
          <button onClick={onShowTour}>Show tour</button>
      </div>
  );
};

Documentation

For demos and documentation, visit driverjs.com.

driverjs-react's People

Contributors

gnvcor avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.