🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

trail-js

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trail-js

A simple and highly customizable walkthrough library which can be used in your react apps to guide users through your website

2.0.1
latest
npm
Version published
Weekly downloads
30
-72.48%
Maintainers
1
Weekly downloads
 
Created
Source

🧭 trail-js — React Walkthrough / Guided Tour Library

trail-js is a lightweight, highly-customizable, and feature-rich walkthrough library for React apps. It allows developers to guide users through product features using interactive steps, tooltips, and navigation logic.

✨ Features

  • Step-by-step guides with DOM element targeting
  • Supports custom content (jsx support)
  • canGoNext validations for conditional progression
  • beforeNext async hooks for side effects
  • Optional backdrop with focus highlighting
  • Responsive positioning with auto-clamping
  • Smooth scroll to target elements
  • Dynamic tooltips with styling overrides

📦 Installation

npm install trail-js
# or
yarn add trail-js

🧠 Basic Usage

import {
  WalkthroughProvider,
  Walkthrough,
  useWalkthrough,
  type WalkthroughStep,
} from "trail-js";

const steps: WalkthroughStep[] = [
  {
    selector: "#start-button",
    content: "Click this button to get started!",
    placement: "bottom",
  },
  {
    selector: "#name-input",
    content: "Enter your name before continuing.",
    placement: "top",
    canGoNext: {
      validate: () => !!document.getElementById("name-input")?.value,
      errorString: "Name is required!",
    },
  },
];

const App = () => (
  <WalkthroughProvider steps={steps}>
    <YourApp />
    <Walkthrough />
  </WalkthroughProvider>
);

🛠️ API Reference

WalkthroughProvider

Wrap your app with this provider and pass the list of steps.

<WalkthroughProvider steps={steps}>
  <App />
</WalkthroughProvider>

Walkthrough

The tooltip and highlight overlay component. Should be placed inside WalkthroughProvider.

<Walkthrough />

🔁 Step Object (WalkthroughStep)

type WalkthroughStep = {
  selector: string;
  content: string | ReactNode;
  placement?: "top" | "bottom" | "left" | "right" | "auto";
  triggerEvent?: string;
  onEnter?: () => void;
  onExit?: () => void;
  beforeNext?: () => void | Promise<void>;
  canGoNext?: {
    validate: () => boolean | Promise<boolean>;
    errorString?: string;
  };
  showBackdrop?: boolean;
  tooltipClassName?: string;
  tooltipStyle?: React.CSSProperties;
  navButtonClassName?: string;
  navButtonStyle?: React.CSSProperties;
  customNavigation?: (controls: WalkthroughControls) => ReactNode;
}

customNavigation Controls

type WalkthroughControls = {
  next: () => void;
  back: () => void;
  skip: () => void;
  goToStep: (index: number) => void;
};

useWalkthrough()

Main hook to control walkthrough progression.

Returns

PropertyTypeDescription
stepsWalkthroughStep[]All defined steps for the current walkthrough
currentStepIndexnumberIndex of the current active step
isActivebooleanWhether walkthrough is active or not
next() => voidMove to the next step
back() => voidMove to the previous step
skip() => voidSkip and end the walkthrough
goToStep(index: number) => voidJump to a specific step

Use Cases

  • User onboarding flows
  • Feature discovery in SaaS apps
  • Interactive documentation
  • Admin dashboards and tutorials
  • Demo mode for products

🎯 Examples

1. Basic Step with Default Navigation

{
  selector: "#submit-button",
  content: "Click to submit the form",
  placement: "right",
}

2. Step with Validation and Custom Error

{
  selector: "#email",
  content: "Please enter a valid email",
  canGoNext: {
    validate: () => /\S+@\S+\.\S+/.test(document.getElementById("email")?.value || ""),
    errorString: "Valid email required!",
  },
}

3. Step with Custom Navigation Buttons

{
  selector: "#next-step",
  content: "Custom nav UI",
  customNavigation: ({ next, back }) => (
    <div>
      <button onClick={back}>← Prev</button>
      <button onClick={next}>Next →</button>
    </div>
  ),
}

🎨 Styling

You can override default styles with CSS classes:

.walkthrough-tooltip {
  background: white;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.walkthrough-overlay {
  background: rgba(0, 0, 0, 0.5);
}

Or use tooltipClassName, tooltipStyle, navButtonClassName, and navButtonStyle props per step.

🧪 Dev / Example

To run the demo locally:

npm install
npm run dev

📄 License

MIT License

🤝 Contributing

Contributions, suggestions, and feedback are welcome!

  • Fork the repo
  • Create a new branch
  • Make your changes
  • Open a PR

💬 Support

Feel free to open an issue or contact via discussions for help or feature requests.

Keywords

walkthrough

FAQs

Package last updated on 20 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts