@atlaskit/onboarding
Version:
An onboarding spotlight introduces new features to users through focused messages or multi-step tours.
35 lines • 1.47 kB
JavaScript
import React, { useEffect, useRef } from 'react';
import NodeResolver from 'react-node-resolver';
/**
* A wrapper component that conditionally applies a NodeResolver to its children.
*
* Note: NodeResolver should not be used in React 18 concurrent mode. This component
* is intended to be removed once the feature flag is removed.
* @param {boolean} props.hasNodeResolver - Determines whether to apply the NodeResolver.
* @param {ReactElement} props.children - The child elements to be wrapped.
* @param {(instance: HTMLDivElement) => void} props.innerRef - A ref callback to get the instance of the HTMLDivElement.
* @returns {ReactElement} The children wrapped with NodeResolver if hasNodeResolver is true, wrape the children in a div setting innerRef with ref to the div.
*/
const NodeResolverSpotlightInner = ({
hasNodeResolver,
children,
innerRef
}) => {
const divRef = useRef(null);
useEffect(() => {
if (!hasNodeResolver) {
var _divRef$current;
innerRef((_divRef$current = divRef.current) === null || _divRef$current === void 0 ? void 0 : _divRef$current.firstElementChild);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasNodeResolver]);
if (hasNodeResolver) {
return /*#__PURE__*/React.createElement(NodeResolver, {
innerRef: innerRef
}, children);
}
return /*#__PURE__*/React.createElement("div", {
ref: divRef
}, children);
};
export default NodeResolverSpotlightInner;