@atlaskit/onboarding
Version:
An onboarding spotlight introduces new features to users through focused messages or multi-step tours.
26 lines (25 loc) • 1.23 kB
JavaScript
import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
import { SpotlightContext } from './spotlight-manager';
/**
* Use spotlight hook returns information about available spotlight targets.
*
* @deprecated Use `@atlaskit/spotlight` instead.
*/
export default function useSpotlight() {
const {
targets
} = useContext(SpotlightContext);
const targetRef = useRef(targets);
useEffect(() => {
targetRef.current = targets;
}, [targets]);
const isTargetRendered = useCallback(target => !!targetRef.current[target], []);
const checkVisibility = useCallback(target => options => {
var _targetRef$current$ta, _targetRef$current$ta2, _targetRef$current$ta3;
return (_targetRef$current$ta = (_targetRef$current$ta2 = targetRef.current[target]) === null || _targetRef$current$ta2 === void 0 ? void 0 : (_targetRef$current$ta3 = _targetRef$current$ta2.checkVisibility) === null || _targetRef$current$ta3 === void 0 ? void 0 : _targetRef$current$ta3.call(_targetRef$current$ta2, options)) !== null && _targetRef$current$ta !== void 0 ? _targetRef$current$ta : false;
}, []);
return useMemo(() => ({
isTargetRendered,
checkVisibility
}), [isTargetRendered, checkVisibility]);
}