@tour-kit/coreHooks
useSpotlight
useSpotlight hook: control spotlight overlay visibility, padding, border radius, and animation for tour steps
domidex01Published
Controls the spotlight overlay that highlights target elements.
Usage
import { useSpotlight } from '@tour-kit/core';
function CustomOverlay() {
const { isVisible, targetRect, overlayStyle } = useSpotlight();
if (!isVisible) return null;
return (
<div style={overlayStyle} className="spotlight-overlay">
{/* Custom spotlight rendering */}
</div>
);
}Return Value
| Property | Type | Description |
|---|---|---|
isVisible | boolean | Whether spotlight is visible |
targetRect | DOMRect | null | Target element bounding rect |
overlayStyle | CSSProperties | Computed overlay styles |
padding | number | Spotlight padding |
borderRadius | number | Spotlight border radius |
show | (element, config?) => void | Show spotlight |
hide | () => void | Hide spotlight |
Manual Control
const { show, hide } = useSpotlight();
// Highlight an element manually
const element = document.getElementById('my-element');
show(element, { padding: 16, borderRadius: 8 });
// Hide spotlight
hide();Custom Spotlight Rendering
function CustomSpotlight() {
const { isVisible, targetRect, padding } = useSpotlight();
if (!isVisible || !targetRect) return null;
const cutoutStyle = {
position: 'absolute',
top: targetRect.top - padding,
left: targetRect.left - padding,
width: targetRect.width + padding * 2,
height: targetRect.height + padding * 2,
};
return (
<div className="spotlight-overlay">
<div style={cutoutStyle} className="spotlight-cutout" />
</div>
);
}Related
<TourOverlay>— the styled component this hook powers.<HeadlessTourOverlay>— render-prop variant that wraps this hook for headless UIs.useElementPosition— sibling hook for raw target rect tracking without the overlay.- Animations guide — how the spotlight transition respects
prefers-reduced-motion.
Ship onboarding, not config.
npm i @tour-kit/core is MIT and free. The Pro packages work unlicensed too — a one-time $99 license removes the production watermark when you ship.
MIT-licensed — no signup, no credit card. Pay once, only when you ship.