@galangel/react-tip-magic

中文文档
1.3.0发布于 2026/08/20Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 6175

A sophisticated, elegant, and performant tooltip library for React with an intelligent floating helper system.

原始使用文档
文档目录15 节
  1. Why React Tip Magic?
  2. Quick Start
  3. Tooltips
  4. Basic Usage
  5. With Keyboard Shortcuts
  6. Positioning & Behavior
  7. Guided Tours
  8. Step content is HTML
  9. When a target isn't there
  10. Where focus lands
  11. Tip Advisor
  12. Data Attributes
  13. Programmatic API
  14. Built With
  15. License

React Tip Magic ✨

A thoughtfully crafted tooltip library for React—simple to use, delightful to experience.

npm version bundle size license

Why React Tip Magic?

Tooltips seem simple, but getting them right takes care. They should appear when needed, stay out of the way when not, and feel natural as users navigate your interface.

React Tip Magic handles the details so you don't have to—positioning, transitions, accessibility, keyboard support—all with a clean, declarative API.

Quick Start

npm install @galangel/react-tip-magic
import { TipMagicProvider } from '@galangel/react-tip-magic';
import '@galangel/react-tip-magic/styles.css';

function App() {
  return (
    <TipMagicProvider>
      <YourApp />
    </TipMagicProvider>
  );
}

That's it. Now add data-tip to any element:

<button data-tip="Save your changes">Save</button>

Tooltips

The core of React Tip Magic. One tooltip instance that gracefully moves between elements, providing a smooth, cohesive experience.

Basic Usage

<button data-tip="Click to save">Save</button>
<button data-tip="Undo last action">Undo</button>

With Keyboard Shortcuts

Display shortcuts alongside your tooltips using the data-tip-shortcut attribute:

<button data-tip="Copy" data-tip-shortcut="⌘C">Copy</button>
<button data-tip="Paste" data-tip-shortcut="⌘V">Paste</button>
<button data-tip="Save" data-tip-shortcut="⌘S">Save</button>

Positioning & Behavior

{
  /* Position control */
}
<button data-tip="Below the button" data-tip-placement="bottom">
  Hover me
</button>;

{
  /* Smooth transitions between grouped elements */
}
<nav>
  <a data-tip="Home" data-tip-move data-tip-group="nav">
    Home
  </a>
  <a data-tip="About" data-tip-move data-tip-group="nav">
    About
  </a>
  <a data-tip="Contact" data-tip-move data-tip-group="nav">
    Contact
  </a>
</nav>;

{
  /* Interactive tooltips that stay visible on hover */
}
<span data-tip="Click <a href='#'>here</a> to learn more" data-tip-html data-tip-interactive>
  More info
</span>;

Guided Tours

Walk users through your interface with step-by-step tours. Helpful for onboarding, feature introductions, or contextual guidance.

import { useTour } from '@galangel/react-tip-magic';

function App() {
  const tour = useTour({
    steps: [
      { target: 'dashboard', title: 'Welcome', content: 'This is your dashboard.' },
      { target: 'create-btn', title: 'Create', content: 'Click here to get started.' },
    ],
    // Built-in Back/Next controls are off by default—turn them on for multi-step tours
    navigation: { showControls: true },
    progress: { show: true },
  });

  return (
    <div>
      <nav data-tip-id="dashboard">Dashboard</nav>
      <button data-tip-id="create-btn" onClick={tour.start}>
        New Project
      </button>
    </div>
  );
}

useTour is headless by default: leave navigation.showControls unset and render your own controls from the returned next, prev, end and progress.

const tour = useTour({ steps });

{
  tour.isActive && (
    <div>
      <span>
        {tour.progress.current} of {tour.progress.total}
      </span>
      <button onClick={tour.prev} disabled={tour.currentStep?.isFirst}>
        Back
      </button>
      <button onClick={tour.next}>{tour.currentStep?.isLast ? 'Finish' : 'Next'}</button>
    </div>
  );
}

Step content is HTML

Step content is injected as HTML so that titles, media and controls work. Use text instead when the value is plain text the library should escape for you:

{ target: 'profile', text: `Signed in as ${user.name}` }

Exactly one of content or text is required — a step with neither, or with both, won't compile. For markup with an interpolated value, keep content and escape the value with the exported escapeHtml:

import { escapeHtml } from '@galangel/react-tip-magic';

{ target: 'profile', content: `Signed in as <b>${escapeHtml(user.name)}</b>` }

When a target isn't there

start() returns false and changes nothing—no onStart, no onStepChange—if no step's target is in the DOM, so a tour that can't render never reports itself as shown. Supply onTargetMissing to handle it yourself (and to keep the library off console.warn):

const tour = useTour({
  steps,
  onTargetMissing: (step) => {
    logger.warn('tour target missing', { target: step.target });
    return 'skip'; // or end the tour, which is the default
  },
});

if (tour.start()) {
  markTourAsSeen();
}

Recovery depends on the direction of travel: next() skips or ends the tour, while prev() and goTo() leave it where it is — the step on screen is still fine. goTo() never skips, so it lands on the step you asked for or returns false.

Where focus lands

A tour panel is a dialog, so focus moves into it when a step opens. autoFocus picks which element inside it:

const tour = useTour({
  steps,
  // 'panel' (default) | 'primary' — Next/Finish, so Enter advances | false — leave focus alone
  navigation: { showControls: true, autoFocus: 'primary' },
});

'primary' falls back to the panel when a step renders no Next/Finish button — never to the close button. Overridable per step via step.navigation.autoFocus.

Tours also support progress indicators, keyboard support, and backdrop highlighting (focus: true, or focus: { dismissOnClick: true } to let a click on the backdrop end the tour)—all configurable to fit your needs.


Tip Advisor

A keyboard shortcut discovery menu. Press a key (F1 by default) to reveal all available shortcuts in your interface, with fuzzy search to quickly find what you need.

import { TipAdvisor } from '@galangel/react-tip-magic';

function App() {
  return (
    <TipMagicProvider>
      <div className="toolbar">
        <button data-tip="Copy" data-tip-shortcut="⌘C">
          Copy
        </button>
        <button data-tip="Paste" data-tip-shortcut="⌘V">
          Paste
        </button>
        <button data-tip="Save" data-tip-shortcut="⌘S">
          Save
        </button>
      </div>

      {/* Press F1 to open the advisor */}
      <TipAdvisor />
    </TipMagicProvider>
  );
}

Features:

  • Fuzzy search with highlighted matches
  • Keyboard navigation (arrow keys + Enter)
  • Hover to preview tooltip locations
  • Click to trigger the associated element

Data Attributes

AttributeDescriptionExample
data-tipTooltip contentdata-tip="Hello"
data-tip-shortcutKeyboard shortcut badgedata-tip-shortcut="⌘S"
data-tip-idElement identifier for toursdata-tip-id="welcome"
data-tip-placementPosition (top, bottom, left, right)data-tip-placement="bottom"
data-tip-delayShow delay in msdata-tip-delay="500"
data-tip-hide-delayHide delay in msdata-tip-hide-delay="100"
data-tip-disabledDisable tooltipdata-tip-disabled
data-tip-htmlParse content as HTMLdata-tip-html
data-tip-interactiveKeep tooltip on hoverdata-tip-interactive
data-tip-moveSmooth move transitiondata-tip-move
data-tip-groupGroup for transitionsdata-tip-group="nav"
data-tip-no-arrowHide tooltip arrowdata-tip-no-arrow

Programmatic API

For more control, use the useTipMagic hook:

import { useTipMagic } from '@galangel/react-tip-magic';

function MyComponent() {
  const { tooltip } = useTipMagic();

  const handleClick = () => {
    tooltip.show('#my-element', 'Dynamic content');
  };

  return (
    <button id="my-element" onClick={handleClick}>
      Click me
    </button>
  );
}

Built With

  • React 18+ with modern hooks
  • TypeScript for type safety
  • Floating UI for positioning
  • Storybook for documentation

License

Apache-2.0


Made with care for the React community

Buy Me A Coffee

版本与发布记录

@galangel/react-tip-magic 共发布 6 个版本,首次发布于 2026/01/14;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/08/202 个月前
1.2.22026/08/182 个月前
1.2.12026/08/182 个月前
1.1.02026/01/1410 个月前
1.0.32026/01/1410 个月前
1.0.22026/01/1410 个月前

关于 @galangel/react-tip-magic 的常见问题

@galangel/react-tip-magic 是什么?

A sophisticated, elegant, and performant tooltip library for React with an intelligent floating helper system.

如何安装 @galangel/react-tip-magic?

在项目目录运行 npm install @galangel/react-tip-magic,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)、react-dom(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@galangel/react-tip-magic 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@galangel/react-tip-magic 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@galangel/react-tip-magic 可以商用吗?

@galangel/react-tip-magic 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@galangel/react-tip-magic 的下载量有多少?

根据 npm 官方下载统计,@galangel/react-tip-magic 在 2026/10/16 – 2026/11/14 这 30 天内被下载 6,175 次,日均约 206 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@galangel/react-tip-magic 还在维护吗?

最新版本 1.3.0 发布于 2026/08/20(2 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/01/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。