Scripts2026年5月28日·1 分钟阅读

Shepherd.js — Guide Users Through Your App Step by Step

A JavaScript library for creating guided tours and onboarding flows with customizable steps, themes, and intelligent element positioning.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Shepherd.js Overview
直接安装命令
npx -y tokrepo@latest install 5acb2ba1-5a2a-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Shepherd.js is a library for building user onboarding tours and feature walkthroughs. It uses Floating UI for smart element positioning and provides a step-based API where each step can attach to a DOM element, display rich HTML content, and include action buttons.

What Shepherd.js Does

  • Creates multi-step guided tours attached to specific UI elements
  • Positions tooltips and modals intelligently with Floating UI collision detection
  • Supports modal overlays that highlight the active element
  • Provides lifecycle hooks for each step (before show, after hide, on cancel)
  • Includes framework wrappers for React, Vue, and Angular

Architecture Overview

Shepherd.js manages a tour as an ordered list of step objects. Each step references a target DOM element and a popover configuration. The library delegates positioning to Floating UI, which calculates optimal placement while avoiding viewport clipping. An overlay layer dims the rest of the page and blocks interaction outside the highlighted element.

Self-Hosting & Configuration

  • Install via npm and import the default CSS theme
  • Create a Tour instance with global defaults for all steps
  • Add steps with attachTo, text, title, and buttons properties
  • Customize the overlay color and opacity via CSS variables
  • Use tour.on() to listen to events like complete, cancel, and show

Key Features

  • Floating UI integration for reliable cross-browser positioning
  • Modal overlay with element highlighting and click-outside blocking
  • Built-in accessibility with focus trapping and ARIA attributes
  • Theming via CSS custom properties or full CSS overrides
  • Framework-specific packages for React, Vue, Ember, and Angular

Comparison with Similar Tools

  • Driver.js — Lighter and zero-dependency; Shepherd.js is more feature-rich with modal overlays
  • Intro.js — Similar feature set but requires a commercial license; Shepherd.js is MIT-licensed
  • React Joyride — React-only; Shepherd.js is framework-agnostic with optional framework wrappers
  • Walktour — Smaller React library; Shepherd.js handles more complex multi-page tours

FAQ

Q: Can I use Shepherd.js with React? A: Yes. Install react-shepherd for a hook-based API that wraps Shepherd.js tours.

Q: How do I style the tour steps? A: Override the default CSS classes or use CSS custom properties to change colors, fonts, and spacing.

Q: Can steps target dynamically rendered elements? A: Yes. Use the beforeShowPromise hook to wait for elements to appear before attaching a step.

Q: Does it support multiple tours on one page? A: Yes. Create separate Tour instances and start them independently.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产