Skip to content

Repository files navigation

React Tip Magic ✨

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

npm versionbundle sizelicense

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';functionApp(){return(<TipMagicProvider><YourApp/></TipMagicProvider>);}

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

<buttondata-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

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

With Keyboard Shortcuts

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

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

Positioning & Behavior

{/* Position control */}<buttondata-tip="Below the button"data-tip-placement="bottom">
Hover me
</button>;{/* Smooth transitions between grouped elements */}<nav><adata-tip="Home"data-tip-movedata-tip-group="nav">
Home
</a><adata-tip="About"data-tip-movedata-tip-group="nav">
About
</a><adata-tip="Contact"data-tip-movedata-tip-group="nav">
Contact
</a></nav>;{/* Interactive tooltips that stay visible on hover */}<spandata-tip="Click <a href='#'>here</a> to learn more"data-tip-htmldata-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';functionApp(){consttour=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 toursnavigation: {showControls: true},progress: {show: true},});return(<div><navdata-tip-id="dashboard">Dashboard</nav><buttondata-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.

consttour=useTour({ steps });{tour.isActive&&(<div><span>{tour.progress.current} of {tour.progress.total}</span><buttononClick={tour.prev}disabled={tour.currentStep?.isFirst}>
Back
</button><buttononClick={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):

consttour=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:

consttour=useTour({
steps,// 'panel' (default) | 'primary' — Next/Finish, so Enter advances | false — leave focus alonenavigation: {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';functionApp(){return(<TipMagicProvider><divclassName="toolbar"><buttondata-tip="Copy"data-tip-shortcut="⌘C">
Copy
</button><buttondata-tip="Paste"data-tip-shortcut="⌘V">
Paste
</button><buttondata-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';functionMyComponent(){const{ tooltip }=useTipMagic();consthandleClick=()=>{tooltip.show('#my-element','Dynamic content');};return(<buttonid="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

About

Tooltip that feels like magic

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages