From b4651417ff729b210da339593542adc93c3d96fb Mon Sep 17 00:00:00 2001 From: "askmanu[bot]" <192355599+askmanu[bot]@users.noreply.github.com> Date: Wed, 15 Oct 2025 20:31:30 +0000 Subject: [PATCH] Added reference documentation for: src/common/Tooltips/Tooltip/Tooltip.js --- src/common/Tooltips/Tooltip/Tooltip.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/common/Tooltips/Tooltip/Tooltip.js b/src/common/Tooltips/Tooltip/Tooltip.js index 7f0c5bdad..043cb3be4 100644 --- a/src/common/Tooltips/Tooltip/Tooltip.js +++ b/src/common/Tooltips/Tooltip/Tooltip.js @@ -5,32 +5,56 @@ const PropTypes = require('prop-types'); const useTooltip = require('../useTooltip'); const styles = require('./styles'); +/** + * Generates a random alphanumeric identifier. + */ const createId = () => (Math.random() + 1).toString(36).substring(7); +/** + * A tooltip component that renders an invisible placeholder and manages tooltip display + * through a context-based tooltip system. The tooltip is shown when the parent element + * is hovered and hidden when the mouse leaves. The component registers itself with the + * tooltip context on mount and cleans up on unmount. + * @returns {JSX.Element} An invisible div placeholder that enables tooltip functionality for its parent element. + */ const Tooltip = ({ label, position, margin = 15 }) => { const tooltip = useTooltip(); const id = React.useRef(createId()); const element = React.useRef(null); + /** + * Activates the tooltip by updating its state in the context. + */ const onMouseEnter = () => { tooltip.update(id.current, { active: true, }); }; + /** + * Deactivates the tooltip by updating its state in the context. + */ const onMouseLeave = () => { tooltip.update(id.current, { active: false, }); }; + /** + * Updates the tooltip label in the context whenever the label prop changes. + */ React.useEffect(() => { tooltip.update(id.current, { label, }); }, [label]); + /** + * Registers the tooltip with the context and attaches mouse event listeners to the + * parent element. Cleans up by removing event listeners and unregistering the tooltip + * when the component unmounts. + */ React.useLayoutEffect(() => { if (element.current && element.current.parentElement) { const parentElement = element.current.parentElement;